diff --git a/core/client/controllers/post-settings-menu.js b/core/client/controllers/post-settings-menu.js index 65b48f71e9..aaf59ae048 100644 --- a/core/client/controllers/post-settings-menu.js +++ b/core/client/controllers/post-settings-menu.js @@ -13,24 +13,6 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ this.addObserver('title', this, 'titleObserver'); } }, - isStaticPage: function (key, val) { - var self = this; - - if (arguments.length > 1) { - this.set('page', val); - - return this.get('model').save().then(function () { - self.notifications.showSuccess('Successfully converted to ' + (val ? 'static page' : 'post')); - - return self.get('page'); - }).catch(function (errors) { - self.notifications.showErrors(errors); - return Ember.RSVP.reject(errors); - }); - } - - return this.get('page'); - }.property('page'), /** * The placeholder is the published date of the post, * or the current date if the pubdate has not been set. @@ -47,14 +29,15 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ slugValue: boundOneWay('slug'), //Lazy load the slug generator for slugPlaceholder slugGenerator: Ember.computed(function () { - return SlugGenerator.create({ghostPaths: this.get('ghostPaths')}); + return SlugGenerator.create({ + ghostPaths: this.get('ghostPaths') + }); }), //Requests slug from title generateSlugPlaceholder: function () { var self = this, - slugGenerator = this.get('slugGenerator'), title = this.get('title'); - slugGenerator.generateSlug(title).then(function (slug) { + this.get('slugGenerator').generateSlug(title).then(function (slug) { self.set('slugPlaceholder', slug); }); }, @@ -80,7 +63,34 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ return this.get('title'); }.property(), + showErrors: function (errors) { + errors = Ember.isArray(errors) ? errors : [errors]; + this.notifications.closePassive(); + this.notifications.showErrors(errors); + }, + showSuccess: function (message) { + this.notifications.closePassive(); + this.notifications.showSuccess(message); + }, actions: { + togglePage: function () { + var value = this.toggleProperty('page'), + self = this; + + // If this is a new post. Don't save the model. Defer the save + // to the user pressing the save button + if (this.get('isNew')) { + return; + } + + return this.get('model').save().then(function () { + self.showSuccess('Successfully converted to ' + (value ? 'static page' : 'post')); + return value; + }).catch(function (errors) { + self.showErrors(errors); + self.get('model').rollback(); + }); + }, /** * triggered by user manually changing slug */ @@ -135,13 +145,13 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ } // Save post model properties excluding any changes to the post body - return self.get('model').save().then(function () { - self.notifications.showSuccess('Permalink successfully changed to ' + - self.get('slug') + '.'); - }).catch(function (errors) { - self.notifications.showErrors(errors); - return Ember.RSVP.reject(errors); - }); + return self.get('model').save(); + }).then(function () { + self.showSuccess('Permalink successfully changed to ' + + self.get('slug') + '.'); + }).catch(function (errors) { + self.showErrors(errors); + self.get('model').rollback(); }); }, @@ -164,37 +174,41 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ return; } - // Do nothing if the user didn't actually change the date - if (publishedAt && publishedAt.isSame(newPublishedAt)) { - return; - } - // Validate new Published date if (!newPublishedAt.isValid()) { errMessage = 'Published Date must be a valid date with format: ' + 'DD MMM YY @ HH:mm (e.g. 6 Dec 14 @ 15:00)'; } - - //Can't publish in the future yet if (newPublishedAt.diff(new Date(), 'h') > 0) { errMessage = 'Published Date cannot currently be in the future.'; } //If errors, notify and exit. if (errMessage) { - this.notifications.showError(errMessage); + this.showErrors(errMessage); + return; + } + + // Do nothing if the user didn't actually change the date + if (publishedAt && publishedAt.isSame(newPublishedAt)) { return; } //Validation complete this.set('published_at', newPublishedAt); + // If this is a new post. Don't save the model. Defer the save + // to the user pressing the save button + if (this.get('isNew')) { + return; + } + this.get('model').save().then(function () { - self.notifications.showSuccess('Publish date successfully changed to ' + + self.showSuccess('Publish date successfully changed to ' + formatDate(self.get('published_at')) + '.'); }).catch(function (errors) { - self.notifications.showErrors(errors); - return Ember.RSVP.reject(errors); + self.showErrors(errors); + self.get('model').rollback(); }); } } diff --git a/core/client/templates/post-settings-menu.hbs b/core/client/templates/post-settings-menu.hbs index 9ef5749d1f..b7b1b76d9b 100644 --- a/core/client/templates/post-settings-menu.hbs +++ b/core/client/templates/post-settings-menu.hbs @@ -22,8 +22,8 @@ - {{input type="checkbox" name="static-page" id="static-page" class="post-setting-static-page" checked=isStaticPage}} - + {{input type="checkbox" name="static-page" id="static-page" class="post-setting-static-page" checked=page}} + diff --git a/core/test/functional/client/content_test.js b/core/test/functional/client/content_test.js index 4690f74e86..28b1db36ca 100644 --- a/core/test/functional/client/content_test.js +++ b/core/test/functional/client/content_test.js @@ -101,7 +101,7 @@ CasperTest.begin('Content list shows correct post status', 7, function testStati test.assert(true, 'post settings menu should be visible after clicking post-settings icon'); }); - casper.thenClick('.post-settings-menu .post-setting-static-page'); + casper.thenClick('.post-settings-menu .post-setting-static-page + label'); casper.waitForSelector('.content-list-content li .entry-meta .status .page', function waitForSuccess() { test.assertSelectorHasText('.content-list-content li .entry-meta .status .page', 'Page', 'status is Page'); @@ -310,7 +310,7 @@ CasperTest.begin('Post can be changed to static page', 7, function suite(test) { test.assert(true, 'post settings should be visible after clicking post-settings icon'); }); - casper.thenClick('.post-settings-menu .post-setting-static-page'); + casper.thenClick('.post-settings-menu .post-setting-static-page + label'); casper.waitForSelector('.notification-success', function waitForSuccess() { test.assert(true, 'got success notification'); @@ -324,7 +324,7 @@ CasperTest.begin('Post can be changed to static page', 7, function suite(test) { test.assertNotVisible('.notification-success', 'success notification should not still exist'); }); - casper.thenClick('.post-settings-menu .post-setting-static-page'); + casper.thenClick('.post-settings-menu .post-setting-static-page + label'); casper.waitForSelector('.notification-success', function waitForSuccess() { test.assert(true, 'got success notification'); diff --git a/core/test/functional/client/editor_test.js b/core/test/functional/client/editor_test.js index c25c3658d4..4bab5425b8 100644 --- a/core/test/functional/client/editor_test.js +++ b/core/test/functional/client/editor_test.js @@ -354,7 +354,7 @@ CasperTest.begin('Post settings menu', 31, function suite(test) { test.assert(true, 'post settings menu should be visible after clicking post-settings icon'); }); - casper.thenClick('.post-settings-menu .post-setting-static-page'); + casper.thenClick('.post-settings-menu .post-setting-static-page + label'); casper.waitForSelector('.notification-success', function waitForSuccess() { test.assert(true, 'got success notification'); @@ -368,7 +368,7 @@ CasperTest.begin('Post settings menu', 31, function suite(test) { test.assertNotVisible('.notification-success', 'success notification should not still exist'); }); - casper.thenClick('.post-settings-menu .post-setting-static-page'); + casper.thenClick('.post-settings-menu .post-setting-static-page + label'); casper.waitForSelector('.notification-success', function waitForSuccess() { test.assert(true, 'got success notification');