mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Admin badge creation bug fixes.
This commit is contained in:
parent
d208e4d517
commit
a79bf11edb
7 changed files with 41 additions and 13 deletions
|
@ -21,15 +21,42 @@ Discourse.AdminBadgesController = Ember.ArrayController.extend({
|
|||
|
||||
/**
|
||||
Badge that is currently selected.
|
||||
|
||||
@property selectedItem
|
||||
@type {Discourse.Badge}
|
||||
**/
|
||||
selectedItem: function() {
|
||||
if (this.get('selectedId') === undefined || this.get('selectedId') === "undefined") {
|
||||
// New Badge
|
||||
return this.get('newBadge');
|
||||
} else {
|
||||
// Existing Badge
|
||||
var selectedId = parseInt(this.get('selectedId'));
|
||||
return this.get('model').filter(function(badge) {
|
||||
return badge.get('id') === selectedId;
|
||||
return parseInt(badge.get('id')) === selectedId;
|
||||
})[0];
|
||||
}.property('selectedId'),
|
||||
}
|
||||
}.property('selectedId', 'newBadge'),
|
||||
|
||||
/**
|
||||
Unsaved badge, if one exists.
|
||||
|
||||
@property newBadge
|
||||
@type {Discourse.Badge}
|
||||
**/
|
||||
newBadge: function() {
|
||||
return this.get('model').filter(function(badge) {
|
||||
return badge.get('id') === undefined;
|
||||
})[0];
|
||||
}.property('model.@each.id'),
|
||||
|
||||
/**
|
||||
Whether a new unsaved badge exists.
|
||||
|
||||
@property newBadgeExists
|
||||
@type {Discourse.Badge}
|
||||
**/
|
||||
newBadgeExists: Em.computed.notEmpty('newBadge'),
|
||||
|
||||
/**
|
||||
We don't allow setting a description if a translation for the given badge
|
||||
|
@ -55,7 +82,7 @@ Discourse.AdminBadgesController = Ember.ArrayController.extend({
|
|||
|
||||
@method newBadge
|
||||
**/
|
||||
newBadge: function() {
|
||||
createNewBadge: function() {
|
||||
var badge = Discourse.Badge.create({
|
||||
name: I18n.t('admin.badges.new_badge')
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
<button {{action newBadge}} class='btn'><i class="fa fa-plus"></i>{{i18n admin.badges.new}}</button>
|
||||
<button {{action createNewBadge}} {{bind-attr disabled=newBadgeExists}} class='btn'><i class="fa fa-plus"></i>{{i18n admin.badges.new}}</button>
|
||||
</div>
|
||||
|
||||
{{#if selectedItem}}
|
||||
|
|
|
@ -115,8 +115,8 @@ Discourse.Badge = Discourse.Model.extend({
|
|||
name: this.get('name'),
|
||||
description: this.get('description'),
|
||||
badge_type_id: this.get('badge_type_id'),
|
||||
allow_title: this.get('allow_title'),
|
||||
multiple_grant: this.get('multiple_grant')
|
||||
allow_title: !!this.get('allow_title'),
|
||||
multiple_grant: !!this.get('multiple_grant')
|
||||
}
|
||||
}).then(function(json) {
|
||||
self.updateFromJson(json);
|
||||
|
|
|
@ -5,6 +5,7 @@ class Badge < ActiveRecord::Base
|
|||
validates :name, presence: true, uniqueness: true
|
||||
validates :badge_type, presence: true
|
||||
validates :allow_title, inclusion: [true, false]
|
||||
validates :multiple_grant, inclusion: [true, false]
|
||||
|
||||
def self.trust_level_badge_ids
|
||||
(1..4).to_a
|
||||
|
@ -33,7 +34,7 @@ end
|
|||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# allow_title :boolean default(FALSE), not null
|
||||
# multiple_grant :boolean default(FALSE)
|
||||
# multiple_grant :boolean default(FALSE), not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class AddMultipleAwardToBadges < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :badges, :multiple_grant, :boolean, default: false
|
||||
add_column :badges, :multiple_grant, :boolean, default: false, null: false
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
|
|
|
@ -35,12 +35,12 @@ describe Admin::BadgesController do
|
|||
|
||||
context '.update' do
|
||||
it 'returns success' do
|
||||
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false
|
||||
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: false
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'updates the badge' do
|
||||
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false
|
||||
xhr :put, :update, id: badge.id, name: "123456", badge_type_id: badge.badge_type_id, allow_title: false, multiple_grant: true
|
||||
badge.reload.name.should eq('123456')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,9 @@ test("canEditDescription", function() {
|
|||
ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name");
|
||||
});
|
||||
|
||||
test("newBadge", function() {
|
||||
test("createNewBadge", function() {
|
||||
var controller = testController(Discourse.AdminBadgesController, []);
|
||||
controller.send('newBadge');
|
||||
controller.send('createNewBadge');
|
||||
equal(controller.get('model.length'), 1, "adds a new badge to the list of badges");
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue