Cleaned up TopicUserSpec, introduces clearing of pinned topics

This commit is contained in:
Robin Ward
2013-03-06 15:17:07 -05:00
parent 3af2ab9022
commit f8d8272406
27 changed files with 2663 additions and 342 deletions
@@ -255,6 +255,15 @@ Discourse.TopicController = Discourse.ObjectController.extend({
this.get('content').toggleStar();
},
/**
Clears the pin from a topic for the currentUser
@method clearPin
**/
clearPin: function() {
this.get('content').clearPin();
},
// Receive notifications for this topic
subscribe: function() {
var bus,
@@ -329,6 +329,27 @@ Discourse.Topic = Discourse.Model.extend({
});
},
/**
Clears the pin from a topic for the currentUser
@method clearPin
**/
clearPin: function() {
var topic = this;
// Clear the pin optimistically from the object
topic.set('pinned', false);
$.ajax("/t/" + this.get('id') + "/clear-pin", {
type: 'PUT',
error: function() {
// On error, put the pin back
topic.set('pinned', true);
}
});
},
// Is the reply to a post directly below it?
isReplyDirectlyBelow: function(post) {
var postBelow, posts;
@@ -68,6 +68,30 @@ Discourse.TopicFooterButtonsView = Ember.ContainerView.extend({
buffer.push("<i class='icon icon-share'></i>");
}
}));
// Add our clear pin button
this.addObject(Discourse.ButtonView.createWithMixins({
textKey: 'topic.clear_pin.title',
helpKey: 'topic.clear_pin.help',
classNameBindings: ['unpinned'],
// Hide the button if it becomes unpinned
unpinned: function() {
// When not logged in don't show the button
if (!Discourse.get('currentUser')) return 'hidden'
return this.get('controller.pinned') ? null : 'hidden';
}.property('controller.pinned'),
click: function(buffer) {
this.get('controller').clearPin();
},
renderIcon: function(buffer) {
buffer.push("<i class='icon icon-pushpin'></i>");
}
}));
}
this.addObject(Discourse.ButtonView.createWithMixins({