diff --git a/ghost/admin/app/components/gh-post-settings-menu.js b/ghost/admin/app/components/gh-post-settings-menu.js index 3dfc5ae9b9..e5e567bbd0 100644 --- a/ghost/admin/app/components/gh-post-settings-menu.js +++ b/ghost/admin/app/components/gh-post-settings-menu.js @@ -24,10 +24,13 @@ export default Component.extend(SettingsMenuMixin, { session: injectService(), settings: injectService(), + model: null, slugValue: boundOneWay('model.slug'), metaTitleScratch: alias('model.metaTitleScratch'), metaDescriptionScratch: alias('model.metaDescriptionScratch'), + _showSettingsMenu: false, + didReceiveAttrs() { this._super(...arguments); @@ -38,6 +41,19 @@ export default Component.extend(SettingsMenuMixin, { this.get('model.author').then((author) => { this.set('selectedAuthor', author); }); + + // reset the publish date on close if it has an error + if (!this.get('showSettingsMenu') && this._showSettingsMenu) { + let post = this.get('model'); + let errors = post.get('errors'); + + if (errors.has('publishedAtBlogDate') || errors.has('publishedAtBlogTime')) { + post.set('publishedAtBlogTZ', post.get('publishedAtUTC')); + post.validate({attribute: 'publishedAtBlog'}); + } + } + + this._showSettingsMenu = this.get('showSettingsMenu'); }, seoTitle: computed('model.titleScratch', 'metaTitleScratch', function () { diff --git a/ghost/admin/app/templates/components/gh-post-settings-menu.hbs b/ghost/admin/app/templates/components/gh-post-settings-menu.hbs index be72b66bd9..151247ed1d 100644 --- a/ghost/admin/app/templates/components/gh-post-settings-menu.hbs +++ b/ghost/admin/app/templates/components/gh-post-settings-menu.hbs @@ -3,7 +3,9 @@

Post Settings

- +
{{gh-image-uploader-with-preview diff --git a/ghost/admin/tests/acceptance/editor-test.js b/ghost/admin/tests/acceptance/editor-test.js index 4149309ab0..c68fcf3169 100644 --- a/ghost/admin/tests/acceptance/editor-test.js +++ b/ghost/admin/tests/acceptance/editor-test.js @@ -79,7 +79,7 @@ describe('Acceptance: Editor', function() { }); it('renders the editor correctly, PSM Publish Date and Save Button', async function () { - server.createList('post', 2); + let [post1] = server.createList('post', 2); let futureTime = moment().tz('Etc/UTC').add(10, 'minutes'); // post id 1 is a draft, checking for draft behaviour now @@ -99,13 +99,34 @@ describe('Acceptance: Editor', function() { .to.equal('Must be in format: "15:00"'); // should error, if the publish time is in the future + // NOTE: date must be selected first, changing the time first will save + // with the new time + await datepickerSelect(testSelector('date-time-picker-datepicker'), moment.tz('Etc/UTC')); await fillIn(testSelector('date-time-picker-time-input'), futureTime.format('HH:mm')); await triggerEvent(testSelector('date-time-picker-time-input'), 'blur'); - await datepickerSelect(testSelector('date-time-picker-datepicker'), futureTime); expect(find(testSelector('date-time-picker-error')).text().trim(), 'inline error response for future time') .to.equal('Must be in the past'); + // closing the PSM will reset the invalid date/time + await click(testSelector('close-settings-menu')); + await click(testSelector('psm-trigger')); + + expect( + find(testSelector('date-time-picker-error')).text().trim(), + 'date picker error after closing PSM' + ).to.equal(''); + + expect( + find(testSelector('date-time-picker-date-input')).val(), + 'PSM date value after closing with invalid date' + ).to.equal(moment(post1.publishedAt).format('MM/DD/YYYY')); + + expect( + find(testSelector('date-time-picker-time-input')).val(), + 'PSM time value after closing with invalid date' + ).to.equal(moment(post1.publishedAt).format('HH:mm')); + // saves the post with the new date let validTime = moment('2017-04-09 12:00'); await fillIn(testSelector('date-time-picker-time-input'), validTime.format('HH:mm'));