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