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";
|
2020-09-13 21:12:22 +02:00
|
|
|
import treeService from "../../services/tree.js";
|
2024-08-05 09:57:36 +08:00
|
|
|
import { t } from "../../services/i18n.js";
|
2020-03-01 12:50:02 +01:00
|
|
|
|
2024-11-23 09:48:18 +02: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 {
|
2025-01-17 23:55:46 +02:00
|
|
|
private isHorizontalLayout: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(isHorizontalLayout: boolean) {
|
2024-11-23 09:48:18 +02:00
|
|
|
super();
|
|
|
|
|
this.isHorizontalLayout = isHorizontalLayout;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-01 12:50:02 +01:00
|
|
|
doRender() {
|
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
|
|
2024-11-23 09:48:18 +02:00
|
|
|
this.$widget.addClass(this.isHorizontalLayout ? "bx-dots-vertical-rounded" : "bx-menu");
|
|
|
|
|
|
2025-01-09 18:07:02 +02: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: [
|
2025-01-09 18:07:02 +02:00
|
|
|
{ title: t("mobile_detail_menu.insert_child_note"), command: "insertChildNote", uiIcon: "bx bx-plus", enabled: note.type !== "search" },
|
|
|
|
|
{ title: t("mobile_detail_menu.delete_this_note"), command: "delete", uiIcon: "bx bx-trash", enabled: note.noteId !== "root" }
|
2020-03-01 12:50:02 +01:00
|
|
|
],
|
2025-01-09 18:07:02 +02:00
|
|
|
selectMenuItemHandler: async ({ command }) => {
|
2020-03-01 12:50:02 +01:00
|
|
|
if (command === "insertChildNote") {
|
2025-01-17 23:55:46 +02:00
|
|
|
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath() ?? undefined);
|
2025-01-09 18:07:02 +02:00
|
|
|
} else if (command === "delete") {
|
2021-05-22 12:35:41 +02:00
|
|
|
const notePath = appContext.tabManager.getActiveContextNotePath();
|
2025-01-17 23:55:46 +02:00
|
|
|
if (!notePath) {
|
|
|
|
|
throw new Error("Cannot get note path to delete.");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 22:37:19 +02:00
|
|
|
const branchId = await treeService.getBranchIdFromUrl(notePath);
|
2020-09-13 21:12:22 +02:00
|
|
|
|
|
|
|
|
if (!branchId) {
|
2024-08-05 09:57:36 +08:00
|
|
|
throw new Error(t("mobile_detail_menu.error_cannot_get_branch_id", { notePath }));
|
2020-09-13 21:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await branchService.deleteNotes([branchId])) {
|
2025-01-09 18:07:02 +02:00
|
|
|
this.triggerCommand("setActiveScreen", { screen: "tree" });
|
2020-03-01 12:50:02 +01:00
|
|
|
}
|
2025-01-09 18:07:02 +02:00
|
|
|
} else {
|
2024-08-05 09:57:36 +08:00
|
|
|
throw new Error(t("mobile_detail_menu.error_unrecognized_command", { command }));
|
2020-03-01 12:50:02 +01:00
|
|
|
}
|
2025-01-18 00:04:06 +02:00
|
|
|
},
|
|
|
|
|
forcePositionOnMobile: true
|
2020-03-01 12:50:02 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 22:27:45 +02:00
|
|
|
export default MobileDetailMenuWidget;
|