|
|
|
@ -1,25 +1,61 @@
|
|
|
|
|
|
|
|
import server from "../services/server.js";
|
|
|
|
|
|
|
|
import treeCache from "../services/tree_cache.js";
|
|
|
|
|
|
|
|
import linkService from "../services/link.js";
|
|
|
|
|
|
|
|
|
|
|
|
const $dialog = $("#delete-notes-dialog");
|
|
|
|
const $dialog = $("#delete-notes-dialog");
|
|
|
|
const $confirmContent = $("#delete-notes-dialog-content");
|
|
|
|
const $confirmContent = $("#delete-notes-dialog-content");
|
|
|
|
const $okButton = $("#delete-notes-dialog-ok-button");
|
|
|
|
const $okButton = $("#delete-notes-dialog-ok-button");
|
|
|
|
const $cancelButton = $("#delete-notes-dialog-cancel-button");
|
|
|
|
const $cancelButton = $("#delete-notes-dialog-cancel-button");
|
|
|
|
const $custom = $("#delete-notes-dialog-custom");
|
|
|
|
const $custom = $("#delete-notes-dialog-custom");
|
|
|
|
|
|
|
|
const $deleteNotesList = $("#delete-notes-list");
|
|
|
|
|
|
|
|
const $brokenRelationsList = $("#broken-relations-list");
|
|
|
|
|
|
|
|
const $deletedNotesCount = $("#deleted-notes-count");
|
|
|
|
|
|
|
|
const $noNoteToDeleteWrapper = $("#no-note-to-delete-wrapper");
|
|
|
|
|
|
|
|
const $deleteNotesListWrapper = $("#delete-notes-list-wrapper");
|
|
|
|
|
|
|
|
const $brokenRelationsListWrapper = $("#broken-relations-wrapper");
|
|
|
|
|
|
|
|
|
|
|
|
const DELETE_NOTE_BUTTON_ID = "delete-notes-dialog-delete-note";
|
|
|
|
const DELETE_NOTE_BUTTON_ID = "delete-notes-dialog-delete-note";
|
|
|
|
|
|
|
|
|
|
|
|
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
|
|
|
|
let $originallyFocused; // element focused before the dialog was opened so we can return to it afterwards
|
|
|
|
|
|
|
|
|
|
|
|
export function showDialog(message) {
|
|
|
|
export async function showDialog(branchIdsToDelete) {
|
|
|
|
$originallyFocused = $(':focus');
|
|
|
|
$originallyFocused = $(':focus');
|
|
|
|
|
|
|
|
|
|
|
|
$custom.hide();
|
|
|
|
$custom.hide();
|
|
|
|
|
|
|
|
|
|
|
|
glob.activeDialog = $dialog;
|
|
|
|
glob.activeDialog = $dialog;
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof message === 'string') {
|
|
|
|
const response = await server.post('delete-notes-preview', {branchIdsToDelete});
|
|
|
|
message = $("<div>").text(message);
|
|
|
|
|
|
|
|
|
|
|
|
$deleteNotesList.empty();
|
|
|
|
|
|
|
|
$brokenRelationsList.empty();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$deleteNotesListWrapper.toggle(response.noteIdsToBeDeleted.length > 0);
|
|
|
|
|
|
|
|
$noNoteToDeleteWrapper.toggle(response.noteIdsToBeDeleted.length === 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const note of await treeCache.getNotes(response.noteIdsToBeDeleted)) {
|
|
|
|
|
|
|
|
$deleteNotesList.append(
|
|
|
|
|
|
|
|
$("<li>").append(
|
|
|
|
|
|
|
|
await linkService.createNoteLink(note.noteId, {showNotePath: true})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$confirmContent.empty().append(message);
|
|
|
|
$deletedNotesCount.text(response.noteIdsToBeDeleted.length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$brokenRelationsListWrapper.toggle(response.brokenRelations.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await treeCache.getNotes(response.brokenRelations.map(br => br.noteId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const attr of response.brokenRelations) {
|
|
|
|
|
|
|
|
$brokenRelationsList.append(
|
|
|
|
|
|
|
|
$("<li>")
|
|
|
|
|
|
|
|
.append(`Note `)
|
|
|
|
|
|
|
|
.append(await linkService.createNoteLink(attr.value))
|
|
|
|
|
|
|
|
.append(` (to be deleted) is referenced by relation <code>${attr.name}</code> originating from `)
|
|
|
|
|
|
|
|
.append(await linkService.createNoteLink(attr.noteId))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$dialog.modal();
|
|
|
|
$dialog.modal();
|
|
|
|
|
|
|
|
|
|
|
|
|