2014-03-23 06:31:45 +04:00
|
|
|
/*global alert */
|
|
|
|
var SettingsUserController = Ember.Controller.extend({
|
2014-05-24 18:43:53 +04:00
|
|
|
coverDefault: '/shared/img/user-cover.png',
|
2014-03-23 06:31:45 +04:00
|
|
|
cover: function () {
|
|
|
|
// @TODO: add {{asset}} subdir path
|
2014-05-24 18:43:53 +04:00
|
|
|
var cover = this.user.get('cover');
|
|
|
|
if (typeof cover !== 'string') {
|
|
|
|
cover = this.get('coverDefault');
|
|
|
|
}
|
|
|
|
return cover;
|
|
|
|
}.property('user.cover', 'coverDefault'),
|
2014-03-23 06:31:45 +04:00
|
|
|
|
|
|
|
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 () {
|
2014-06-24 14:00:28 +04:00
|
|
|
var self = this;
|
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
alert('@TODO: Saving user...');
|
|
|
|
|
|
|
|
if (this.user.validate().get('isValid')) {
|
|
|
|
this.user.save().then(function (response) {
|
2014-06-24 14:00:28 +04:00
|
|
|
|
|
|
|
// @TODO This should call closePassive() to only close passive notifications
|
|
|
|
self.notifications.closeAll();
|
2014-03-23 06:31:45 +04:00
|
|
|
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...');
|
2014-03-31 13:57:50 +04:00
|
|
|
var passwordProperties = this.getProperties('password', 'newPassword', 'ne2Password');
|
2014-03-23 06:31:45 +04:00
|
|
|
|
|
|
|
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;
|