Skip to content

Commit 959a1c3

Browse files
Merge pull request #427 from ExtremeFiretop/ExtremeFiretop-Cleanup-Changelog
Cleanup Changelog Function
2 parents 66f4882 + a0f7283 commit 959a1c3

1 file changed

Lines changed: 76 additions & 56 deletions

File tree

MerlinAU.asp

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -796,64 +796,84 @@ const fwUpdateDirPath =
796796
}
797797
};
798798
799-
function ShowLatestChangelog()
800-
{
801-
document.form.action_script.value = 'start_MerlinAUdownloadchangelog';
802-
document.form.action_wait.value = 10;
803-
804-
// Open popup **before** form submission to avoid browser popup blocking //
805-
var changelogWindow = window.open("", "ChangelogPopup", "width=800,height=600,scrollbars=1,resizable=1");
799+
function fetchChangelog(startTime) {
800+
$.ajax({
801+
url: '/ext/MerlinAU/changelog.htm',
802+
dataType: 'text',
803+
timeout: 1500, // each attempt times out after 9 seconds
804+
success: function(data) {
805+
$('#changelogData').html('<pre>' + data + '</pre>');
806+
},
807+
error: function() {
808+
var currentTime = new Date().getTime();
809+
// if less than 10 seconds have elapsed since we started, retry after 500ms
810+
if (currentTime - startTime < 10000) {
811+
setTimeout(function() {
812+
fetchChangelog(startTime);
813+
}, 500);
814+
} else {
815+
$('#changelogData').html('<p>Failed to load the changelog.</p>');
816+
}
817+
}
818+
});
819+
}
806820
807-
if (!changelogWindow)
808-
{
809-
alert("Popup blocked! Please allow popups for this site to view the changelog.");
810-
return;
821+
function ShowLatestChangelog(e) {
822+
if (e) e.preventDefault();
823+
824+
// Define the loading message
825+
var loadingMessage = '<p>Please wait and allow up to 10 seconds for the changelog to load.<br>' +
826+
'Click on "Cancel" button to stop and exit this dialog.</p>';
827+
828+
// If the modal already exists, update its content for a fresh fetch.
829+
if ($('#changelogModal').length) {
830+
$('#changelogData').html(loadingMessage);
831+
$('#closeChangelogModal').text("Cancel");
832+
} else {
833+
// Create modal overlay if it doesn't exist
834+
$('body').append(
835+
'<div id="changelogModal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; ' +
836+
'background:rgba(0,0,0,0.8); z-index:10000;">' +
837+
'<div id="changelogContent" style="position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); ' +
838+
'background:#fff; color:#000; padding:20px; max-height:90%; overflow:auto; width:80%; max-width:800px;">' +
839+
'<h2 style="margin-top:0; color:#000;">Latest Changelog</h2>' +
840+
'<button id="closeChangelogModal" style="float:right; font-size:14px; cursor:pointer;">Cancel</button>' +
841+
'<div id="changelogData" style="font-family:monospace; white-space:pre-wrap; margin-top:10px; color:#000;">' +
842+
loadingMessage +
843+
'</div>' +
844+
'</div>' +
845+
'</div>'
846+
);
847+
$('#closeChangelogModal').on('click', function(){
848+
$('#changelogModal').hide();
849+
});
811850
}
812-
813-
changelogWindow.document.open();
814-
changelogWindow.document.write("<html><head><title>Latest Changelog</title></head>");
815-
changelogWindow.document.write("<body style='font-family:monospace; white-space:pre-wrap;'>");
816-
changelogWindow.document.write("<p>Loading latest changelog...</p>");
817-
changelogWindow.document.write("</body></html>");
818-
changelogWindow.document.close();
819-
820-
// Now submit the form (which might trigger a page refresh) //
821-
showLoading();
822-
document.form.submit();
823-
824-
// Delay the AJAX request slightly (but make sure it runs before page refresh) //
851+
852+
// Show the modal overlay
853+
$('#changelogModal').show();
854+
855+
// Trigger the backend shell script via form submission (using AJAX)
856+
var formData = $('form[name="form"]').serializeArray();
857+
formData.push({ name: "action_script", value: "start_MerlinAUdownloadchangelog" });
858+
formData.push({ name: "action_wait", value: "10" });
859+
860+
$.post('start_apply.htm', formData)
861+
.done(function(response) {
862+
console.log("Changelog trigger submitted successfully.");
863+
})
864+
.fail(function() {
865+
console.error("Failed to submit changelog trigger.");
866+
});
867+
868+
// Record the start time and wait 8 seconds before attempting to fetch the changelog
869+
var startTime = new Date().getTime();
825870
setTimeout(function() {
826-
$.ajax({
827-
url: '/ext/MerlinAU/changelog.htm',
828-
dataType: 'text',
829-
timeout: 9000,
830-
success: function(data)
831-
{
832-
// Ensure the popup is still open before modifying it //
833-
if (changelogWindow && !changelogWindow.closed)
834-
{
835-
changelogWindow.document.open();
836-
changelogWindow.document.write("<html><head><title>Latest Changelog</title></head>");
837-
changelogWindow.document.write("<body style='font-family:monospace; white-space:pre-wrap;'>");
838-
changelogWindow.document.write("<pre>" + data + "</pre>");
839-
changelogWindow.document.write("</body></html>");
840-
changelogWindow.document.close();
841-
}
842-
},
843-
error: function()
844-
{
845-
if (changelogWindow && !changelogWindow.closed)
846-
{
847-
changelogWindow.document.open();
848-
changelogWindow.document.write("<html><head><title>Changelog Error</title></head>");
849-
changelogWindow.document.write("<body style='font-family:monospace; white-space:pre-wrap;'>");
850-
changelogWindow.document.write("<p>Failed to load the changelog.</p>");
851-
changelogWindow.document.write("</body></html>");
852-
changelogWindow.document.close();
853-
}
854-
}
855-
});
856-
}, 8000); // Delay slightly to allow form processing, but not too much //
871+
fetchChangelog(startTime);
872+
// Once the changelog has loaded, update the button text to "Close"
873+
$('#closeChangelogModal').text("Close");
874+
}, 8000);
875+
876+
return false;
857877
}
858878
859879
// **Control "Approve/Block Changelog" Checkbox State** //
@@ -2483,7 +2503,7 @@ function initializeCollapsibleSections()
24832503
<div class="formfonttitle" id="headerTitle" style="text-align:center;">MerlinAU</div>
24842504
<div style="margin:10px 0 10px 5px;" class="splitLine"></div>
24852505
<div class="formfontdesc">This is the MerlinAU add-on integrated into the router WebUI
2486-
<span style="margin-left:8px;" id="WikiURL"">[
2506+
<span style="margin-left:8px;" id="WikiURL">[
24872507
<a style="font-weight:bolder; text-decoration:underline; cursor:pointer;"
24882508
href="https://github.com/ExtremeFiretop/MerlinAutoUpdate-Router/wiki"
24892509
title="Go to MerlinAU Wiki page" target="_blank">Wiki</a> ]

0 commit comments

Comments
 (0)