Show system badges in the admin interface but don't allow editing them.
This commit is contained in:
parent
9e3c08b5ee
commit
6225b83f4a
|
@ -15,5 +15,21 @@ Discourse.AdminBadgeController = Discourse.ObjectController.extend({
|
|||
@property selected
|
||||
@type {Boolean}
|
||||
**/
|
||||
selected: Discourse.computed.propertyEqual('model.name', 'parentController.selectedItem.name')
|
||||
selected: Discourse.computed.propertyEqual('model.name', 'parentController.selectedItem.name'),
|
||||
|
||||
/**
|
||||
Show the displayName only if it is different from the name.
|
||||
|
||||
@property showDisplayName
|
||||
@type {Boolean}
|
||||
**/
|
||||
showDisplayName: Discourse.computed.propertyNotEqual('selectedItem.name', 'selectedItem.displayName'),
|
||||
|
||||
/**
|
||||
Don't allow editing if this is a system badge.
|
||||
|
||||
@property readOnly
|
||||
@type {Boolean}
|
||||
**/
|
||||
readOnly: Ember.computed.lt('model.id', 100)
|
||||
});
|
||||
|
|
|
@ -10,16 +10,8 @@ Discourse.AdminBadgesController = Ember.ArrayController.extend({
|
|||
itemController: 'adminBadge',
|
||||
|
||||
/**
|
||||
Show the displayName only if it is different from the name.
|
||||
|
||||
@property showDisplayName
|
||||
@type {Boolean}
|
||||
**/
|
||||
showDisplayName: Discourse.computed.propertyNotEqual('selectedItem.name', 'selectedItem.displayName'),
|
||||
|
||||
/**
|
||||
We don't allow setting a description if a translation for the given badge name
|
||||
exists.
|
||||
We don't allow setting a description if a translation for the given badge
|
||||
name exists.
|
||||
|
||||
@property canEditDescription
|
||||
@type {Boolean}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
Discourse.AdminBadgesRoute = Discourse.Route.extend({
|
||||
|
||||
model: function() {
|
||||
return Discourse.Badge.findAll().then(function(badges) {
|
||||
return badges.filter(function(badge) {
|
||||
return badge.id >= 100;
|
||||
});
|
||||
});
|
||||
return Discourse.Badge.findAll();
|
||||
},
|
||||
|
||||
setupController: function(controller, model) {
|
||||
|
|
|
@ -18,19 +18,19 @@
|
|||
</div>
|
||||
|
||||
{{#if selectedItem}}
|
||||
{{#with selectedItem}}
|
||||
{{#with selectedItem controller='adminBadge'}}
|
||||
<div class='current-badge span13'>
|
||||
<form class="form-horizontal">
|
||||
<div>
|
||||
<label for="name">{{i18n admin.badges.name}}</label>
|
||||
{{input type="text" name="name" value=name}}
|
||||
{{input type="text" name="name" value=name disabled=readOnly}}
|
||||
</div>
|
||||
|
||||
{{#if controller.showDisplayName}}
|
||||
<div>
|
||||
<strong>{{i18n admin.badges.display_name}}</strong>
|
||||
{{displayName}}
|
||||
</div>
|
||||
{{#if showDisplayName}}
|
||||
<div>
|
||||
<strong>{{i18n admin.badges.display_name}}</strong>
|
||||
{{displayName}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div>
|
||||
|
@ -38,7 +38,8 @@
|
|||
{{view Ember.Select name="badge_type_id" value=badge_type_id
|
||||
content=controller.badgeTypes
|
||||
optionValuePath="content.id"
|
||||
optionLabelPath="content.name"}}
|
||||
optionLabelPath="content.name"
|
||||
disabled=readOnly}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -50,18 +51,20 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>
|
||||
{{input type="checkbox" checked=allow_title}}
|
||||
{{i18n admin.badges.allow_title}}
|
||||
</span>
|
||||
</div>
|
||||
{{#unless readOnly}}
|
||||
<div>
|
||||
<span>
|
||||
{{input type="checkbox" checked=allow_title}}
|
||||
{{i18n admin.badges.allow_title}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class='buttons'>
|
||||
<button {{action save}} {{bind-attr disabled=controller.disableSave}} class='btn btn-primary'>{{i18n admin.badges.save}}</button>
|
||||
<span class='saving'>{{savingStatus}}</span>
|
||||
<a {{action destroy}} class='delete-link'>{{i18n admin.badges.delete}}</a>
|
||||
</div>
|
||||
<div class='buttons'>
|
||||
<button {{action save}} {{bind-attr disabled=controller.disableSave}} class='btn btn-primary'>{{i18n admin.badges.save}}</button>
|
||||
<span class='saving'>{{savingStatus}}</span>
|
||||
<a {{action destroy}} class='delete-link'>{{i18n admin.badges.delete}}</a>
|
||||
</div>
|
||||
{{/unless}}
|
||||
</form>
|
||||
</div>
|
||||
{{/with}}
|
||||
|
|
|
@ -1,30 +1,15 @@
|
|||
module("Discourse.AdminBadgesController");
|
||||
|
||||
test("showDisplayName", function() {
|
||||
var badge, controller;
|
||||
|
||||
badge = Discourse.Badge.create({name: "Test Badge"});
|
||||
controller = testController(Discourse.AdminBadgesController, [badge]);
|
||||
controller.send('selectBadge', badge);
|
||||
ok(!controller.get('showDisplayName'), "does not show displayName when it is the same as the name");
|
||||
|
||||
this.stub(I18n, "t").returns("translated string");
|
||||
badge = Discourse.Badge.create({name: "Test Badge"});
|
||||
controller = testController(Discourse.AdminBadgesController, [badge]);
|
||||
controller.send('selectBadge', badge);
|
||||
ok(controller.get('showDisplayName'), "shows the displayName when it is different from the name");
|
||||
});
|
||||
|
||||
test("canEditDescription", function() {
|
||||
var badge, controller;
|
||||
|
||||
badge = Discourse.Badge.create({name: "Test Badge"});
|
||||
badge = Discourse.Badge.create({id: 101, name: "Test Badge"});
|
||||
controller = testController(Discourse.AdminBadgesController, [badge]);
|
||||
controller.send('selectBadge', badge);
|
||||
ok(controller.get('canEditDescription'), "allows editing description when a translation exists for the badge name");
|
||||
|
||||
this.stub(I18n, "t").returns("translated string");
|
||||
badge = Discourse.Badge.create({name: "Test Badge"});
|
||||
badge = Discourse.Badge.create({id: 102, name: "Test Badge"});
|
||||
controller = testController(Discourse.AdminBadgesController, [badge]);
|
||||
controller.send('selectBadge', badge);
|
||||
ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name");
|
||||
|
@ -38,7 +23,7 @@ test("newBadge", function() {
|
|||
});
|
||||
|
||||
test("selectBadge", function() {
|
||||
var badge = Discourse.Badge.create({name: "Test Badge"}),
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
controller = testController(Discourse.AdminBadgesController, [badge]);
|
||||
|
||||
controller.send('selectBadge', badge);
|
||||
|
@ -46,8 +31,8 @@ test("selectBadge", function() {
|
|||
});
|
||||
|
||||
test("save", function() {
|
||||
var badge = Discourse.Badge.create({name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({name: "Other Badge"}),
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
||||
controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]);
|
||||
|
||||
controller.send('selectBadge', badge);
|
||||
|
@ -57,8 +42,8 @@ test("save", function() {
|
|||
});
|
||||
|
||||
test("destroy", function() {
|
||||
var badge = Discourse.Badge.create({name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({name: "Other Badge"}),
|
||||
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
||||
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
||||
controller = testController(Discourse.AdminBadgesController, [badge, otherBadge]);
|
||||
|
||||
this.stub(badge, 'destroy').returns(Ember.RSVP.resolve({}));
|
||||
|
|
Loading…
Reference in New Issue