mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Merge pull request #2035 from ErisDS/issue-1908
Post settings don't render on change
This commit is contained in:
commit
b42962c97a
1 changed files with 26 additions and 10 deletions
|
@ -5,6 +5,10 @@
|
||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var 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 @ HH:mm';
|
||||||
|
|
||||||
Ghost.View.PostSettings = Ghost.View.extend({
|
Ghost.View.PostSettings = Ghost.View.extend({
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
@ -17,11 +21,10 @@
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
if (this.model) {
|
if (this.model) {
|
||||||
|
// These three items can be updated outside of the post settings menu, so have to be listened to.
|
||||||
this.listenTo(this.model, 'change:id', this.render);
|
this.listenTo(this.model, 'change:id', this.render);
|
||||||
this.listenTo(this.model, 'change:status', this.render);
|
|
||||||
this.listenTo(this.model, 'change:published_at', this.render);
|
|
||||||
this.listenTo(this.model, 'change:page', this.render);
|
|
||||||
this.listenTo(this.model, 'change:title', this.updateSlugPlaceholder);
|
this.listenTo(this.model, 'change:title', this.updateSlugPlaceholder);
|
||||||
|
this.listenTo(this.model, 'change:published_at', this.updatePublishedDate);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -29,8 +32,7 @@
|
||||||
var slug = this.model ? this.model.get('slug') : '',
|
var slug = this.model ? this.model.get('slug') : '',
|
||||||
pubDate = this.model ? this.model.get('published_at') : 'Not Published',
|
pubDate = this.model ? this.model.get('published_at') : 'Not Published',
|
||||||
$pubDateEl = this.$('.post-setting-date'),
|
$pubDateEl = this.$('.post-setting-date'),
|
||||||
$postSettingSlugEl = this.$('.post-setting-slug'),
|
$postSettingSlugEl = this.$('.post-setting-slug');
|
||||||
publishedDateFormat = 'DD MMM YY @ HH:mm';
|
|
||||||
|
|
||||||
$postSettingSlugEl.val(slug);
|
$postSettingSlugEl.val(slug);
|
||||||
|
|
||||||
|
@ -41,10 +43,10 @@
|
||||||
|
|
||||||
// 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(publishedDateFormat);
|
pubDate = moment(pubDate).format(displayDateFormat);
|
||||||
$pubDateEl.attr('placeholder', '');
|
$pubDateEl.attr('placeholder', '');
|
||||||
} else {
|
} else {
|
||||||
$pubDateEl.attr('placeholder', moment().format(publishedDateFormat));
|
$pubDateEl.attr('placeholder', moment().format(displayDateFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.model && this.model.get('id')) {
|
if (this.model && this.model.get('id')) {
|
||||||
|
@ -130,6 +132,7 @@
|
||||||
},
|
},
|
||||||
error : function (model, xhr) {
|
error : function (model, xhr) {
|
||||||
/*jslint unparam:true*/
|
/*jslint unparam:true*/
|
||||||
|
slugEl.value = model.previous('slug');
|
||||||
Ghost.notifications.addItem({
|
Ghost.notifications.addItem({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
||||||
|
@ -139,13 +142,23 @@
|
||||||
});
|
});
|
||||||
}, 500),
|
}, 500),
|
||||||
|
|
||||||
|
|
||||||
|
updatePublishedDate: function () {
|
||||||
|
var pubDate = this.model.get('published_at') ? moment(this.model.get('published_at'))
|
||||||
|
.format(displayDateFormat) : '',
|
||||||
|
$pubDateEl = this.$('.post-setting-date');
|
||||||
|
|
||||||
|
// Only change the date if it's different
|
||||||
|
if (pubDate && $pubDateEl.val() !== pubDate) {
|
||||||
|
$pubDateEl.val(pubDate);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
editDate: _.debounce(function (e) {
|
editDate: _.debounce(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var self = this,
|
var self = this,
|
||||||
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 @ HH:mm',
|
|
||||||
errMessage = '',
|
errMessage = '',
|
||||||
pubDate = self.model.get('published_at'),
|
pubDate = moment(self.model.get('published_at')).format(displayDateFormat),
|
||||||
pubDateEl = e.currentTarget,
|
pubDateEl = e.currentTarget,
|
||||||
newPubDate = pubDateEl.value,
|
newPubDate = pubDateEl.value,
|
||||||
pubDateMoment,
|
pubDateMoment,
|
||||||
|
@ -228,6 +241,8 @@
|
||||||
},
|
},
|
||||||
error : function (model, xhr) {
|
error : function (model, xhr) {
|
||||||
/*jslint unparam:true*/
|
/*jslint unparam:true*/
|
||||||
|
// Reset back to original value
|
||||||
|
pubDateEl.value = pubDateMoment ? pubDateMoment.format(displayDateFormat) : '';
|
||||||
Ghost.notifications.addItem({
|
Ghost.notifications.addItem({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
||||||
|
@ -266,6 +281,7 @@
|
||||||
},
|
},
|
||||||
error : function (model, xhr) {
|
error : function (model, xhr) {
|
||||||
/*jslint unparam:true*/
|
/*jslint unparam:true*/
|
||||||
|
pageEl.prop('checked', model.previous('page'));
|
||||||
Ghost.notifications.addItem({
|
Ghost.notifications.addItem({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
message: Ghost.Views.Utils.getRequestErrorMessage(xhr),
|
||||||
|
|
Loading…
Add table
Reference in a new issue