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/widgets/topic-status.js.es6
Gerhard Schlager 70cdb42173 FIX: Tooltip for unlisted topics wasn't shown in topic list
The locale key had to be renamed, because this key is also used as CSS class.
The "invisible" CSS class makes the icon invisible. "unlisted" doesn't have that effect.
2019-01-15 16:13:06 +01:00

47 lines
1.4 KiB
JavaScript

import { createWidget } from "discourse/widgets/widget";
import { iconNode } from "discourse-common/lib/icon-library";
import { h } from "virtual-dom";
import { escapeExpression } from "discourse/lib/utilities";
function renderIcon(name, key, canAct) {
const iconArgs = key === "unpinned" ? { class: "unpinned" } : null,
icon = iconNode(name, iconArgs);
const attributes = {
title: escapeExpression(I18n.t(`topic_statuses.${key}.help`))
};
return h(`${canAct ? "a" : "span"}.topic-status`, attributes, icon);
}
export default createWidget("topic-status", {
tagName: "div.topic-statuses",
html(attrs) {
const topic = attrs.topic;
const canAct = this.currentUser && !attrs.disableActions;
const result = [];
const renderIconIf = (conditionProp, name, key) => {
if (!topic.get(conditionProp)) {
return;
}
result.push(renderIcon(name, key, canAct));
};
renderIconIf("is_warning", "envelope", "warning");
if (topic.get("closed") && topic.get("archived")) {
renderIcon("lock", "locked_and_archived");
} else {
renderIconIf("closed", "lock", "locked");
renderIconIf("archived", "lock", "archived");
}
renderIconIf("pinned", "thumbtack", "pinned");
renderIconIf("unpinned", "thumbtack", "unpinned");
renderIconIf("invisible", "far-eye-slash", "unlisted");
return result;
}
});