mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added BS dialog for confirm
This commit is contained in:
parent
b8feb4cce3
commit
19a07c699c
38
src/public/javascripts/dialogs/confirm.js
Normal file
38
src/public/javascripts/dialogs/confirm.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
const $dialog = $("#confirm-dialog");
|
||||||
|
const $confirmContent = $("#confirm-dialog-content");
|
||||||
|
const $okButton = $("#confirm-dialog-ok-button");
|
||||||
|
const $cancelButton = $("#confirm-dialog-cancel-button");
|
||||||
|
|
||||||
|
let resolve;
|
||||||
|
|
||||||
|
function confirm(message) {
|
||||||
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
|
$confirmContent.text(message);
|
||||||
|
|
||||||
|
$dialog.modal();
|
||||||
|
|
||||||
|
return new Promise((res, rej) => { resolve = res; });
|
||||||
|
}
|
||||||
|
|
||||||
|
$dialog.on('shown.bs.modal', () => $okButton.trigger("focus"));
|
||||||
|
|
||||||
|
$dialog.on("hidden.bs.modal", () => {
|
||||||
|
if (resolve) {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function doResolve(ret) {
|
||||||
|
resolve(ret);
|
||||||
|
resolve = null;
|
||||||
|
|
||||||
|
$dialog.modal("hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
$cancelButton.click(() => doResolve(false));
|
||||||
|
$okButton.click(() => doResolve(true));
|
||||||
|
|
||||||
|
export default {
|
||||||
|
confirm
|
||||||
|
}
|
@ -8,6 +8,7 @@ import infoService from "./info.js";
|
|||||||
import attributeAutocompleteService from "./attribute_autocomplete.js";
|
import attributeAutocompleteService from "./attribute_autocomplete.js";
|
||||||
import promptDialog from "../dialogs/prompt.js";
|
import promptDialog from "../dialogs/prompt.js";
|
||||||
import infoDialog from "../dialogs/info.js";
|
import infoDialog from "../dialogs/info.js";
|
||||||
|
import confirmDialog from "../dialogs/confirm.js";
|
||||||
|
|
||||||
const $component = $("#note-detail-relation-map");
|
const $component = $("#note-detail-relation-map");
|
||||||
const $relationMapContainer = $("#relation-map-container");
|
const $relationMapContainer = $("#relation-map-container");
|
||||||
@ -293,7 +294,7 @@ function connectionContextMenuHandler(connection, event) {
|
|||||||
|
|
||||||
contextMenuWidget.initContextMenu(event, contextMenuItems, async (event, cmd) => {
|
contextMenuWidget.initContextMenu(event, contextMenuItems, async (event, cmd) => {
|
||||||
if (cmd === 'remove') {
|
if (cmd === 'remove') {
|
||||||
if (!confirm("Are you sure you want to remove the relation?")) {
|
if (!await confirmDialog.confirm("Are you sure you want to remove the relation?")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,14 +382,14 @@ $relationMapContainer.on("contextmenu", ".note-box", e => {
|
|||||||
|
|
||||||
async function noteContextMenuHandler(event, cmd) {
|
async function noteContextMenuHandler(event, cmd) {
|
||||||
const $noteBox = $(event.originalTarget).closest(".note-box");
|
const $noteBox = $(event.originalTarget).closest(".note-box");
|
||||||
const noteId = $noteBox.prop("id");
|
const noteId = idToNoteId($noteBox.prop("id"));
|
||||||
|
|
||||||
if (cmd === "remove") {
|
if (cmd === "remove") {
|
||||||
if (!confirm("Are you sure you want to remove the note from this diagram?")) {
|
if (!await confirmDialog.confirm("Are you sure you want to remove the note from this diagram?")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsPlumbInstance.remove(noteId);
|
jsPlumbInstance.remove(noteIdToId(noteId));
|
||||||
|
|
||||||
mapData.notes = mapData.notes.filter(note => note.noteId !== noteId);
|
mapData.notes = mapData.notes.filter(note => note.noteId !== noteId);
|
||||||
|
|
||||||
|
23
src/views/dialogs/confirm.ejs
Normal file
23
src/views/dialogs/confirm.ejs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<div id="confirm-dialog" class="modal mx-auto" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title mr-auto">Confirmation</h5>
|
||||||
|
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div id="confirm-dialog-content"></div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn btn-default btn-sm" id="confirm-dialog-cancel-button">Cancel</button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button class="btn btn-primary btn-sm" id="confirm-dialog-ok-button">OK</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -12,7 +12,7 @@
|
|||||||
<div id="info-dialog-content"></div>
|
<div id="info-dialog-content"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class="btn btn-primary btn-sm" id="info-dialog-ok-button">OK <kbd>enter</kbd></button>
|
<button class="btn btn-primary btn-sm" id="info-dialog-ok-button">OK</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -184,6 +184,7 @@
|
|||||||
<% include dialogs/sql_console.ejs %>
|
<% include dialogs/sql_console.ejs %>
|
||||||
<% include dialogs/info.ejs %>
|
<% include dialogs/info.ejs %>
|
||||||
<% include dialogs/prompt.ejs %>
|
<% include dialogs/prompt.ejs %>
|
||||||
|
<% include dialogs/confirm.ejs %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user