From e6e1402571aef0eb5e1f5f539ef04a775320de48 Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Fri, 23 Jun 2023 23:47:34 -0600 Subject: [PATCH] add jquery ui and modal dialogs to reload and delete buttons --- res/app.js | 124 +++++++++++++++++++++++++++++++++++++-------------- src/head.php | 14 +++--- 2 files changed, 96 insertions(+), 42 deletions(-) diff --git a/res/app.js b/res/app.js index ad675e1..e9fd840 100755 --- a/res/app.js +++ b/res/app.js @@ -317,18 +317,7 @@ $(document).ready(function () { window.open('/genDocs.php?cmd=genDocUniqueItems', '_blank'); }); - // Delete button event - $('.btn-delete').click(function (event) { - event.preventDefault(); // Prevent default button click behavior - // delete item index - $.get('/ajax/uniqueitems.php?cmd=delete&index=' + $(".uniqueform input[name='index']").val(), function (response) { - // Handle the response from the server - // remove option from list - $('.uniqueitems-select option[value="' + $(".uniqueform input[name='index']").val() + '"]').remove(); - console.log(response); - }); - }); // Save button event $('.btn-save').click(function (event) { @@ -500,31 +489,100 @@ $(document).ready(function () { // Reload Mod files $('#reload-button').on('click', function () { - $("#TabContent").hide(); - showLoadingSpinner(); - $.get('/reload.php') - .done(function (response) { - console.log('Request successful'); - console.log(response); + // Create a dialog with OK/Cancel buttons + $('
').html( + "Warning: Reloading all TXT/TBL files!

" + + "This action will reload all the TXT/TBL files into the database, overwriting any existing data. It will not modify your TXT/TBL files or mod files.

" + + "Please note that while this step is generally safe, it's always recommended to back up your mod files before proceeding.

" + + "Are you absolutely sure you want to proceed with this operation?" + ).dialog({ + title: "Confirmation", + modal: true, + resizable: false, + buttons: { + OK: function () { + // OK button clicked + console.log("OK button clicked"); - // Perform additional actions or handle the response here - hideLoadingSpinner(); - $("#TabContent").show(); - }) - .fail(function (jqXHR, textStatus, errorThrown) { - console.log('Request failed'); - console.log(jqXHR); - console.log(textStatus); - console.log(errorThrown); + // Show loading spinner and disable the button + $("#TabContent").hide(); + showLoadingSpinner(); + $('#reload-button').prop('disabled', true); - // Handle the error or show an error message + // Send the request to reload.php + $.get('/reload.php') + .done(function (response) { + console.log('Request successful'); + console.log(response); - }) - .always(function () { - // Hide the loading overlay and enable the button - $('#loading-overlay').fadeOut(); - $('#reload-button').prop('disabled', false); - }); + // Perform additional actions or handle the response here + hideLoadingSpinner(); + $("#TabContent").show(); + }) + .fail(function (jqXHR, textStatus, errorThrown) { + console.log('Request failed'); + console.log(jqXHR); + console.log(textStatus); + console.log(errorThrown); + + // Handle the error or show an error message + }) + .always(function () { + // Hide the loading overlay and enable the button + $('#loading-overlay').fadeOut(); + $('#reload-button').prop('disabled', false); + }); + + $(this).dialog("close"); + }, + Cancel: function () { + // Cancel button clicked + console.log("Cancel button clicked"); + + $(this).dialog("close"); + } + } + }); + }); + + // Reload Mod files + $('.btn-delete').on('click', function () { + event.preventDefault(); // Prevent default button click behavior + // Create a dialog with OK/Cancel buttons + $('
').html( + "Warning: This will delete the item from the database and the TXT file on disk!

" + + "There is no UNDO for this. Make sure you want to delete this row before you proceed.

" + + "It's always recommended to back up your mod files before proceeding.

" + + "Are you absolutely sure you want to proceed with this operation?" + ).dialog({ + title: "Confirmation", + modal: true, + resizable: false, + buttons: { + OK: function () { + // OK button clicked + console.log("OK button clicked"); + // Delete button event + + // delete item index + $.get('/ajax/uniqueitems.php?cmd=delete&index=' + $(".uniqueform input[name='index']").val(), function (response) { + // Handle the response from the server + // remove option from list + $('.uniqueitems-select option[value="' + $(".uniqueform input[name='index']").val() + '"]').remove(); + console.log(response); + }); + + + $(this).dialog("close"); + }, + Cancel: function () { + // Cancel button clicked + console.log("Cancel button clicked"); + + $(this).dialog("close"); + } + } + }); }); diff --git a/src/head.php b/src/head.php index d87fe37..f034bd7 100755 --- a/src/head.php +++ b/src/head.php @@ -52,11 +52,7 @@ - - +