import AbstractSearchOption from "./abstract_search_option.js";
import { t } from "../../services/i18n.js";
const TPL = `
|
${t("order_by.order_by")}
|
|
|
`;
export default class OrderBy extends AbstractSearchOption {
static get optionName() {
return "orderBy";
}
static get attributeType() {
return "label";
}
static async create(noteId: string) {
await AbstractSearchOption.setAttribute(noteId, "label", "orderBy", "relevancy");
await AbstractSearchOption.setAttribute(noteId, "label", "orderDirection", "asc");
}
doRender() {
const $option = $(TPL);
const $orderBy = $option.find("select[name=orderBy]");
$orderBy.on("change", async () => {
const orderBy = String($orderBy.val());
await this.setAttribute("label", "orderBy", orderBy);
});
$orderBy.val(this.note.getLabelValue("orderBy") ?? "");
const $orderDirection = $option.find("select[name=orderDirection]");
$orderDirection.on("change", async () => {
const orderDirection = String($orderDirection.val());
await this.setAttribute("label", "orderDirection", orderDirection);
});
$orderDirection.val(this.note.getLabelValue("orderDirection") || "asc");
return $option;
}
async deleteOption() {
await this.deleteAttribute("label", "orderDirection");
await super.deleteOption();
}
}