Skip to content

Commit

Permalink
UX: separate custom from automatic groups in user admin
Browse files Browse the repository at this point in the history
REFACTOR: some moar ES6 refactoring
  • Loading branch information
ZogStriP committed Mar 17, 2015
1 parent 56e01a7 commit 9cbd0f8
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 351 deletions.
33 changes: 19 additions & 14 deletions app/assets/javascripts/admin/components/admin-group-selector.js.es6
@@ -1,31 +1,36 @@
export default Ember.Component.extend({
tagName: 'div',

didInsertElement: function(){
_init: function(){
this.$("input").select2({
multiple: true,
width: '100%',
query: function(opts){
opts.callback({
results: this.get("available").map(this._format)
});
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)});
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)});
this.triggerAction({
action:"groupRemoved",
actionContext: evt.removed.id
});
}
}.bind(this));

this._refreshOnReset();
},
}.on("didInsertElement"),

_format: function(item){
return {"text": item.name, "id": item.id, "locked": item.automatic};
_format(item) {
return {
"text": item.name,
"id": item.id,
"locked": item.automatic
};
},

_refreshOnReset: function() {
Expand Down
81 changes: 46 additions & 35 deletions app/assets/javascripts/admin/controllers/admin-user-index.js.es6
Expand Up @@ -11,58 +11,61 @@ export default ObjectController.extend(CanCheckEmails, {

primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),

custom_groups: Ember.computed.filter("model.groups", function(g){
return (!g.automatic && g.visible);
}),
automaticGroups: function() {
return this.get("model.automaticGroups").map((g) => g.name).join(", ");
}.property("model.automaticGroups"),

userFields: function() {
var siteUserFields = this.site.get('user_fields'),
userFields = this.get('user_fields');
const siteUserFields = this.site.get('user_fields'),
userFields = this.get('user_fields');

if (!Ember.isEmpty(siteUserFields)) {
return siteUserFields.map(function(uf) {
var value = userFields ? userFields[uf.get('id').toString()] : null;
return {name: uf.get('name'), value: value};
let value = userFields ? userFields[uf.get('id').toString()] : null;
return { name: uf.get('name'), value: value };
});
}
return [];
}.property('user_fields.@each'),

actions: {
toggleTitleEdit: function() {
toggleTitleEdit() {
this.toggleProperty('editingTitle');
},

saveTitle: function() {
Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
saveTitle() {
const self = this;

return Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
data: {title: this.get('title')},
type: 'PUT'
}).then(null, function(e){
}).catch(function(e) {
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
}).finally(function() {
self.send('toggleTitleEdit');
});

this.send('toggleTitleEdit');
},

generateApiKey: function() {
generateApiKey() {
this.get('model').generateApiKey();
},

groupAdded: function(added){
groupAdded(added) {
this.get('model').groupAdded(added).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},

groupRemoved: function(removed){
this.get('model').groupRemoved(removed).catch(function() {
groupRemoved(groupId) {
this.get('model').groupRemoved(groupId).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},

savePrimaryGroup: function() {
var self = this;
Discourse.ajax("/admin/users/" + this.get('id') + "/primary_group", {
savePrimaryGroup() {
const self = this;

return Discourse.ajax("/admin/users/" + this.get('id') + "/primary_group", {
type: 'PUT',
data: {primary_group_id: this.get('primary_group_id')}
}).then(function () {
Expand All @@ -72,33 +75,41 @@ export default ObjectController.extend(CanCheckEmails, {
});
},

resetPrimaryGroup: function() {
resetPrimaryGroup() {
this.set('primary_group_id', this.get('originalPrimaryGroupId'));
},

regenerateApiKey: function() {
var self = this;
bootbox.confirm(I18n.t("admin.api.confirm_regen"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if (result) {
self.get('model').generateApiKey();
regenerateApiKey() {
const self = this;

bootbox.confirm(
I18n.t("admin.api.confirm_regen"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(result) {
if (result) { self.get('model').generateApiKey(); }
}
});
);
},

revokeApiKey: function() {
var self = this;
bootbox.confirm(I18n.t("admin.api.confirm_revoke"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if (result) {
self.get('model').revokeApiKey();
revokeApiKey() {
const self = this;

bootbox.confirm(
I18n.t("admin.api.confirm_revoke"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(result) {
if (result) { self.get('model').revokeApiKey(); }
}
});
);
},

anonymize: function() {
anonymize() {
this.get('model').anonymize();
},

destroy: function() {
destroy() {
this.get('model').destroy();
}
}
Expand Down

0 comments on commit 9cbd0f8

Please sign in to comment.