fixed confirmDeleteNoteBoxWithNote

This commit is contained in:
zadam 2022-06-16 21:30:05 +02:00
parent 7ac8dc6785
commit c5bc23d511
3 changed files with 34 additions and 18 deletions

View File

@ -7,7 +7,15 @@ async function info(message) {
async function confirm(message) { async function confirm(message) {
return new Promise(res => return new Promise(res =>
appContext.triggerCommand("showConfirmDialog", {message, callback: res})); appContext.triggerCommand("showConfirmDialog", {
message,
callback: x => res(x.confirmed)
}));
}
async function confirmDeleteNoteBoxWithNote(title) {
return new Promise(res =>
appContext.triggerCommand("showConfirmDeleteNoteBoxWithNoteDialog", {title, callback: res}));
} }
async function prompt(props) { async function prompt(props) {
@ -18,5 +26,6 @@ async function prompt(props) {
export default { export default {
info, info,
confirm, confirm,
confirmDeleteNoteBoxWithNote,
prompt prompt
}; };

View File

@ -79,22 +79,27 @@ export default class ConfirmDialog extends BasicWidget {
this.resolve = callback; this.resolve = callback;
} }
confirmDeleteNoteBoxWithNoteEvent({title, callback}) { showConfirmDeleteNoteBoxWithNoteDialogEvent({title, callback}) {
glob.activeDialog = this.$widget; glob.activeDialog = this.$widget;
this.$confirmContent.text(`Are you sure you want to remove the note "${title}" from relation map?`); this.$confirmContent.text(`Are you sure you want to remove the note "${title}" from relation map?`);
this.$custom.empty() this.$custom.empty()
.append("<br/>") .append("<br/>")
.append($("<div>").addClass("form-check") .append($("<div>")
.append($("<label>") .addClass("form-check")
.addClass("form-check-label") .append(
.attr("style", "text-decoration: underline dotted black") $("<label>")
.attr("title", "If you don't check this, note will be only removed from relation map, but will stay as a note.") .addClass("form-check-label")
.append($("<input>") .attr("style", "text-decoration: underline dotted var(--main-text-color)")
.attr("type", "checkbox") .attr("title", "If you don't check this, the note will be only removed from the relation map.")
.addClass("form-check-input " + DELETE_NOTE_BUTTON_CLASS)) .append(
.text("Also delete note"))); $("<input>")
.attr("type", "checkbox")
.addClass("form-check-input " + DELETE_NOTE_BUTTON_CLASS)
)
.append("Also delete the note")
));
this.$custom.show(); this.$custom.show();
@ -103,12 +108,12 @@ export default class ConfirmDialog extends BasicWidget {
this.resolve = callback; this.resolve = callback;
} }
isDeleteNoteChecked() {
return this.$widget.find("." + DELETE_NOTE_BUTTON_CLASS + ":checked").length > 0;
}
doResolve(ret) { doResolve(ret) {
this.resolve(ret); this.resolve({
confirmed: ret,
isDeleteNoteChecked: this.$widget.find("." + DELETE_NOTE_BUTTON_CLASS + ":checked").length > 0
});
this.resolve = null; this.resolve = null;
this.$widget.modal("hide"); this.$widget.modal("hide");

View File

@ -196,13 +196,15 @@ export default class RelationMapTypeWidget extends TypeWidget {
appContext.tabManager.openTabWithNoteWithHoisting(noteId); appContext.tabManager.openTabWithNoteWithHoisting(noteId);
} }
else if (command === "remove") { else if (command === "remove") {
if (!await dialogService.confirmDeleteNoteBoxWithNote($title.text())) { const result = await dialogService.confirmDeleteNoteBoxWithNote($title.text());
if (!result.confirmed) {
return; return;
} }
this.jsPlumbInstance.remove(this.noteIdToId(noteId)); this.jsPlumbInstance.remove(this.noteIdToId(noteId));
if (confirmDialog.isDeleteNoteChecked()) { if (result.isDeleteNoteChecked) {
const taskId = utils.randomString(10); const taskId = utils.randomString(10);
await server.remove(`notes/${noteId}?taskId=${taskId}&last=true`); await server.remove(`notes/${noteId}?taskId=${taskId}&last=true`);