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() { 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() { toggleArchived: function() {

View File

@ -134,12 +134,24 @@ Discourse.Topic = Discourse.Model.extend({
toggleStatus: function(property) { toggleStatus: function(property) {
this.toggleProperty(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); this.set('details.auto_close_at', null);
} }
if (property === 'pinned') {
this.set('pinned_at', value ? moment() : null);
}
return Discourse.ajax(this.get('url') + "/status", { return Discourse.ajax(this.get('url') + "/status", {
type: 'PUT', 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>
<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> <button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.unpin}}</button>
{{else}} {{else}}
<button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.pin}}</button> <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, :draft_sequence,
:starred, :starred,
:posted, :posted,
:pinned, :pinned, # Is topic pinned and viewer hasn't cleared the pin?
:pinned_at, # Ignores clear pin
:details, :details,
:highest_post_number, :highest_post_number,
:last_read_post_number, :last_read_post_number,
@ -146,6 +147,10 @@ class TopicViewSerializer < ApplicationSerializer
PinnedCheck.new(object.topic, object.topic_user).pinned? PinnedCheck.new(object.topic, object.topic_user).pinned?
end end
def pinned_at
object.topic.pinned_at
end
def actions_summary def actions_summary
result = [] result = []
return [] unless post = object.posts.try(:first) return [] unless post = object.posts.try(:first)