mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
c5a8a0c860
closes #5903, refs #5409 - switch alert/notification component tests from unit to integration where appropriate - rename `notifications.closeAll` to `notifications.clearAll` to better represent it's behaviour - add concept of a "key" to alerts/notifications and ability to close only specified keys through notifications service - close duplicate alerts/notifications before showing a new one - specify a key for all existing alerts - close failure alerts on successful retries - clear all currently displayed alerts on successful sign-in
100 lines
3.0 KiB
JavaScript
100 lines
3.0 KiB
JavaScript
import Ember from 'ember';
|
|
import SettingsSaveMixin from 'ghost/mixins/settings-save';
|
|
import randomPassword from 'ghost/utils/random-password';
|
|
|
|
export default Ember.Controller.extend(SettingsSaveMixin, {
|
|
notifications: Ember.inject.service(),
|
|
config: Ember.inject.service(),
|
|
|
|
selectedTheme: Ember.computed('model.activeTheme', 'themes', function () {
|
|
var activeTheme = this.get('model.activeTheme'),
|
|
themes = this.get('themes'),
|
|
selectedTheme;
|
|
|
|
themes.forEach(function (theme) {
|
|
if (theme.name === activeTheme) {
|
|
selectedTheme = theme;
|
|
}
|
|
});
|
|
|
|
return selectedTheme;
|
|
}),
|
|
|
|
logoImageSource: Ember.computed('model.logo', function () {
|
|
return this.get('model.logo') || '';
|
|
}),
|
|
|
|
coverImageSource: Ember.computed('model.cover', function () {
|
|
return this.get('model.cover') || '';
|
|
}),
|
|
|
|
isDatedPermalinks: Ember.computed('model.permalinks', {
|
|
set: function (key, value) {
|
|
this.set('model.permalinks', value ? '/:year/:month/:day/:slug/' : '/:slug/');
|
|
|
|
var slugForm = this.get('model.permalinks');
|
|
return slugForm !== '/:slug/';
|
|
},
|
|
get: function () {
|
|
var slugForm = this.get('model.permalinks');
|
|
|
|
return slugForm !== '/:slug/';
|
|
}
|
|
}),
|
|
|
|
themes: Ember.computed(function () {
|
|
return this.get('model.availableThemes').reduce(function (themes, t) {
|
|
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;
|
|
}, []);
|
|
}).readOnly(),
|
|
|
|
generatePassword: Ember.observer('model.isPrivate', function () {
|
|
this.get('model.errors').remove('password');
|
|
if (this.get('model.isPrivate') && this.get('model.hasDirtyAttributes')) {
|
|
this.get('model').set('password', randomPassword());
|
|
}
|
|
}),
|
|
|
|
save: function () {
|
|
var notifications = this.get('notifications'),
|
|
config = this.get('config');
|
|
|
|
return this.get('model').save().then(function (model) {
|
|
config.set('blogTitle', model.get('title'));
|
|
|
|
return model;
|
|
}).catch(function (error) {
|
|
if (error) {
|
|
notifications.showAPIError(error, {key: 'settings.save'});
|
|
}
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
validate: function (property) {
|
|
this.get('model').validate({property: property});
|
|
},
|
|
|
|
checkPostsPerPage: function () {
|
|
var postsPerPage = this.get('model.postsPerPage');
|
|
|
|
if (postsPerPage < 1 || postsPerPage > 1000 || isNaN(postsPerPage)) {
|
|
this.set('model.postsPerPage', 5);
|
|
}
|
|
},
|
|
|
|
setTheme: function (theme) {
|
|
this.set('model.activeTheme', theme.name);
|
|
}
|
|
}
|
|
});
|