mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
989d19837e
closes #3012 - Inject notification object into router - Listen to didTransition / observe currentPath to close notifications - Close notifications on successful save actions
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
/*global alert */
|
|
var SettingsUserController = Ember.Controller.extend({
|
|
coverDefault: '/shared/img/user-cover.png',
|
|
cover: function () {
|
|
// @TODO: add {{asset}} subdir path
|
|
var cover = this.user.get('cover');
|
|
if (typeof cover !== 'string') {
|
|
cover = this.get('coverDefault');
|
|
}
|
|
return cover;
|
|
}.property('user.cover', 'coverDefault'),
|
|
|
|
coverTitle: function () {
|
|
return this.get('user.name') + '\'s Cover Image';
|
|
}.property('user.name'),
|
|
|
|
image: function () {
|
|
// @TODO: add {{asset}} subdir path
|
|
return 'background-image: url(' + this.user.getWithDefault('image', '/shared/img/user-image.png') + ')';
|
|
}.property('user.image'),
|
|
|
|
actions: {
|
|
save: function () {
|
|
var self = this;
|
|
|
|
alert('@TODO: Saving user...');
|
|
|
|
if (this.user.validate().get('isValid')) {
|
|
this.user.save().then(function (response) {
|
|
|
|
// @TODO This should call closePassive() to only close passive notifications
|
|
self.notifications.closeAll();
|
|
alert('Done saving' + JSON.stringify(response));
|
|
}, function () {
|
|
alert('Error saving.');
|
|
});
|
|
} else {
|
|
alert('Errors found! ' + JSON.stringify(this.user.get('errors')));
|
|
}
|
|
},
|
|
|
|
password: function () {
|
|
alert('@TODO: Changing password...');
|
|
var passwordProperties = this.getProperties('password', 'newPassword', 'ne2Password');
|
|
|
|
if (this.user.validatePassword(passwordProperties).get('passwordIsValid')) {
|
|
this.user.saveNewPassword(passwordProperties).then(function () {
|
|
alert('Success!');
|
|
// Clear properties from view
|
|
this.setProperties({
|
|
'password': '',
|
|
'newpassword': '',
|
|
'ne2password': ''
|
|
});
|
|
}.bind(this), function (errors) {
|
|
alert('Errors ' + JSON.stringify(errors));
|
|
});
|
|
} else {
|
|
alert('Errors found! ' + JSON.stringify(this.user.get('passwordErrors')));
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
export default SettingsUserController; |