0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Merge pull request #6564 from szelpe/publishedDate

Fixed bugs regarding the published date input field validation.
This commit is contained in:
Kevin Ansfield 2016-04-06 11:58:00 +01:00
commit 5def00185c

View file

@ -290,10 +290,6 @@ export default Controller.extend(SettingsMenuMixin, {
* (#1351) * (#1351)
*/ */
setPublishedAt(userInput) { setPublishedAt(userInput) {
let newPublishedAt = parseDateString(userInput);
let publishedAt = moment(this.get('model.publishedAt'));
let errMessage = '';
if (!userInput) { if (!userInput) {
// Clear out the publishedAt field for a draft // Clear out the publishedAt field for a draft
if (this.get('model.isDraft')) { if (this.get('model.isDraft')) {
@ -303,12 +299,18 @@ export default Controller.extend(SettingsMenuMixin, {
return; return;
} }
let newPublishedAt = parseDateString(userInput);
let publishedAt = moment(this.get('model.publishedAt'));
let errMessage = '';
// Clear previous errors
this.get('model.errors').remove('post-setting-date');
// Validate new Published date // Validate new Published date
if (!newPublishedAt.isValid()) { if (!newPublishedAt.isValid()) {
errMessage = 'Published Date must be a valid date with format: ' + errMessage = 'Published Date must be a valid date with format: ' +
'DD MMM YY @ HH:mm (e.g. 6 Dec 14 @ 15:00)'; 'DD MMM YY @ HH:mm (e.g. 6 Dec 14 @ 15:00)';
} } else if (newPublishedAt.diff(new Date(), 'h') > 0) {
if (newPublishedAt.diff(new Date(), 'h') > 0) {
errMessage = 'Published Date cannot currently be in the future.'; errMessage = 'Published Date cannot currently be in the future.';
} }
@ -318,14 +320,14 @@ export default Controller.extend(SettingsMenuMixin, {
return; return;
} }
// Do nothing if the user didn't actually change the date // Validation complete, update the view
this.set('model.publishedAt', newPublishedAt);
// Don't save the date if the user didn't actually changed the date
if (publishedAt && publishedAt.isSame(newPublishedAt)) { if (publishedAt && publishedAt.isSame(newPublishedAt)) {
return; return;
} }
// Validation complete
this.set('model.publishedAt', newPublishedAt);
// If this is a new post. Don't save the model. Defer the save // If this is a new post. Don't save the model. Defer the save
// to the user pressing the save button // to the user pressing the save button
if (this.get('model.isNew')) { if (this.get('model.isNew')) {