2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-05-11 18:35:55 +03:00
|
|
|
import randomPassword from 'ghost/utils/random-password';
|
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
export default Ember.Controller.extend({
|
|
|
|
notifications: Ember.inject.service(),
|
|
|
|
|
2014-12-30 05:11:24 +03:00
|
|
|
selectedTheme: null,
|
|
|
|
|
2015-02-09 18:57:50 +03:00
|
|
|
logoImageSource: Ember.computed('model.logo', function () {
|
|
|
|
return this.get('model.logo') || '';
|
|
|
|
}),
|
|
|
|
|
|
|
|
coverImageSource: Ember.computed('model.cover', function () {
|
|
|
|
return this.get('model.cover') || '';
|
|
|
|
}),
|
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
isDatedPermalinks: Ember.computed('model.permalinks', {
|
|
|
|
set: function (key, value) {
|
2014-12-30 05:11:24 +03:00
|
|
|
this.set('model.permalinks', value ? '/:year/:month/:day/:slug/' : '/:slug/');
|
2014-03-21 06:55:32 +04:00
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
var slugForm = this.get('model.permalinks');
|
|
|
|
return slugForm !== '/:slug/';
|
|
|
|
},
|
|
|
|
get: function () {
|
|
|
|
var slugForm = this.get('model.permalinks');
|
2014-03-21 06:55:32 +04:00
|
|
|
|
2015-06-03 05:56:42 +03:00
|
|
|
return slugForm !== '/:slug/';
|
|
|
|
}
|
2014-07-30 05:57:19 +04:00
|
|
|
}),
|
2014-03-21 06:55:32 +04:00
|
|
|
|
2014-07-30 05:57:19 +04:00
|
|
|
themes: Ember.computed(function () {
|
2014-12-30 05:11:24 +03:00
|
|
|
return this.get('model.availableThemes').reduce(function (themes, t) {
|
2014-06-20 06:29:49 +04:00
|
|
|
var theme = {};
|
|
|
|
|
|
|
|
theme.name = t.name;
|
|
|
|
theme.label = t.package ? t.package.name + ' - ' + t.package.version : t.name;
|
|
|
|
theme.package = t.package;
|
|
|
|
theme.active = !!t.active;
|
|
|
|
|
|
|
|
themes.push(theme);
|
|
|
|
|
|
|
|
return themes;
|
|
|
|
}, []);
|
2014-07-30 05:57:19 +04:00
|
|
|
}).readOnly(),
|
2014-06-20 06:29:49 +04:00
|
|
|
|
2015-05-11 18:35:55 +03:00
|
|
|
generatePassword: Ember.observer('model.isPrivate', function () {
|
|
|
|
if (this.get('model.isPrivate') && this.get('model.isDirty')) {
|
|
|
|
this.get('model').set('password', randomPassword());
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2014-03-21 06:55:32 +04:00
|
|
|
actions: {
|
2014-06-18 00:20:54 +04:00
|
|
|
save: function () {
|
2015-05-26 05:10:50 +03:00
|
|
|
var notifications = this.get('notifications');
|
2014-03-21 06:55:32 +04:00
|
|
|
|
2014-06-20 06:29:49 +04:00
|
|
|
return this.get('model').save().then(function (model) {
|
2015-05-26 05:10:50 +03:00
|
|
|
notifications.showSuccess('Settings successfully saved.');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2014-06-20 06:29:49 +04:00
|
|
|
return model;
|
2014-06-24 10:33:24 +04:00
|
|
|
}).catch(function (errors) {
|
2015-05-26 05:10:50 +03:00
|
|
|
notifications.showErrors(errors);
|
2014-06-24 10:33:24 +04:00
|
|
|
});
|
2014-03-21 06:55:32 +04:00
|
|
|
},
|
2014-08-19 02:56:28 +04:00
|
|
|
|
|
|
|
checkPostsPerPage: function () {
|
2014-12-30 05:11:24 +03:00
|
|
|
var postsPerPage = this.get('model.postsPerPage');
|
|
|
|
|
|
|
|
if (postsPerPage < 1 || postsPerPage > 1000 || isNaN(postsPerPage)) {
|
|
|
|
this.set('model.postsPerPage', 5);
|
2014-08-19 02:56:28 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 06:55:32 +04:00
|
|
|
}
|
|
|
|
});
|