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-07-21 22:03:11 +04:00
|
|
|
if (Ember.isBlank(cover)) {
|
2014-05-24 18:43:53 +04:00
|
|
|
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-16 21:12:45 +04:00
|
|
|
var lastLogin = this.get('user.last_login');
|
|
|
|
|
|
|
|
return lastLogin ? lastLogin.fromNow() : '';
|
|
|
|
|
2014-07-02 07:44:39 +04:00
|
|
|
}.property('user.last_login'),
|
|
|
|
|
|
|
|
created_at: function () {
|
2014-07-16 21:12:45 +04:00
|
|
|
var createdAt = this.get('user.created_at');
|
|
|
|
|
|
|
|
return createdAt ? createdAt.fromNow() : '';
|
2014-07-02 07:44:39 +04:00
|
|
|
}.property('user.created_at'),
|
|
|
|
|
2014-07-29 09:50:34 +04:00
|
|
|
isAuthor: function () {
|
|
|
|
return this.get('user.isAuthor');
|
|
|
|
}.property('user.isAuthor'),
|
|
|
|
|
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;
|
|
|
|
|
2014-07-29 17:35:48 +04:00
|
|
|
this.get('model').resendInvite().then(function (result) {
|
2014-07-08 09:24:07 +04:00
|
|
|
var notificationText = 'Invitation resent! (' + self.get('email') + ')';
|
2014-07-29 17:35:48 +04:00
|
|
|
// If sending the invitation email fails, the API will still return a status of 201
|
|
|
|
// but the user's status in the response object will be 'invited-pending'.
|
|
|
|
if (result.users[0].status === 'invited-pending') {
|
|
|
|
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
|
|
|
|
} else {
|
|
|
|
self.get('model').set('status', result.users[0].status);
|
|
|
|
self.notifications.showSuccess(notificationText, false);
|
|
|
|
}
|
2014-07-08 09:24:07 +04:00
|
|
|
}).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;
|