FIX: pin/unpin button in topic admin menu needs to ignore whether the admin user cleared the pin

This commit is contained in:
Neil Lalonde 2014-03-12 14:47:04 -04:00
parent 42ca83ece5
commit 3175c85fa6
4 changed files with 23 additions and 5 deletions

View File

@ -163,7 +163,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
},
togglePinned: function() {
this.get('content').toggleStatus('pinned');
// Note that this is different than clearPin
this.get('content').setStatus('pinned', this.get('pinned_at') ? false : true);
},
toggleArchived: function() {

View File

@ -134,12 +134,24 @@ Discourse.Topic = Discourse.Model.extend({
toggleStatus: function(property) {
this.toggleProperty(property);
if (property === 'closed' && this.get('closed')) {
this.saveStatus(property, this.get(property) ? true : false);
},
setStatus: function(property, value) {
this.set(property, value);
this.saveStatus(property, value);
},
saveStatus: function(property, value) {
if (property === 'closed' && value === true) {
this.set('details.auto_close_at', null);
}
if (property === 'pinned') {
this.set('pinned_at', value ? moment() : null);
}
return Discourse.ajax(this.get('url') + "/status", {
type: 'PUT',
data: {status: property, enabled: this.get(property) ? 'true' : 'false' }
data: {status: property, enabled: value ? 'true' : 'false' }
});
},

View File

@ -29,7 +29,7 @@
</li>
<li>
{{#if pinned}}
{{#if pinned_at}}
<button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.unpin}}</button>
{{else}}
<button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.pin}}</button>

View File

@ -31,7 +31,8 @@ class TopicViewSerializer < ApplicationSerializer
:draft_sequence,
:starred,
:posted,
:pinned,
:pinned, # Is topic pinned and viewer hasn't cleared the pin?
:pinned_at, # Ignores clear pin
:details,
:highest_post_number,
:last_read_post_number,
@ -146,6 +147,10 @@ class TopicViewSerializer < ApplicationSerializer
PinnedCheck.new(object.topic, object.topic_user).pinned?
end
def pinned_at
object.topic.pinned_at
end
def actions_summary
result = []
return [] unless post = object.posts.try(:first)