discourse/app/assets/javascripts/select-kit/components/pinned-options.js
Robin Ward eab560fe2a
DEV: import I18n instead of global usage (#9768)
Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
Co-authored-by: Robin Ward <robin.ward@gmail.com>

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
2020-05-13 16:23:41 -04:00

61 lines
1.7 KiB
JavaScript

import I18n from "I18n";
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
import { iconHTML } from "discourse-common/lib/icon-library";
import { computed, action } from "@ember/object";
const UNPINNED = "unpinned";
const PINNED = "pinned";
export default DropdownSelectBoxComponent.extend({
pluginApiIdentifiers: ["pinned-options"],
classNames: ["pinned-options"],
modifySelection(content) {
const pinnedGlobally = this.get("topic.pinned_globally");
const pinned = this.value;
const globally = pinnedGlobally ? "_globally" : "";
const state = pinned ? `pinned${globally}` : UNPINNED;
const title = I18n.t(`topic_statuses.${state}.title`);
content.label = `<span>${title}</span>${iconHTML("caret-down")}`.htmlSafe();
content.title = title;
content.name = state;
content.icon = `thumbtack${state === UNPINNED ? " unpinned" : ""}`;
return content;
},
content: computed(function() {
const globally = this.topic.pinned_globally ? "_globally" : "";
return [
{
id: PINNED,
name: I18n.t(`topic_statuses.pinned${globally}.title`),
description: this.site.mobileView
? null
: I18n.t(`topic_statuses.pinned${globally}.help`),
icon: "thumbtack"
},
{
id: UNPINNED,
name: I18n.t("topic_statuses.unpinned.title"),
icon: "thumbtack unpinned",
description: this.site.mobileView
? null
: I18n.t("topic_statuses.unpinned.help")
}
];
}),
@action
onChange(value) {
const topic = this.topic;
if (value === UNPINNED) {
return topic.clearPin();
} else {
return topic.rePin();
}
}
});