mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
43bf325800
closes #7014 - uses the `AjaxServiceSupport` mixin from `ember-ajax` to replace Ember Data's internal `ajax` method with our own ajax service - normalizes all error handling to use `ember-ajax` style errors - default to the `application/vnd.api+json` content-type so that we don't have a mix of urlencoded and plain JSON content - fix `normalizeErrorResponse` in our `ajax` service so that it doesn't add an empty `errors` array to payloads
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
import {A as emberA} from 'ember-array/utils';
|
|
import ModalComponent from 'ghost-admin/components/modals/base';
|
|
import {isInvalidError} from 'ember-ajax/errors';
|
|
|
|
export default ModalComponent.extend({
|
|
actions: {
|
|
updateEmail(newEmail) {
|
|
this.set('model.email', newEmail);
|
|
this.set('model.hasValidated', emberA());
|
|
this.get('model.errors').clear();
|
|
},
|
|
|
|
confirm() {
|
|
let confirmAction = this.get('confirm');
|
|
|
|
this.set('submitting', true);
|
|
|
|
confirmAction().then(() => {
|
|
this.send('closeModal');
|
|
}).catch((error) => {
|
|
// TODO: server-side validation errors should be serialized
|
|
// properly so that errors are added to the model's errors
|
|
// property
|
|
if (error && isInvalidError(error)) {
|
|
let [firstError] = error.errors;
|
|
let {message} = firstError;
|
|
|
|
if (message && message.match(/email/i)) {
|
|
this.get('model.errors').add('email', message);
|
|
this.get('model.hasValidated').pushObject('email');
|
|
return;
|
|
}
|
|
}
|
|
|
|
// this is a route action so it should bubble up to the global
|
|
// error handler
|
|
throw error;
|
|
}).finally(() => {
|
|
if (!this.get('isDestroying') && !this.get('isDestroyed')) {
|
|
this.set('submitting', false);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|