2017-11-21 18:53:09 +08:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
|
|
|
import { on } from "ember-addons/ember-computed-decorators";
|
2018-06-15 23:03:24 +08:00
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
2017-11-21 18:53:09 +08:00
|
|
|
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["pinned-options"],
|
|
|
|
classNames: "pinned-options",
|
|
|
|
allowInitialValueMutation: false,
|
|
|
|
|
|
|
|
autoHighlight() {},
|
|
|
|
|
|
|
|
computeHeaderContent() {
|
2019-01-19 17:05:51 +08:00
|
|
|
let content = this._super(...arguments);
|
2017-11-21 18:53:09 +08:00
|
|
|
const pinnedGlobally = this.get("topic.pinned_globally");
|
2019-05-27 16:15:39 +08:00
|
|
|
const pinned = this.computedValue;
|
2017-11-21 18:53:09 +08:00
|
|
|
const globally = pinnedGlobally ? "_globally" : "";
|
|
|
|
const state = pinned ? `pinned${globally}` : "unpinned";
|
|
|
|
const title = I18n.t(`topic_statuses.${state}.title`);
|
|
|
|
|
2017-12-22 20:08:12 +08:00
|
|
|
content.label = `${title}${iconHTML("caret-down")}`.htmlSafe();
|
|
|
|
content.title = title;
|
|
|
|
content.name = state;
|
2018-11-27 05:49:57 +08:00
|
|
|
content.icon = `thumbtack${state === "unpinned" ? " unpinned" : ""}`;
|
2017-11-21 18:53:09 +08:00
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
@on("init")
|
|
|
|
_setContent() {
|
|
|
|
const globally = this.get("topic.pinned_globally") ? "_globally" : "";
|
|
|
|
|
|
|
|
this.set("content", [
|
|
|
|
{
|
|
|
|
id: "pinned",
|
|
|
|
name: I18n.t("topic_statuses.pinned" + globally + ".title"),
|
2018-06-15 23:03:24 +08:00
|
|
|
description: I18n.t("topic_statuses.pinned" + globally + ".help"),
|
2018-11-27 05:49:57 +08:00
|
|
|
icon: "thumbtack"
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "unpinned",
|
|
|
|
name: I18n.t("topic_statuses.unpinned.title"),
|
2018-11-27 05:49:57 +08:00
|
|
|
icon: "thumbtack unpinned",
|
2018-06-15 23:03:24 +08:00
|
|
|
description: I18n.t("topic_statuses.unpinned.help")
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2018-01-11 16:39:51 +08:00
|
|
|
actions: {
|
|
|
|
onSelect() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const topic = this.topic;
|
2018-01-11 16:39:51 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.computedValue === "unpinned") {
|
2018-01-11 16:39:51 +08:00
|
|
|
topic.clearPin();
|
|
|
|
} else {
|
|
|
|
topic.rePin();
|
|
|
|
}
|
2017-11-21 18:53:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|