2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
const {Controller, PromiseProxyMixin, computed, inject} = Ember;
|
|
|
|
const {alias} = computed;
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
export default Controller.extend({
|
|
|
|
notifications: inject.service(),
|
2014-12-10 01:44:36 +00:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
userPostCount: computed('model.id', function () {
|
|
|
|
let query = {
|
|
|
|
filter: `author:${this.get('model.slug')}`,
|
|
|
|
status: 'all'
|
|
|
|
};
|
|
|
|
|
|
|
|
let promise = this.store.query('post', query).then((results) => {
|
2014-12-10 01:44:36 +00:00
|
|
|
return results.meta.pagination.total;
|
|
|
|
});
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
return Ember.Object.extend(PromiseProxyMixin, {
|
|
|
|
count: alias('content'),
|
2014-12-10 01:44:36 +00:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
inflection: computed('count', function () {
|
2014-12-10 01:44:36 +00:00
|
|
|
return this.get('count') > 1 ? 'posts' : 'post';
|
|
|
|
})
|
2015-10-28 11:36:45 +00:00
|
|
|
}).create({promise});
|
2014-12-10 01:44:36 +00:00
|
|
|
}),
|
|
|
|
|
2014-08-04 11:36:45 -07:00
|
|
|
confirm: {
|
|
|
|
accept: {
|
|
|
|
text: 'Delete User',
|
2014-08-06 14:34:08 +03:00
|
|
|
buttonClass: 'btn btn-red'
|
2014-08-04 11:36:45 -07:00
|
|
|
},
|
|
|
|
reject: {
|
|
|
|
text: 'Cancel',
|
2014-08-06 14:34:08 +03:00
|
|
|
buttonClass: 'btn btn-default btn-minor'
|
2014-08-04 11:36:45 -07:00
|
|
|
}
|
2015-10-28 11:36:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
confirmAccept() {
|
|
|
|
let user = this.get('model');
|
|
|
|
|
|
|
|
user.destroyRecord().then(() => {
|
|
|
|
this.get('notifications').closeAlerts('user.delete');
|
|
|
|
this.store.unloadAll('post');
|
|
|
|
this.transitionToRoute('team');
|
|
|
|
}, () => {
|
|
|
|
this.get('notifications').showAlert('The user could not be deleted. Please try again.', {type: 'error', key: 'user.delete.failed'});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
confirmReject() {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 11:36:45 -07:00
|
|
|
}
|
|
|
|
});
|