70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
/**
|
|
The route for editing a user's email
|
|
|
|
@class PreferencesEmailRoute
|
|
@extends Discourse.RestrictedUserRoute
|
|
@namespace Discourse
|
|
@module Discourse
|
|
**/
|
|
Discourse.PreferencesEmailRoute = Discourse.RestrictedUserRoute.extend({
|
|
model: function() {
|
|
return this.modelFor('user');
|
|
},
|
|
|
|
renderTemplate: function() {
|
|
this.render({ into: 'user', outlet: 'userOutlet' });
|
|
},
|
|
|
|
setupController: function(controller, model) {
|
|
controller.setProperties({ model: model, newEmail: model.get('email') });
|
|
},
|
|
|
|
// A bit odd, but if we leave to /preferences we need to re-render that outlet
|
|
exit: function() {
|
|
this._super();
|
|
this.render('preferences', { into: 'user', outlet: 'userOutlet', controller: 'preferences' });
|
|
}
|
|
});
|
|
|
|
|
|
/**
|
|
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,
|
|
|
|
newEmailEmpty: Em.computed.empty('newEmail'),
|
|
saveDisabled: Em.computed.or('saving', 'newEmailEmpty', 'taken', 'unchanged'),
|
|
unchanged: Discourse.computed.propertyEqual('newEmail', 'email'),
|
|
|
|
saveButtonText: function() {
|
|
if (this.get('saving')) return I18n.t("saving");
|
|
return I18n.t("user.change");
|
|
}.property('saving'),
|
|
|
|
changeEmail: function() {
|
|
var preferencesEmailController = this;
|
|
this.set('saving', true);
|
|
return this.get('content').changeEmail(this.get('newEmail')).then(function() {
|
|
preferencesEmailController.set('success', true);
|
|
}, function() {
|
|
preferencesEmailController.setProperties({
|
|
error: true,
|
|
saving: false
|
|
});
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
|