2015-02-12 21:22:32 -07:00
|
|
|
import Ember from 'ember';
|
2015-08-10 09:43:49 -06:00
|
|
|
import SettingsSaveMixin from 'ghost/mixins/settings-save';
|
2015-05-11 09:35:55 -06:00
|
|
|
import randomPassword from 'ghost/utils/random-password';
|
|
|
|
|
2016-01-19 07:03:27 -06:00
|
|
|
const {
|
|
|
|
Controller,
|
|
|
|
computed,
|
|
|
|
inject: {service},
|
|
|
|
observer
|
|
|
|
} = Ember;
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
export default Controller.extend(SettingsSaveMixin, {
|
2015-11-18 10:50:48 +00:00
|
|
|
|
|
|
|
showUploadLogoModal: false,
|
|
|
|
showUploadCoverModal: false,
|
|
|
|
|
2016-01-19 07:03:27 -06:00
|
|
|
notifications: service(),
|
|
|
|
config: service(),
|
2015-06-13 09:34:09 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
selectedTheme: computed('model.activeTheme', 'themes', function () {
|
|
|
|
let activeTheme = this.get('model.activeTheme');
|
|
|
|
let themes = this.get('themes');
|
|
|
|
let selectedTheme;
|
|
|
|
|
|
|
|
themes.forEach((theme) => {
|
2015-06-13 09:34:09 -05:00
|
|
|
if (theme.name === activeTheme) {
|
|
|
|
selectedTheme = theme;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return selectedTheme;
|
|
|
|
}),
|
2014-12-29 21:11:24 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
logoImageSource: computed('model.logo', function () {
|
2015-02-09 15:57:50 +00:00
|
|
|
return this.get('model.logo') || '';
|
|
|
|
}),
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
coverImageSource: computed('model.cover', function () {
|
2015-02-09 15:57:50 +00:00
|
|
|
return this.get('model.cover') || '';
|
|
|
|
}),
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
isDatedPermalinks: computed('model.permalinks', {
|
|
|
|
set(key, value) {
|
2014-12-29 21:11:24 -05:00
|
|
|
this.set('model.permalinks', value ? '/:year/:month/:day/:slug/' : '/:slug/');
|
2014-03-20 21:55:32 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
let slugForm = this.get('model.permalinks');
|
2015-06-02 20:56:42 -06:00
|
|
|
return slugForm !== '/:slug/';
|
|
|
|
},
|
2015-10-28 11:36:45 +00:00
|
|
|
|
|
|
|
get() {
|
|
|
|
let slugForm = this.get('model.permalinks');
|
2014-03-20 21:55:32 -05:00
|
|
|
|
2015-06-02 20:56:42 -06:00
|
|
|
return slugForm !== '/:slug/';
|
|
|
|
}
|
2014-07-29 19:57:19 -06:00
|
|
|
}),
|
2014-03-20 21:55:32 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
themes: computed(function () {
|
2014-12-29 21:11:24 -05:00
|
|
|
return this.get('model.availableThemes').reduce(function (themes, t) {
|
2015-10-28 11:36:45 +00:00
|
|
|
let theme = {};
|
2014-06-20 02:29:49 +00:00
|
|
|
|
|
|
|
theme.name = t.name;
|
2015-10-28 11:36:45 +00:00
|
|
|
theme.label = t.package ? `${t.package.name} - ${t.package.version}` : t.name;
|
2014-06-20 02:29:49 +00:00
|
|
|
theme.package = t.package;
|
|
|
|
theme.active = !!t.active;
|
|
|
|
|
|
|
|
themes.push(theme);
|
|
|
|
|
|
|
|
return themes;
|
|
|
|
}, []);
|
2014-07-29 19:57:19 -06:00
|
|
|
}).readOnly(),
|
2014-06-20 02:29:49 +00:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
generatePassword: observer('model.isPrivate', function () {
|
2015-09-02 10:01:20 +01:00
|
|
|
this.get('model.errors').remove('password');
|
2015-09-03 12:06:50 +01:00
|
|
|
if (this.get('model.isPrivate') && this.get('model.hasDirtyAttributes')) {
|
2015-05-11 09:35:55 -06:00
|
|
|
this.get('model').set('password', randomPassword());
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
save() {
|
|
|
|
let notifications = this.get('notifications');
|
|
|
|
let config = this.get('config');
|
2015-07-07 18:14:23 +01:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
return this.get('model').save().then((model) => {
|
2015-08-10 09:43:49 -06:00
|
|
|
config.set('blogTitle', model.get('title'));
|
2014-03-20 21:55:32 -05:00
|
|
|
|
2015-08-10 09:43:49 -06:00
|
|
|
return model;
|
2015-10-28 11:36:45 +00:00
|
|
|
}).catch((error) => {
|
2015-08-10 09:43:49 -06:00
|
|
|
if (error) {
|
2015-10-07 15:44:23 +01:00
|
|
|
notifications.showAPIError(error, {key: 'settings.save'});
|
2015-08-10 09:43:49 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2014-06-24 06:33:24 +00:00
|
|
|
|
2015-08-10 09:43:49 -06:00
|
|
|
actions: {
|
2015-10-28 11:36:45 +00:00
|
|
|
validate(property) {
|
|
|
|
this.get('model').validate({property});
|
2014-03-20 21:55:32 -05:00
|
|
|
},
|
2014-08-18 18:56:28 -04:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
checkPostsPerPage() {
|
|
|
|
let postsPerPage = this.get('model.postsPerPage');
|
2014-12-29 21:11:24 -05:00
|
|
|
|
|
|
|
if (postsPerPage < 1 || postsPerPage > 1000 || isNaN(postsPerPage)) {
|
|
|
|
this.set('model.postsPerPage', 5);
|
2014-08-18 18:56:28 -04:00
|
|
|
}
|
2015-06-13 09:34:09 -05:00
|
|
|
},
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
setTheme(theme) {
|
2015-06-13 09:34:09 -05:00
|
|
|
this.set('model.activeTheme', theme.name);
|
2015-11-18 10:50:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleUploadCoverModal() {
|
|
|
|
this.toggleProperty('showUploadCoverModal');
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleUploadLogoModal() {
|
|
|
|
this.toggleProperty('showUploadLogoModal');
|
2014-08-18 18:56:28 -04:00
|
|
|
}
|
2014-03-20 21:55:32 -05:00
|
|
|
}
|
|
|
|
});
|