From 3175c85fa6e08611b8dc9261803d5e4227d6c40a Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 12 Mar 2014 14:47:04 -0400 Subject: [PATCH] FIX: pin/unpin button in topic admin menu needs to ignore whether the admin user cleared the pin --- .../discourse/controllers/topic_controller.js | 3 ++- app/assets/javascripts/discourse/models/topic.js | 16 ++++++++++++++-- .../templates/topic_admin_menu.js.handlebars | 2 +- app/serializers/topic_view_serializer.rb | 7 ++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index bae43bbbc..8bd38af64 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -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() { diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index e13fd0cc5..ca4858cd4 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -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' } }); }, diff --git a/app/assets/javascripts/discourse/templates/topic_admin_menu.js.handlebars b/app/assets/javascripts/discourse/templates/topic_admin_menu.js.handlebars index 647d5bd71..5c569f98b 100644 --- a/app/assets/javascripts/discourse/templates/topic_admin_menu.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic_admin_menu.js.handlebars @@ -29,7 +29,7 @@
  • - {{#if pinned}} + {{#if pinned_at}} {{else}} diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index e3d0ed792..db7d04955 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -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)