diff --git a/app/assets/javascripts/admin/controllers/admin-customize-themes-edit.js.es6 b/app/assets/javascripts/admin/controllers/admin-customize-themes-edit.js.es6 index aab84d2ab92..d6526a6b5f1 100644 --- a/app/assets/javascripts/admin/controllers/admin-customize-themes-edit.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-customize-themes-edit.js.es6 @@ -1,5 +1,5 @@ import { url } from 'discourse/lib/computed'; -import { default as computed } from 'ember-addons/ember-computed-decorators'; +import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; export default Ember.Controller.extend({ maximized: false, @@ -11,6 +11,43 @@ export default Ember.Controller.extend({ {id: 2, name: I18n.t('admin.customize.theme.mobile')} ], + @computed('onlyOverridden') + showCommon() { + return this.shouldShow('common'); + }, + + @computed('onlyOverridden') + showDesktop() { + return this.shouldShow('desktop'); + }, + + @computed('onlyOverridden') + showMobile() { + return this.shouldShow('mobile'); + }, + + @observes('onlyOverridden') + onlyOverriddenChanged() { + if (this.get('onlyOverridden')) { + if (!this.get('model').hasEdited(this.get('currentTargetName'), this.get('fieldName'))) { + let target = (this.get('showCommon') && 'common') || + (this.get('showDesktop') && 'desktop') || + (this.get('showMobile') && 'mobile'); + + let fields = this.get('model.theme_fields'); + let field = fields && fields.find(f => (f.target === target)); + this.replaceRoute('adminCustomizeThemes.edit', this.get('model.id'), target, field && field.name); + } + } + }, + + shouldShow(target){ + if(!this.get("onlyOverridden")) { + return true; + } + return this.get("model").hasEdited(target); + }, + currentTarget: 0, setTargetName: function(name) { @@ -54,9 +91,8 @@ export default Ember.Controller.extend({ } }, - - @computed("currentTarget") - fields(target) { + @computed("currentTarget", "onlyOverridden") + fields(target, onlyOverridden) { let fields = [ "scss", "head_tag", "header", "after_header", "body_tag", "footer" ]; @@ -65,6 +101,12 @@ export default Ember.Controller.extend({ fields.push("embedded_scss"); } + if (onlyOverridden) { + const model = this.get("model"); + const targetName = this.get("currentTargetName"); + fields = fields.filter(name => model.hasEdited(targetName, name)); + } + return fields.map(name=>{ let hash = { key: (`admin.customize.theme.${name}.text`), diff --git a/app/assets/javascripts/admin/models/theme.js.es6 b/app/assets/javascripts/admin/models/theme.js.es6 index 463d54b2586..e2c05912c8c 100644 --- a/app/assets/javascripts/admin/models/theme.js.es6 +++ b/app/assets/javascripts/admin/models/theme.js.es6 @@ -20,6 +20,15 @@ const Theme = RestModel.extend({ return hash; }, + hasEdited(target, name){ + if (name) { + return !Em.isEmpty(this.getField(target, name)); + } else { + let fields = this.get("theme_fields") || []; + return fields.any(field => (field.target === target && !Em.isEmpty(field.value))); + } + }, + getField(target, name) { let themeFields = this.get("themeFields"); let key = target + " " + name; diff --git a/app/assets/javascripts/admin/templates/customize-themes-edit.hbs b/app/assets/javascripts/admin/templates/customize-themes-edit.hbs index 88ec4e838bd..18cf25ee698 100644 --- a/app/assets/javascripts/admin/templates/customize-themes-edit.hbs +++ b/app/assets/javascripts/admin/templates/customize-themes-edit.hbs @@ -2,25 +2,41 @@