diff --git a/app/assets/javascripts/discourse/controllers/badges/show.js.es6 b/app/assets/javascripts/discourse/controllers/badges/show.js.es6 index 5904def6c9d..11d01f32a76 100644 --- a/app/assets/javascripts/discourse/controllers/badges/show.js.es6 +++ b/app/assets/javascripts/discourse/controllers/badges/show.js.es6 @@ -25,9 +25,9 @@ export default Ember.Controller.extend(BadgeSelectController, { return username ? userCount : modelCount; }, - @computed("model.has_title_badges") - canSelectTitle(hasTitleBadges) { - return this.siteSettings.enable_badges && hasTitleBadges; + @computed("model.allow_title", "model.has_badge", "model") + canSelectTitle(hasTitleBadges, hasBadge) { + return this.siteSettings.enable_badges && hasTitleBadges && hasBadge; }, actions: { diff --git a/app/assets/javascripts/discourse/templates/badges/show.hbs b/app/assets/javascripts/discourse/templates/badges/show.hbs index b834a798c6b..fab3e9a5aad 100644 --- a/app/assets/javascripts/discourse/templates/badges/show.hbs +++ b/app/assets/javascripts/discourse/templates/badges/show.hbs @@ -9,17 +9,13 @@ {{badge-card badge=model size="large" count=userBadges.grant_count}}
- {{#if model.allow_title}} + {{#if canSelectTitle}}
{{i18n 'badges.allow_title'}} - {{#if userBadges}} - {{#if model.allow_title}} - {{d-button + {{d-button class='btn btn-small pad-left no-text' action='toggleSetUserTitle' icon='pencil'}} - {{/if}} - {{/if}}
{{/if}} {{#if model.multiple_grant}} @@ -29,10 +25,13 @@ {{/if}}
-
- {{badge-title selectableUserBadges=selectableUserBadges user=user}} - -
+ + {{#if canSelectTitle}} +
+ {{badge-title selectableUserBadges=selectableUserBadges user=user}} + +
+ {{/if}} {{#if userBadges}} diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb index 5d1466ebb7d..7b11f789206 100644 --- a/app/controllers/badges_controller.rb +++ b/app/controllers/badges_controller.rb @@ -47,6 +47,9 @@ class BadgesController < ApplicationController if user_badge && user_badge.notification user_badge.notification.update_attributes read: true end + if user_badge + @badge.has_badge = true + end end serialized = MultiJson.dump(serialize_data(@badge, BadgeSerializer, root: "badge", include_long_description: true)) diff --git a/app/models/badge.rb b/app/models/badge.rb index 637cb240103..f8c41e7db19 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -65,6 +65,9 @@ class Badge < ActiveRecord::Base # other consts AutobiographerMinBioLength = 10 + # used by serializer + attr_accessor :has_badge + def self.trigger_hash Hash[*( Badge::Trigger.constants.map { |k| diff --git a/app/serializers/badge_serializer.rb b/app/serializers/badge_serializer.rb index a726a4dde4d..d3bbd873390 100644 --- a/app/serializers/badge_serializer.rb +++ b/app/serializers/badge_serializer.rb @@ -1,10 +1,18 @@ class BadgeSerializer < ApplicationSerializer attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id, - :system, :long_description, :slug + :system, :long_description, :slug, :has_badge has_one :badge_type + def include_has_badge? + object.has_badge + end + + def has_badge + true + end + def system object.system? end