discourse/app/assets/javascripts/admin/controllers/admin_user_controller.js

113 lines
3.3 KiB
JavaScript
Raw Normal View History

/**
The top-level controller for user pages in admin.
Ember assertion says that this class needs to be defined even if it's empty.
@class AdminUserController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserController = Discourse.ObjectController.extend({});
/**
A controller related to viewing a user in the admin section
@class AdminUserIndexController
@extends Discourse.ObjectController
@namespace Discourse
@module Discourse
**/
Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
editingTitle: false,
showApproval: Discourse.computed.setting('must_approve_users'),
showBadges: Discourse.computed.setting('enable_badges'),
2014-03-05 07:52:20 -05:00
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.[]"),
2013-09-16 14:08:55 -04:00
actions: {
toggleTitleEdit: function() {
this.toggleProperty('editingTitle');
},
2013-09-16 14:08:55 -04:00
saveTitle: function() {
Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
data: {title: this.get('title')},
type: 'PUT'
}).then(null, function(e){
bootbox.alert(I18n.t("generic_error_with_reason", {error: "http: " + e.status + " - " + e.body}));
});
this.send('toggleTitleEdit');
2013-10-22 15:53:08 -04:00
},
generateApiKey: function() {
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", {
type: 'PUT',
data: {primary_group_id: this.get('primary_group_id')}
}).then(function () {
self.set('originalPrimaryGroupId', self.get('primary_group_id'));
}).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},
resetPrimaryGroup: function() {
this.set('primary_group_id', this.get('originalPrimaryGroupId'));
},
2013-10-22 15:53:08 -04:00
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();
}
});
},
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();
}
});
2013-09-16 14:08:55 -04:00
}
}
});