Ghost/ghost/admin/controllers/modals/transfer-owner.js

53 lines
1.7 KiB
JavaScript
Raw Normal View History

var TransferOwnerController = Ember.Controller.extend({
actions: {
confirmAccept: function () {
var user = this.get('model'),
url = this.get('ghostPaths.url').api('users', 'owner'),
self = this;
2014-09-28 19:39:25 +04:00
self.get('dropdown').closeDropdowns();
ic.ajax.request(url, {
type: 'PUT',
data: {
owner: [{
id: user.get('id')
}]
}
}).then(function (response) {
// manually update the roles for the users that just changed roles
// because store.pushPayload is not working with embedded relations
if (response && Ember.isArray(response.users)) {
response.users.forEach(function (userJSON) {
var user = self.store.getById('user', userJSON.id),
role = self.store.getById('role', userJSON.roles[0].id);
user.set('role', role);
});
}
self.notifications.showSuccess('Ownership successfully transferred to ' + user.get('name'));
}).catch(function (error) {
self.notifications.showAPIError(error);
});
},
confirmReject: function () {
return false;
}
},
confirm: {
accept: {
2014-08-06 15:34:08 +04:00
text: 'Yep - I\'m sure',
buttonClass: 'btn btn-red'
},
reject: {
2014-08-06 15:34:08 +04:00
text: 'Cancel',
buttonClass: 'btn btn-default btn-minor'
}
}
});
export default TransferOwnerController;