2016-06-30 21:14:25 +03:00
|
|
|
import Component from 'ember-component';
|
|
|
|
import injectService from 'ember-service/inject';
|
2016-05-24 15:06:59 +03:00
|
|
|
import boundOneWay from 'ghost-admin/utils/bound-one-way';
|
|
|
|
import {formatDate} from 'ghost-admin/utils/date-formatting';
|
2016-06-18 14:44:23 +03:00
|
|
|
import {InvokeActionMixin} from 'ember-invoke-action';
|
2017-04-05 20:45:35 +03:00
|
|
|
import moment from 'moment';
|
2015-12-08 12:58:32 +03:00
|
|
|
|
2016-06-18 14:44:23 +03:00
|
|
|
export default Component.extend(InvokeActionMixin, {
|
2015-12-08 12:58:32 +03:00
|
|
|
tagName: 'span',
|
2017-04-14 19:22:14 +03:00
|
|
|
classNames: 'gh-input-icon gh-icon-calendar',
|
2015-12-08 12:58:32 +03:00
|
|
|
|
|
|
|
datetime: boundOneWay('value'),
|
|
|
|
inputClass: null,
|
|
|
|
inputId: null,
|
|
|
|
inputName: null,
|
2017-03-17 20:16:21 +03:00
|
|
|
settings: injectService(),
|
2015-12-08 12:58:32 +03:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2017-03-17 20:16:21 +03:00
|
|
|
let datetime = this.get('datetime') || moment.utc();
|
|
|
|
let blogTimezone = this.get('settings.activeTimezone');
|
2015-12-08 12:58:32 +03:00
|
|
|
|
2016-04-06 18:26:58 +03:00
|
|
|
if (!this.get('update')) {
|
2015-12-08 12:58:32 +03:00
|
|
|
throw new Error(`You must provide an \`update\` action to \`{{${this.templateName}}}\`.`);
|
|
|
|
}
|
|
|
|
|
2017-03-17 20:16:21 +03:00
|
|
|
this.set('datetime', formatDate(datetime || moment.utc(), blogTimezone));
|
2015-12-08 12:58:32 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
focusOut() {
|
|
|
|
let datetime = this.get('datetime');
|
|
|
|
|
2016-06-18 14:44:23 +03:00
|
|
|
this.invokeAction('update', datetime);
|
2015-12-08 12:58:32 +03:00
|
|
|
}
|
|
|
|
});
|