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

61 lines
2.4 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";
import { t } from "../../services/i18n.js";
2020-03-01 12:50:02 +01:00
const TPL = `<button type="button" class="action-button bx" style="padding-top: 10px;"></button>`;
2020-03-01 12:50:02 +01:00
class MobileDetailMenuWidget extends BasicWidget {
constructor(isHorizontalLayout) {
super();
this.isHorizontalLayout = isHorizontalLayout;
}
2020-03-01 12:50:02 +01:00
doRender() {
this.$widget = $(TPL);
this.$widget.addClass(this.isHorizontalLayout ? "bx-dots-vertical-rounded" : "bx-menu");
2020-03-01 12:50:02 +01:00
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: [
{ title: t("mobile_detail_menu.insert_child_note"), command: "insertChildNote", uiIcon: "bx bx-plus",
2020-03-01 12:50:02 +01:00
enabled: note.type !== 'search' },
{ title: t("mobile_detail_menu.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.getBranchIdFromUrl(notePath);
if (!branchId) {
throw new Error(t("mobile_detail_menu.error_cannot_get_branch_id", { notePath }));
}
if (await branchService.deleteNotes([branchId])) {
this.triggerCommand('setActiveScreen', {screen:'tree'})
2020-03-01 12:50:02 +01:00
}
}
else {
throw new Error(t("mobile_detail_menu.error_unrecognized_command", { command }));
2020-03-01 12:50:02 +01:00
}
}
});
});
}
}
2020-07-03 22:27:45 +02:00
export default MobileDetailMenuWidget;