FIX: pin/unpin button in topic admin menu needs to ignore whether the admin user cleared the pin
This commit is contained in:
parent
42ca83ece5
commit
3175c85fa6
|
@ -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() {
|
||||
|
|
|
@ -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' }
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue