mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #917 from jgable/publishedAtTime
Allow published_at times to be specified
This commit is contained in:
commit
e4f2165f0c
1 changed files with 26 additions and 10 deletions
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
// Insert the published date, and make it editable if it exists.
|
// Insert the published date, and make it editable if it exists.
|
||||||
if (this.model && this.model.get('published_at')) {
|
if (this.model && this.model.get('published_at')) {
|
||||||
pubDate = moment(pubDate).format('DD MMM YY');
|
pubDate = moment(pubDate).format('DD MMM YY HH:mm');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.model && this.model.get('id')) {
|
if (this.model && this.model.get('id')) {
|
||||||
|
@ -93,14 +93,29 @@
|
||||||
editDate: function (e) {
|
editDate: function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var self = this,
|
var self = this,
|
||||||
parseDateFormats = ['DD MMM YY', 'DD MMM YYYY', 'DD/MM/YY', 'DD/MM/YYYY', 'DD-MM-YY', 'DD-MM-YYYY'],
|
parseDateFormats = ['DD MMM YY HH:mm', 'DD MMM YYYY HH:mm', 'DD/MM/YY HH:mm', 'DD/MM/YYYY HH:mm', 'DD-MM-YY HH:mm', 'DD-MM-YYYY HH:mm'],
|
||||||
displayDateFormat = 'DD MMM YY',
|
displayDateFormat = 'DD MMM YY HH:mm',
|
||||||
errMessage = '',
|
errMessage = '',
|
||||||
pubDate = self.model.get('published_at'),
|
pubDate = self.model.get('published_at'),
|
||||||
pubDateMoment = moment(pubDate, parseDateFormats),
|
|
||||||
pubDateEl = e.currentTarget,
|
pubDateEl = e.currentTarget,
|
||||||
newPubDate = pubDateEl.value,
|
newPubDate = pubDateEl.value,
|
||||||
newPubDateMoment = moment(newPubDate, parseDateFormats);
|
pubDateMoment,
|
||||||
|
newPubDateMoment;
|
||||||
|
|
||||||
|
// Check for missing time stamp on current model
|
||||||
|
// If no time specified, add a 12:00
|
||||||
|
if (!pubDate.slice(-5).match(/\d+:\d\d/)) {
|
||||||
|
pubDate += " 12:00";
|
||||||
|
}
|
||||||
|
|
||||||
|
pubDateMoment = moment(pubDate, parseDateFormats);
|
||||||
|
|
||||||
|
// Same for new date
|
||||||
|
if (!newPubDate.slice(-5).match(/\d+:\d\d/)) {
|
||||||
|
newPubDate += " 12:00";
|
||||||
|
}
|
||||||
|
|
||||||
|
newPubDateMoment = moment(newPubDate, parseDateFormats);
|
||||||
|
|
||||||
// Ensure the published date has changed
|
// Ensure the published date has changed
|
||||||
if (newPubDate.length === 0 || pubDateMoment.isSame(newPubDateMoment)) {
|
if (newPubDate.length === 0 || pubDateMoment.isSame(newPubDateMoment)) {
|
||||||
|
@ -110,7 +125,7 @@
|
||||||
|
|
||||||
// Validate new Published date
|
// Validate new Published date
|
||||||
if (!newPubDateMoment.isValid()) {
|
if (!newPubDateMoment.isValid()) {
|
||||||
errMessage = 'Published Date must be a valid date with format: DD MMM YY (e.g. 6 Dec 14)';
|
errMessage = 'Published Date must be a valid date with format: DD MMM YY HH:mm (e.g. 6 Dec 14 15:00)';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newPubDateMoment.diff(new Date(), 'h') > 0) {
|
if (newPubDateMoment.diff(new Date(), 'h') > 0) {
|
||||||
|
@ -118,22 +133,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errMessage.length) {
|
if (errMessage.length) {
|
||||||
|
// Show error message
|
||||||
Ghost.notifications.addItem({
|
Ghost.notifications.addItem({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: errMessage,
|
message: errMessage,
|
||||||
status: 'passive'
|
status: 'passive'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset back to original value and return
|
||||||
pubDateEl.value = pubDateMoment.format(displayDateFormat);
|
pubDateEl.value = pubDateMoment.format(displayDateFormat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save new 'Published' date
|
// Save new 'Published' date
|
||||||
this.model.save({
|
this.model.save({
|
||||||
// Temp Fix. Set hour to 12 instead of 00 to avoid some TZ issues.
|
published_at: newPubDateMoment.toDate()
|
||||||
published_at: newPubDateMoment.hour(12).toDate()
|
|
||||||
}, {
|
}, {
|
||||||
success : function (model, response, options) {
|
success : function (model) {
|
||||||
/*jslint unparam:true*/
|
|
||||||
pubDateEl.value = moment(model.get('published_at')).format(displayDateFormat);
|
pubDateEl.value = moment(model.get('published_at')).format(displayDateFormat);
|
||||||
Ghost.notifications.addItem({
|
Ghost.notifications.addItem({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
|
Loading…
Add table
Reference in a new issue