mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
b858232369
refs #5777 - adds new `gh-datetime-input` that takes a one-way-bound value and formats it, only triggering the supplied `update` action on focus-out - fixes bug in PSM's `setPublishedAt` action if model's `published_at` is a Date object not a Moment object
33 lines
834 B
JavaScript
33 lines
834 B
JavaScript
import Ember from 'ember';
|
|
import TextInputMixin from 'ghost/mixins/text-input';
|
|
import boundOneWay from 'ghost/utils/bound-one-way';
|
|
import {formatDate} from 'ghost/utils/date-formatting';
|
|
|
|
const {Component} = Ember;
|
|
|
|
export default Component.extend(TextInputMixin, {
|
|
tagName: 'span',
|
|
classNames: 'input-icon icon-calendar',
|
|
|
|
datetime: boundOneWay('value'),
|
|
inputClass: null,
|
|
inputId: null,
|
|
inputName: null,
|
|
|
|
didReceiveAttrs() {
|
|
let datetime = this.get('datetime') || moment();
|
|
|
|
if (!this.attrs.update) {
|
|
throw new Error(`You must provide an \`update\` action to \`{{${this.templateName}}}\`.`);
|
|
}
|
|
|
|
this.set('datetime', formatDate(datetime));
|
|
},
|
|
|
|
focusOut() {
|
|
let datetime = this.get('datetime');
|
|
|
|
this.attrs.update(datetime);
|
|
}
|
|
});
|