Add extensibility endpoints for clicking on topic list item rows

This commit is contained in:
Robin Ward 2017-12-22 14:01:17 -05:00
parent 3ae9d91d86
commit ea9c1e5cf8
2 changed files with 35 additions and 9 deletions

View File

@ -1,7 +1,21 @@
import { showEntrance } from "discourse/components/topic-list-item";
import { showEntrance, navigateToTopic } from "discourse/components/topic-list-item";
export default Ember.Component.extend({
click: showEntrance,
attributeBindings: ['topic.id:data-topic-id'],
classNameBindings: [':latest-topic-list-item', 'topic.archived', 'topic.visited']
classNameBindings: [':latest-topic-list-item', 'topic.archived', 'topic.visited'],
showEntrance,
navigateToTopic,
click(e) {
// for events undefined has a different meaning than false
if (this.showEntrance(e) === false) {
return false;
}
return this.unhandledRowClick(e, this.get('topic'));
},
// Can be overwritten by plugins to handle clicks on other parts of the row
unhandledRowClick() { },
});

View File

@ -20,6 +20,12 @@ export function showEntrance(e) {
}
}
export function navigateToTopic(topic, href) {
this.appEvents.trigger('header:update-topic', topic);
DiscourseURL.routeTo(href || topic.get('url'));
return false;
}
export default Ember.Component.extend(bufferedRender({
rerenderTriggers: ['bulkSelectEnabled', 'topic.pinned'],
tagName: 'tr',
@ -107,8 +113,10 @@ export default Ember.Component.extend(bufferedRender({
return false;
}.property(),
showEntrance,
click(e) {
const result = showEntrance.call(this, e);
const result = this.showEntrance(e);
if (result === false) { return result; }
const topic = this.get('topic');
@ -124,19 +132,23 @@ export default Ember.Component.extend(bufferedRender({
}
if (target.hasClass('raw-topic-link')) {
if (wantsNewWindow(e)) { return true; }
this.appEvents.trigger('header:update-topic', topic);
DiscourseURL.routeTo(target.attr('href'));
return false;
if (wantsNewWindow(e)) { return true; }
return this.navigateToTopic(topic, target.attr('href'));
}
if (target.closest('a.topic-status').length === 1) {
this.get('topic').togglePinnedForUser();
return false;
}
return this.unhandledRowClick(e, topic);
},
navigateToTopic,
// Can be overwritten by plugins to handle clicks on other parts of the row
unhandledRowClick() { },
highlight(opts = { isLastViewedTopic: false }) {
const $topic = this.$();
$topic