2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2017-05-29 21:50:03 +03:00
|
|
|
import moment from 'moment';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {computed} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
2017-10-30 12:38:01 +03:00
|
|
|
clock: service(),
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
post: null,
|
|
|
|
saveType: null,
|
2017-05-23 16:30:00 +03:00
|
|
|
isClosing: null,
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
// used to set minDate in datepicker
|
|
|
|
_minDate: null,
|
|
|
|
|
|
|
|
'data-test-publishmenu-scheduled': true,
|
|
|
|
|
|
|
|
timeToPublished: computed('post.publishedAtUTC', 'clock.second', function () {
|
|
|
|
let publishedAtUTC = this.get('post.publishedAtUTC');
|
|
|
|
|
2017-05-22 19:03:04 +03:00
|
|
|
if (!publishedAtUTC) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-11 16:39:45 +03:00
|
|
|
this.get('clock.second');
|
|
|
|
|
|
|
|
return publishedAtUTC.toNow(true);
|
|
|
|
}),
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this.set('_minDate', new Date());
|
2019-03-06 16:53:54 +03:00
|
|
|
this.setSaveType('schedule');
|
2017-04-11 16:39:45 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setSaveType(type) {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this.saveType !== type) {
|
2017-04-11 16:39:45 +03:00
|
|
|
this.set('_minDate', new Date());
|
2019-03-06 16:53:54 +03:00
|
|
|
this.setSaveType(type);
|
2017-04-11 16:39:45 +03:00
|
|
|
|
|
|
|
// when draft switch to now to avoid validation errors
|
|
|
|
// when schedule switch back to saved date to avoid unnecessary re-scheduling
|
|
|
|
if (type === 'draft') {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.post.set('publishedAtBlogTZ', new Date());
|
2017-04-11 16:39:45 +03:00
|
|
|
} else {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.post.set('publishedAtBlogTZ', this.get('post.publishedAtUTC'));
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
this.post.validate();
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setDate(date) {
|
2019-03-06 16:53:54 +03:00
|
|
|
let post = this.post;
|
2017-04-11 16:39:45 +03:00
|
|
|
let dateString = moment(date).format('YYYY-MM-DD');
|
|
|
|
|
|
|
|
post.set('publishedAtBlogDate', dateString);
|
|
|
|
return post.validate();
|
|
|
|
},
|
|
|
|
|
|
|
|
setTime(time) {
|
2019-03-06 16:53:54 +03:00
|
|
|
let post = this.post;
|
2017-04-11 16:39:45 +03:00
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
if (!this.isClosing) {
|
2017-05-23 16:30:00 +03:00
|
|
|
post.set('publishedAtBlogTime', time);
|
|
|
|
return post.validate();
|
|
|
|
}
|
2017-04-11 16:39:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|