Show which category colors have already been used when creating/editing a category
This commit is contained in:
parent
bbdf47d26d
commit
93f36cdf93
Binary file not shown.
Before Width: | Height: | Size: 530 B After Width: | Height: | Size: 842 B |
|
@ -37,7 +37,7 @@
|
||||||
<div class='input-prepend input-append' style="margin-top: 10px;">
|
<div class='input-prepend input-append' style="margin-top: 10px;">
|
||||||
<span class='color-title'>{{i18n category.background_color}}:</span>
|
<span class='color-title'>{{i18n category.background_color}}:</span>
|
||||||
<span class='add-on'>#</span>{{view Discourse.TextField valueBinding="color" placeholderKey="category.color_placeholder" maxlength="6"}}
|
<span class='add-on'>#</span>{{view Discourse.TextField valueBinding="color" placeholderKey="category.color_placeholder" maxlength="6"}}
|
||||||
{{view Discourse.ColorsView colorsBinding="view.backgroundColors" valueBinding="color"}}
|
{{view Discourse.ColorsView colorsBinding="view.backgroundColors" usedColorsBinding="view.usedBackgroundColors" valueBinding="color"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='input-prepend input-append'>
|
<div class='input-prepend input-append'>
|
||||||
|
|
|
@ -17,13 +17,16 @@ Discourse.ColorsView = Ember.ContainerView.extend({
|
||||||
createButtons: function() {
|
createButtons: function() {
|
||||||
var colors = this.get('colors');
|
var colors = this.get('colors');
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
var isUsed, usedColors = this.get('usedColors') || [];
|
||||||
|
|
||||||
colors.each(function(color) {
|
colors.each(function(color) {
|
||||||
|
isUsed = usedColors.indexOf(color.toUpperCase()) >= 0;
|
||||||
_this.addObject(Discourse.View.create({
|
_this.addObject(Discourse.View.create({
|
||||||
tagName: 'button',
|
tagName: 'button',
|
||||||
attributeBindings: ['style'],
|
attributeBindings: ['style', 'title'],
|
||||||
classNames: ['colorpicker'],
|
classNames: ['colorpicker'].concat( isUsed ? ['used-color'] : ['unused-color'] ),
|
||||||
style: 'background-color: #' + color + ';',
|
style: 'background-color: #' + color + ';',
|
||||||
|
title: isUsed ? I18n.t("js.category.already_used") : null,
|
||||||
click: function() {
|
click: function() {
|
||||||
_this.set("value", color);
|
_this.set("value", color);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,6 +29,13 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
||||||
return Discourse.SiteSettings.category_colors.split("|").map(function(i) { return i.toUpperCase(); });
|
return Discourse.SiteSettings.category_colors.split("|").map(function(i) { return i.toUpperCase(); });
|
||||||
}.property('Discourse.SiteSettings.category_colors'),
|
}.property('Discourse.SiteSettings.category_colors'),
|
||||||
|
|
||||||
|
usedBackgroundColors: function() {
|
||||||
|
return Discourse.site.categories.map(function(c) {
|
||||||
|
// If editing a category, don't include its color:
|
||||||
|
return (!this.get('category.id') || this.get('category.color').toUpperCase() !== c.color.toUpperCase()) ? c.color.toUpperCase() : null;
|
||||||
|
}, this).compact();
|
||||||
|
}.property('Discourse.site.categories', 'category.id', 'category.color'),
|
||||||
|
|
||||||
title: function() {
|
title: function() {
|
||||||
if (this.get('category.id')) return Em.String.i18n("category.edit_long");
|
if (this.get('category.id')) return Em.String.i18n("category.edit_long");
|
||||||
return Em.String.i18n("category.create");
|
return Em.String.i18n("category.create");
|
||||||
|
|
|
@ -21,9 +21,12 @@
|
||||||
|
|
||||||
.colorpicker {
|
.colorpicker {
|
||||||
border: 1px solid $darkish_gray;
|
border: 1px solid $darkish_gray;
|
||||||
width: 15px;
|
|
||||||
height: 15px;
|
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
&.used-color {
|
||||||
|
background: image-url("chosen-sprite.png") 1px 13px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -705,6 +705,7 @@ en:
|
||||||
no_description: "There is no description for this category."
|
no_description: "There is no description for this category."
|
||||||
change_in_category_topic: "visit category topic to edit the description"
|
change_in_category_topic: "visit category topic to edit the description"
|
||||||
hotness: "Hotness"
|
hotness: "Hotness"
|
||||||
|
already_used: 'This color has been used by another category'
|
||||||
|
|
||||||
flagging:
|
flagging:
|
||||||
title: 'Why are you flagging this post?'
|
title: 'Why are you flagging this post?'
|
||||||
|
|
Loading…
Reference in New Issue