diff --git a/MerlinAU.asp b/MerlinAU.asp index 911b46ac..893c27b2 100644 --- a/MerlinAU.asp +++ b/MerlinAU.asp @@ -796,64 +796,84 @@ const fwUpdateDirPath = } }; -function ShowLatestChangelog() -{ - document.form.action_script.value = 'start_MerlinAUdownloadchangelog'; - document.form.action_wait.value = 10; - - // Open popup **before** form submission to avoid browser popup blocking // - var changelogWindow = window.open("", "ChangelogPopup", "width=800,height=600,scrollbars=1,resizable=1"); +function fetchChangelog(startTime) { + $.ajax({ + url: '/ext/MerlinAU/changelog.htm', + dataType: 'text', + timeout: 1500, // each attempt times out after 9 seconds + success: function(data) { + $('#changelogData').html('
' + data + ''); + }, + error: function() { + var currentTime = new Date().getTime(); + // if less than 10 seconds have elapsed since we started, retry after 500ms + if (currentTime - startTime < 10000) { + setTimeout(function() { + fetchChangelog(startTime); + }, 500); + } else { + $('#changelogData').html('
Failed to load the changelog.
'); + } + } + }); +} - if (!changelogWindow) - { - alert("Popup blocked! Please allow popups for this site to view the changelog."); - return; +function ShowLatestChangelog(e) { + if (e) e.preventDefault(); + + // Define the loading message + var loadingMessage = 'Please wait and allow up to 10 seconds for the changelog to load.
' +
+ 'Click on "Cancel" button to stop and exit this dialog.
Loading latest changelog...
"); - changelogWindow.document.write(""); - changelogWindow.document.close(); - - // Now submit the form (which might trigger a page refresh) // - showLoading(); - document.form.submit(); - - // Delay the AJAX request slightly (but make sure it runs before page refresh) // + + // Show the modal overlay + $('#changelogModal').show(); + + // Trigger the backend shell script via form submission (using AJAX) + var formData = $('form[name="form"]').serializeArray(); + formData.push({ name: "action_script", value: "start_MerlinAUdownloadchangelog" }); + formData.push({ name: "action_wait", value: "10" }); + + $.post('start_apply.htm', formData) + .done(function(response) { + console.log("Changelog trigger submitted successfully."); + }) + .fail(function() { + console.error("Failed to submit changelog trigger."); + }); + + // Record the start time and wait 8 seconds before attempting to fetch the changelog + var startTime = new Date().getTime(); setTimeout(function() { - $.ajax({ - url: '/ext/MerlinAU/changelog.htm', - dataType: 'text', - timeout: 9000, - success: function(data) - { - // Ensure the popup is still open before modifying it // - if (changelogWindow && !changelogWindow.closed) - { - changelogWindow.document.open(); - changelogWindow.document.write("" + data + ""); - changelogWindow.document.write(""); - changelogWindow.document.close(); - } - }, - error: function() - { - if (changelogWindow && !changelogWindow.closed) - { - changelogWindow.document.open(); - changelogWindow.document.write("
Failed to load the changelog.
"); - changelogWindow.document.write(""); - changelogWindow.document.close(); - } - } - }); - }, 8000); // Delay slightly to allow form processing, but not too much // + fetchChangelog(startTime); + // Once the changelog has loaded, update the button text to "Close" + $('#closeChangelogModal').text("Close"); + }, 8000); + + return false; } // **Control "Approve/Block Changelog" Checkbox State** // @@ -2483,7 +2503,7 @@ function initializeCollapsibleSections()