Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cancel: function(model, successCallback, withdrawFromCompliance = false) {
var params = `withdraw_from_compliance=${withdrawFromCompliance}`;
var requestPromise = PromiseController.create({
promise: request({
url: `${EmberENV.apiBaseUrl}/interests/${model.get('id')}?${params}`,
type: 'DELETE'
}).then(successCallback, () => {
notify('The interaction could not be cancelled.', 'error');
})
});
return requestPromise;
}
});
amendCompletion: function() {
let completionForm = this.get('completionForm');
let completion = completionForm.get('model');
let requestParams = `interaction_completion_id=${completion.get('id')}`;
PromiseController.create({
promise: request({
url: `${EmberENV.apiBaseUrl}/interaction_completion_amendments?${requestParams}`,
type: 'POST'
}).then((response) => {
this.store.pushPayload(response);
let newCompletion = this.store.createRecord('interactionCompletion', {
interaction: this.get('model')
});
this.set('completionForm.model', newCompletion);
completionForm.set('editingDisabled', false);
}, () => {
notify('There has been an error amending the interaction.', 'error');
})
});
},
reschedule: function() {
var model = this.get('model');
this.transitionToRoute('dashboard.schedule-interaction', this.get('model.id'));
model.set('scheduledCallTime', null);
model.set('actioned', false);
this.set('requestPromise', PromiseController.create({
promise: model.save().then(() => {
this.get('dashboard').propertyDidChange('scheduledInteractions');
this.get('dashboard').propertyDidChange('interactionsToSchedule');
}, () => {
notify('There has been an error rescheduling the interaction.', 'error');
model.rollback();
this.transitionToRoute('dashboard.interaction', this.get('model.id'));
})
}));
},
_queryDidChange: function() {
var query = this.get('query');
if (query && query.length > 2) {
var requestPromise = PromiseController.create({
promise: request(`${EmberENV.apiBaseUrl}/quick_jumps`, {
data: { q: query }
}).then(response => {
if (requestPromise !== this.get('requestPromise')) { return; }
this.set('results', _.chain(response.responses)
.map(function(response) {
if (Ember.isBlank(response.hits)) {
return [];
} else {
return response.hits.hits;
}
})
.flatten()
.value()
);
save: function() {
if (this.get('isValid')) {
this.setPersistedValues();
var requestPromise = PromiseController.create({
promise: this.get('model').save().catch(() => {
if (this.get('model.errors.length') > 0) {
this.set('errors', this.get('model.errors'));
} else {
notify(this.get('genericErrorMessage'), 'error');
}
return Ember.RSVP.Promise.reject();
})
});
this.set('requestPromise', requestPromise);
return requestPromise;
} else {
return Ember.RSVP.Promise.reject('Form validation failed');