2014-08-12 19:04:36 -04:00
|
|
|
import ObjectController from 'discourse/controllers/object';
|
2014-09-29 16:31:05 -04:00
|
|
|
import CanCheckEmails from 'discourse/mixins/can-check-emails';
|
2014-08-12 19:04:36 -04:00
|
|
|
|
2014-09-29 16:31:05 -04:00
|
|
|
export default ObjectController.extend(CanCheckEmails, {
|
2013-06-25 18:39:20 -04:00
|
|
|
editingTitle: false,
|
2014-07-23 16:54:04 -04:00
|
|
|
originalPrimaryGroupId: null,
|
|
|
|
availableGroups: null,
|
2013-06-25 18:39:20 -04:00
|
|
|
|
2014-04-24 17:39:34 -04:00
|
|
|
showApproval: Discourse.computed.setting('must_approve_users'),
|
|
|
|
showBadges: Discourse.computed.setting('enable_badges'),
|
2014-03-05 07:52:20 -05:00
|
|
|
|
2014-02-10 16:59:36 -05:00
|
|
|
primaryGroupDirty: Discourse.computed.propertyNotEqual('originalPrimaryGroupId', 'primary_group_id'),
|
|
|
|
|
2014-07-15 09:43:53 -04:00
|
|
|
custom_groups: Ember.computed.filter("model.groups", function(g){
|
|
|
|
return (!g.automatic && g.visible);
|
|
|
|
}),
|
2014-07-13 14:11:38 -04:00
|
|
|
|
2014-09-26 14:48:34 -04:00
|
|
|
userFields: function() {
|
|
|
|
var siteUserFields = this.site.get('user_fields'),
|
|
|
|
userFields = this.get('user_fields');
|
|
|
|
|
2014-12-10 13:15:30 -05:00
|
|
|
if (!Ember.isEmpty(siteUserFields)) {
|
2014-09-26 14:48:34 -04:00
|
|
|
return siteUserFields.map(function(uf) {
|
|
|
|
var value = userFields ? userFields[uf.get('id').toString()] : null;
|
|
|
|
return {name: uf.get('name'), value: value};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}.property('user_fields.@each'),
|
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
actions: {
|
|
|
|
toggleTitleEdit: function() {
|
|
|
|
this.toggleProperty('editingTitle');
|
|
|
|
},
|
2013-06-25 18:39:20 -04:00
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2014-07-13 14:11:38 -04:00
|
|
|
groupAdded: function(added){
|
2014-07-15 10:11:39 -04:00
|
|
|
this.get('model').groupAdded(added).catch(function() {
|
2014-07-13 14:11:38 -04:00
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
},
|
2014-07-15 10:11:39 -04:00
|
|
|
|
2014-07-13 14:11:38 -04:00
|
|
|
groupRemoved: function(removed){
|
2014-07-15 10:11:39 -04:00
|
|
|
this.get('model').groupRemoved(removed).catch(function() {
|
2014-07-13 14:11:38 -04:00
|
|
|
bootbox.alert(I18n.t('generic_error'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-02-10 16:59:36 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2015-03-10 13:06:08 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
anonymize: function() {
|
|
|
|
this.get('model').anonymize();
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.get('model').destroy();
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
|
|
|
}
|
2013-09-09 12:21:47 -04:00
|
|
|
|
2013-07-08 19:32:16 -04:00
|
|
|
});
|