0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Adding theme switcher to settings/general

closes #488 and #107
- added dropdown for theme selection on general page
- added GET /api/v0.1/themes to retrieve available themes
- modified settings model to get available themes
- modified updateSettignsCache to remove path from settings.activeTheme
This commit is contained in:
Sebastian 2013-08-30 13:20:30 +02:00
parent 73643f6faf
commit 6294a8fc4d
4 changed files with 30 additions and 6 deletions

View file

@ -4,7 +4,7 @@
// Set the url manually and id to '0' to force PUT requests
Ghost.Models.Settings = Backbone.Model.extend({
url: '/api/v0.1/settings/',
url: Ghost.settings.apiRoot + '/settings',
id: "0",
defaults: {
title: 'My Blog',

View file

@ -0,0 +1,9 @@
/*global window, document, Ghost, $, _, Backbone */
(function () {
"use strict";
Ghost.Models.Themes = Backbone.Model.extend({
url: Ghost.settings.apiRoot + '/themes'
});
}());

View file

@ -50,6 +50,15 @@
</select>
</div>
<div class="form-group">
<label for="activeTheme"><strong>Theme</strong></label>
<select id="activeTheme" name="general[activeTheme]">
{{#each availableThemes}}
<option value="{{ name }}" {{#if active}}selected{{/if}}>{{ name }}</option>
{{/each}}
</select>
</div>
</fieldset>
<hr />

View file

@ -41,7 +41,8 @@
showContent: function (id) {
var self = this,
model;
model,
themes;
Ghost.router.navigate('/settings/' + id);
Ghost.trigger('urlchange');
@ -53,9 +54,13 @@
this.pane = new Settings[id]({ el: '.settings-content'});
if (!this.models.hasOwnProperty(this.pane.options.modelType)) {
themes = this.models.Themes = new Ghost.Models.Themes();
model = this.models[this.pane.options.modelType] = new Ghost.Models[this.pane.options.modelType]();
model.fetch().then(function () {
self.renderPane(model);
themes.fetch().then(function () {
model.fetch().then(function () {
model.set({availableThemes: themes.toJSON()});
self.renderPane(model);
});
});
} else {
model = this.models[this.pane.options.modelType];
@ -134,12 +139,13 @@
},
saveSettings: function () {
this.model.unset('availableThemes');
this.model.save({
title: this.$('#blog-title').val(),
email: this.$('#email-address').val(),
logo: this.$('#logo').attr("src"),
icon: this.$('#icon').attr("src")
icon: this.$('#icon').attr("src"),
activeTheme: this.$('#activeTheme').val()
}, {
success: this.saveSuccess,
error: this.saveError