2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-05-27 03:41:12 +03:00
|
|
|
import {request as ajax} from 'ic-ajax';
|
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
2015-05-26 05:10:50 +03:00
|
|
|
dropdown: Ember.inject.service(),
|
|
|
|
ghostPaths: Ember.inject.service('ghost-paths'),
|
|
|
|
notifications: Ember.inject.service(),
|
|
|
|
|
2014-07-23 14:41:31 +04:00
|
|
|
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
|
|
|
|
2015-05-27 03:41:12 +03:00
|
|
|
ajax(url, {
|
2014-07-30 19:40:30 +04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-19 00:56:18 +03:00
|
|
|
self.get('notifications').showAlert('Ownership successfully transferred to ' + user.get('name'), {type: 'success'});
|
2014-07-30 19:40:30 +04:00
|
|
|
}).catch(function (error) {
|
2015-05-26 05:10:50 +03:00
|
|
|
self.get('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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|