mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
UX: Show translated badge names and badge groupings
FIX: Disallow renaming of system badges FIX: Disallow renaming/deleting of system badge groupings UX: Use "modern" button style in badge groupings dialog
This commit is contained in:
parent
f0694d491a
commit
8517674a32
8 changed files with 45 additions and 42 deletions
|
@ -2,15 +2,13 @@ export default Ember.Controller.extend({
|
||||||
needs: ['modal'],
|
needs: ['modal'],
|
||||||
|
|
||||||
modelChanged: function(){
|
modelChanged: function(){
|
||||||
|
const model = this.get('model');
|
||||||
var grouping = Em.Object.extend({});
|
const copy = Em.A();
|
||||||
|
const store = this.store;
|
||||||
var model = this.get('model');
|
|
||||||
var copy = Em.A();
|
|
||||||
|
|
||||||
if(model){
|
if(model){
|
||||||
model.forEach(function(o){
|
model.forEach(function(o){
|
||||||
copy.pushObject(grouping.create(o));
|
copy.pushObject(store.createRecord('badge-grouping', o));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +16,8 @@ export default Ember.Controller.extend({
|
||||||
}.observes('model'),
|
}.observes('model'),
|
||||||
|
|
||||||
moveItem: function(item, delta){
|
moveItem: function(item, delta){
|
||||||
var copy = this.get('workingCopy');
|
const copy = this.get('workingCopy');
|
||||||
var index = copy.indexOf(item);
|
const index = copy.indexOf(item);
|
||||||
if (index + delta < 0 || index + delta >= copy.length){
|
if (index + delta < 0 || index + delta >= copy.length){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -50,14 +48,14 @@ export default Ember.Controller.extend({
|
||||||
item.set("editing", false);
|
item.set("editing", false);
|
||||||
},
|
},
|
||||||
add: function(){
|
add: function(){
|
||||||
var obj = Em.Object.create({editing: true, name: "Enter Name"});
|
const obj = this.store.createRecord('badge-grouping', {editing: true, name: I18n.t('admin.badges.badge_grouping')});
|
||||||
this.get('workingCopy').pushObject(obj);
|
this.get('workingCopy').pushObject(obj);
|
||||||
},
|
},
|
||||||
saveAll: function(){
|
saveAll: function(){
|
||||||
var self = this;
|
const self = this;
|
||||||
var items = this.get('workingCopy');
|
var items = this.get('workingCopy');
|
||||||
var groupIds = items.map(function(i){return i.get("id") || -1;});
|
const groupIds = items.map(function(i){return i.get("id") || -1;});
|
||||||
var names = items.map(function(i){return i.get("name");});
|
const names = items.map(function(i){return i.get("name");});
|
||||||
|
|
||||||
Discourse.ajax('/admin/badges/badge_groupings',{
|
Discourse.ajax('/admin/badges/badge_groupings',{
|
||||||
data: {ids: groupIds, names: names},
|
data: {ids: groupIds, names: names},
|
||||||
|
@ -66,14 +64,13 @@ export default Ember.Controller.extend({
|
||||||
items = self.get("model");
|
items = self.get("model");
|
||||||
items.clear();
|
items.clear();
|
||||||
data.badge_groupings.forEach(function(g){
|
data.badge_groupings.forEach(function(g){
|
||||||
items.pushObject(Em.Object.create(g));
|
items.pushObject(self.store.createRecord('badge-grouping', g));
|
||||||
});
|
});
|
||||||
self.set('model', null);
|
self.set('model', null);
|
||||||
self.set('workingCopy', null);
|
self.set('workingCopy', null);
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
},function(){
|
},function(){
|
||||||
// TODO we can do better
|
bootbox.alert(I18n.t('generic_error'));
|
||||||
bootbox.alert("Something went wrong");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Badge from 'discourse/models/badge';
|
import Badge from 'discourse/models/badge';
|
||||||
|
import BadgeGrouping from 'discourse/models/badge-grouping';
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
_json: null,
|
_json: null,
|
||||||
|
@ -13,14 +14,19 @@ export default Discourse.Route.extend({
|
||||||
|
|
||||||
setupController: function(controller, model) {
|
setupController: function(controller, model) {
|
||||||
var json = this._json,
|
var json = this._json,
|
||||||
triggers = [];
|
triggers = [],
|
||||||
|
badgeGroupings = [];
|
||||||
|
|
||||||
_.each(json.admin_badges.triggers,function(v,k){
|
_.each(json.admin_badges.triggers,function(v,k){
|
||||||
triggers.push({id: v, name: I18n.t('admin.badges.trigger_type.'+k)});
|
triggers.push({id: v, name: I18n.t('admin.badges.trigger_type.'+k)});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
json.badge_groupings.forEach(function(badgeGroupingJson) {
|
||||||
|
badgeGroupings.push(BadgeGrouping.create(badgeGroupingJson));
|
||||||
|
});
|
||||||
|
|
||||||
controller.setProperties({
|
controller.setProperties({
|
||||||
badgeGroupings: json.badge_groupings,
|
badgeGroupings: badgeGroupings,
|
||||||
badgeTypes: json.badge_types,
|
badgeTypes: json.badge_types,
|
||||||
protectedSystemFields: json.admin_badges.protected_system_fields,
|
protectedSystemFields: json.admin_badges.protected_system_fields,
|
||||||
badgeTriggers: triggers,
|
badgeTriggers: triggers,
|
||||||
|
|
|
@ -2,25 +2,22 @@
|
||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
<div>
|
<div>
|
||||||
<label for="name">{{i18n 'admin.badges.name'}}</label>
|
<label for="name">{{i18n 'admin.badges.name'}}</label>
|
||||||
|
{{#if readOnly}}
|
||||||
|
{{input type="text" name="name" value=buffered.displayName disabled=true}}
|
||||||
|
{{else}}
|
||||||
{{input type="text" name="name" value=buffered.name}}
|
{{input type="text" name="name" value=buffered.name}}
|
||||||
</div>
|
|
||||||
|
|
||||||
{{#if showDisplayName}}
|
|
||||||
<div>
|
|
||||||
<strong>{{i18n 'admin.badges.display_name'}}</strong>
|
|
||||||
{{buffered.displayName}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="name">{{i18n 'admin.badges.icon'}}</label>
|
<label for="icon">{{i18n 'admin.badges.icon'}}</label>
|
||||||
{{input type="text" name="name" value=buffered.icon}}
|
{{input type="text" name="icon" value=buffered.icon}}
|
||||||
<p class='help'>{{i18n 'admin.badges.icon_help'}}</p>
|
<p class='help'>{{i18n 'admin.badges.icon_help'}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="name">{{i18n 'admin.badges.image'}}</label>
|
<label for="image">{{i18n 'admin.badges.image'}}</label>
|
||||||
{{input type="text" name="name" value=buffered.image}}
|
{{input type="text" name="image" value=buffered.image}}
|
||||||
<p class='help'>{{i18n 'admin.badges.icon_help'}}</p>
|
<p class='help'>{{i18n 'admin.badges.icon_help'}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -40,7 +37,7 @@
|
||||||
value=buffered.badge_grouping_id
|
value=buffered.badge_grouping_id
|
||||||
content=badgeGroupings
|
content=badgeGroupings
|
||||||
optionValuePath="content.id"
|
optionValuePath="content.id"
|
||||||
optionLabelPath="content.name"}}
|
optionLabelPath="content.displayName"}}
|
||||||
<button {{action "editGroupings"}} class='btn'>{{fa-icon 'pencil'}}</button>
|
<button {{action "editGroupings"}} class='btn'>{{fa-icon 'pencil'}}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@
|
||||||
<li>
|
<li>
|
||||||
{{#if wc.editing}}
|
{{#if wc.editing}}
|
||||||
{{input value=wc.name}}
|
{{input value=wc.name}}
|
||||||
<button {{action "save" wc}}><i class="fa fa-check"></i></button>
|
<button {{action "save" wc}} class="btn no-text">{{fa-icon 'check'}}</button>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{wc.name}}
|
{{wc.displayName}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class='actions'>
|
<div class='actions'>
|
||||||
<button {{action "edit" wc}}><i class="fa fa-pencil"></i></button>
|
<button {{action "edit" wc}} class="btn no-text" {{bind-attr disabled="wc.system"}}>{{fa-icon 'pencil'}}</button>
|
||||||
<button {{action "up" wc}}><i class="fa fa-toggle-up"></i></button>
|
<button {{action "up" wc}} class="btn no-text">{{fa-icon 'toggle-up'}}</button>
|
||||||
<button {{action "down" wc}}><i class="fa fa-toggle-down"></i></button>
|
<button {{action "down" wc}} class="btn no-text">{{fa-icon 'toggle-down'}}</button>
|
||||||
<button {{action "delete" wc}}><i class="fa fa-times"></i></button>
|
<button {{action "delete" wc}} class="btn no-text btn-danger" {{bind-attr disabled="wc.system"}}>{{fa-icon 'times'}}</button>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default RestModel.extend({
|
||||||
return this.get('name').toLowerCase().replace(/\s/g, '_');
|
return this.get('name').toLowerCase().replace(/\s/g, '_');
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed
|
@computed('name')
|
||||||
displayName() {
|
displayName() {
|
||||||
const i18nKey = `badges.badge_grouping.${this.get('i18nNameKey')}.name`;
|
const i18nKey = `badges.badge_grouping.${this.get('i18nNameKey')}.name`;
|
||||||
return I18n.t(i18nKey, {defaultValue: this.get('name')});
|
return I18n.t(i18nKey, {defaultValue: this.get('name')});
|
||||||
|
|
|
@ -1606,10 +1606,9 @@ and (max-width : 500px) {
|
||||||
border-bottom: 1px solid #dfdfdf;
|
border-bottom: 1px solid #dfdfdf;
|
||||||
}
|
}
|
||||||
.actions {
|
.actions {
|
||||||
font-size: 1.214em;
|
|
||||||
float: right;
|
float: right;
|
||||||
a {
|
.btn {
|
||||||
margin-left: 5px;
|
padding: 3px 6px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class BadgeGrouping < ActiveRecord::Base
|
||||||
has_many :badges
|
has_many :badges
|
||||||
|
|
||||||
def system?
|
def system?
|
||||||
id && id < 5
|
id && id <= 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_position=(pos)
|
def default_position=(pos)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class BadgeGroupingSerializer < ApplicationSerializer
|
class BadgeGroupingSerializer < ApplicationSerializer
|
||||||
attributes :id, :name, :description, :position
|
attributes :id, :name, :description, :position, :system
|
||||||
|
|
||||||
|
def system
|
||||||
|
object.system?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue