import AbstractSearchOption from "./abstract_search_option.js";
const TPL = `
Order by
|
|
|
`;
export default class OrderBy extends AbstractSearchOption {
static get optionName() { return "orderBy" };
static get attributeType() { return "label" };
static async create(noteId) {
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 = $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 = $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();
}
}