diff --git a/app/assets/javascripts/admin/components/admin-group-selector.js.es6 b/app/assets/javascripts/admin/components/admin-group-selector.js.es6 new file mode 100644 index 000000000..c78f1ff89 --- /dev/null +++ b/app/assets/javascripts/admin/components/admin-group-selector.js.es6 @@ -0,0 +1,39 @@ +export default Ember.Component.extend({ + tagName: 'div', + + didInsertElement: function(){ + this.$("input").select2({ + multiple: true, + width: '100%', + query: function(opts){ + opts.callback({ + results: this.get("available").map(this._format) + }); + }.bind(this) + }).on("change", function(evt) { + if (evt.added){ + this.triggerAction({action: "groupAdded", + actionContext: this.get("available" + ).findBy("id", evt.added.id)}); + } else if (evt.removed) { + this.triggerAction({action:"groupRemoved", + actionContext: this.get("selected" + ).findBy("id", evt.removed.id)}); + } + }.bind(this)); + + Discourse.Group.findAll().then(function(groups){ + this.set("available", groups.filterBy("automatic", false)); + }.bind(this)); + + this.refreshOnReset(); + }, + + _format: function(item){ + return {"text": item.name, "id": item.id, "locked": item.automatic}; + }, + + refreshOnReset: function() { + this.$("input").select2("data", this.get("selected").map(this._format)); + }.observes("selected") +}); \ No newline at end of file diff --git a/app/assets/javascripts/admin/controllers/admin_user_controller.js b/app/assets/javascripts/admin/controllers/admin_user_controller.js index 50dff9a2f..5fc95f505 100644 --- a/app/assets/javascripts/admin/controllers/admin_user_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_user_controller.js @@ -25,6 +25,12 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({ primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'), + custom_groups: function(){ + return this.get("model.groups").filter(function(g){ + return (!g.automatic && g.visible); + }); + }.property("model.groups.[]"), + actions: { toggleTitleEdit: function() { this.toggleProperty('editingTitle'); @@ -45,6 +51,28 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({ this.get('model').generateApiKey(); }, + groupAdded: function(added){ + var self = this; + Discourse.ajax("/admin/users/" + this.get('id') + "/groups", { + type: 'POST', + data: {group_id: added.id} + }).then(function () { + self.get('model.groups').pushObject(added); + }).catch(function() { + bootbox.alert(I18n.t('generic_error')); + }); + }, + groupRemoved: function(removed){ + var self = this; + Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, { + type: 'DELETE' + }).then(function () { + self.set('model.groups.[]', self.get('model.groups').rejectBy("id", removed.id)); + }).catch(function() { + bootbox.alert(I18n.t('generic_error')); + }); + }, + savePrimaryGroup: function() { var self = this; Discourse.ajax("/admin/users/" + this.get('id') + "/primary_group", { diff --git a/app/assets/javascripts/admin/templates/user_index.js.handlebars b/app/assets/javascripts/admin/templates/user_index.js.handlebars index dddcee603..fccb6d13a 100644 --- a/app/assets/javascripts/admin/templates/user_index.js.handlebars +++ b/app/assets/javascripts/admin/templates/user_index.js.handlebars @@ -53,20 +53,18 @@