X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Fajax-common.js;h=4dad7897362968bb390f6c43440c051c6f52f310;hb=0ab2e7a1001f1ccdb1b7c09dd0114b9c80f0df98;hp=7d06cd07fbfad0da824af0d8ea7760b70b106a8e;hpb=ca256746fe0757a23df4064824c8fe2087ad5634;p=mailer.git diff --git a/js/ajax-common.js b/js/ajax-common.js index 7d06cd07fb..4dad789736 100644 --- a/js/ajax-common.js +++ b/js/ajax-common.js @@ -1,13 +1,8 @@ /** * Common JavaScript functions for AJAX requests (they are general purpose). * -------------------------------------------------------------------- - * $Revision:: $ - * $Date:: $ - * $Tag:: 0.2.1-FINAL $ - * $Author:: $ - * -------------------------------------------------------------------- * Copyright (c) 2003 - 2009 by Roland Haeder - * Copyright (c) 2009 - 2012 by Mailer Developer Team + * Copyright (c) 2009 - 2013 by Mailer Developer Team * For more information visit: http://mxchange.org * * This program is free software; you can redistribute it and/or modify @@ -53,14 +48,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 +155,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 +227,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 +238,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 +259,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 +267,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 +419,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 +537,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 +639,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 +661,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 +935,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