Files
Trilium/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js

52 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-26 09:40:02 +02:00
import BasicWidget from "../basic_widget.js";
2022-12-01 13:07:23 +01:00
import appContext from "../../components/app_context.js";
2022-08-05 16:44:26 +02:00
import contextMenu from "../../menus/context_menu.js";
2020-04-26 09:40:02 +02:00
import noteCreateService from "../../services/note_create.js";
import branchService from "../../services/branches.js";
import treeService from "../../services/tree.js";
2020-03-01 12:50:02 +01:00
const TPL = `<button type="button" class="action-button bx bx-menu" style="padding-top: 10px;"></button>`;
2020-03-01 12:50:02 +01:00
class MobileDetailMenuWidget extends BasicWidget {
doRender() {
this.$widget = $(TPL);
this.$widget.on("click", async e => {
2021-05-22 12:35:41 +02:00
const note = appContext.tabManager.getActiveContextNote();
2020-03-01 12:50:02 +01:00
contextMenu.show({
x: e.pageX,
y: e.pageY,
items: [
2022-05-31 22:45:57 +02:00
{ title: "Insert child note", command: "insertChildNote", uiIcon: "bx bx-plus",
2020-03-01 12:50:02 +01:00
enabled: note.type !== 'search' },
2022-05-31 22:45:57 +02:00
{ title: "Delete this note", command: "delete", uiIcon: "bx bx-trash",
2020-03-01 12:50:02 +01:00
enabled: note.noteId !== 'root' }
],
selectMenuItemHandler: async ({command}) => {
if (command === "insertChildNote") {
2021-05-22 12:35:41 +02:00
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath());
2020-03-01 12:50:02 +01:00
}
else if (command === "delete") {
2021-05-22 12:35:41 +02:00
const notePath = appContext.tabManager.getActiveContextNotePath();
const branchId = await treeService.getBranchIdFromNotePath(notePath);
if (!branchId) {
throw new Error(`Cannot get branchId for notePath ${notePath}`);
}
if (await branchService.deleteNotes([branchId])) {
this.triggerCommand('setActiveScreen', {screen:'tree'})
2020-03-01 12:50:02 +01:00
}
}
else {
throw new Error("Unrecognized command " + command);
}
}
});
});
}
}
2020-07-03 22:27:45 +02:00
export default MobileDetailMenuWidget;