Merge pull request #806 from ZogStriP/clear-pin-link-in-list-topics-view

Add a clear pin link in the list topics view
This commit is contained in:
Sam 2013-05-02 16:45:46 -07:00
commit 3ca263568e
3 changed files with 17 additions and 5 deletions

View file

@ -53,6 +53,11 @@ Discourse.ListTopicsController = Discourse.ObjectController.extend({
topic.toggleStar(); topic.toggleStar();
}, },
// clear a pinned topic
clearPin: function(topic) {
topic.clearPin();
},
toggleRankDetails: function() { toggleRankDetails: function() {
this.toggleProperty('rankDetailsVisible'); this.toggleProperty('rankDetailsVisible');
}, },

View file

@ -371,13 +371,17 @@ Discourse.Topic = Discourse.Model.extend({
}, },
hasExcerpt: function() { hasExcerpt: function() {
return this.get('excerpt') && this.get('excerpt').length > 0; return this.get('pinned') && this.get('excerpt') && this.get('excerpt').length > 0;
}.property('excerpt'), }.property('pinned', 'excerpt'),
excerptTruncated: function() { excerptTruncated: function() {
var e = this.get('excerpt'); var e = this.get('excerpt');
return( e && e.substr(e.length - 8,8) === '…' ); return( e && e.substr(e.length - 8,8) === '…' );
}.property('excerpt') }.property('excerpt'),
canClearPin: function() {
return this.get('pinned') && (this.get('last_read_post_number') === this.get('highest_post_number'));
}.property('pinned', 'last_read_post_number', 'highest_post_number')
}); });
Discourse.Topic.reopenClass({ Discourse.Topic.reopenClass({

View file

@ -29,11 +29,14 @@
<a href="{{lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a> <a href="{{lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
{{/if}} {{/if}}
{{#if excerpt}} {{#if hasExcerpt}}
<div class="topic-excerpt"> <div class="topic-excerpt">
{{excerpt}} {{excerpt}}
{{#if excerptTruncated}} {{#if excerptTruncated}}
<a href="{{lastReadUrl}}">{{i18n read_more}}</a> {{#unless canClearPin}}<a href="{{lastReadUrl}}">{{i18n read_more}}</a>{{/unless}}
{{/if}}
{{#if canClearPin}}
<a href="#" {{action clearPin this target="controller"}} title="{{unbound i18n topic.clear_pin.help}}">{{i18n topic.clear_pin.title}}</a>
{{/if}} {{/if}}
</div> </div>
{{/if}} {{/if}}