FIX: allow selection of no title

This commit is contained in:
Sam 2014-07-14 18:06:50 +10:00
parent 192e286b15
commit 4a2cc269ab
4 changed files with 15 additions and 5 deletions

View File

@ -18,7 +18,13 @@ export default Ember.ArrayController.extend({
}
}.property('saving'),
selectableUserBadges: Em.computed.filterBy('model', 'badge.allow_title', true),
selectableUserBadges: function() {
var items = this.get('model').filterBy('badge.allow_title', true);
items.unshiftObject(Em.Object.create({
badge: Discourse.Badge.create({name: I18n.t('badges.no_title')})
}));
return items;
}.property('model'),
selectedUserBadge: function() {
var selectedUserBadgeId = parseInt(this.get('selectedUserBadgeId'));

View File

@ -8,9 +8,9 @@
</div>
<div class="control-group">
<label class="control-label">{{i18n badges.title}}</label>
<label class="control-label"></label>
<div class="controls">
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.name" content=selectableUserBadges}}
{{combo-box valueAttribute="id" value=selectedUserBadgeId nameProperty="badge.displayName" content=selectableUserBadges}}
</div>
</div>

View File

@ -67,10 +67,13 @@ class UsersController < ApplicationController
user = fetch_user_from_params
guardian.ensure_can_edit!(user)
user_badge = UserBadge.find(params[:user_badge_id])
if user_badge.user == user && user_badge.badge.allow_title?
user_badge = UserBadge.find_by(id: params[:user_badge_id])
if user_badge && user_badge.user == user && user_badge.badge.allow_title?
user.title = user_badge.badge.name
user.save!
else
user.title = ''
user.save!
end
render nothing: true

View File

@ -1953,6 +1953,7 @@ en:
one: "1 granted"
other: "%{count} granted"
select_badge_for_title: Select a badge to use as your title
no_title: "<no title>"
badge:
editor:
name: Editor