mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 05:23:39 +08:00
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { ajax } from 'discourse/lib/ajax';
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
|
|
|
export default Ember.Controller.extend({
|
|
users: null,
|
|
groupId: null,
|
|
saving: false,
|
|
bulkAddResponse: null,
|
|
|
|
@computed('saving', 'users', 'groupId')
|
|
buttonDisabled(saving, users, groupId) {
|
|
return saving || !groupId || !users || !users.length;
|
|
},
|
|
|
|
actions: {
|
|
addToGroup() {
|
|
if (this.get('saving')) { return; }
|
|
|
|
const users = this.get('users').split("\n")
|
|
.uniq()
|
|
.reject(x => x.length === 0);
|
|
|
|
this.set('saving', true);
|
|
ajax('/admin/groups/bulk', {
|
|
data: { users, group_id: this.get('groupId') },
|
|
method: 'PUT'
|
|
}).then(result => {
|
|
this.set('bulkAddResponse', result);
|
|
this.transitionToRoute('adminGroups.bulkComplete');
|
|
}).catch(popupAjaxError).finally(() => {
|
|
this.set('saving', false);
|
|
});
|
|
|
|
}
|
|
}
|
|
});
|