Add ability to specify custom font awesome icon for badges.

This commit is contained in:
Vikhyat Korrapati 2014-06-10 13:02:22 +05:30
parent 7fa972676a
commit e0fd1f6f5e
8 changed files with 24 additions and 5 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 disabled=readonly}}
</div>
{{#if showDisplayName}}
@ -33,6 +33,11 @@
</div>
{{/if}}
<div>
<label for="name">{{i18n admin.badges.icon}}</label>
{{input type="text" name="name" value=icon disabled=readonly}}
</div>
<div>
<label for="badge_type_id">{{i18n admin.badges.badge_type}}</label>
{{view Ember.Select name="badge_type_id" value=badge_type_id

View File

@ -7,5 +7,9 @@ export default Ember.Component.extend({
showGrantCount: function() {
return this.get('count') && this.get('count') > 1;
}.property('count')
}.property('count'),
isIcon: function() {
return this.get('badge.icon').match(/^fa-/);
}.property('badge.icon')
});

View File

@ -116,7 +116,8 @@ Discourse.Badge = Discourse.Model.extend({
description: this.get('description'),
badge_type_id: this.get('badge_type_id'),
allow_title: !!this.get('allow_title'),
multiple_grant: !!this.get('multiple_grant')
multiple_grant: !!this.get('multiple_grant'),
icon: this.get('icon')
}
}).then(function(json) {
self.updateFromJson(json);

View File

@ -1,6 +1,8 @@
{{#link-to 'badges.show' badge}}
<span {{bind-attr class=":user-badge badgeTypeClassName" data-badge-name="badge.name" title="badge.displayDescription"}}>
<i class='fa fa-certificate'></i>
{{#if isIcon}}
<i {{bind-attr class=":fa badge.icon"}}></i>
{{/if}}
{{badge.displayName}}
{{#if showGrantCount}}
<span class="count">(&times;&nbsp;{{count}})</span>

View File

@ -36,6 +36,7 @@ class Admin::BadgesController < Admin::AdminController
badge.badge_type = BadgeType.find(params[:badge_type_id])
badge.allow_title = params[:allow_title]
badge.multiple_grant = params[:multiple_grant]
badge.icon = params[:icon]
badge
end
end

View File

@ -1,5 +1,5 @@
class BadgeSerializer < ApplicationSerializer
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant
attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon
has_one :badge_type
end

View File

@ -1856,6 +1856,7 @@ en:
no_badges: There are no badges that can be granted.
allow_title: Allow badge to be used as a title
multiple_grant: Can be granted multiple times
icon: Icon
lightbox:
download: "download"

View File

@ -0,0 +1,5 @@
class AddIconToBadges < ActiveRecord::Migration
def change
add_column :badges, :icon, :string, default: "fa-certificate"
end
end