diff --git a/core/client/views/blog.js b/core/client/views/blog.js index 9818ce2ae9..b52e8a8691 100644 --- a/core/client/views/blog.js +++ b/core/client/views/blog.js @@ -178,7 +178,9 @@ activeId: null, events: { - 'click .post-controls .post-edit' : 'editPost' + 'click .post-controls .post-edit' : 'editPost', + 'click .featured' : 'toggleFeatured', + 'click .unfeatured' : 'toggleFeatured' }, initialize: function (options) { @@ -199,6 +201,33 @@ window.location = '/ghost/editor/' + this.model.get('id') + '/'; }, + toggleFeatured: function (e) { + var self = this, + featured = !self.model.get('featured'), + featuredEl = $(e.currentTarget), + model = this.collection.get(this.activeId); + + model.save({ + featured: featured + }, { + success : function (model, response, options) { + featuredEl.removeClass("featured unfeatured").addClass(featured ? "featured" : "unfeatured"); + Ghost.notifications.addItem({ + type: 'success', + message: "Post successfully marked as " + (featured ? "featured" : "not featured") + ".", + status: 'passive' + }); + }, + error : function (model, xhr) { + Ghost.notifications.addItem({ + type: 'error', + message: Ghost.Views.Utils.getRequestErrorMessage(xhr), + status: 'passive' + }); + } + }); + }, + templateName: "preview", render: function () { @@ -220,4 +249,4 @@ }); -}()); \ No newline at end of file +}()); diff --git a/core/test/functional/admin/content_test.js b/core/test/functional/admin/content_test.js index 485ab2a02a..5edd70b0a9 100644 --- a/core/test/functional/admin/content_test.js +++ b/core/test/functional/admin/content_test.js @@ -65,4 +65,41 @@ CasperTest.begin('Infinite scrolling', 1, function suite(test) { casper.thenOpen(url + 'ghost/content/', function testTitleAndUrl() { test.assertTitle('Ghost Admin', 'Ghost admin has no title'); }); -}); \ No newline at end of file +}); + +CasperTest.begin("Posts can be marked as featured", 4, function suite(test) { + // Create a sample post + casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() { + test.assertTitle('Ghost Admin', 'Ghost admin has no title'); + }); + + casper.then(function createTestPost() { + casper.sendKeys('#entry-title', testPost.title); + casper.writeContentToCodeMirror(testPost.html); + }); + + casper.thenClick('.js-publish-button'); + + casper.waitForResource(/posts/, function checkPostWasCreated() { + test.assertExists('.notification-success', 'got success notification'); + }); + + // Begin test + casper.thenOpen(url + "ghost/content/", function testTitleAndUrl() { + test.assertTitle("Ghost Admin", "Ghost admin has no title"); + }); + + // Mark as featured + casper.waitForSelector('.unfeatured' , function() { + this.click('.unfeatured'); + }); + + // Mark as not featured + casper.waitForSelector('.featured' , function() { + this.click('.featured'); + }); + + casper.waitForResource(/posts/, function checkPostWasMarkedAsFeatured() { + test.assertExists('.notification-success', 'got success notification'); + }); +});