Ghost/ghost/admin/app/components/gh-datetime-input.js
Kevin Ansfield c3b49b45cf 🎨 synchronous settings service
no issue
- adds `settings` service that acts as a proxy to the singular settings model with methods to fetch and reload, also prevents accidentally loading only some settings types which has caused problems in the past
- updates app boot, signin, and signup processes to fetch settings ensuring that any part of the app can grab settings synchronously if needed
- removes `timeZone` service, it's no longer needed as we can grab `settings.activeTimezone` directly
- replaces all store queries for the settings model with appropriate `settings` methods
- refactors `apps/*` routes/controllers, they had become a little convoluted with the way they were dealing with settings and the new service helped to clean that up
2017-03-20 07:43:49 -05:00

34 lines
1.0 KiB
JavaScript

import Component from 'ember-component';
import injectService from 'ember-service/inject';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import {formatDate} from 'ghost-admin/utils/date-formatting';
import {InvokeActionMixin} from 'ember-invoke-action';
export default Component.extend(InvokeActionMixin, {
tagName: 'span',
classNames: 'input-icon icon-calendar',
datetime: boundOneWay('value'),
inputClass: null,
inputId: null,
inputName: null,
settings: injectService(),
didReceiveAttrs() {
let datetime = this.get('datetime') || moment.utc();
let blogTimezone = this.get('settings.activeTimezone');
if (!this.get('update')) {
throw new Error(`You must provide an \`update\` action to \`{{${this.templateName}}}\`.`);
}
this.set('datetime', formatDate(datetime || moment.utc(), blogTimezone));
},
focusOut() {
let datetime = this.get('datetime');
this.invokeAction('update', datetime);
}
});