Skip to content

Commit

Permalink
correctly pick the selected theme based on what is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed May 15, 2017
1 parent e865a44 commit f114d63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
@@ -1,6 +1,6 @@
import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
import { listThemes, previewTheme, setLocalTheme } from 'discourse/lib/theme-selector';
import { currentThemeKey, listThemes, previewTheme, setLocalTheme } from 'discourse/lib/theme-selector';
import { popupAjaxError } from 'discourse/lib/ajax-error';

export default Ember.Controller.extend(PreferencesTabController, {
Expand Down Expand Up @@ -31,6 +31,11 @@ export default Ember.Controller.extend(PreferencesTabController, {
return this.siteSettings.available_locales.split('|').map(s => ({ name: s, value: s }));
},

@computed()
themeKey() {
return currentThemeKey();
},

userSelectableThemes: function(){
return listThemes(this.site);
}.property(),
Expand All @@ -40,22 +45,25 @@ export default Ember.Controller.extend(PreferencesTabController, {
return themes && themes.length > 1;
},

@observes("model.user_option.theme_key")
@observes("themeKey")
themeKeyChanged() {
let key = this.get("model.user_option.theme_key");
let key = this.get("themeKey");
previewTheme(key);
},

actions: {
save() {
this.set('saved', false);
const makeThemeDefault = this.get("makeThemeDefault");
if (makeThemeDefault) {
this.set('model.user_option.theme_key', this.get('themeKey'));
}

return this.get('model').save(this.get('saveAttrNames')).then(() => {
this.set('saved', true);

if (!makeThemeDefault) {
setLocalTheme(this.get('model.user_option.theme_key'), this.get('model.user_option.theme_key_seq'));
setLocalTheme(this.get('themeKey'), this.get('model.user_option.theme_key_seq'));
}

}).catch(popupAjaxError);
Expand Down
Expand Up @@ -2,7 +2,7 @@
<div class="control-group theme">
<label class="control-label">{{i18n 'user.theme'}}</label>
<div class="controls">
{{combo-box content=userSelectableThemes value=model.user_option.theme_key}}
{{combo-box content=userSelectableThemes value=themeKey}}
</div>
<div class="controls">
{{preference-checkbox labelKey="user.theme_default_on_all_devices" checked=makeThemeDefault}}
Expand Down

0 comments on commit f114d63

Please sign in to comment.