mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
FEATURE: Change name from admin page.
https://github.com/discourse/discourse/pull/4770
This commit is contained in:

committed by
Guo Xiang Tan

parent
10fb13d204
commit
9065df76ad
@ -2,8 +2,11 @@ import { ajax } from 'discourse/lib/ajax';
|
||||
import CanCheckEmails from 'discourse/mixins/can-check-emails';
|
||||
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
||||
import { userPath } from 'discourse/lib/url';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Controller.extend(CanCheckEmails, {
|
||||
editingUsername: false,
|
||||
editingName: false,
|
||||
editingTitle: false,
|
||||
originalPrimaryGroupId: null,
|
||||
availableGroups: null,
|
||||
@ -55,23 +58,58 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
||||
anonymize() { return this.get('model').anonymize(); },
|
||||
destroy() { return this.get('model').destroy(); },
|
||||
|
||||
toggleUsernameEdit() {
|
||||
this.set('userUsernameValue', this.get('model.username'));
|
||||
this.toggleProperty('editingUsername');
|
||||
},
|
||||
|
||||
saveUsername() {
|
||||
const oldUsername = this.get('model.username');
|
||||
this.set('model.username', this.get('userUsernameValue'));
|
||||
|
||||
return ajax(`/users/${oldUsername.toLowerCase()}/preferences/username`, {
|
||||
data: { new_username: this.get('userUsernameValue') },
|
||||
type: 'PUT'
|
||||
}).catch(e => {
|
||||
this.set('model.username', oldUsername);
|
||||
popupAjaxError(e);
|
||||
}).finally(() => this.toggleProperty('editingUsername'));
|
||||
},
|
||||
|
||||
toggleNameEdit() {
|
||||
this.set('userNameValue', this.get('model.name'));
|
||||
this.toggleProperty('editingName');
|
||||
},
|
||||
|
||||
saveName() {
|
||||
const oldName = this.get('model.name');
|
||||
this.set('model.name', this.get('userNameValue'));
|
||||
|
||||
return ajax(userPath(`${this.get('model.username').toLowerCase()}.json`), {
|
||||
data: { name: this.get('userNameValue') },
|
||||
type: 'PUT'
|
||||
}).catch(e => {
|
||||
this.set('model.name', oldName);
|
||||
popupAjaxError(e);
|
||||
}).finally(() => this.toggleProperty('editingName'));
|
||||
},
|
||||
|
||||
toggleTitleEdit() {
|
||||
this.set('userTitleValue', this.get('model.title'));
|
||||
this.toggleProperty('editingTitle');
|
||||
},
|
||||
|
||||
saveTitle() {
|
||||
const self = this;
|
||||
const prevTitle = this.get('userTitleValue');
|
||||
|
||||
this.set('model.title', this.get('userTitleValue'));
|
||||
return ajax(userPath(`${this.get('model.username').toLowerCase()}.json`), {
|
||||
data: {title: this.get('userTitleValue')},
|
||||
type: 'PUT'
|
||||
}).catch(function(e) {
|
||||
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');
|
||||
});
|
||||
}).catch(e => {
|
||||
this.set('model.title', prevTitle);
|
||||
popupAjaxError(e);
|
||||
}).finally(() => this.toggleProperty('editingTitle'));
|
||||
},
|
||||
|
||||
generateApiKey() {
|
||||
|
Reference in New Issue
Block a user