FEATURE: allow overriding badge names

FEATURE: allow html in badge description
This commit is contained in:
Sam 2014-07-17 12:25:16 +10:00
parent e9e4ec0e52
commit e8ca1a2469
7 changed files with 29 additions and 18 deletions

View File

@ -23,7 +23,7 @@
<form class="form-horizontal"> <form class="form-horizontal">
<div> <div>
<label for="name">{{i18n admin.badges.name}}</label> <label for="name">{{i18n admin.badges.name}}</label>
{{input type="text" name="name" value=name disabled=readOnly}} {{input type="text" name="name" value=name}}
</div> </div>
{{#if showDisplayName}} {{#if showDisplayName}}
@ -35,7 +35,7 @@
<div> <div>
<label for="name">{{i18n admin.badges.icon}}</label> <label for="name">{{i18n admin.badges.icon}}</label>
{{input type="text" name="name" value=icon disabled=readOnly}} {{input type="text" name="name" value=icon}}
</div> </div>
<div> <div>

View File

@ -55,6 +55,11 @@ Discourse.Badge = Discourse.Model.extend({
return translation; return translation;
}.property('i18nNameKey'), }.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 Display-friendly description string. Returns either a translation or the
original description string. original description string.
@ -62,9 +67,9 @@ Discourse.Badge = Discourse.Model.extend({
@property displayDescription @property displayDescription
@type {String} @type {String}
**/ **/
displayDescription: function() { displayDescriptionHtml: function() {
var translated = this.get('translatedDescription'); var translated = this.get('translatedDescription');
return translated === null ? this.get('description') : translated; return (translated === null ? this.get('description') : translated) || "";
}.property('description', 'translatedDescription'), }.property('description', 'translatedDescription'),
/** /**

View File

@ -7,7 +7,7 @@
<tr> <tr>
<td class='granted'>{{#if this.has_badge}}<i class='fa fa-check'></i>{{/if}}</td> <td class='granted'>{{#if this.has_badge}}<i class='fa fa-check'></i>{{/if}}</td>
<td class='badge'>{{user-badge badge=this}}</td> <td class='badge'>{{user-badge badge=this}}</td>
<td class='description'>{{displayDescription}}</td> <td class='description'>{{{displayDescriptionHtml}}}</td>
<td class='grant-count'>{{i18n badges.granted count=grant_count}}</td> <td class='grant-count'>{{i18n badges.granted count=grant_count}}</td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -175,6 +175,9 @@ SQL
!self.multiple_grant? !self.multiple_grant?
end end
def default_name=(val)
self.name ||= val
end
end end
# == Schema Information # == Schema Information

View File

@ -0,0 +1,3 @@
class BadgeGrouping < ActiveRecord::Base
has_many :badges
end

View File

@ -2001,7 +2001,7 @@ en:
description: Quoted a user description: Quoted a user
read_guidelines: read_guidelines:
name: Read Guidelines name: Read Guidelines
description: Read the community guidelines description: Read the <a href="/guidelines">community guidelines</a>
reader: reader:
name: Reader name: Reader
description: Read every post in a topic with more than 50 posts description: Read every post in a topic with more than 50 posts

View File

@ -9,7 +9,7 @@ trust_level_badges = [
trust_level_badges.each do |spec| trust_level_badges.each do |spec|
Badge.seed do |b| Badge.seed do |b|
b.id = spec[:id] b.id = spec[:id]
b.name = spec[:name] b.default_name = spec[:name]
b.badge_type_id = spec[:type] b.badge_type_id = spec[:type]
b.query = Badge::Queries.trust_level(spec[:id]) b.query = Badge::Queries.trust_level(spec[:id])
@ -20,7 +20,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::Reader b.id = Badge::Reader
b.name = "Reader" b.default_name = "Reader"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = false b.target_posts = false
@ -30,7 +30,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::ReadGuidelines b.id = Badge::ReadGuidelines
b.name = "Read Guidelines" b.default_name = "Read Guidelines"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = false b.target_posts = false
@ -39,7 +39,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::FirstLink b.id = Badge::FirstLink
b.name = "First Link" b.default_name = "First Link"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
@ -48,7 +48,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::FirstQuote b.id = Badge::FirstQuote
b.name = "First Quote" b.default_name = "First Quote"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
@ -57,7 +57,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::FirstLike b.id = Badge::FirstLike
b.name = "First Like" b.default_name = "First Like"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
@ -66,7 +66,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::FirstFlag b.id = Badge::FirstFlag
b.name = "First Flag" b.default_name = "First Flag"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = false b.target_posts = false
@ -75,7 +75,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::FirstShare b.id = Badge::FirstShare
b.name = "First Share" b.default_name = "First Share"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
@ -84,7 +84,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::Welcome b.id = Badge::Welcome
b.name = "Welcome" b.default_name = "Welcome"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
@ -93,7 +93,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::Autobiographer b.id = Badge::Autobiographer
b.name = "Autobiographer" b.default_name = "Autobiographer"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.query = Badge::Queries::Autobiographer b.query = Badge::Queries::Autobiographer
@ -101,7 +101,7 @@ end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::Editor b.id = Badge::Editor
b.name = "Editor" b.default_name = "Editor"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.query = Badge::Queries::Editor b.query = Badge::Queries::Editor
@ -118,7 +118,7 @@ like_badges = [
like_badges.each do |spec| like_badges.each do |spec|
Badge.seed do |b| Badge.seed do |b|
b.id = spec[:id] b.id = spec[:id]
b.name = spec[:name] b.default_name = spec[:name]
b.badge_type_id = spec[:type] b.badge_type_id = spec[:type]
b.multiple_grant = spec[:multiple] b.multiple_grant = spec[:multiple]
b.target_posts = true b.target_posts = true