2014-03-23 06:31:45 +04:00
|
|
|
/*global alert */
|
2014-07-01 19:58:26 +04:00
|
|
|
var SettingsUserController = Ember.ObjectController.extend({
|
|
|
|
|
|
|
|
user: Ember.computed.alias('model'),
|
|
|
|
|
2014-07-02 07:44:39 +04:00
|
|
|
email: Ember.computed.readOnly('user.email'),
|
|
|
|
|
2014-05-24 18:43:53 +04:00
|
|
|
coverDefault: '/shared/img/user-cover.png',
|
2014-07-02 07:44:39 +04:00
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
cover: function () {
|
|
|
|
// @TODO: add {{asset}} subdir path
|
2014-07-01 19:58:26 +04:00
|
|
|
var cover = this.get('user.cover');
|
2014-05-24 18:43:53 +04:00
|
|
|
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
|
2014-07-02 07:44:39 +04:00
|
|
|
return 'background-image: url(' + this.getWithDefault('user.image', '/shared/img/user-image.png') + ')';
|
|
|
|
}.property('user.image'),
|
|
|
|
|
|
|
|
imageUrl: function () {
|
|
|
|
// @TODO: add {{asset}} subdir path
|
|
|
|
return this.getWithDefault('user.image', '/shared/img/user-image.png');
|
2014-03-23 06:31:45 +04:00
|
|
|
}.property('user.image'),
|
|
|
|
|
2014-07-02 07:44:39 +04:00
|
|
|
last_login: function () {
|
|
|
|
return moment(this.get('user.last_login')).fromNow();
|
|
|
|
}.property('user.last_login'),
|
|
|
|
|
|
|
|
created_at: function () {
|
|
|
|
return moment(this.get('user.created_at')).fromNow();
|
|
|
|
}.property('user.created_at'),
|
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
actions: {
|
2014-07-02 07:44:39 +04:00
|
|
|
revoke: function () {
|
|
|
|
alert('@TODO: revoke users invitation');
|
|
|
|
},
|
|
|
|
|
|
|
|
resend: function () {
|
|
|
|
alert('@TODO: resend users invitation');
|
|
|
|
},
|
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
save: function () {
|
2014-07-01 19:58:26 +04:00
|
|
|
var user = this.get('user'),
|
|
|
|
self = this;
|
2014-06-30 01:45:03 +04:00
|
|
|
|
|
|
|
self.notifications.closePassive();
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
alert('@TODO: Saving user...');
|
|
|
|
|
2014-07-01 19:58:26 +04:00
|
|
|
if (user.validate().get('isValid')) {
|
|
|
|
user.save().then(function (response) {
|
2014-03-23 06:31:45 +04:00
|
|
|
alert('Done saving' + JSON.stringify(response));
|
|
|
|
}, function () {
|
|
|
|
alert('Error saving.');
|
|
|
|
});
|
|
|
|
} else {
|
2014-07-01 19:58:26 +04:00
|
|
|
alert('Errors found! ' + JSON.stringify(user.get('errors')));
|
2014-03-23 06:31:45 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
password: function () {
|
|
|
|
alert('@TODO: Changing password...');
|
2014-07-01 19:58:26 +04:00
|
|
|
var user = this.get('user'),
|
|
|
|
passwordProperties = this.getProperties('password', 'newPassword', 'ne2Password');
|
2014-03-23 06:31:45 +04:00
|
|
|
|
2014-07-01 19:58:26 +04:00
|
|
|
if (user.validatePassword(passwordProperties).get('passwordIsValid')) {
|
|
|
|
user.saveNewPassword(passwordProperties).then(function () {
|
2014-03-23 06:31:45 +04:00
|
|
|
alert('Success!');
|
|
|
|
// Clear properties from view
|
|
|
|
this.setProperties({
|
|
|
|
'password': '',
|
|
|
|
'newpassword': '',
|
|
|
|
'ne2password': ''
|
|
|
|
});
|
|
|
|
}.bind(this), function (errors) {
|
|
|
|
alert('Errors ' + JSON.stringify(errors));
|
|
|
|
});
|
|
|
|
} else {
|
2014-07-01 19:58:26 +04:00
|
|
|
alert('Errors found! ' + JSON.stringify(user.get('passwordErrors')));
|
2014-03-23 06:31:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-06-30 01:45:03 +04:00
|
|
|
export default SettingsUserController;
|