]> git.mxchange.org Git - mailer.git/blobdiff - js/ajax-common.js
Continued on AJAX installer to start first step (more are easily to add)
[mailer.git] / js / ajax-common.js
index 5430232af831b8d403442c1fd8ea2a533ade8dc6..ccef02a08a3608b479660f663b851db652bddcc2 100644 (file)
@@ -28,9 +28,6 @@
 
 // Init variables
 var currentTabId       = null;
-var processDisplayed   = false;
-var errorDisplayed     = false;
-var warningDisplayed   = false;
 var defaultTabId       = null;
 var footerElements     = new Array();
 var changedElements    = new Array();
@@ -50,10 +47,27 @@ function setCurrentTabId (tabId) {
        currentTabId = tabId;
 }
 
+// Checks whether a given element is visible by checking 'display: none'
+function isElementVisible (prefix, element) {
+       // Get element
+       var el = document.getElementById(prefix + '_' + element);
+
+       // Is element set?
+       if (el == null || el == undefined) {
+               throw new '"' + prefix + '_' + element + '" does not exist.';
+       }
+
+       // Default is visible
+       var isVisible = ((el.style.display == undefined) || ((el.style.display != 'none') && (el.style.display != '')));
+
+       // Return status
+       return isVisible;
+}
+
 // Marks a tab navigation entry
 function markTabNavigation (prefix, tab) {
        // Is process working?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if
@@ -253,7 +267,7 @@ function sendAjaxRequest (level, doValue, extra, isJson) {
 // Enables footer navigation buttons
 function enableFooterNavigation (prefix, tabId) {
        // Is process working?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if
@@ -277,7 +291,7 @@ function enableFooterNavigation (prefix, tabId) {
 // Requests an AJAX content
 function requestAjaxContent (prefix, htmlId, tabId, footerNavigation) {
        // Is process working?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if
@@ -357,9 +371,6 @@ function displayTestWindow (prefix, element) {
                        // Enable element
                        enableElement(element);
                });
-
-               // Mark 'warning' as displayed
-               warningDisplayed = true;
        } else {
                // Display error message
                displayErrorWindow(prefix, getAjaxContent());
@@ -375,8 +386,11 @@ function displayChangedWarningWindow (prefix, button) {
        // Fade error out for eye-candy, if open
        closeErrorWindow(prefix);
 
+       // Fade it out for eye-candy
+       closeProcessWindow(prefix);
+
        // Abort here if warningDisplayed is still true
-       if (warningDisplayed == true) {
+       if (isElementVisible(prefix, 'warning')) {
                // Make sure this doesn't happen
                return;
        } // END - if
@@ -388,8 +402,7 @@ function displayChangedWarningWindow (prefix, button) {
 
                // Fade the warning in
                $('#' + prefix + '_warning').fadeIn('slow', function() {
-                       // Mark warning as displayed
-                       warningDisplayed = true;
+                       // Do nothing for now
                });
        } else {
                // Display error message
@@ -406,8 +419,11 @@ function displayErrorWindow (prefix, ajax_content) {
        // Fade it out for eye-candy
        closeErrorWindow(prefix);
 
+       // Fade it out for eye-candy
+       closeProcessWindow(prefix);
+
        // Abort here if errorDisplayed is still true
-       if (errorDisplayed == true) {
+       if (isElementVisible(prefix, 'error')) {
                // Make sure this doesn't happen
                return;
        } // END - if
@@ -421,8 +437,7 @@ function displayErrorWindow (prefix, ajax_content) {
 
        // Fade the error in
        $('#' + prefix + '_error').fadeIn('slow', function() {
-               // Mark error as displayed
-               errorDisplayed = true;
+               // Do nothing for now
        });
 }
 
@@ -439,29 +454,35 @@ function displayProcessWindow (prefix, ajax_content) {
        closeProcessWindow(prefix);
 
        // Abort here if processDisplayed is still true
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // 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);
+               // Set HTML content
+               setProcessContent(prefix, ajax_content.reply_content);
        } else {
-               $('#' + prefix + '_process_content').html(ajax_content);
+               setProcessContent(prefix, ajax_content);
        }
 
        // Fade the process in
        $('#' + prefix + '_process').fadeIn('slow', function() {
-               // Mark process as displayed
-               processDisplayed = true;
+               // Do nothing for now
        });
 }
 
+// Sets "process content"
+function setProcessContent (prefix, content) {
+       // Set HTML content
+       $('#' + prefix + '_process_content').html(content);
+}
+
 // Waits until the window has been closed
 function closeErrorLocked () {
        // Has all been loaded?
-       if (errorDisplayed == false) {
+       if (!isElementVisible(prefix, 'error')) {
                // Then release ready()
                $.holdReady(false);
        } else {
@@ -473,7 +494,7 @@ function closeErrorLocked () {
 // Waits until the window has been closed
 function closeProcessLocked () {
        // Has all been loaded?
-       if (processDisplayed == false) {
+       if (!isElementVisible(prefix, 'process')) {
                // Then release ready()
                $.holdReady(false);
        } else {
@@ -485,7 +506,7 @@ function closeProcessLocked () {
 // Closes an error window
 function closeErrorWindow (prefix, waitClose, resetCurrentTabId) {
        // Is the error displayed?
-       if (errorDisplayed == true) {
+       if (isElementVisible(prefix, 'error')) {
                // Shall we wait ("sync") until the animation has completed?
                if (waitClose == true) {
                        // Hold the ready status
@@ -498,9 +519,6 @@ function closeErrorWindow (prefix, waitClose, resetCurrentTabId) {
                        if (resetCurrentTabId == true) {
                                setCurrentTabId(defaultTabId);
                        } // END - if
-
-                       // Mark it as closed
-                       errorDisplayed = false;
                });
 
                // Shall this animation be "synchronized"?
@@ -514,7 +532,7 @@ function closeErrorWindow (prefix, waitClose, resetCurrentTabId) {
 // Closes an process window
 function closeProcessWindow (prefix, waitClose, resetCurrentTabId) {
        // Is the process displayed?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Shall we wait ("sync") until the animation has completed?
                if (waitClose == true) {
                        // Hold the ready status
@@ -527,9 +545,6 @@ function closeProcessWindow (prefix, waitClose, resetCurrentTabId) {
                        if (resetCurrentTabId == true) {
                                setCurrentTabId(defaultTabId);
                        } // END - if
-
-                       // Mark it as closed
-                       processDisplayed = false;
                });
 
                // Shall this animation be "synchronized"?
@@ -543,7 +558,7 @@ function closeProcessWindow (prefix, waitClose, resetCurrentTabId) {
 // Waits until the window has been closed
 function closeWarningLocked () {
        // Has all been loaded?
-       if (warningDisplayed == false) {
+       if (!isElementVisible(prefix, 'warning')) {
                // Then release ready()
                $.holdReady(false);
        } else {
@@ -556,7 +571,7 @@ function closeWarningLocked () {
 function closeWarningWindow (prefix, waitClose, resetCurrentTabId) {
        //* DEBUG: */ alert('prefix=' + prefix + ',waitClose=' + waitClose + ' - ENTERED!');
        // Is the warning displayed?
-       if (warningDisplayed == true) {
+       if (isElementVisible(prefix, 'warning')) {
                // Shall we wait ("sync") until the animation has completed?
                //* DEBUG: */ alert('prefix=' + prefix + ',waitClose=' + waitClose + ',warningDisplayed=true');
                if (waitClose == true) {
@@ -567,14 +582,9 @@ function closeWarningWindow (prefix, waitClose, resetCurrentTabId) {
                // Yes, then fade it out
                $('#' + prefix + '_warning').fadeOut('fast', function() {
                        // Set current tab id to default
-                       //* DEBUG: */ alert('closeWarningWindow(): prefix=' + prefix + ',waitClose=' + waitClose + ',defaultTab=' + defaultTabId + ' - Calling setCurrentTabId()');
                        if (resetCurrentTabId == true) {
                                setCurrentTabId(defaultTabId);
                        } // END - if
-
-                       // Mark it as closed
-                       warningDisplayed = false;
-                       //* DEBUG: */ alert('closeWarningWindow(): waitClose=' + waitClose + ',resetCurrentTabId=' + resetCurrentTabId + ',warningDisplayed=false');
                });
 
                // Shall this animation be "synchronized"?
@@ -599,7 +609,7 @@ function doFooterPage (prefix, htmlId, button) {
        } // END - if
 
        // Is process working?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if
@@ -709,7 +719,7 @@ 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) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if
@@ -807,7 +817,7 @@ function doSaveChangesPage (prefix, htmlId, page) {
 // Saves changed settings and continues with given tab
 function doSaveChangesContinue (prefix, htmlId, tab) {
        // Is process working?
-       if (processDisplayed == true) {
+       if (isElementVisible(prefix, 'process')) {
                // Then exit silently
                return;
        } // END - if