delete notes dialog WIP

This commit is contained in:
zadam 2021-03-18 23:23:35 +01:00
parent 76aa7d1451
commit d62558d97a
4 changed files with 31 additions and 54 deletions

View File

@ -1,30 +1,31 @@
import server from "../services/server.js";
import treeCache from "../services/tree_cache.js";
import linkService from "../services/link.js";
import utils from "../services/utils.js";
const $dialog = $("#delete-notes-dialog");
const $confirmContent = $("#delete-notes-dialog-content");
const $okButton = $("#delete-notes-dialog-ok-button");
const $cancelButton = $("#delete-notes-dialog-cancel-button");
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 $brokenRelationsCount = $("#broke-relations-count");
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 branchIds = null;
let resolve = null;
export async function showDialog(branchIdsToDelete) {
branchIds = branchIdsToDelete;
$originallyFocused = $(':focus');
$custom.hide();
glob.activeDialog = $dialog;
const response = await server.post('delete-notes-preview', {branchIdsToDelete});
$deleteNotesList.empty();
@ -44,6 +45,7 @@ export async function showDialog(branchIdsToDelete) {
$deletedNotesCount.text(response.noteIdsToBeDeleted.length);
$brokenRelationsListWrapper.toggle(response.brokenRelations.length > 0);
$brokenRelationsCount.text(response.brokenRelations.length);
await treeCache.getNotes(response.brokenRelations.map(br => br.noteId));
@ -57,9 +59,9 @@ export async function showDialog(branchIdsToDelete) {
);
}
$dialog.modal();
utils.openDialog($dialog);
return new Promise((res, rej) => { resolve = res; });
return new Promise((res, rej) => resolve = res);
}
export function isDeleteNoteChecked() {
@ -68,23 +70,17 @@ export function isDeleteNoteChecked() {
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
$dialog.on("hidden.bs.modal", () => {
if (resolve) {
resolve(false);
}
$cancelButton.on('click', () => {
utils.closeActiveDialog();
if ($originallyFocused) {
$originallyFocused.trigger('focus');
$originallyFocused = null;
}
resolve({proceed: false});
});
function doResolve(ret) {
resolve(ret);
resolve = null;
$okButton.on('click', () => {
utils.closeActiveDialog();
$dialog.modal("hide");
}
$cancelButton.on('click', () => doResolve(false));
$okButton.on('click', () => doResolve(true));
resolve({
proceed: true,
deleteClones: false
});
});

View File

@ -75,30 +75,11 @@ async function deleteNotes(branchIdsToDelete) {
}
const deleteNotesDialog = await import("../dialogs/delete_notes.js");
deleteNotesDialog.showDialog(branchIdsToDelete);
const $deleteClonesCheckbox = $('<div class="form-check">')
.append($('<input type="checkbox" class="form-check-input" id="delete-clones-checkbox">'))
.append($('<label for="delete-clones-checkbox">')
.text("Also delete all note clones")
.attr("title", "all clones of selected notes will be deleted and as such the whole note will be deleted."));
const $nodeTitles = $("<ul>");
for (const branchId of branchIdsToDelete) {
const note = await treeCache.getBranch(branchId).getNote();
$nodeTitles.append($("<li>").text(note.title));
}
const $confirmText = $("<div>")
.append($("<p>").text('This will delete the following notes and their sub-notes: '))
.append($nodeTitles)
.append($deleteClonesCheckbox);
const {proceed, deleteClones} = await deleteNotesDialog.showDialog(branchIdsToDelete);
if (!proceed) {
return false;
const deleteClones = $deleteClonesCheckbox.find("input").is(":checked");
}
const taskId = utils.randomString(10);

View File

@ -256,7 +256,7 @@ function getDeleteNotesPreview(req) {
let brokenRelations = [];
if (noteIdsToBeDeleted.length > 0) {
if (noteIdsToBeDeleted.size > 0) {
sql.fillParamList(noteIdsToBeDeleted);
brokenRelations = sql.getRows(`

View File

@ -12,19 +12,19 @@
<div id="delete-notes-list-wrapper">
<h5>Following notes will be deleted (<span id="deleted-notes-count"></span>)</h5>
<ul id="delete-notes-list" style="max-height: 400px; overflow: auto;"></ul>
<ul id="delete-notes-list" style="max-height: 300px; overflow: auto;"></ul>
</div>
<div id="no-note-to-delete-wrapper">
<strong>No note will be deleted (only clones).</strong>
<div id="no-note-to-delete-wrapper" class="alert alert-info">
No note will be deleted (only clones).
</div>
<div id="broken-relations-wrapper">
<h5>Broken relations</h5>
<div class="alert alert-danger">
<h5>Following relations will be broken and deleted (<span id="broke-relations-count"></span>)</h5>
Below can be seen relations which will be broken after notes mentioned above are deleted.
<ul id="broken-relations-list" style="max-height: 400px; overflow: auto;"></ul>
<ul id="broken-relations-list" style="max-height: 300px; overflow: auto;"></ul>
</div>
</div>
</div>
<div class="modal-footer">