Add descriptions. Make all the actions buttons. Add a revert button to colors. Add a new variable: quaternary.

This commit is contained in:
Neil Lalonde 2014-05-13 14:50:42 -04:00
parent 3b1e1731dc
commit 4980cff802
12 changed files with 143 additions and 58 deletions

View File

@ -35,16 +35,28 @@ Discourse.AdminCustomizeColorsController = Ember.ArrayController.extend({
return; return;
} }
var matches = Em.A(), self = this, baseColor; var matches = Em.A();
_.each(this.get('selectedItem.colors'), function(color){ _.each(this.get('selectedItem.colors'), function(color){
baseColor = self.get('baseColors').get(color.get('name')); if (color.get('overridden')) matches.pushObject(color);
if (color.get('hex') !== baseColor.get('hex')) matches.pushObject(color);
}); });
this.set('colors', matches); this.set('colors', matches);
}.observes('onlyOverridden'), }.observes('onlyOverridden'),
updateEnabled: function() {
var selectedItem = this.get('selectedItem');
if (selectedItem.get('enabled')) {
this.get('model').forEach(function(c) {
if (c !== selectedItem) {
c.set('enabled', false);
c.startTrackingChanges();
c.notifyPropertyChange('description');
}
});
}
},
actions: { actions: {
selectColorScheme: function(colorScheme) { selectColorScheme: function(colorScheme) {
if (this.get('selectedItem')) { this.get('selectedItem').set('selected', false); } if (this.get('selectedItem')) { this.get('selectedItem').set('selected', false); }
@ -63,22 +75,24 @@ Discourse.AdminCustomizeColorsController = Ember.ArrayController.extend({
this.set('onlyOverridden', false); this.set('onlyOverridden', false);
}, },
revert: function(color) {
color.revert();
},
undo: function(color) { undo: function(color) {
color.undo(); color.undo();
}, },
save: function() { toggleEnabled: function() {
var selectedItem = this.get('selectedItem'); var selectedItem = this.get('selectedItem');
selectedItem.save(); selectedItem.toggleProperty('enabled');
if (selectedItem.get('enabled')) { selectedItem.save({enabledOnly: true});
this.get('model').forEach(function(c) { this.updateEnabled();
if (c !== selectedItem) { },
c.set('enabled', false);
c.startTrackingChanges(); save: function() {
c.notifyPropertyChange('description'); this.get('selectedItem').save();
} this.updateEnabled();
});
}
}, },
copy: function(colorScheme) { copy: function(colorScheme) {

View File

@ -47,21 +47,25 @@ Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
return (!this.get('id')); return (!this.get('id'));
}.property('id'), }.property('id'),
save: function() { save: function(opts) {
if (this.get('is_base') || this.get('disableSave')) return; if (this.get('is_base') || this.get('disableSave')) return;
var self = this; var self = this;
this.set('savingStatus', I18n.t('saving')); this.set('savingStatus', I18n.t('saving'));
this.set('saving',true); this.set('saving',true);
var data = { name: this.name, enabled: this.enabled }; var data = { enabled: this.enabled };
data.colors = []; if (!opts || !opts.enabledOnly) {
_.each(this.get('colors'), function(c) { data.name = this.name;
if (!self.id || c.get('changed')) {
data.colors.pushObject({name: c.get('name'), hex: c.get('hex')}); data.colors = [];
} _.each(this.get('colors'), function(c) {
}); if (!self.id || c.get('changed')) {
data.colors.pushObject({name: c.get('name'), hex: c.get('hex')});
}
});
}
return Discourse.ajax("/admin/color_schemes" + (this.id ? '/' + this.id : '') + '.json', { return Discourse.ajax("/admin/color_schemes" + (this.id ? '/' + this.id : '') + '.json', {
data: JSON.stringify({"color_scheme": data}), data: JSON.stringify({"color_scheme": data}),
@ -70,10 +74,14 @@ Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
contentType: 'application/json' contentType: 'application/json'
}).then(function(result) { }).then(function(result) {
if(result.id) { self.set('id', result.id); } if(result.id) { self.set('id', result.id); }
self.startTrackingChanges(); if (!opts || !opts.enabledOnly) {
_.each(self.get('colors'), function(c) { self.startTrackingChanges();
c.startTrackingChanges(); _.each(self.get('colors'), function(c) {
}); c.startTrackingChanges();
});
} else {
self.set('originals.enabled', data.enabled);
}
self.set('savingStatus', I18n.t('saved')); self.set('savingStatus', I18n.t('saved'));
self.set('saving', false); self.set('saving', false);
self.notifyPropertyChange('description'); self.notifyPropertyChange('description');
@ -107,7 +115,7 @@ Discourse.ColorScheme.reopenClass({
name: colorScheme.name, name: colorScheme.name,
enabled: colorScheme.enabled, enabled: colorScheme.enabled,
is_base: colorScheme.is_base, is_base: colorScheme.is_base,
colors: colorScheme.colors.map(function(c) { return Discourse.ColorSchemeColor.create({name: c.name, hex: c.hex}); }) colors: colorScheme.colors.map(function(c) { return Discourse.ColorSchemeColor.create({name: c.name, hex: c.hex, default_hex: c.default_hex}); })
})); }));
}); });
colorSchemes.set('loading', false); colorSchemes.set('loading', false);

View File

@ -19,18 +19,37 @@ Discourse.ColorSchemeColor = Discourse.Model.extend({
this.notifyPropertyChange('hex'); // force changed property to be recalculated this.notifyPropertyChange('hex'); // force changed property to be recalculated
}, },
// Whether value has changed since it was last saved.
changed: function() { changed: function() {
if (!this.originals) return false; if (!this.originals) return false;
if (this.get('hex') !== this.originals['hex']) return true; if (this.get('hex') !== this.originals['hex']) return true;
return false; return false;
}.property('hex'), }.property('hex'),
// Whether the current value is different than Discourse's default color scheme.
overridden: function() {
return this.get('hex') !== this.get('default_hex');
}.property('hex', 'default_hex'),
// Whether the saved value is different than Discourse's default color scheme.
savedIsOverriden: function() {
return this.get('originals').hex !== this.get('default_hex');
}.property('hex', 'default_hex'),
revert: function() {
this.set('hex', this.get('default_hex'));
},
undo: function() { undo: function() {
if (this.originals) this.set('hex', this.originals['hex']); if (this.originals) this.set('hex', this.originals['hex']);
}, },
translatedName: function() { translatedName: function() {
return I18n.t('admin.customize.colors.' + this.get('name')); return I18n.t('admin.customize.colors.' + this.get('name') + '.name');
}.property('name'),
description: function() {
return I18n.t('admin.customize.colors.' + this.get('name') + '.description');
}.property('name'), }.property('name'),
/** /**

View File

@ -18,10 +18,16 @@
<div class="controls"> <div class="controls">
<button {{action save}} {{bind-attr disabled="disableSave"}} class='btn'>{{i18n admin.customize.save}}</button> <button {{action save}} {{bind-attr disabled="disableSave"}} class='btn'>{{i18n admin.customize.save}}</button>
<span {{bind-attr class=":saving savingStatus::hidden" }}>{{savingStatus}}</span> <button {{action toggleEnabled}} class="btn">
{{#if enabled}}
{{i18n disable}}
{{else}}
{{i18n enable}}
{{/if}}
</button>
<button {{action copy this}} class='btn'><i class="fa fa-copy"></i> {{i18n admin.customize.copy}}</button> <button {{action copy this}} class='btn'><i class="fa fa-copy"></i> {{i18n admin.customize.copy}}</button>
<span>{{view Ember.Checkbox checkedBinding="enabled"}} {{i18n admin.customize.enabled}}</span> <button {{action destroy}} class='btn btn-danger'><i class="fa fa-trash-o"></i> {{i18n admin.customize.delete}}</button>
<a {{action destroy}} class='delete-link'>{{i18n admin.customize.delete}}</a> <span {{bind-attr class=":saving savingStatus::hidden" }}>{{savingStatus}}</span>
</div> </div>
{{/with}} {{/with}}
@ -48,10 +54,15 @@
<tbody> <tbody>
{{#each colors}} {{#each colors}}
<tr {{bind-attr class="changed valid:valid:invalid"}}> <tr {{bind-attr class="changed valid:valid:invalid"}}>
<td class="name" {{bind-attr title="name"}}>{{translatedName}}</td> <td class="name" {{bind-attr title="name"}}>
<b>{{translatedName}}</b>
<br/>
<span class="description">{{description}}</span>
</td>
<td class="hex">{{color-input hexValue=hex brightnessValue=brightness valid=valid}}</td> <td class="hex">{{color-input hexValue=hex brightnessValue=brightness valid=valid}}</td>
<td class="changed"> <td class="actions">
<button {{bind-attr class=":btn :undo changed::invisible"}} {{action undo this}}>undo</button> <button {{bind-attr class=":btn :revert savedIsOverriden::invisible"}} {{action revert this}} title="{{i18n admin.customize.colors.revert_title}}">{{i18n revert}}</button>
<button {{bind-attr class=":btn :undo changed::invisible"}} {{action undo this}} title="{{i18n admin.customize.colors.undo_title}}">{{i18n undo}}</button>
</td> </td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -155,7 +155,7 @@
} }
li a.active { li a.active {
color: $secondary; color: $secondary;
background-color: $danger; background-color: $quaternary;
} }
} }
@ -435,13 +435,11 @@ section.details {
.colors { .colors {
thead th { border: none; } thead th { border: none; }
td.hex { width: 100px; } td.hex { width: 100px; }
td.changed { width: 300px; } td.actions { width: 200px; }
.hex-input { width: 80px; } .hex-input { width: 80px; margin-bottom: 0; }
.hex { text-align: center; } .hex { text-align: center; }
.description { color: scale-color($primary, $lightness: 50%); }
.changed .name {
color: scale-color($highlight, $lightness: -50%);
}
.invalid .hex input { .invalid .hex input {
background-color: white; background-color: white;
color: black; color: black;

View File

@ -30,13 +30,13 @@
font-size: 16px; font-size: 16px;
line-height: 20px; line-height: 20px;
&:hover { &:hover {
color: $danger; color: $quaternary;
background-color: scale-color($danger, $lightness: 70%); background-color: scale-color($quaternary, $lightness: 70%);
} }
} }
&.active > a, > a.active { &.active > a, > a.active {
color: $secondary; color: $secondary;
background-color: $danger; background-color: $quaternary;
} }
} }
} }
@ -69,7 +69,7 @@
.active > a, .active > a,
.active .fa-chevron-right { .active .fa-chevron-right {
color: $secondary; color: $secondary;
background-color: $danger; background-color: $quaternary;
} }
.count { .count {
font-size: 12px; font-size: 12px;

View File

@ -1,6 +1,7 @@
$primary: #333333 !default; $primary: #333333 !default;
$secondary: #ffffff !default; $secondary: #ffffff !default;
$tertiary: #0088cc !default; $tertiary: #0088cc !default;
$quaternary: #e45735 !default;
$header_background: #ffffff !default; $header_background: #ffffff !default;
$header_primary: #333333 !default; $header_primary: #333333 !default;
$highlight: #ffff4d !default; $highlight: #ffff4d !default;

View File

@ -59,7 +59,7 @@ animation: modal .25s;
.modal-header { .modal-header {
border-bottom: 1px solid scale-color($primary, $lightness: 90%); border-bottom: 1px solid scale-color($primary, $lightness: 90%);
h3 { h3 {
color: $danger; color: $quaternary;
font-size: 20px; font-size: 20px;
padding: 10px 15px 7px; padding: 10px 15px 7px;
} }

View File

@ -50,7 +50,7 @@
} }
.modal-header { .modal-header {
h3 { h3 {
color: $danger; color: $quaternary;
font-size: 15px; font-size: 15px;
padding: 0 0 0 20px; padding: 0 0 0 20px;
} }

View File

@ -1,7 +1,11 @@
class ColorSchemeColorSerializer < ApplicationSerializer class ColorSchemeColorSerializer < ApplicationSerializer
attributes :name, :hex attributes :name, :hex, :default_hex
def hex def hex
object.hex # otherwise something crazy is returned object.hex # otherwise something crazy is returned
end end
def default_hex
ColorScheme.base_colors[object.name]
end
end end

View File

@ -19,8 +19,8 @@ class ColorSchemeRevisor
ColorScheme.where('id != ?', @color_scheme.id).update_all enabled: false ColorScheme.where('id != ?', @color_scheme.id).update_all enabled: false
end end
@color_scheme.name = @params[:name] @color_scheme.name = @params[:name] if @params.has_key?(:name)
@color_scheme.enabled = @params[:enabled] @color_scheme.enabled = @params[:enabled] if @params.has_key?(:enabled)
new_version = false new_version = false
if @params[:colors] if @params[:colors]

View File

@ -161,6 +161,11 @@ en:
uploading: "Uploading..." uploading: "Uploading..."
uploaded: "Uploaded!" uploaded: "Uploaded!"
enable: "Enable"
disable: "Disable"
undo: "Undo"
revert: "Revert"
choose_topic: choose_topic:
none_found: "No topics found." none_found: "No topics found."
title: title:
@ -1465,15 +1470,40 @@ en:
new_name: "New Color Scheme" new_name: "New Color Scheme"
copy_name_prefix: "Copy of" copy_name_prefix: "Copy of"
delete_confirm: "Delete this color scheme?" delete_confirm: "Delete this color scheme?"
primary: 'primary' undo: "undo"
secondary: 'secondary' undo_title: "Undo your changes to this color since the last time it was saved."
tertiary: 'tertiary' revert: "revert"
header_background: "header background" revert_title: "Reset this color to Discourse's default color scheme."
header_primary: "header primary" primary:
highlight: 'highlight' name: 'primary'
danger: 'danger' description: 'Most text, icons, and borders.'
success: 'success' secondary:
love: 'love' name: 'secondary'
description: 'The main background color, and text color of some buttons.'
tertiary:
name: 'tertiary'
description: 'Links, some buttons, notifications, and accent color.'
quaternary:
name: "quaternary"
description: "Navigation links."
header_background:
name: "header background"
description: "Background color of the site's header."
header_primary:
name: "header primary"
description: "Text and icons in the site's header."
highlight:
name: 'highlight'
description: 'The background color of highlighted elements on the page, such as posts and topics.'
danger:
name: 'danger'
description: 'Highlight color for actions like deleting posts and topics.'
success:
name: 'success'
description: 'Used to indicate an action was successful.'
love:
name: 'love'
description: "The like button's color."
email: email: