X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=js%2Fajax-common.js;h=5430232af831b8d403442c1fd8ea2a533ade8dc6;hp=bc21661064bd09dee2931f13fce8074b43b35752;hb=df4166450ac4788f58931bd5d30c617432a63f9d;hpb=7baeed3903bdc29839f248f690528b2758665986 diff --git a/js/ajax-common.js b/js/ajax-common.js index bc21661064..5430232af8 100644 --- a/js/ajax-common.js +++ b/js/ajax-common.js @@ -28,6 +28,7 @@ // Init variables var currentTabId = null; +var processDisplayed = false; var errorDisplayed = false; var warningDisplayed = false; var defaultTabId = null; @@ -51,6 +52,12 @@ function setCurrentTabId (tabId) { // Marks a tab navigation entry function markTabNavigation (prefix, tab) { + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Get all li-tags var li = document.getElementsByTagName('li'); @@ -101,7 +108,12 @@ function disableElement (element) { // Enables a given footer navigation element function enableFooterNavigationPage (element) { // Remove the 'disabled' class and attribute - enableElement('input#' + element + '_page'); + if (element == 'finish') { + enableElement('input#finish'); + } else { + enableElement('input#' + element + '_page'); + disableElement('input#finish'); + } } // Resets footer navigation by adding CSS class 'disabled' @@ -189,10 +201,10 @@ function sendAjaxRequest (level, doValue, extra, isJson) { // Is ajax_content set? if (ajax_content.reply_content == undefined) { // This shall not happen - throw new 'ajax_content.reply_content not returned from ajax.php, please fix your scripts.'; + throw new 'ajax_content.reply_content not returned from ajax.php, please fix your scripts. (1)'; } else if (ajax_content.reply_content == null) { // This shall not happen, too - throw new 'ajax_content.reply_content=null from ajax.php, please fix your scripts.'; + throw new 'ajax_content.reply_content=null from ajax.php, please fix your scripts. (2)'; } // Set AJAX reply @@ -206,11 +218,27 @@ function sendAjaxRequest (level, doValue, extra, isJson) { error: function (ajax_content) { // Is ajax_content set? if (ajax_content.reply_content == undefined) { - // This shall not happen - throw new 'ajax_content.reply_content not returned from ajax.php, please fix your scripts.'; + // Is 'responseText' there? + if (ajax_content.responseText != undefined) { + // Then parse it + var obj = jQuery.parseJSON(ajax_content.responseText.replace('%20', ' ')); + + // Is 'reply_content' set? + if (obj.reply_content == undefined) { + // This shall not happen + throw new 'obj.reply_content not returned from ajax.php, please fix your scripts. (3)'; + } // END - if + + // Set it + setAjaxReply(obj.reply_content, false); + return false; + } else { + // This shall not happen + throw new 'ajax_content.reply_content not returned from ajax.php, please fix your scripts. (4)'; + } } else if (ajax_content.reply_content == null) { // This shall not happen, too - throw new 'ajax_content.reply_content=null from ajax.php, please fix your scripts.'; + throw new 'ajax_content.reply_content=null from ajax.php, please fix your scripts. (5)'; } // Set AJAX reply @@ -224,6 +252,12 @@ function sendAjaxRequest (level, doValue, extra, isJson) { // Enables footer navigation buttons function enableFooterNavigation (prefix, tabId) { + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Reset both footer navigation first resetFooterNavigation(); @@ -242,6 +276,12 @@ function enableFooterNavigation (prefix, tabId) { // Requests an AJAX content function requestAjaxContent (prefix, htmlId, tabId, footerNavigation) { + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Check if this request is disabled if ($('#' + prefix + '_' + tabId).hasClass('tab_disabled')) { // Clicked on a disabled tabId so blur it @@ -386,6 +426,38 @@ function displayErrorWindow (prefix, ajax_content) { }); } +// Displays the process window for given prefix and content +function displayProcessWindow (prefix, ajax_content) { + // Fade out warning window, if open + //* DEBUG: */ alert('displayProcessWindow(): prefix=' + prefix + ' - calling closeWarningWindow()'); + closeWarningWindow(prefix); + + // Fade it out for eye-candy + closeErrorWindow(prefix); + + // Fade it out for eye-candy + closeProcessWindow(prefix); + + // Abort here if processDisplayed is still true + if (processDisplayed == true) { + // Make sure this doesn't happen + return; + } // END - if + + // Copy the response text to the process variable + if (ajax_content.reply_content != undefined) { + $('#' + prefix + '_process_content').html(ajax_content.reply_content); + } else { + $('#' + prefix + '_process_content').html(ajax_content); + } + + // Fade the process in + $('#' + prefix + '_process').fadeIn('slow', function() { + // Mark process as displayed + processDisplayed = true; + }); +} + // Waits until the window has been closed function closeErrorLocked () { // Has all been loaded? @@ -398,6 +470,18 @@ function closeErrorLocked () { } } +// Waits until the window has been closed +function closeProcessLocked () { + // Has all been loaded? + if (processDisplayed == false) { + // Then release ready() + $.holdReady(false); + } else { + // Recursive call again + window.setTimeout('closeProcessLocked()', 10); + } +} + // Closes an error window function closeErrorWindow (prefix, waitClose, resetCurrentTabId) { // Is the error displayed? @@ -427,6 +511,35 @@ function closeErrorWindow (prefix, waitClose, resetCurrentTabId) { } // END - if } +// Closes an process window +function closeProcessWindow (prefix, waitClose, resetCurrentTabId) { + // Is the process displayed? + if (processDisplayed == true) { + // Shall we wait ("sync") until the animation has completed? + if (waitClose == true) { + // Hold the ready status + $.holdReady(true); + } // END - if + + // Yes, then fade it out + $('#' + prefix + '_process').fadeOut('fast', function() { + // Set current tab id to default + if (resetCurrentTabId == true) { + setCurrentTabId(defaultTabId); + } // END - if + + // Mark it as closed + processDisplayed = false; + }); + + // Shall this animation be "synchronized"? + if (waitClose == true) { + // Wait for the window has been closed + closeProcessLocked(); + } // END - if + } // END - if +} + // Waits until the window has been closed function closeWarningLocked () { // Has all been loaded? @@ -485,6 +598,12 @@ function doFooterPage (prefix, htmlId, button) { return; } // END - if + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Is there a 'next' entry? //* DEBUG: */ alert('doFooterPage(): button=' + button + ',currentTabId=' + currentTabId + ',nextPage[currentTabId]=' + nextPage[currentTabId]); if ((button == 'next') && (nextPage[currentTabId] != null)) { @@ -589,6 +708,12 @@ function processAjaxResponseContent (prefix, ajax_content) { // Saves changes by sending the data to the AJAX backend script function saveChanges (prefix) { + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Mark all elements as unchanged markAllElementsAsUnchanged(); @@ -681,6 +806,12 @@ function doSaveChangesPage (prefix, htmlId, page) { // Saves changed settings and continues with given tab function doSaveChangesContinue (prefix, htmlId, tab) { + // Is process working? + if (processDisplayed == true) { + // Then exit silently + return; + } // END - if + // Save the changes saveChanges(prefix);