This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/preferences_email_controller.js

49 lines
1.3 KiB
JavaScript

(function() {
Discourse.PreferencesEmailController = Ember.ObjectController.extend(Discourse.Presence, {
taken: false,
saving: false,
error: false,
success: false,
saveDisabled: (function() {
if (this.get('saving')) {
return true;
}
if (this.blank('newEmail')) {
return true;
}
if (this.get('taken')) {
return true;
}
if (this.get('unchanged')) {
return true;
}
}).property('newEmail', 'taken', 'unchanged', 'saving'),
unchanged: (function() {
return this.get('newEmail') === this.get('content.email');
}).property('newEmail', 'content.email'),
initializeEmail: (function() {
return this.set('newEmail', this.get('content.email'));
}).observes('content.email'),
saveButtonText: (function() {
if (this.get('saving')) {
return Em.String.i18n("saving");
}
return Em.String.i18n("user.change_email.action");
}).property('saving'),
changeEmail: function() {
var _this = this;
this.set('saving', true);
return this.get('content').changeEmail(this.get('newEmail')).then(function() {
return _this.set('success', true);
}, function() {
/* Error
*/
_this.set('error', true);
return _this.set('saving', false);
});
}
});
}).call(this);