discourse/app/assets/javascripts/admin/controllers/admin-user-index.js.es6

122 lines
3.3 KiB
Plaintext
Raw Normal View History

2016-07-01 01:55:44 +08:00
import { ajax } from 'discourse/lib/ajax';
import CanCheckEmails from 'discourse/mixins/can-check-emails';
2015-08-08 03:08:27 +08:00
import { propertyNotEqual, setting } from 'discourse/lib/computed';
2014-08-13 07:04:36 +08:00
export default Ember.Controller.extend(CanCheckEmails, {
editingTitle: false,
originalPrimaryGroupId: null,
availableGroups: null,
userTitleValue: null,
2015-08-08 03:08:27 +08:00
showApproval: setting('must_approve_users'),
showBadges: setting('enable_badges'),
2014-03-05 20:52:20 +08:00
2015-08-08 03:08:27 +08:00
primaryGroupDirty: propertyNotEqual('originalPrimaryGroupId', 'model.primary_group_id'),
automaticGroups: function() {
return this.get("model.automaticGroups").map((g) => g.name).join(", ");
}.property("model.automaticGroups"),
userFields: function() {
const siteUserFields = this.site.get('user_fields'),
userFields = this.get('model.user_fields');
if (!Ember.isEmpty(siteUserFields)) {
return siteUserFields.map(function(uf) {
let value = userFields ? userFields[uf.get('id').toString()] : null;
return { name: uf.get('name'), value: value };
});
}
return [];
}.property('model.user_fields.[]'),
2013-09-17 02:08:55 +08:00
actions: {
toggleTitleEdit() {
this.set('userTitleValue', this.get('model.title'));
2013-09-17 02:08:55 +08:00
this.toggleProperty('editingTitle');
},
saveTitle() {
const self = this;
2016-07-01 01:55:44 +08:00
return ajax("/users/" + this.get('model.username').toLowerCase(), {
data: {title: this.get('userTitleValue')},
2013-09-17 02:08:55 +08:00
type: 'PUT'
}).catch(function(e) {
2013-09-17 02:08:55 +08:00
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
}).finally(function() {
self.set('model.title', self.get('userTitleValue'));
self.toggleProperty('editingTitle');
2013-09-17 02:08:55 +08:00
});
2013-10-23 03:53:08 +08:00
},
generateApiKey() {
2013-10-23 03:53:08 +08:00
this.get('model').generateApiKey();
},
groupAdded(added) {
2014-07-15 22:11:39 +08:00
this.get('model').groupAdded(added).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},
2014-07-15 22:11:39 +08:00
groupRemoved(groupId) {
this.get('model').groupRemoved(groupId).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},
savePrimaryGroup() {
const self = this;
2016-07-01 01:55:44 +08:00
return ajax("/admin/users/" + this.get('model.id') + "/primary_group", {
type: 'PUT',
data: {primary_group_id: this.get('model.primary_group_id')}
}).then(function () {
self.set('originalPrimaryGroupId', self.get('model.primary_group_id'));
}).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},
resetPrimaryGroup() {
this.set('model.primary_group_id', this.get('originalPrimaryGroupId'));
},
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(); }
2013-10-23 03:53:08 +08:00
}
);
2013-10-23 03:53:08 +08:00
},
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(); }
2013-10-23 03:53:08 +08:00
}
);
2015-03-11 01:06:08 +08:00
},
anonymize() {
2015-03-11 01:06:08 +08:00
this.get('model').anonymize();
},
destroy() {
2015-03-11 01:06:08 +08:00
this.get('model').destroy();
2013-09-17 02:08:55 +08:00
}
}
});