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">
<div>
<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>
{{#if showDisplayName}}
@ -35,7 +35,7 @@
<div>
<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>

View File

@ -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'),
/**

View File

@ -7,7 +7,7 @@
<tr>
<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='description'>{{displayDescription}}</td>
<td class='description'>{{{displayDescriptionHtml}}}</td>
<td class='grant-count'>{{i18n badges.granted count=grant_count}}</td>
</tr>
{{/each}}

View File

@ -175,6 +175,9 @@ SQL
!self.multiple_grant?
end
def default_name=(val)
self.name ||= val
end
end
# == 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
read_guidelines:
name: Read Guidelines
description: Read the community guidelines
description: Read the <a href="/guidelines">community guidelines</a>
reader:
name: Reader
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|
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