2014-03-21 06:55:32 +04:00
|
|
|
var validator = window.validator;
|
|
|
|
|
|
|
|
import BaseModel from 'ghost/models/base';
|
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
var SettingsModel = BaseModel.extend({
|
2014-03-21 06:55:32 +04:00
|
|
|
url: BaseModel.apiRoot + '/settings/?type=blog,theme,app',
|
|
|
|
|
|
|
|
title: null,
|
|
|
|
description: null,
|
|
|
|
email: null,
|
|
|
|
logo: null,
|
|
|
|
cover: null,
|
|
|
|
defaultLang: null,
|
|
|
|
postsPerPage: null,
|
|
|
|
forceI18n: null,
|
|
|
|
permalinks: null,
|
|
|
|
activeTheme: null,
|
|
|
|
activeApps: null,
|
|
|
|
installedApps: null,
|
|
|
|
availableThemes: null,
|
|
|
|
availableApps: null,
|
|
|
|
|
|
|
|
validate: function () {
|
|
|
|
var validationErrors = [],
|
|
|
|
postsPerPage;
|
|
|
|
|
|
|
|
if (!validator.isLength(this.get('title'), 0, 150)) {
|
|
|
|
validationErrors.push({message: "Title is too long", el: 'title'});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(this.get('description'), 0, 200)) {
|
|
|
|
validationErrors.push({message: "Description is too long", el: 'description'});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isEmail(this.get('email')) || !validator.isLength(this.get('email'), 0, 254)) {
|
|
|
|
validationErrors.push({message: "Please supply a valid email address", el: 'email'});
|
|
|
|
}
|
|
|
|
|
|
|
|
postsPerPage = this.get('postsPerPage');
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage > 1000) {
|
|
|
|
validationErrors.push({message: "Please use a number less than 1000", el: 'postsPerPage'});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage < 0) {
|
|
|
|
validationErrors.push({message: "Please use a number greater than 0", el: 'postsPerPage'});
|
|
|
|
}
|
|
|
|
|
|
|
|
return validationErrors;
|
2014-04-08 02:01:46 +04:00
|
|
|
},
|
|
|
|
exportPath: BaseModel.adminRoot + '/export/',
|
|
|
|
importFrom: function (file) {
|
|
|
|
var formData = new FormData();
|
|
|
|
formData.append('importfile', file);
|
|
|
|
return ic.ajax.request(BaseModel.apiRoot + '/db/', {
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
|
|
|
},
|
|
|
|
type: 'POST',
|
|
|
|
data: formData,
|
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
contentType: false,
|
|
|
|
processData: false
|
|
|
|
});
|
|
|
|
},
|
|
|
|
sendTestEmail: function () {
|
|
|
|
return ic.ajax.request(BaseModel.apiRoot + '/mail/test/', {
|
|
|
|
type: 'POST',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': $('meta[name="csrf-param"]').attr('content')
|
|
|
|
}
|
|
|
|
});
|
2014-03-21 06:55:32 +04:00
|
|
|
}
|
2014-04-08 02:01:46 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default SettingsModel;
|