From e8ca1a24694876414b82b69fb827996388d7a5a7 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Jul 2014 12:25:16 +1000 Subject: [PATCH] FEATURE: allow overriding badge names FEATURE: allow html in badge description --- .../admin/templates/badges.js.handlebars | 4 ++-- .../javascripts/discourse/models/badge.js | 9 +++++-- .../templates/badges/index.js.handlebars | 2 +- app/models/badge.rb | 3 +++ app/models/badge_grouping.rb | 3 +++ config/locales/client.en.yml | 2 +- db/fixtures/006_badges.rb | 24 +++++++++---------- 7 files changed, 29 insertions(+), 18 deletions(-) create mode 100644 app/models/badge_grouping.rb diff --git a/app/assets/javascripts/admin/templates/badges.js.handlebars b/app/assets/javascripts/admin/templates/badges.js.handlebars index 8ee9affe5aa..2d61db40b29 100644 --- a/app/assets/javascripts/admin/templates/badges.js.handlebars +++ b/app/assets/javascripts/admin/templates/badges.js.handlebars @@ -23,7 +23,7 @@
- {{input type="text" name="name" value=name disabled=readOnly}} + {{input type="text" name="name" value=name}}
{{#if showDisplayName}} @@ -35,7 +35,7 @@
- {{input type="text" name="name" value=icon disabled=readOnly}} + {{input type="text" name="name" value=icon}}
diff --git a/app/assets/javascripts/discourse/models/badge.js b/app/assets/javascripts/discourse/models/badge.js index a848d326814..8d017ee8504 100644 --- a/app/assets/javascripts/discourse/models/badge.js +++ b/app/assets/javascripts/discourse/models/badge.js @@ -55,6 +55,11 @@ Discourse.Badge = Discourse.Model.extend({ return translation; }.property('i18nNameKey'), + displayDescription: function(){ + // we support html in description but in most places do not need it + return this.get('displayDescriptionHtml').replace(/<[^>]*>/g, ""); + }.property('displayDescriptionHtml'), + /** Display-friendly description string. Returns either a translation or the original description string. @@ -62,9 +67,9 @@ Discourse.Badge = Discourse.Model.extend({ @property displayDescription @type {String} **/ - displayDescription: function() { + displayDescriptionHtml: function() { var translated = this.get('translatedDescription'); - return translated === null ? this.get('description') : translated; + return (translated === null ? this.get('description') : translated) || ""; }.property('description', 'translatedDescription'), /** diff --git a/app/assets/javascripts/discourse/templates/badges/index.js.handlebars b/app/assets/javascripts/discourse/templates/badges/index.js.handlebars index 646af7065b0..91dc57a9dc9 100644 --- a/app/assets/javascripts/discourse/templates/badges/index.js.handlebars +++ b/app/assets/javascripts/discourse/templates/badges/index.js.handlebars @@ -7,7 +7,7 @@ {{#if this.has_badge}}{{/if}} {{user-badge badge=this}} - {{displayDescription}} + {{{displayDescriptionHtml}}} {{i18n badges.granted count=grant_count}} {{/each}} diff --git a/app/models/badge.rb b/app/models/badge.rb index 33367993605..d9db26ab4f4 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -175,6 +175,9 @@ SQL !self.multiple_grant? end + def default_name=(val) + self.name ||= val + end end # == Schema Information diff --git a/app/models/badge_grouping.rb b/app/models/badge_grouping.rb new file mode 100644 index 00000000000..9a6fc917738 --- /dev/null +++ b/app/models/badge_grouping.rb @@ -0,0 +1,3 @@ +class BadgeGrouping < ActiveRecord::Base + has_many :badges +end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 28bb9b6e1b9..c49cf26ae10 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2001,7 +2001,7 @@ en: description: Quoted a user read_guidelines: name: Read Guidelines - description: Read the community guidelines + description: Read the community guidelines reader: name: Reader description: Read every post in a topic with more than 50 posts diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index d4f69e6b242..649fb0268e3 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -9,7 +9,7 @@ trust_level_badges = [ trust_level_badges.each do |spec| Badge.seed do |b| b.id = spec[:id] - b.name = spec[:name] + b.default_name = spec[:name] b.badge_type_id = spec[:type] b.query = Badge::Queries.trust_level(spec[:id]) @@ -20,7 +20,7 @@ end Badge.seed do |b| b.id = Badge::Reader - b.name = "Reader" + b.default_name = "Reader" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false @@ -30,7 +30,7 @@ end Badge.seed do |b| b.id = Badge::ReadGuidelines - b.name = "Read Guidelines" + b.default_name = "Read Guidelines" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false @@ -39,7 +39,7 @@ end Badge.seed do |b| b.id = Badge::FirstLink - b.name = "First Link" + b.default_name = "First Link" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -48,7 +48,7 @@ end Badge.seed do |b| b.id = Badge::FirstQuote - b.name = "First Quote" + b.default_name = "First Quote" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -57,7 +57,7 @@ end Badge.seed do |b| b.id = Badge::FirstLike - b.name = "First Like" + b.default_name = "First Like" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -66,7 +66,7 @@ end Badge.seed do |b| b.id = Badge::FirstFlag - b.name = "First Flag" + b.default_name = "First Flag" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false @@ -75,7 +75,7 @@ end Badge.seed do |b| b.id = Badge::FirstShare - b.name = "First Share" + b.default_name = "First Share" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -84,7 +84,7 @@ end Badge.seed do |b| b.id = Badge::Welcome - b.name = "Welcome" + b.default_name = "Welcome" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -93,7 +93,7 @@ end Badge.seed do |b| b.id = Badge::Autobiographer - b.name = "Autobiographer" + b.default_name = "Autobiographer" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.query = Badge::Queries::Autobiographer @@ -101,7 +101,7 @@ end Badge.seed do |b| b.id = Badge::Editor - b.name = "Editor" + b.default_name = "Editor" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.query = Badge::Queries::Editor @@ -118,7 +118,7 @@ like_badges = [ like_badges.each do |spec| Badge.seed do |b| b.id = spec[:id] - b.name = spec[:name] + b.default_name = spec[:name] b.badge_type_id = spec[:type] b.multiple_grant = spec[:multiple] b.target_posts = true