Heacy rewrite/cleanup:
[mailer.git] / js / ajax-common.js
index 69bd8a50c6f97d4cc0d479f8f9e5500e53c5bf1e..dd2f5c8f580fa9e3f91e836b7aae831164b9c7fa 100644 (file)
@@ -53,14 +53,17 @@ function setCurrentTabId (tabId) {
 
 // Checks whether a given element is visible by checking 'display: none'
 function isElementVisible (prefix, element) {
+       //* DEBUG: */ alert('isElementVisible(' + prefix + ',' + element + ') Called!');
+
        // Get element
        var el = document.getElementById(prefix + '_' + element);
+       //* DEBUG: */ alert('isElementVisible(): el=' + el);
 
        // Is element set?
        if ((el === null) || (el == undefined)) {
-               throw new '"' + prefix + '_' + element + '" does not exist.';
+               throw new ('prefix=' + prefix + ',element=' + element + ' does not exist.');
        } else if ((el.style.display == undefined) || (el.style.display == '')) {
-               throw new '"' + prefix + '_' + element + '" has no style.display element.';
+               throw new ('prefix=' + prefix + ',element=' + element + ' has no style.display element.');
        }
 
        // Default is visible
@@ -157,7 +160,7 @@ function getAjaxContent () {
        // Is it defined?
        if (data['ajax_content'] == undefined) {
                // Not set
-               throw new 'ajax_content requested but not set.';
+               throw new('ajax_content requested but not set.');
        } // END - if
 
        // Return it
@@ -229,10 +232,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. (1)';
+                               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. (2)';
+                               throw new('ajax_content.reply_content=null from ajax.php, please fix your scripts. (2)');
                        }
 
                        // Set AJAX reply
@@ -240,6 +243,13 @@ function sendAjaxRequest (level, doValue, extra, isJson) {
 
                        // Mark it as success
                        setAjaxSuccess(true);
+
+                       // Was there a redirect?
+                       if ((ajax_content.redirect != undefined) && (ajax_content.redirect != null)) {
+                               // Redirect URL detected
+                               // @TODO Need this be secured?
+                               document.location.href = ajax_content.redirect;
+                       } // END - if
                },
 
                // Called in case of an error (e.g. HTTP response status not '200 OK')
@@ -254,7 +264,7 @@ function sendAjaxRequest (level, doValue, extra, isJson) {
                                        // 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)';
+                                               throw new('obj.reply_content not returned from ajax.php, please fix your scripts. (3)');
                                        } // END - if
 
                                        // Set it
@@ -262,15 +272,22 @@ function sendAjaxRequest (level, doValue, extra, isJson) {
                                        return false;
                                } else {
                                        // This shall not happen
-                                       throw new 'ajax_content.reply_content not returned from ajax.php, please fix your scripts. (4)';
+                                       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. (5)';
+                               throw new('ajax_content.reply_content=null from ajax.php, please fix your scripts. (5)');
                        }
 
                        // Set AJAX reply
                        setAjaxReply(ajax_content.reply_content, isJson);
+
+                       // Was there a redirect?
+                       if ((ajax_content.redirect != undefined) && (ajax_content.redirect != null)) {
+                               // Redirect URL detected
+                               // @TODO Need this be secured?
+                               document.location.href = ajax_content.redirect;
+                       } // END - if
                }
        });
 
@@ -407,12 +424,15 @@ function displayChangedWarningWindow (prefix, button) {
        closeAllWindows(prefix);
 
        // Abort here if warningDisplayed is still true
+       //* DEBUG: */ alert('displayChangedWarningWindow(): Calling isElementVisible(' + prefix + ', warning)');
        if (isElementVisible(prefix, 'warning')) {
                // Make sure this doesn't happen
+               //* DEBUG: */ alert('displayChangedWarningWindow(): isElementVisible(' + prefix + ', warning)=true');
                return;
        } // END - if
 
        // Request it from the AJAX backend
+       //* DEBUG: */ alert('displayChangedWarningWindow(): Calling sendAjaxRequest(' + prefix + ', button=' + button  + ',changedElements()=' + changedElements.join(':') + ')');
        if (sendAjaxRequest(prefix, 'change_warning', '&button=' + button + '&elements=' + changedElements.join(':')) === true) {
                // Transfer the returned content to the prefix_warning_content id
                setWarningContent(prefix, getAjaxContent());
@@ -522,10 +542,15 @@ function setSuccessContent (prefix, content) {
 
 // Close all windows
 function closeAllWindows (prefix) {
+       //* DEBUG: */ alert('closeAllWindows(): Calling closeWarningWindow(' + prefix + ', true, false)');
        closeWarningWindow(prefix, true, false);
+       //* DEBUG: */ alert('closeAllWindows(): Calling closeErrorWindow(' + prefix + ', true, false)');
        closeErrorWindow(prefix, true, false);
+       //* DEBUG: */ alert('closeAllWindows(): Calling closeProgressWindow(' + prefix + ', true, false)');
        closeProgressWindow(prefix, true, false);
+       //* DEBUG: */ alert('closeAllWindows(): Calling closeSuccessWindow(' + prefix + ', true, false)');
        closeSuccessWindow(prefix, true, false);
+       //* DEBUG: */ alert('closeAllWindows(): EXIT!');
 }
 
 // Waits until the window has been closed
@@ -619,6 +644,7 @@ function closeSuccessLocked (prefix) {
 // Closes an success window
 function closeSuccessWindow (prefix, waitClose, resetCurrentTabId) {
        // Is the success displayed?
+       //* DEBUG: */ alert('closeSuccessWindow(): prefix=' + prefix + ',waitClose=' + waitClose + ',resetCurrentTabId=' + resetCurrentTabId + ' - ENTERED!');
        if (isElementVisible(prefix, 'success')) {
                // Shall we wait ("sync") until the animation has completed?
                if (waitClose === true) {
@@ -640,6 +666,7 @@ function closeSuccessWindow (prefix, waitClose, resetCurrentTabId) {
                        closeSuccessLocked(prefix);
                } // END - if
        } // END - if
+       //* DEBUG: */ alert('closeSuccessWindow(): prefix=' + prefix + ',waitClose=' + waitClose + ',resetCurrentTabId=' + resetCurrentTabId + ' - EXIT!');
 }
 
 // Waits until the window has been closed
@@ -913,7 +940,7 @@ function doSaveChangesContinue (prefix, htmlId, tab) {
        saveChanges(prefix);
 
        // Close the window
-       //* DEBUG: */ alert('doSaveChangesPage(): prefix=' + prefix + ',htmlId=' + htmlId + ',tab=' + tab + ' - calling closeWarningWindow()');
+       //* DEBUG: */ alert('doSaveChangesContinue(): prefix=' + prefix + ',htmlId=' + htmlId + ',tab=' + tab + ' - calling closeWarningWindow()');
        closeWarningWindow(prefix, true, false);
 
        // Load requested content