This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/basic-topic-list.js.es6
2019-05-27 10:15:39 +02:00

71 lines
1.7 KiB
JavaScript

import computed from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
loadingMore: Ember.computed.alias("topicList.loadingMore"),
loading: Ember.computed.not("loaded"),
@computed("topicList.loaded")
loaded() {
var topicList = this.topicList;
if (topicList) {
return topicList.get("loaded");
} else {
return true;
}
},
_topicListChanged: function() {
this._initFromTopicList(this.topicList);
}.observes("topicList.[]"),
_initFromTopicList(topicList) {
if (topicList !== null) {
this.set("topics", topicList.get("topics"));
this.rerender();
}
},
init() {
this._super(...arguments);
const topicList = this.topicList;
if (topicList) {
this._initFromTopicList(topicList);
}
},
click(e) {
// Mobile basic-topic-list doesn't use the `topic-list-item` view so
// the event for the topic entrance is never wired up.
if (!this.site.mobileView) {
return;
}
let target = $(e.target);
if (target.closest(".posts-map").length) {
const topicId = target.closest("tr").attr("data-topic-id");
if (topicId) {
if (target.prop("tagName") !== "A") {
let targetLinks = target.find("a");
if (targetLinks.length) {
target = targetLinks;
} else {
targetLinks = target.closest("a");
if (targetLinks.length) {
target = targetLinks;
} else {
return false;
}
}
}
const topic = this.topics.findBy("id", parseInt(topicId));
this.appEvents.trigger("topic-entrance:show", {
topic,
position: target.offset()
});
}
return false;
}
}
});