mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-11 00:37:55 +03:00
Working settings
This commit is contained in:
parent
28bfa8feeb
commit
1af28bc2ac
@ -13,6 +13,18 @@
|
||||
$('.settings-content').fadeOut().delay(250);
|
||||
$(newPage).fadeIn();
|
||||
|
||||
},
|
||||
|
||||
defaultSettings = {
|
||||
title: 'My Blog',
|
||||
description: ''
|
||||
},
|
||||
|
||||
getSettings = function () {
|
||||
return $.extend(defaultSettings, {
|
||||
title : $('#blog-title').val(),
|
||||
description : $('#blog-description').val()
|
||||
});
|
||||
};
|
||||
|
||||
$(document).ready(function () {
|
||||
@ -31,22 +43,18 @@
|
||||
checkboxClass: 'icheckbox_square-grey'
|
||||
});
|
||||
|
||||
$('.button-save').click(function(e){
|
||||
$('.button-save').click(function (e) {
|
||||
e.preventDefault();
|
||||
console.log(getSettings());
|
||||
})
|
||||
var data = getSettings();
|
||||
$.ajax({
|
||||
method: 'PUT',
|
||||
url: '/api/v0.1/settings/edit',
|
||||
data: data,
|
||||
success: function (res, xhr, c) {
|
||||
console.log(xhr, c);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var defaultSettings = {
|
||||
title: 'My Blog',
|
||||
description: ''
|
||||
};
|
||||
|
||||
function getSettings () {
|
||||
return $.extend(defaultSettings, {
|
||||
title : $('#blog-title').val(),
|
||||
description : $('#blog-description').val()
|
||||
});
|
||||
}
|
||||
|
||||
}(jQuery));
|
@ -131,10 +131,16 @@
|
||||
});
|
||||
},
|
||||
'settings': function (req, res) {
|
||||
res.render('settings', {
|
||||
bodyClass: 'settings',
|
||||
adminNav: setSelected(adminNavbar, 'settings')
|
||||
});
|
||||
api.settings.browse()
|
||||
.then(function (settings) {
|
||||
settings = settings.toJSON();
|
||||
settings = _.object(_.pluck(settings, 'key'), _.pluck(settings, 'value'));
|
||||
res.render('settings', {
|
||||
bodyClass: 'settings',
|
||||
adminNav: setSelected(adminNavbar, 'settings'),
|
||||
settings: settings
|
||||
});
|
||||
});
|
||||
},
|
||||
'debug': { /* ugly temporary stuff for managing the app before it's properly finished */
|
||||
index: function (req, res) {
|
||||
|
@ -27,11 +27,12 @@
|
||||
</section>
|
||||
</header>
|
||||
<section class="content">
|
||||
{{#with settings}}
|
||||
<form id="settings-general">
|
||||
<fieldset>
|
||||
<label>
|
||||
<b>Blog Title</b>
|
||||
<input id="blog-title" type="text" value="John O'Nolan" />
|
||||
<input id="blog-title" type="text" value="{{title}}" />
|
||||
<p>How your blog name appears on the site</p>
|
||||
</label>
|
||||
|
||||
@ -81,7 +82,7 @@
|
||||
|
||||
</fieldset>
|
||||
|
||||
|
||||
{{/with}}
|
||||
</form>
|
||||
</section>
|
||||
</section>
|
||||
|
@ -63,11 +63,11 @@
|
||||
browse: function (options) {
|
||||
return when.call(ghost.dataProvider().settings.browse, options);
|
||||
},
|
||||
read: function (key) {
|
||||
return when.call(ghost.dataProvider().settings.read, key);
|
||||
read: function (options) {
|
||||
return when.call(ghost.dataProvider().settings.read, options.key);
|
||||
},
|
||||
edit: function (key, value) {
|
||||
return when.call(ghost.dataProvider().settings.edit, key, value);
|
||||
edit: function (options) {
|
||||
return when.call(ghost.dataProvider().settings.edit, options);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
models = require('./models'),
|
||||
bcrypt = require('bcrypt'),
|
||||
when = require("when"),
|
||||
_ = require("underscore"),
|
||||
DataProvider,
|
||||
instance;
|
||||
|
||||
@ -128,27 +129,23 @@
|
||||
DataProvider.prototype.settings = function () { };
|
||||
|
||||
DataProvider.prototype.settings.browse = function (_args, callback) {
|
||||
models.Settings.forge(_args).fetch().then(function(settings){
|
||||
models.Settings.forge(_args).fetch().then(function (settings) {
|
||||
callback(null, settings);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
DataProvider.prototype.settings.read = function (_key, callback) {
|
||||
models.Settings.forge({ key: _key }).fetch().then(function(setting){
|
||||
models.Setting.forge({ key: _key }).fetch().then(function (setting) {
|
||||
callback(null, setting);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
DataProvider.prototype.settings.edit = function (_key, _value, callback) {
|
||||
var promise;
|
||||
if (typeof _key === 'object') {
|
||||
promise = when.all(_.map(settings, function (value, key) {
|
||||
models.Setting.forge({ key: _key }).set('value', _value).save();
|
||||
}));
|
||||
} else {
|
||||
promise = models.Setting.forge({ key: _key }).set('value', _value).save();
|
||||
}
|
||||
promise.then(function (settings) {
|
||||
DataProvider.prototype.settings.edit = function (_data, callback) {
|
||||
when.all(_.map(_data, function (value, key) {
|
||||
return models.Setting.forge({ key: key }).fetch().then(function (setting) {
|
||||
return setting.set('value', value).save();
|
||||
});
|
||||
})).then(function (settings) {
|
||||
callback(null, settings);
|
||||
}, callback);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user