mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
Merge pull request #762 from ericterpstra/402-pub-date
Enabled post setting to change published date
This commit is contained in:
commit
116bca1ff0
@ -18,14 +18,14 @@
|
||||
<input class="post-setting-slug" type="text" value="{{{slug}}}">
|
||||
</div>
|
||||
</li>
|
||||
<!--<li class="post-setting">
|
||||
<li class="post-setting">
|
||||
<div class="post-setting-label">
|
||||
<label for="url">Pub Date</label>
|
||||
</div>
|
||||
<div class="post-setting-field">
|
||||
<input class="post-setting-date" type="text" value=""><span class="post-setting-calendar"></span>
|
||||
<input class="post-setting-date" disabled type="text" value="">
|
||||
</div>
|
||||
</li>-->
|
||||
</li>
|
||||
<li><a href="#" class="delete">Delete</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The Post Settings Menu available in the content preview screen, as well as the post editor.
|
||||
|
||||
/*global window, document, $, _, Backbone, Ghost */
|
||||
/*global window, document, $, _, Backbone, Ghost, moment */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
@ -10,17 +10,30 @@
|
||||
events: {
|
||||
'blur .post-setting-slug' : 'editSlug',
|
||||
'click .post-setting-slug' : 'selectSlug',
|
||||
'blur .post-setting-date' : 'editDate',
|
||||
'click .delete' : 'deletePost'
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var slug = this.model ? this.model.get('slug') : '';
|
||||
//var pubDate = this.model.get('published_at');
|
||||
initialize: function () {
|
||||
if (this.model) {
|
||||
this.listenTo(this.model, 'change:status', this.render);
|
||||
}
|
||||
},
|
||||
|
||||
//pubDate = moment(pubDate).format('DD MMM YY');
|
||||
render: function () {
|
||||
var slug = this.model ? this.model.get('slug') : '',
|
||||
pubDate = this.model ? this.model.get('published_at') : 'Not Published',
|
||||
$pubDateEl = $('.post-setting-date');
|
||||
|
||||
$('.post-setting-slug').val(slug);
|
||||
//$('.post-setting-date').val(pubDate);
|
||||
|
||||
// Insert the published date, and make it editable if it exists.
|
||||
if (this.model && this.model.get('published_at')) {
|
||||
pubDate = moment(pubDate).format('DD MMM YY');
|
||||
$pubDateEl.removeAttr('disabled');
|
||||
}
|
||||
|
||||
$pubDateEl.val(pubDate);
|
||||
},
|
||||
|
||||
selectSlug: function (e) {
|
||||
@ -57,6 +70,59 @@
|
||||
});
|
||||
},
|
||||
|
||||
editDate: function (e) {
|
||||
e.preventDefault();
|
||||
var self = this,
|
||||
momentPubDate,
|
||||
errMessage = '',
|
||||
pubDate = self.model.get('published_at'),
|
||||
pubDateEl = e.currentTarget,
|
||||
newPubDate = pubDateEl.value;
|
||||
|
||||
// Ensure the published date has changed
|
||||
if (newPubDate.length === 0 || pubDate === newPubDate) {
|
||||
pubDateEl.value = pubDate === undefined ? 'Not Published' : moment(pubDate).format("DD MMM YY");
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate new Published date
|
||||
momentPubDate = moment(newPubDate, ["DD MMM YY", "DD MMM YYYY", "DD/MM/YY", "DD/MM/YYYY", "DD-MM-YY", "DD-MM-YYYY"]);
|
||||
if (!momentPubDate.isValid()) {
|
||||
errMessage = 'Published Date must be a valid date with format: DD MMM YY (e.g. 6 Dec 14)';
|
||||
}
|
||||
|
||||
if (momentPubDate.diff(new Date(), 'h') > 0) {
|
||||
errMessage = 'Published Date cannot currently be in the future.';
|
||||
}
|
||||
|
||||
if (errMessage.length) {
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: errMessage,
|
||||
status: 'passive'
|
||||
});
|
||||
pubDateEl.value = moment(pubDate).format("DD MMM YY");
|
||||
return;
|
||||
}
|
||||
|
||||
// Save new 'Published' date
|
||||
this.model.save({
|
||||
published_at: momentPubDate.toDate()
|
||||
}, {
|
||||
success : function (model, response, options) {
|
||||
pubDateEl.value = moment(model.get('published_at')).format("DD MMM YY");
|
||||
},
|
||||
error : function (model, xhr) {
|
||||
Ghost.notifications.addItem({
|
||||
type: 'error',
|
||||
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
||||
status: 'passive'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
deletePost: function (e) {
|
||||
e.preventDefault();
|
||||
var self = this;
|
||||
|
Loading…
Reference in New Issue
Block a user