Cleaned up TopicUserSpec, introduces clearing of pinned topics
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user