Merge pull request #1119 from halfdan/featured-post-button

Posts can now be featured by clicking on the star icon
This commit is contained in:
Hannah Wolfe 2013-10-22 12:38:43 -07:00
commit 7ddc2fa287
2 changed files with 69 additions and 3 deletions

View File

@ -180,7 +180,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) {
@ -201,6 +203,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 () {
@ -222,4 +251,4 @@
});
}());
}());

View File

@ -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');
});
});
});
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');
});
});