2020-05-13 16:23:41 -04:00
|
|
|
import { action, computed } from "@ember/object";
|
2022-05-13 14:58:26 -05:00
|
|
|
import { htmlSafe } from "@ember/template";
|
2024-08-23 12:17:07 +01:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2024-11-19 20:45:18 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2023-10-10 19:38:59 +01:00
|
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
2024-08-23 12:17:07 +01:00
|
|
|
import {
|
|
|
|
pluginApiIdentifiers,
|
|
|
|
selectKitOptions,
|
|
|
|
} from "select-kit/components/select-kit";
|
2020-03-10 09:56:55 +01:00
|
|
|
|
|
|
|
const UNPINNED = "unpinned";
|
|
|
|
const PINNED = "pinned";
|
2017-11-21 11:53:09 +01:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@classNames("pinned-options")
|
|
|
|
@selectKitOptions({
|
|
|
|
showCaret: true,
|
|
|
|
})
|
|
|
|
@pluginApiIdentifiers("pinned-options")
|
|
|
|
export default class PinnedOptions extends DropdownSelectBoxComponent {
|
2020-02-03 14:22:14 +01:00
|
|
|
modifySelection(content) {
|
2017-11-21 11:53:09 +01:00
|
|
|
const pinnedGlobally = this.get("topic.pinned_globally");
|
2020-02-03 14:22:14 +01:00
|
|
|
const pinned = this.value;
|
2017-11-21 11:53:09 +01:00
|
|
|
const globally = pinnedGlobally ? "_globally" : "";
|
2020-03-10 09:56:55 +01:00
|
|
|
const state = pinned ? `pinned${globally}` : UNPINNED;
|
2024-11-19 20:45:18 +00:00
|
|
|
const title = i18n(`topic_statuses.${state}.title`);
|
2017-11-21 11:53:09 +01:00
|
|
|
|
2022-05-13 14:58:26 -05:00
|
|
|
content.label = htmlSafe(`<span>${title}</span>`);
|
2017-12-22 13:08:12 +01:00
|
|
|
content.title = title;
|
|
|
|
content.name = state;
|
2020-03-10 09:56:55 +01:00
|
|
|
content.icon = `thumbtack${state === UNPINNED ? " unpinned" : ""}`;
|
2017-11-21 11:53:09 +01:00
|
|
|
return content;
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2017-11-21 11:53:09 +01:00
|
|
|
|
2024-08-23 12:17:07 +01:00
|
|
|
@computed
|
|
|
|
get content() {
|
2020-02-03 14:22:14 +01:00
|
|
|
const globally = this.topic.pinned_globally ? "_globally" : "";
|
2017-11-21 11:53:09 +01:00
|
|
|
|
2020-02-03 14:22:14 +01:00
|
|
|
return [
|
2017-11-21 11:53:09 +01:00
|
|
|
{
|
2020-03-10 09:56:55 +01:00
|
|
|
id: PINNED,
|
2024-11-19 20:45:18 +00:00
|
|
|
name: i18n(`topic_statuses.pinned${globally}.title`),
|
2020-02-04 15:34:56 +01:00
|
|
|
description: this.site.mobileView
|
|
|
|
? null
|
2024-11-19 20:45:18 +00:00
|
|
|
: i18n(`topic_statuses.pinned${globally}.help`),
|
2018-11-26 16:49:57 -05:00
|
|
|
icon: "thumbtack",
|
2017-11-21 11:53:09 +01:00
|
|
|
},
|
|
|
|
{
|
2020-03-10 09:56:55 +01:00
|
|
|
id: UNPINNED,
|
2024-11-19 20:45:18 +00:00
|
|
|
name: i18n("topic_statuses.unpinned.title"),
|
2018-11-26 16:49:57 -05:00
|
|
|
icon: "thumbtack unpinned",
|
2020-02-04 15:34:56 +01:00
|
|
|
description: this.site.mobileView
|
|
|
|
? null
|
2024-11-19 20:45:18 +00:00
|
|
|
: i18n("topic_statuses.unpinned.help"),
|
2017-11-21 11:53:09 +01:00
|
|
|
},
|
2020-02-03 14:22:14 +01:00
|
|
|
];
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
2017-11-21 11:53:09 +01:00
|
|
|
|
2020-03-10 09:56:55 +01:00
|
|
|
@action
|
|
|
|
onChange(value) {
|
|
|
|
const topic = this.topic;
|
2018-01-11 09:39:51 +01:00
|
|
|
|
2020-03-10 09:56:55 +01:00
|
|
|
if (value === UNPINNED) {
|
|
|
|
return topic.clearPin();
|
|
|
|
} else {
|
|
|
|
return topic.rePin();
|
2017-11-21 11:53:09 +01:00
|
|
|
}
|
2024-08-23 12:17:07 +01:00
|
|
|
}
|
|
|
|
}
|