Move name, avatar, and title fields from profile tab to account tab

This commit is contained in:
Neil Lalonde 2017-05-04 12:03:59 -04:00
parent de0d13e4ef
commit c98601129b
5 changed files with 79 additions and 53 deletions

View File

@ -1,9 +1,17 @@
import CanCheckEmails from 'discourse/mixins/can-check-emails';
import { default as computed } from "ember-addons/ember-computed-decorators";
import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
import { setting } from 'discourse/lib/computed';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend(CanCheckEmails, PreferencesTabController, {
saveAttrNames: ['name'],
canEditName: setting('enable_names'),
newNameInput: null,
passwordProgress: null,
cannotDeleteAccount: Em.computed.not('currentUser.can_delete_account'),
@ -15,12 +23,34 @@ export default Ember.Controller.extend(CanCheckEmails, PreferencesTabController,
});
},
@computed()
nameInstructions() {
return I18n.t(this.siteSettings.full_name_required ? 'user.name.instructions_required' : 'user.name.instructions');
},
@computed("model.has_title_badges")
canSelectTitle(hasTitleBadges) {
return this.siteSettings.enable_badges && hasTitleBadges;
},
@computed()
canChangePassword() {
return !this.siteSettings.enable_sso && this.siteSettings.enable_local_logins;
},
actions: {
save() {
this.set('saved', false);
const model = this.get('model');
model.set('name', this.get('newNameInput'));
return model.save(this.get('saveAttrNames')).then(() => {
this.set('saved', true);
}).catch(popupAjaxError);
},
changePassword() {
if (!this.get('passwordProgress')) {
this.set('passwordProgress', I18n.t("user.change_password.in_progress"));

View File

@ -1,13 +1,11 @@
import { default as computed } from "ember-addons/ember-computed-decorators";
import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
import { setting } from 'discourse/lib/computed';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { cook } from 'discourse/lib/text';
export default Ember.Controller.extend(PreferencesTabController, {
saveAttrNames: [
'name',
'bio_raw',
'website',
'location',
@ -18,20 +16,6 @@ export default Ember.Controller.extend(PreferencesTabController, {
'date_of_birth'
],
canEditName: setting('enable_names'),
newNameInput: null,
@computed()
nameInstructions() {
return I18n.t(this.siteSettings.full_name_required ? 'user.name.instructions_required' : 'user.name.instructions');
},
@computed("model.has_title_badges")
canSelectTitle(hasTitleBadges) {
return this.siteSettings.enable_badges && hasTitleBadges;
},
@computed("model.user_fields.@each.value")
userFields() {
let siteUserFields = this.site.get('user_fields');

View File

@ -11,6 +11,22 @@
</div>
</div>
{{#if canEditName}}
<div class="control-group pref-name">
<label class="control-label">{{i18n 'user.name.title'}}</label>
<div class="controls">
{{#if model.can_edit_name}}
{{text-field value=newNameInput classNames="input-xxlarge"}}
{{else}}
<span class='static'>{{model.name}}</span>
{{/if}}
</div>
<div class='instructions'>
{{nameInstructions}}
</div>
</div>
{{/if}}
{{#if canCheckEmails}}
<div class="control-group pref-email">
<label class="control-label">{{i18n 'user.email.title'}}</label>
@ -49,10 +65,40 @@
</div>
{{/if}}
<div class="control-group pref-avatar">
<label class="control-label">{{i18n 'user.avatar.title'}}</label>
<div class="controls">
{{! we want the "huge" version even though we're downsizing it to "large" in CSS }}
{{bound-avatar model "huge"}}
{{#unless siteSettings.sso_overrides_avatar}}
{{d-button action="showAvatarSelector" class="pad-left" icon="pencil"}}
{{/unless}}
</div>
</div>
{{#if canSelectTitle}}
<div class="control-group pref-title">
<label class="control-label">{{i18n 'user.title.title'}}</label>
<div class="controls">
<span class="static">{{model.title}}</span>
{{#link-to "preferences.badgeTitle" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
</div>
</div>
{{/if}}
{{plugin-outlet name="user-preferences-account"}}
<br/>
{{plugin-outlet name="user-custom-controls" args=(hash model=model)}}
<div class="control-group save-button">
<div class="controls">
{{partial 'user/preferences/save-button'}}
</div>
</div>
{{#if model.canDeleteAccount}}
<div class="control-group delete-account">
<br/>

View File

@ -1,40 +1,3 @@
{{#if canEditName}}
<div class="control-group pref-name">
<label class="control-label">{{i18n 'user.name.title'}}</label>
<div class="controls">
{{#if model.can_edit_name}}
{{text-field value=newNameInput classNames="input-xxlarge"}}
{{else}}
<span class='static'>{{model.name}}</span>
{{/if}}
</div>
<div class='instructions'>
{{nameInstructions}}
</div>
</div>
{{/if}}
{{#if canSelectTitle}}
<div class="control-group pref-title">
<label class="control-label">{{i18n 'user.title.title'}}</label>
<div class="controls">
<span class="static">{{model.title}}</span>
{{#link-to "preferences.badgeTitle" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
</div>
</div>
{{/if}}
<div class="control-group pref-avatar">
<label class="control-label">{{i18n 'user.avatar.title'}}</label>
<div class="controls">
{{! we want the "huge" version even though we're downsizing it to "large" in CSS }}
{{bound-avatar model "huge"}}
{{#unless siteSettings.sso_overrides_avatar}}
{{d-button action="showAvatarSelector" class="pad-left" icon="pencil"}}
{{/unless}}
</div>
</div>
{{#if siteSettings.allow_profile_backgrounds}}
<div class="control-group pref-profile-bg">
<label class="control-label">{{i18n 'user.change_profile_background.title'}}</label>

View File

@ -18,6 +18,9 @@ test("update some fields", () => {
});
};
fillIn(".pref-name input[type=text]", "Jon Snow");
savePreferences();
click(".preferences-nav .nav-profile a");
fillIn("#edit-location", "Westeros");
savePreferences();