Files
discourse/app/assets/javascripts/discourse/controllers/preferences_email_controller.js
2013-04-04 17:26:22 -04:00

52 lines
1.4 KiB
JavaScript

/**
This controller supports actions related to updating one's email address
@class PreferencesEmailController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.PreferencesEmailController = Discourse.ObjectController.extend({
taken: false,
saving: false,
error: false,
success: false,
newEmail: null,
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() {
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);
});
}
});