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-07-13 08:01:26 +04:00
|
|
|
coverDefault: function () {
|
|
|
|
return this.get('ghostPaths.url').asset('/shared/img/user-cover.png');
|
|
|
|
}.property('ghostPaths'),
|
|
|
|
|
|
|
|
userDefault: function () {
|
|
|
|
return this.get('ghostPaths.url').asset('/shared/img/user-image.png');
|
|
|
|
}.property('ghostPaths'),
|
2014-07-02 07:44:39 +04:00
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
cover: function () {
|
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 () {
|
2014-07-13 08:01:26 +04:00
|
|
|
return 'background-image: url(' + this.get('imageUrl') + ')';
|
|
|
|
}.property('imageUrl'),
|
2014-07-02 07:44:39 +04:00
|
|
|
|
|
|
|
imageUrl: function () {
|
2014-07-13 08:01:26 +04:00
|
|
|
return this.get('user.image') || this.get('userDefault');
|
2014-03-23 06:31:45 +04:00
|
|
|
}.property('user.image'),
|
|
|
|
|
2014-07-02 07:44:39 +04:00
|
|
|
last_login: function () {
|
2014-07-14 20:32:55 +04:00
|
|
|
return this.get('user.last_login').fromNow();
|
2014-07-02 07:44:39 +04:00
|
|
|
}.property('user.last_login'),
|
|
|
|
|
|
|
|
created_at: function () {
|
2014-07-14 20:32:55 +04:00
|
|
|
return this.get('user.created_at').fromNow();
|
2014-07-02 07:44:39 +04:00
|
|
|
}.property('user.created_at'),
|
|
|
|
|
2014-03-23 06:31:45 +04:00
|
|
|
actions: {
|
2014-07-02 07:44:39 +04:00
|
|
|
revoke: function () {
|
2014-07-08 09:24:07 +04:00
|
|
|
var self = this,
|
|
|
|
email = this.get('email');
|
|
|
|
|
|
|
|
this.get('model').destroyRecord().then(function () {
|
|
|
|
var notificationText = 'Invitation revoked. (' + email + ')';
|
|
|
|
self.notifications.showSuccess(notificationText, false);
|
|
|
|
}).catch(function (error) {
|
|
|
|
self.notifications.closePassive();
|
|
|
|
self.notifications.showAPIError(error);
|
|
|
|
});
|
2014-07-02 07:44:39 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
resend: function () {
|
2014-07-08 09:24:07 +04:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.get('model').resendInvite().then(function () {
|
|
|
|
var notificationText = 'Invitation resent! (' + self.get('email') + ')';
|
|
|
|
self.notifications.showSuccess(notificationText, false);
|
|
|
|
}).catch(function (error) {
|
|
|
|
self.notifications.closePassive();
|
|
|
|
self.notifications.showAPIError(error);
|
|
|
|
});
|
2014-07-02 07:44:39 +04:00
|
|
|
},
|
|
|
|
|
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
|
|
|
|
2014-07-14 20:32:55 +04:00
|
|
|
user.save({ format: false }).then(function (model) {
|
|
|
|
self.notifications.closePassive();
|
|
|
|
self.notifications.showSuccess('Settings successfully saved.');
|
2014-03-23 06:31:45 +04:00
|
|
|
|
2014-07-14 20:32:55 +04:00
|
|
|
return model;
|
|
|
|
}).catch(function (errors) {
|
|
|
|
self.notifications.closePassive();
|
2014-07-13 08:01:26 +04:00
|
|
|
self.notifications.showErrors(errors);
|
|
|
|
});
|
2014-03-23 06:31:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
password: function () {
|
2014-07-01 19:58:26 +04:00
|
|
|
var user = this.get('user'),
|
2014-07-13 08:01:26 +04:00
|
|
|
self = this;
|
|
|
|
|
|
|
|
if (user.get('isPasswordValid')) {
|
|
|
|
user.saveNewPassword().then(function (model) {
|
2014-03-23 06:31:45 +04:00
|
|
|
|
|
|
|
// Clear properties from view
|
2014-07-13 08:01:26 +04:00
|
|
|
user.setProperties({
|
2014-03-23 06:31:45 +04:00
|
|
|
'password': '',
|
2014-07-13 08:01:26 +04:00
|
|
|
'newPassword': '',
|
|
|
|
'ne2Password': ''
|
2014-03-23 06:31:45 +04:00
|
|
|
});
|
2014-07-13 08:01:26 +04:00
|
|
|
|
|
|
|
self.notifications.closePassive();
|
|
|
|
self.notifications.showSuccess('Password updated.');
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}).catch(function (errors) {
|
|
|
|
self.notifications.closePassive();
|
|
|
|
self.notifications.showAPIError(errors);
|
2014-03-23 06:31:45 +04:00
|
|
|
});
|
|
|
|
} else {
|
2014-07-13 08:01:26 +04:00
|
|
|
self.notifications.showErrors(user.get('passwordValidationErrors'));
|
2014-03-23 06:31:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-06-30 01:45:03 +04:00
|
|
|
export default SettingsUserController;
|