2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-07-23 14:41:31 +04:00
|
|
|
var TransferOwnerController = Ember.Controller.extend({
|
|
|
|
actions: {
|
|
|
|
confirmAccept: function () {
|
|
|
|
var user = this.get('model'),
|
2014-07-30 19:40:30 +04:00
|
|
|
url = this.get('ghostPaths.url').api('users', 'owner'),
|
2014-07-23 14:41:31 +04:00
|
|
|
self = this;
|
|
|
|
|
2014-09-28 19:39:25 +04:00
|
|
|
self.get('dropdown').closeDropdowns();
|
2014-07-26 09:12:37 +04:00
|
|
|
|
2014-07-30 19:40:30 +04:00
|
|
|
ic.ajax.request(url, {
|
|
|
|
type: 'PUT',
|
|
|
|
data: {
|
|
|
|
owner: [{
|
2014-10-25 01:09:50 +04:00
|
|
|
id: user.get('id')
|
2014-07-30 19:40:30 +04:00
|
|
|
}]
|
|
|
|
}
|
2014-07-31 17:41:10 +04:00
|
|
|
}).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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-26 09:12:37 +04:00
|
|
|
self.notifications.showSuccess('Ownership successfully transferred to ' + user.get('name'));
|
2014-07-30 19:40:30 +04:00
|
|
|
}).catch(function (error) {
|
|
|
|
self.notifications.showAPIError(error);
|
2014-07-23 14:41:31 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmReject: function () {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
confirm: {
|
|
|
|
accept: {
|
2014-08-06 15:34:08 +04:00
|
|
|
text: 'Yep - I\'m sure',
|
|
|
|
buttonClass: 'btn btn-red'
|
2014-07-23 14:41:31 +04:00
|
|
|
},
|
|
|
|
reject: {
|
2014-08-06 15:34:08 +04:00
|
|
|
text: 'Cancel',
|
|
|
|
buttonClass: 'btn btn-default btn-minor'
|
2014-07-23 14:41:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-10-25 01:09:50 +04:00
|
|
|
export default TransferOwnerController;
|