mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-18 17:31:53 +08:00
refactor(client/ts): use context_menu in note_type_chooser
This commit is contained in:
parent
5f0ace2886
commit
10f8da8015
@ -1,23 +1,10 @@
|
||||
import server from "./server.js";
|
||||
import froca from "./froca.js";
|
||||
import { t } from "./i18n.js";
|
||||
|
||||
interface NoteTypeSeparator {
|
||||
title: "----"
|
||||
}
|
||||
|
||||
export interface NoteType {
|
||||
title: string;
|
||||
command?: string;
|
||||
type: string;
|
||||
uiIcon: string;
|
||||
templateNoteId?: string;
|
||||
}
|
||||
|
||||
type NoteTypeItem = NoteType | NoteTypeSeparator;
|
||||
import { MenuItem } from "../menus/context_menu.js";
|
||||
|
||||
async function getNoteTypeItems(command?: string) {
|
||||
const items: NoteTypeItem[] = [
|
||||
const items: MenuItem[] = [
|
||||
{ title: t("note_types.text"), command: command, type: "text", uiIcon: "bx bx-note" },
|
||||
{ title: t("note_types.code"), command: command, type: "code", uiIcon: "bx bx-code" },
|
||||
{ title: t("note_types.saved-search"), command: command, type: "search", uiIcon: "bx bx-file-find" },
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { MenuCommandItem } from "../../menus/context_menu.js";
|
||||
import { t } from "../../services/i18n.js";
|
||||
import noteTypesService, { NoteType } from "../../services/note_types.js";
|
||||
import noteTypesService from "../../services/note_types.js";
|
||||
import BasicWidget from "../basic_widget.js";
|
||||
|
||||
const TPL = `
|
||||
@ -9,7 +10,7 @@ const TPL = `
|
||||
/* note type chooser needs to be higher than other dialogs from which it is triggered, e.g. "add link"*/
|
||||
z-index: 1100 !important;
|
||||
}
|
||||
|
||||
|
||||
.note-type-chooser-dialog .note-type-dropdown {
|
||||
position: relative;
|
||||
font-size: large;
|
||||
@ -67,7 +68,7 @@ export default class NoteTypeChooserDialog extends BasicWidget {
|
||||
}
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$widget = $(TPL);
|
||||
// TODO: Remove once we import bootstrap the right way
|
||||
//@ts-ignore
|
||||
this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget);
|
||||
@ -126,12 +127,13 @@ export default class NoteTypeChooserDialog extends BasicWidget {
|
||||
for (const noteType of noteTypes) {
|
||||
if (noteType.title === '----') {
|
||||
this.$noteTypeDropdown.append($('<h6 class="dropdown-header">').append(t("note_type_chooser.templates")));
|
||||
} else {
|
||||
} else {
|
||||
const commandItem = (noteType as MenuCommandItem)
|
||||
this.$noteTypeDropdown.append(
|
||||
$('<a class="dropdown-item" tabindex="0">')
|
||||
.attr("data-note-type", (noteType as NoteType).type)
|
||||
.attr("data-template-note-id", (noteType as NoteType).templateNoteId || "")
|
||||
.append($("<span>").addClass((noteType as NoteType).uiIcon))
|
||||
.attr("data-note-type", commandItem.type)
|
||||
.attr("data-template-note-id", commandItem.templateNoteId || "")
|
||||
.append($("<span>").addClass(commandItem.uiIcon))
|
||||
.append(` ${noteType.title}`)
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user