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-14 10:19:00 -04:00
parent 3b1e1731dc
commit 4980cff802
12 changed files with 143 additions and 58 deletions
@@ -47,21 +47,25 @@ Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
return (!this.get('id'));
}.property('id'),
save: function() {
save: function(opts) {
if (this.get('is_base') || this.get('disableSave')) return;
var self = this;
this.set('savingStatus', I18n.t('saving'));
this.set('saving',true);
var data = { name: this.name, enabled: this.enabled };
var data = { enabled: this.enabled };
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')});
}
});
if (!opts || !opts.enabledOnly) {
data.name = this.name;
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', {
data: JSON.stringify({"color_scheme": data}),
@@ -70,10 +74,14 @@ Discourse.ColorScheme = Discourse.Model.extend(Ember.Copyable, {
contentType: 'application/json'
}).then(function(result) {
if(result.id) { self.set('id', result.id); }
self.startTrackingChanges();
_.each(self.get('colors'), function(c) {
c.startTrackingChanges();
});
if (!opts || !opts.enabledOnly) {
self.startTrackingChanges();
_.each(self.get('colors'), function(c) {
c.startTrackingChanges();
});
} else {
self.set('originals.enabled', data.enabled);
}
self.set('savingStatus', I18n.t('saved'));
self.set('saving', false);
self.notifyPropertyChange('description');
@@ -107,7 +115,7 @@ Discourse.ColorScheme.reopenClass({
name: colorScheme.name,
enabled: colorScheme.enabled,
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);
@@ -19,18 +19,37 @@ Discourse.ColorSchemeColor = Discourse.Model.extend({
this.notifyPropertyChange('hex'); // force changed property to be recalculated
},
// Whether value has changed since it was last saved.
changed: function() {
if (!this.originals) return false;
if (this.get('hex') !== this.originals['hex']) return true;
return false;
}.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() {
if (this.originals) this.set('hex', this.originals['hex']);
},
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'),
/**