diff --git a/app/assets/javascripts/discourse/controllers/preferences_controller.js b/app/assets/javascripts/discourse/controllers/preferences_controller.js index cfe7efeae83..32c5805cc62 100644 --- a/app/assets/javascripts/discourse/controllers/preferences_controller.js +++ b/app/assets/javascripts/discourse/controllers/preferences_controller.js @@ -16,11 +16,15 @@ Discourse.PreferencesController = Discourse.ObjectController.extend({ saveDisabled: function() { if (this.get('saving')) return true; - if (this.blank('name')) return true; + if (Discourse.SiteSettings.enable_names && this.blank('name')) return true; if (this.blank('email')) return true; return false; }.property('saving', 'name', 'email'), + canEditName: function() { + return Discourse.SiteSettings.enable_names; + }.property(), + digestFrequencies: [{ name: I18n.t('user.email_digests.daily'), value: 1 }, { name: I18n.t('user.email_digests.weekly'), value: 7 }, { name: I18n.t('user.email_digests.bi_weekly'), value: 14 }], diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index 7fa3df262a1..646aed889ad 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -35,6 +35,20 @@ Discourse.User = Discourse.Model.extend({ }; }.property('username_lower'), + /** + This user's display name. Returns the name if possible, otherwise returns the + username. + + @property displayName + @type {String} + **/ + displayName: function() { + if (Discourse.SiteSettings.enable_names && !this.blank('name')) { + return this.get('name'); + } + return this.get('username'); + }.property('username', 'name'), + /** This user's website. diff --git a/app/assets/javascripts/discourse/models/user_action.js b/app/assets/javascripts/discourse/models/user_action.js index 0d0a2c2bc21..3adebb62748 100644 --- a/app/assets/javascripts/discourse/models/user_action.js +++ b/app/assets/javascripts/discourse/models/user_action.js @@ -85,7 +85,7 @@ Discourse.UserAction = Discourse.Model.extend({ post_number: '#' + this.get('reply_to_post_number'), user1Url: this.get('userUrl'), user2Url: this.get('targetUserUrl'), - another_user: this.get('target_name') + another_user: this.get('targetDisplayName') })); }.property('descriptionKey'), @@ -99,6 +99,9 @@ Discourse.UserAction = Discourse.Model.extend({ }.property('target_username'), presentName: Em.computed.any('name', 'username'), + targetDisplayName: Em.computed.any('target_name', 'target_username'), + actingDisplayName: Em.computed.any('acting_name', 'acting_username'), + targetUserUrl: Discourse.computed.url('target_username', '/users/%@'), usernameLower: function() { @@ -170,7 +173,7 @@ Discourse.UserAction = Discourse.Model.extend({ this.setProperties({ username: this.get('acting_username'), avatar_template: this.get('acting_avatar_template'), - name: this.get('acting_name') + name: this.get('actingDisplayName') }); } }); diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index 506d98d710d..eb420815f59 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -30,7 +30,7 @@ {{#unless showExtraInfo}}
{{#if currentUser}} - {{currentUser.name}} + {{currentUser.displayName}} {{else}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars index 7e5ccb14c41..dc85543869a 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/preferences.js.handlebars @@ -15,15 +15,17 @@
-
- -
- {{textField value=name classNames="input-xxlarge"}} + {{#if canEditName}} +
+ +
+ {{textField value=name classNames="input-xxlarge"}} +
+
+ {{i18n user.name.instructions}} +
-
- {{i18n user.name.instructions}} -
-
+ {{/if}}
diff --git a/app/serializers/basic_user_serializer.rb b/app/serializers/basic_user_serializer.rb index 1deede21e82..db8f7d02d30 100644 --- a/app/serializers/basic_user_serializer.rb +++ b/app/serializers/basic_user_serializer.rb @@ -1,3 +1,7 @@ class BasicUserSerializer < ApplicationSerializer attributes :id, :username, :avatar_template + + def include_name? + SiteSetting.enable_names? + end end diff --git a/app/serializers/user_action_serializer.rb b/app/serializers/user_action_serializer.rb index 0fa62156c53..5f2345f6f38 100644 --- a/app/serializers/user_action_serializer.rb +++ b/app/serializers/user_action_serializer.rb @@ -45,6 +45,18 @@ class UserActionSerializer < ApplicationSerializer ) end + def include_name? + SiteSetting.enable_names? + end + + def include_target_name? + include_name? + end + + def include_acting_name? + include_name? + end + def slug Slug.for(object.title) end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 5af590cb167..7c778f21543 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -94,10 +94,6 @@ class UserSerializer < BasicUserSerializer User.gravatar_template(object.email) end - def include_name? - SiteSetting.enable_names? - end - def include_suspended? object.suspended? end