Semi-stable version with old variable names
This commit is contained in:
@@ -23,6 +23,8 @@ jQuery(document).ready(function ($) {
|
||||
|
||||
});
|
||||
|
||||
const colors = ["rgb(255, 0, 0)", "rgb(0, 255, 0)", "#ff9d00"];
|
||||
|
||||
function displayMsg(type, msg) {
|
||||
const now = Date.now();
|
||||
|
||||
@@ -37,7 +39,6 @@ function displayMsg(type, msg) {
|
||||
lastMsgTime = now;
|
||||
lastMsgContent = msg;
|
||||
|
||||
const colors = ["rgb(255, 0, 0)", "rgb(0, 255, 0)", "#ff9d00"];
|
||||
if (type !== 0 && type !== 1 && type !== 2) return;
|
||||
|
||||
const d = new Date();
|
||||
@@ -58,33 +59,95 @@ function displayMsg(type, msg) {
|
||||
setTimeout(() => fadeOutDiv($div), 5000);
|
||||
}
|
||||
|
||||
function displayConfirm(type, msg) {
|
||||
function displayConfirm(msg = null) {
|
||||
return new Promise((resolve) => {
|
||||
const colors = ["rgb(255, 0, 0)", "rgb(0, 255, 0)", "#ff9d00"];
|
||||
if (![0, 1, 2].includes(type)) return resolve(false);
|
||||
|
||||
const $div = $('<div class="confirmBox"></div>')
|
||||
.css({ 'border-color': colors[type] })
|
||||
.text(msg);
|
||||
// Created clean layout references
|
||||
const $heading = $('<h3>', { class: 'confirmImportantHeading', text: 'Bitte bestätige diese Aktion' });
|
||||
const $text = $('<p>', { class: 'confirmImportantText', text: msg || 'Diese Aktion ist unumkehrbar.' });
|
||||
|
||||
const $buttonDiv = $('<div class="buttonConfirmDiv"></div>');
|
||||
const $buttonYes = $('<button class="confirmYesButton">Ja</button>');
|
||||
const $buttonNo = $('<button class="confirmNoButton">Nein</button>');
|
||||
const $submitBtn = $('<button>', { class: 'confirmImportantConfrimBtn', text: "Bestätigen" });
|
||||
const $cancelBtn = $('<button>', { class: 'confirmImportantCancelBtn', text: "Abbrechen" });
|
||||
const $btnDiv = $('<div>', { class: 'confirmImportantBtnDiv' }).append($cancelBtn, $submitBtn);
|
||||
|
||||
$buttonDiv.append($buttonNo, $buttonYes);
|
||||
$div.append($buttonDiv);
|
||||
$msgDiv.append($div);
|
||||
const $textDiv = $('<div>', { class: 'confirmImportantTextDiv' }).append($heading, $text);
|
||||
const $box = $('<div>', { class: 'confirmImportantBox' }).append($textDiv, $btnDiv);
|
||||
const $displayBg = $('<div>', { class: 'confirmImportantBg' }).append($box);
|
||||
|
||||
$buttonYes.on('click', function () {
|
||||
fadeOutDiv($div);
|
||||
resolve(true);
|
||||
$('body').append($displayBg);
|
||||
|
||||
const closeModal = (result) => {
|
||||
$(document).off('keydown', handleEscape);
|
||||
$displayBg.remove();
|
||||
resolve(result);
|
||||
};
|
||||
|
||||
const handleEscape = function (e) {
|
||||
if (e.key === 'Escape' || e.key === 'Esc') {
|
||||
closeModal(false);
|
||||
}
|
||||
};
|
||||
$(document).on('keydown', handleEscape);
|
||||
|
||||
$submitBtn.on('click', function () {
|
||||
closeModal(true);
|
||||
});
|
||||
|
||||
$buttonNo.on('click', function () {
|
||||
fadeOutDiv($div);
|
||||
resolve(false);
|
||||
$cancelBtn.on('click', function () {
|
||||
closeModal(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function displayConfirmImportant(msg = null, deleteString = "LOESCHEN") {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
const trimmedString = deleteString.trim();
|
||||
|
||||
// Created clean layout references
|
||||
const $heading = $('<h3>', { class: 'confirmImportantHeading', text: 'Bitte bestätige diese Aktion' });
|
||||
const $text = $('<p>', { class: 'confirmImportantText', text: msg || 'Diese Aktion ist unumkehrbar.' });
|
||||
|
||||
const $label = $('<label>', { class: 'confirmImportantLabel', for: 'confirmImportantInput', text: `Bitte geben Sie im untenstehenden Feld "${deleteString}" ein, um fortzufahren` });
|
||||
const $input = $('<input>', { class: 'confirmImportantInput', id: 'confirmImportantInput', type: "text", placeholder: `Hier "${deleteString}" eingeben` });
|
||||
const $inputDiv = $('<div>', { class: 'confirmImportantInputDiv' }).append($label, $input);
|
||||
|
||||
const $submitBtn = $('<button>', { class: 'confirmImportantConfrimBtn notValidBtn', text: "Bestätigen" });
|
||||
const $cancelBtn = $('<button>', { class: 'confirmImportantCancelBtn', text: "Abbrechen" });
|
||||
const $btnDiv = $('<div>', { class: 'confirmImportantBtnDiv' }).append($cancelBtn, $submitBtn);
|
||||
|
||||
const $textDiv = $('<div>', { class: 'confirmImportantTextDiv' }).append($heading, $text);
|
||||
const $box = $('<div>', { class: 'confirmImportantBox' }).append($textDiv, $inputDiv, $btnDiv);
|
||||
const $displayBg = $('<div>', { class: 'confirmImportantBg' }).append($box);
|
||||
|
||||
$('body').append($displayBg);
|
||||
|
||||
const closeModal = (result) => {
|
||||
$(document).off('keydown', handleEscape);
|
||||
$displayBg.remove();
|
||||
resolve(result);
|
||||
};
|
||||
|
||||
const handleEscape = function (e) {
|
||||
if (e.key === 'Escape' || e.key === 'Esc') {
|
||||
closeModal(false);
|
||||
}
|
||||
};
|
||||
$(document).on('keydown', handleEscape);
|
||||
|
||||
$input.on('input', function () {
|
||||
const matches = $(this).val().trim() === trimmedString;
|
||||
$submitBtn.toggleClass('notValidBtn', !matches);
|
||||
$(this).toggleClass('ok', matches).toggleClass('notOk', !matches);
|
||||
});
|
||||
|
||||
setTimeout(() => $div.addClass('show'), 50);
|
||||
$submitBtn.on('click', function () {
|
||||
if ($input.val().trim() !== trimmedString || $submitBtn.hasClass('notValidBtn')) return;
|
||||
closeModal(true);
|
||||
});
|
||||
|
||||
$cancelBtn.on('click', function () {
|
||||
closeModal(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user