REFACTOR: preferences/email controller (#7633)

This commit is contained in:
Joffrey JAFFEUX 2019-05-29 15:53:42 +02:00 committed by GitHub
parent 5e7e32510a
commit f2858e03c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ export default Ember.Controller.extend({
newEmail: null,
newEmailEmpty: Ember.computed.empty("newEmail"),
saveDisabled: Ember.computed.or(
"saving",
"newEmailEmpty",
@ -18,17 +19,8 @@ export default Ember.Controller.extend({
"unchanged",
"invalidEmail"
),
unchanged: propertyEqual("newEmailLower", "currentUser.email"),
reset() {
this.setProperties({
taken: false,
saving: false,
error: false,
success: false,
newEmail: null
});
},
unchanged: propertyEqual("newEmailLower", "currentUser.email"),
@computed("newEmail")
newEmailLower(newEmail) {
@ -56,23 +48,32 @@ export default Ember.Controller.extend({
}
},
reset() {
this.setProperties({
taken: false,
saving: false,
error: false,
success: false,
newEmail: null
});
},
actions: {
changeEmail() {
const self = this;
this.set("saving", true);
return this.model.changeEmail(this.newEmail).then(
() => self.set("success", true),
() => this.set("success", true),
e => {
self.setProperties({ error: true, saving: false });
this.setProperties({ error: true, saving: false });
if (
e.jqXHR.responseJSON &&
e.jqXHR.responseJSON.errors &&
e.jqXHR.responseJSON.errors[0]
) {
self.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
this.set("errorMessage", e.jqXHR.responseJSON.errors[0]);
} else {
self.set("errorMessage", I18n.t("user.change_email.error"));
this.set("errorMessage", I18n.t("user.change_email.error"));
}
}
);