/* @@BEGIN_COPYRIGHT@@ */ /* Licensed Internal Code - Property of IBM */ /* 3931 3932 Licensed Internal Code */ /* (C) Copyright IBM Corp. 2000, 2022 All Rights Reserved. */ /* @@END_COPYRIGHT@@ */ /*********************************************************** {COPYRIGHT-TOP} *** * Licensed Materials - Property of IBM * Tivoli Presentation Services * * ************************************************************ {COPYRIGHT-END} *** *******************************************************************************/ /******************************************************************************* * This file contains AJAX utility functions. ******************************************************************************/ var isAJAXOutstanding = false; var inputData = new FormsData(); var ajaxTables = new Array(); var refreshForm = ""; var refreshParams = new Array(); var requestTimeout = 0;// Time in milliseconds var requestor = undefined; var traceID = null; var traceAriaLabel = "Power Consumption table"; var OVERRIDE_FOCUS = 'overrideFocus'; require([ "dojo/request", // request.post "dojo/parser" ], function(request) { startRequest = function(form, actionValue, focusElementId) { if (!isAJAXOutstanding) { isAJAXOutstanding = true; var inputFieldsArray = getQueryInputFields(form, actionValue); var inputFields = convertInputFieldsArrayToString(inputFieldsArray); // Save all the form fields so we can save user changes during the request. inputData.initialize(); //window.status = "Retrieving data from server"; window.document.body.style.cursor = "wait"; var idx = form.action.indexOf('#'); if (idx > -1) { wclajax_debug("Removing anchor"); form.action = form.action.substring(0, idx); } // Save the request so we can refresh if we get new content. refreshForm = form.action; refreshParams = inputFieldsArray; wclajax_debug("Request; Post Form : "+form.id+", action: " +form.action); wclajax_debug("Input: "+inputFields); var actionString = getActionString(form); actionString = addAuimlTransactionSupport(actionString, inputFields); wclajax_debugInfo("action [" + actionString + "]"); request.post(actionString, { preventCache: true, data: convertArrayToObject(inputFieldsArray), handleAs: "text", timeout: requestTimeout }).response.then(createHandleStateChange(focusElementId), handleRequestErrorDojo); return true; } return false; }; startRequestSingleUpdate = function(form, actionValue, action) { if (!isAJAXOutstanding) { isAJAXOutstanding = true; var inputFieldsArray = getQueryInputFieldsSingleUpdate(form, actionValue, action); var inputFields = convertInputFieldsArrayToString(inputFieldsArray); // Save all the form fields so we can save user changes during the request. inputData.initialize(); //window.status = "Retrieving data from server"; window.document.body.style.cursor = "wait"; var idx = form.action.indexOf('#'); if (idx > -1) { wclajax_debug("Removing anchor"); form.action = form.action.substring(0, idx); } // Save the request so we can refresh if we get new content. refreshForm = form.action; refreshParams = inputFieldsArray; var actionString = getActionString(form); request.post(actionString, { preventCache: true, data: convertArrayToObject(inputFieldsArray), handleAs: "text", timeout: requestTimeout }).response.then(handleStateChange, handleRequestErrorDojo); return true; } return false; }; startHrefRequest = function(url, form, actionValue) { if (!isAJAXOutstanding) { isAJAXOutstanding = true; wclajax_debugInfo("Request: " + url); // Save the request so we can refresh if we encounter an error if ( typeof form != 'undefined' ) { refreshForm = form; if ( actionValue ) { refreshParams = queryInputFields(form, actionValue); } } request.get(url + "&IsAjaxInvoked=YES" + getForms(), { preventCache: true, handleAs: "text", timeout: requestTimeout }).response.then(handleStateChange, handleRequestErrorDojo); return true; } return false; }; startDataRequest = function(form, actionValue, func, r) { if (!isAJAXOutstanding) { isAJAXOutstanding = true; requestor = r; var inputFieldsArray; if(form[form.wh.value].value.indexOf("changeSelected") != -1){ inputFieldsArray = getSelectedRowsInput(form); if(inputFieldsArray['#selectedRows'] !== undefined){ actionValue = 'changeSelected(' + inputFieldsArray['#selectedRows'].join(',') + ')'; delete inputFieldsArray['#selectedRows']; }else{ actionValue = 'changeSelected()'; } putInputValueIntoArray(inputFieldsArray, form.wh.value, actionValue); putInputValueIntoArray(inputFieldsArray, 'IsAjaxInvoked', 'YES'); putInputValueIntoArray(inputFieldsArray, 'AjaxForms', getFormsList()); // TODO: de-hardcode 'wh' ? putInputValueIntoArray(inputFieldsArray, 'wh', form.wh.value); // ajax in portlets putAjaxInPortletsParams(inputFieldsArray, form); } else if (form[form.wh.value].value.indexOf("rowRefresh") != -1 || form[form.wh.value].value.indexOf("cellRefresh") != -1) { inputFieldsArray = new Array(); putInputValueIntoArray(inputFieldsArray, form.wh.value, actionValue); putInputValueIntoArray(inputFieldsArray, 'IsAjaxInvoked', 'YES'); putInputValueIntoArray(inputFieldsArray, 'AjaxForms', getFormsList()); // TODO: de-hardcode 'wh' ? putInputValueIntoArray(inputFieldsArray, 'wh', form.wh.value); // ajax in portlets putAjaxInPortletsParams(inputFieldsArray, form); }else{ inputFieldsArray = getQueryInputFields(form, actionValue); } var inputFields = "IsAjaxDataRequest=YES&"+convertInputFieldsArrayToString(inputFieldsArray); // Save all the form fields so we can save user changes during the // request. inputData.initialize(); //window.status = "Retrieving data from server"; //window.document.body.style.cursor = "wait"; var idx = form.action.indexOf('#'); if (idx > -1) { wclajax_debug("Removing anchor"); form.action = form.action.substring(0, idx); } // Save the request so we can refresh if we get new content. refreshForm = form.action; refreshParams = inputFieldsArray; wclajax_debugInfo("Request; Post Form : " + form.id + ", action: " + form.action); wclajax_debugInfo("Input: "+inputFields); var actionString = getActionString(form); request.post(actionString, { preventCache: true, data: convertArrayToObject(inputFieldsArray), handleAs: "text", timeout: requestTimeout }).response.then(func, handleRequestErrorDojo); } }; startServerSyncRequest = function(form, actionValue, func, r) { if (!isAJAXOutstanding) { isAJAXOutstanding = true; requestor = r; var inputFieldsArray = getQueryInputFields(form, actionValue); var inputFields = "IsAjaxServerSync=YES&"+convertInputFieldsArrayToString(inputFieldsArray); // Save all the form fields so we can save user changes during the // request. inputData.initialize(); //window.status = "Retrieving data from server"; // window.document.body.style.cursor = "wait"; var idx = form.action.indexOf('#'); if (idx > -1) { wclajax_debug("Removing anchor"); form.action = form.action.substring(0, idx); } // Save the request so we can refresh if we get new content. refreshForm = form.action; refreshParams = inputFieldsArray; wclajax_debugInfo("Request; Post Form : " + form.id + ", action: " + form.action); wclajax_debugInfo("Input: "+inputFields); var actionString = getActionString(form); request.post(actionString, { preventCache: true, data: convertArrayToObject(inputFieldsArray), handleAs: "text", timeout: requestTimeout }).response.then(func, handleRequestErrorDojo); } }; startRefreshRequest = function(refreshFormAction, refreshInputFields, ajaxRefresh) { delete refreshInputFields["IsAjaxInvoked"]; if (ajaxRefresh != null && ajaxRefresh == "YES") { refreshInputFields["AjaxRefresh"]=["YES"]; } wclajax_debug("startRefreshRequest : form [" + refreshFormAction + "] action [" + convertInputFieldsArrayToString(refreshInputFields) + "]"); isAJAXOutstanding = true; //window.status = "Retrieving data from server"; window.document.body.style.cursor = "wait"; request.post(refreshFormAction, { preventCache: true, data: convertArrayToObject(refreshInputFields), handleAs: "text", timeout: requestTimeout }).response.then(handleRefreshStateChange, handleRequestErrorDojo); }; handleLoginPortlet = function(responseString) { var result = false; // The portlet login JSP spits out invalid HTML. Firefox won't display // invalid HTML when you set document.body.innerHTML. Let's see if this // is the login portlet and if it is then let's minimize and then maximize // it so FF will redraw it correctly. if (WClient.isBrowserMozilla()) { var indexJsp = responseString.indexOf("LoginView.jsp"); var indexForm = responseString.indexOf("name=\"LoginForm\""); var indexUser = responseString.indexOf("id=\"userID\" name=\"wps.portlets.userid\""); if ((indexJsp != -1) && (indexForm != -1) && (indexUser != -1)) { result = true; try { wclajax_debug("handleLoginPortlet : refreshing login portlet..."); // Minimize the login portlet. var minimize = responseString.substring(0, indexForm).lastIndexOf("src='/wps/themes/html/title_alt_minimize.gif'"); var hrefStart = responseString.substring(0, minimize).lastIndexOf("href='") + "href='".length; var hrefEnd = responseString.substring(hrefStart).indexOf("'") + hrefStart; var minHref = responseString.substring(hrefStart, hrefEnd); request.post(minHref, { preventCache: true, handleAs: "text", timeout: requestTimeout }).response.then(restoreLoginPortlet, handleRequestErrorDojo); } catch (err) { wclajax_debugErr("Got an error refreshing login portlet [" + err.name + "] [" + err.message + "]"); window.location = null; } } } return result; }; }); // end require function convertArrayToObject(arr) { const obj = {}; Object.keys(arr).forEach(function(key) { obj[key] = arr[key]; }); return obj; } function getFormsList(){ var formsList = ""; if (document.forms != null) { var addForm = false; var formDivs = null; for (var i = 0; i < document.forms.length; ++i) { addForm = false; var parent = document.forms[i].parentNode; while (!addForm && parent) { if ((parent.nodeType == 1) && (parent.getAttribute("wcl_ajax_container") == "true")) { addForm = true; } parent = parent.parentNode; } if (addForm) { formsList += document.forms[i].name + ","; } } wclajax_debug("AJAX forms [" + formsList + "]"); } return formsList; } function getForms() { var formsList = getFormsList(); if (formsList.length > 0) { formsList = "&AjaxForms=" + formsList; } return formsList; } function putInputValueIntoArray(arr, index, val){ if(arr!=null && index!=null){ if(arr[index]!=null){ arr[index].push(val); } else { arr[index]=[]; arr[index].push(val); } } } function putAjaxInPortletsParams(arr, form){ if ( form.namespace && form.wcl_psk ) { arr["namespace"] = form.namespace.value; arr["wcl_psk"] = form.wcl_psk.value; } } function getSelectedRowsInput(form){ var fieldArray = new Array(); var rows = new Array(); if (form != null) { fieldList = form.getElementsByTagName("input"); if (fieldList.length != 0) { for ( var i = 0; i < fieldList.length; i++) { var fieldName = fieldList.item(i).getAttribute("name"); var fieldType = fieldList.item(i).getAttribute("type"); // Only process input tags with a NAME attr, and if row is selected if ((fieldName != null) && (fieldName != "") && isInSelectedRow(fieldList.item(i))) { var row = getRowNumber(fieldList.item(i)); rows[' ' +row] = row; if (fieldType != null) { fieldType = fieldType.toLowerCase(); } if ((fieldType == "text") || (fieldType == "hidden") || (fieldType == "password")) { wclajax_debugInfo("queryInputFields: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); } else if (((fieldType == "checkbox") || (fieldType == "radio")) && (fieldList.item(i).checked)) { wclajax_debugInfo("queryInputFields: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); } } } } var selectList = form.getElementsByTagName("select"); if (selectList.length != 0) { for ( var i = 0; i < selectList.length; i++) { if(isInSelectedRow(selectList.item(i))){ var row = getRowNumber(selectList.item(i)); rows[' ' +row] = row; var sel = selectList.item(i); for ( var j = 0; j < sel.length; j++) { if (sel.options[j].selected == true) { wclajax_debugInfo("queryInputFields: select name is '" + sel.name + "' value is '" + sel.options[j].value + "' encodeURI: '" + encodeURI(sel.options[j].value) + "'"); putInputValueIntoArray(fieldArray, sel.name, sel.options[j].value); } } } } } var textAreaList = form.getElementsByTagName("textarea"); if (textAreaList.length != 0) { for ( var i = 0; i < textAreaList.length; i++) { var textArea = textAreaList.item(i); if (textArea.name != null && textArea.name != "" && isInSelectedRow(textAreaList.item(i))) { var row = getRowNumber(textAreaList.item(i)); rows[' ' +row] = row; wclajax_debugInfo("queryInputFields: textarea name is '" + textArea.name + "' value is '" + textArea.value + "' encodeURI: '" + encodeURI(textArea.value) + "'"); putInputValueIntoArray(fieldArray, textArea.name, textArea.value); } } } putInputValueIntoArray(fieldArray, "btimestamp", new Date().getTime()); } for(i in rows){ putInputValueIntoArray(fieldArray, '#selectedRows', rows[i]); } return fieldArray; } function getSelectedRowNumbers(selectName){ var rows = new Array(); checkboxes = document.getElementsByName(selectName); for(var i=0; i < checkboxes.length; i++){ if(checkboxes[i].checked){ rows.push(checkboxes[i].value); } } return rows; } function getQueryInputFields(form, actionValue) { var fieldArray = new Array(); if (form != null) { wclajax_debug("action: " + actionValue); putInputValueIntoArray(fieldArray, 'IsAjaxInvoked', 'YES'); // fieldArray['IsAjaxInvoked']='YES'; // Add the list of form names so we can tell when we're all done with // AJAX request in the form renderer. putInputValueIntoArray(fieldArray, 'AjaxForms', getFormsList()); // fieldArray['AjaxForms']=getFormsList(); var fieldList = form.getElementsByTagName("input"); if (fieldList.length != 0) { for (var i = 0; i < fieldList.length; i++) { var fieldName = fieldList.item(i).getAttribute("name"); var fieldType = fieldList.item(i).getAttribute("type"); var disabled = fieldList.item(i).getAttribute("disabled"); //-01 Don't include disabled input elements if (!WClient.isBrowserInternetExplorer()){ if(disabled != null && (disabled == "" || disabled == true || disabled == "true" )) { disabled = true; }else{ disabled = false; } } // Only process input tags with a NAME attr. if ((fieldName != null) && (fieldName != "") && ( disabled == false || disabled == null ) ) { if (fieldType != null) { fieldType = fieldType.toLowerCase(); } if ((fieldType == "text") || (fieldType == "hidden") || (fieldType == "password")) { wclajax_debugInfo("queryInputFields: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if (((fieldType == "checkbox") || (fieldType == "radio")) && (fieldList.item(i).checked)) { wclajax_debugInfo("queryInputFields: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if ((actionValue != null) && (actionValue != "") && (fieldName == actionValue)) { if ((fieldType == "submit") || (fieldType == "reset")) { putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if (fieldType == "image") { putInputValueIntoArray(fieldArray, fieldName+ ".x", "1"); // fieldArray[fieldName + ".x"]="1"; putInputValueIntoArray(fieldArray, fieldName+ ".y", "1"); // fieldArray[fieldName + ".y"]="1"; } } } } } var selectList = form.getElementsByTagName("select"); if (selectList.length != 0) { for (var i = 0; i < selectList.length; i++) { var sel = selectList.item(i); for (var j = 0; j < sel.length; j++) { if (sel.options[j].selected == true) { wclajax_debugInfo("queryInputFields: select name is '" + sel.name + "' value is '" + sel.options[j].value + "' encodeURI: '" + encodeURI(sel.options[j].value) + "'"); putInputValueIntoArray(fieldArray, sel.name, sel.options[j].value); // fieldArray[sel.name]=sel.options[j].value; } } } } var textAreaList = form.getElementsByTagName("textarea"); if (textAreaList.length != 0) { for (var i = 0; i < textAreaList.length; i++) { var textArea = textAreaList.item(i); if (textArea.name != null && textArea.name != "") { wclajax_debugInfo("queryInputFields: textarea name is '" + textArea.name + "' value is '" + textArea.value + "' encodeURI: '" + encodeURI(textArea.value) + "'"); putInputValueIntoArray(fieldArray, textArea.name, textArea.value); // fieldArray[textArea.name]=textArea.value; } } } putInputValueIntoArray(fieldArray, "btimestamp", new Date().getTime()); // fieldArray["btimestamp"]=new Date().getTime(); } return fieldArray; } function convertInputFieldsArrayToString(fieldArray){ var fieldString = ""; for (var i in fieldArray) { for(var j in fieldArray[i]){ fieldString+=i+"="+encodeURI(fieldArray[i][j])+"&"; } } fieldString=fieldString.substring(0,fieldString.length-1); return fieldString; } function getQueryInputFieldsSingleUpdate(form, actionValue, action){ var fieldArray = new Array(); if (form != null) { wclajax_debug("action: " + actionValue); putInputValueIntoArray(fieldArray, 'IsAjaxInvoked', 'YES'); // fieldArray['IsAjaxInvoked']='YES'; putInputValueIntoArray(fieldArray, 'IsAjaxUpdate', 'TRUE'); // fieldArray['IsAjaxUpdate']='TRUE'; putInputValueIntoArray(fieldArray, 'menuId', action); // fieldArray['menuId']=action; // Add the list of form names so we can tell when we're all done with // AJAX request in the form renderer. putInputValueIntoArray(fieldArray, 'AjaxForms', getFormsList()); // fieldArray['AjaxForms']=getFormsList(); fieldList = form.getElementsByTagName("input"); if (fieldList.length != 0) { for (var i = 0; i < fieldList.length; i++) { var fieldName = fieldList.item(i).getAttribute("name"); var fieldType = fieldList.item(i).getAttribute("type"); // Only process input tags with a NAME attr. if ((fieldName != null) && (fieldName != "")) { if (fieldType != null) { fieldType = fieldType.toLowerCase(); } if ((fieldType == "text") || (fieldType == "hidden") || (fieldType == "password")) { wclajax_debugInfo("queryInputFieldsSingleUpdate: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if (((fieldType == "checkbox") || (fieldType == "radio")) && (fieldList.item(i).checked)) { wclajax_debugInfo("queryInputFieldsSingleUpdate: input fieldName is '" + fieldName + "' value is '" + fieldList.item(i).value + "' encodeURI: '" + encodeURI(fieldList.item(i).value) + "'"); putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if ((actionValue != null) && (actionValue != "") && (fieldName == actionValue)) { if ((fieldType == "submit") || (fieldType == "reset")) { putInputValueIntoArray(fieldArray, fieldName, fieldList.item(i).value); // fieldArray[fieldName]=fieldList.item(i).value; } else if (fieldType == "image") { putInputValueIntoArray(fieldArray, fieldName+ ".x", "1"); // fieldArray[fieldName+ ".x"]="1"; putInputValueIntoArray(fieldArray, fieldName+ ".y", "1"); // fieldArray[fieldName+ ".y"]="1"; } } } } } var selectList = form.getElementsByTagName("select"); if (selectList.length != 0) { for (var i = 0; i < selectList.length; i++) { var sel = selectList.item(i); for (var j = 0; j < sel.length; j++) { if (sel.options[j].selected == true) { wclajax_debugInfo("queryInputFieldsSingleUpdate: select name is '" + sel.name + "' value is '" + sel.options[j].value + "' encodeURI: '" + encodeURI(sel.options[j].value) + "'"); putInputValueIntoArray(fieldArray, sel.name, sel.options[j].value); // fieldArray[sel.name]=sel.options[j].value; } } } } var textAreaList = form.getElementsByTagName("textarea"); if (textAreaList.length != 0) { for (var i = 0; i < textAreaList.length; i++) { var textArea = textAreaList.item(i); if (textArea.name != null && textArea.name != "") { wclajax_debugInfo("queryInputFieldsSingleUpdate: textarea name is '" + textArea.name + "' value is '" + textArea.value + "' encodeURI: '" + encodeURI(textArea.value) + "'"); putInputValueIntoArray(fieldArray, textArea.name, textArea.value); // fieldArray[textArea.name]=textArea.value; } } } putInputValueIntoArray(fieldArray, "btimestamp", new Date().getTime()); // fieldArray["btimestamp"]=new Date().getTime(); } return fieldArray; } function getResponseHeadElement(responseText) { var result = null; var upperResponse = responseText.toUpperCase(); var headStartIndex = upperResponse.indexOf(""); var headEndIndex = upperResponse.indexOf(""); if (headStartIndex != -1 && headEndIndex != -1) { var headElement = document.createElement('div'); headElement.innerHTML = '' + responseText.substring( headStartIndex + "".length, headEndIndex) + ''; result = headElement; } headStartIndex = upperResponse.indexOf("", headEndIndex); while (headStartIndex != -1) { var styleStartIndex = upperResponse.indexOf("", styleStartIndex); var cssEndIndex = upperResponse.indexOf("", cssStartIndex); if (cssStartIndex != -1 && cssEndIndex != -1) { var cssCode = responseText.substring(cssStartIndex+1, cssEndIndex); //@wcl team -changed offset back to 1. addCss(cssCode); } headEndIndex = upperResponse.indexOf("", headStartIndex); headStartIndex = upperResponse.indexOf("", headEndIndex); } return result; } function getHeadlessResponseText(responseText) { var result = responseText; var upperResponse = responseText.toUpperCase(); var headStartIndex = upperResponse.indexOf(""); var headEndIndex = upperResponse.indexOf(""); if (headStartIndex != -1 && headEndIndex != -1) { result = responseText.substring(0, headStartIndex) + responseText.substring(headEndIndex + "".length); } return result; } function addCss(cssCode) { var styleElement = document.createElement("style"); styleElement.type = "text/css"; if (styleElement.styleSheet) { styleElement.styleSheet.cssText = cssCode; } else { styleElement.appendChild(document.createTextNode(cssCode)); } document.getElementsByTagName("head")[0].appendChild(styleElement); } // TG: takes about 100 ms on average.. some improvements may be needed // (ie. parse response only once and reuse DOM fragment with updateAjaxDivs) function getScriptReferences(response){ var responseContainer = document.createElement('div'); responseContainer.innerHTML = response; // this takes time var scriptsContainer = document.createElement('div'); var scripts = responseContainer.getElementsByTagName('script'); for(var i=0; i 0) { wclajax_debug("-> addScriptsToHead: "+(scriptContent != null ? scriptContent.length : 0)); var documentHead = document.getElementsByTagName('head').item(0); var currentScripts = documentHead.getElementsByTagName('script'); var scriptExists; var numberExistingScripts = currentScripts.length; //if no visible menu is open, remove existing buildMenu_* function //definitions from documentHead to decrease processing time on future updates if ( (typeof visibleMenu_ == "undefined") || (visibleMenu_ == null) ) { for (var i = numberExistingScripts-1; i >= 0; i--) { try { if ( currentScripts[i].innerHTML && currentScripts[i].innerHTML.indexOf('function buildMenu_') != -1 ) { documentHead.removeChild(currentScripts[i]); } } catch (e) { } } } numberExistingScripts = currentScripts.length; for (var j = 0; j < scriptContent.length; j++) { var newScript = scriptContent[j]; try { scriptExists = false; //auto-add buildMenu function definitions, otherwise add script only if script does not already exist in head if ( scriptContent[j].innerHTML && scriptContent[j].innerHTML.indexOf('function buildMenu_') != -1 ) { scriptExists = false; } else { if ( (typeof visibleMenu_ != "undefined") && newScript.src && (newScript.src.indexOf("context_ie.js") != -1) && WClient.isBrowserInternetExplorer() && WClient.isBrowserVersion8Up() ) { scriptExists = true; } for ( var i = 0; i < numberExistingScripts && !scriptExists; i++) { var existingScript = currentScripts[i]; if (((newScript.type && existingScript.type && newScript.type == existingScript.type) || (newScript.lang && existingScript.lang && newScript.lang == existingScript.lang) || (newScript.language && existingScript.language && newScript.language == existingScript.language)) && ((newScript.src && existingScript.src && newScript.src == existingScript.src) || (newScript.innerHTML && existingScript.innerHTML && newScript.innerHTML == existingScript.innerHTML))) { scriptExists = true; break; } } } if (scriptExists) { // Even though we won't add this script go ahead and run it. // This is necessary for frames when the frame reload script (fMgr) is included in the response. if (newScript.innerHTML) { eval(newScript.innerHTML); } } else { wclajax_debug("Adding script(" + j + ") : " + scriptToString(newScript)); newScript = document.createElement('script'); documentHead.appendChild(newScript); if (scriptContent[j].type) newScript.type = scriptContent[j].type; if (scriptContent[j].lang) newScript.lang = scriptContent[j].lang; if (scriptContent[j].language) newScript.language = scriptContent[j].language; if (scriptContent[j].src) newScript.src = scriptContent[j].src; // IE doesn't allow the innerHTML to be set. // if (scriptContent[j].innerHTML) newScript.innerHTML = // scriptContent[j].innerHTML; if (scriptContent[j].innerHTML) newScript.text = scriptContent[j].innerHTML; // Unfortunately this doesn't work... // documentHead.appendChild(scriptContent[j]); } } catch (scriptError) { wclajax_debugErr("Error adding script(" + j + ") : " + scriptToString(newScript)); wclajax_debugErr("Error name [" + scriptError.name + "] message [" + scriptError.message + "]"); } } } } wclajax_debug("<- addScriptsToHead"); } function addStylesToHead(documentElement) { if (documentElement != null) { var styleContent = documentElement.getElementsByTagName('style'); if (styleContent != null && styleContent.length > 0) { var documentHead = document.getElementsByTagName('head').item(0); var currentStyles = documentHead.getElementsByTagName('style'); var styleExists; var numberExistingStyles = currentStyles.length; for (var j = 0; j < styleContent.length; j++) { var newStyle = styleContent[j]; try { styleExists = false; for ( var i = 0; i < numberExistingStyles && !styleExists; i++) { var existingStyle = currentStyles[i]; if (((newStyle.type && existingStyle.type && newStyle.type == existingStyle.type) || (newStyle.lang && existingStyle.lang && newStyle.lang == existingStyle.lang)) && (newStyle.innerHTML && existingStyle.innerHTML && newStyle.innerHTML == existingStyle.innerHTML)) { styleExists = true; break; } } if (!styleExists) { wclajax_debug("Adding style(" + j + ") : " + styleToString(newStyle)); newStyle = document.createElement('style'); documentHead.appendChild(newStyle); if (styleContent[j].type) newStyle.type = styleContent[j].type; if (styleContent[j].lang) newStyle.lang = styleContent[j].lang; if (styleContent[j].styleSheet) { newStyle.styleSheet.cssText = styleContent[j].innerHTML; } else { newStyle.innerHTML = styleContent[j].innerHTML; } // Unfortunately this doesn't work... // documentHead.appendChild(styleContent[j]); } } catch (styleError) { wclajax_debugErr("Error adding style(" + j + ") : " + styleToString(newStyle)); wclajax_debugErr("Error name [" + styleError.name + "] message [" + styleError.message + "]"); } } } } } function addLinksToHead(documentElement) { if (documentElement != null) { var linkContent = documentElement.getElementsByTagName('link'); if (linkContent != null && linkContent.length > 0) { var documentHead = document.getElementsByTagName('head').item(0); var currentLinks = documentHead.getElementsByTagName('link'); var linkExists; var numberExistingLinks = currentLinks.length; for (var j = 0; j < linkContent.length; j++) { var newLink = linkContent[j]; try { linkExists = false; for ( var i = 0; i < numberExistingLinks && !linkExists; i++) { var existingLink = currentLinks[i]; if (((newLink.type && existingLink.type && newLink.type == existingLink.type) || (newLink.rel && existingLink.rel && newLink.rel == existingLink.rel)) && (newLink.href && existingLink.href && newLink.href == existingLink.href)) { linkExists = true; break; } } if (!linkExists) { wclajax_debug("Adding link(" + j + ") : " + linkToString(newLink)); newLink = document.createElement('link'); documentHead.appendChild(newLink); if (linkContent[j].type) newLink.type = linkContent[j].type; if (linkContent[j].rel) newLink.rel = linkContent[j].rel; if (linkContent[j].href) newLink.href = linkContent[j].href; // Unfortunately this doesn't work... // documentHead.appendChild(linkContent[j]); } } catch (linkError) { wclajax_debugErr("Error adding link(" + j + ") : " + linkToString(newLink)); wclajax_debugErr("Error name [" + linkError.name + "] message [" + linkError.message + "]"); } } } } } function scriptToString(script){ return "type [" + (script.type ? script.type : "") + "] " + "lang [" + (script.lang ? script.lang : "") + "]" + " language [" + (script.language ? script.language : "") + "] " + "src [" + (script.src ? script.src : "") + "] " + "html [" + (script.innerHTML ? script.innerHTML : "") + "]"; } function styleToString(style){ return "type [" + (style.type ? style.type : "") + "] " + "lang [" + (style.lang ? style.lang : "") + "]" + "html [" + (style.innerHTML ? style.innerHTML : "") + "]"; } function linkToString(link){ return "type [" + (link.type ? link.type : "") + "] " + "rel [" + (link.rel ? link.rel : "") + "]" + "href [" + (link.href ? link.href : "") + "]"; } function createNewScriptBasedOn(baseScript) { var newScript = document.createElement('script'); if (baseScript.type) { newScript.type = baseScript.type; } if (baseScript.lang) { newScript.lang = baseScript.lang; } if (baseScript.language) { newScript.language = baseScript.language; } if (baseScript.getAttribute("runOnAjax")) { newScript.setAttribute("runOnAjax", baseScript.getAttribute("runOnAjax")); } if (baseScript.src) { newScript.src = baseScript.src; } if (baseScript.innerHTML) { newScript.text = baseScript.innerHTML; } return newScript; } //replaceScriptsInDocument - replace scripts in targetElement with new script elements based on // those found in sourceElement (based on addScriptsToDocument) // -in: sourceElement - ajax response container that was created from innerHTML; its script must // be recreated in the targetElement or they will be ignored by Mozilla/WebKit browsers // targetElemnt - container into which scripts will be added/replaced //-out: none function replaceScriptsInDocument(sourceElement, targetElement) { var sourceScripts = sourceElement.getElementsByTagName('script'); wclajax_debug("-> replaceScriptsInDocument"); if (sourceScripts != null && sourceScripts.length > 0) { var scriptsAdded = new Array(); var skipped = 0; //debug scripts to process for ( var j = 0; j < sourceScripts.length; j++) { var sourceScript = sourceScripts[j]; wclajax_debug("replaceScriptsInDocument : sourceScript[" + j + "] = " + scriptToString(sourceScript)); } wclajax_debug("replaceScriptsInDocument : source scripts [" + sourceScripts.length + "]"); for ( var j = 0; j < sourceScripts.length; j++) { var sourceScript = sourceScripts[j]; try { // If the script is the setupTableAjax script save it for later // so it won't flash the page. if ( (!WClient.isBrowserInternetExplorer()) || (!sourceScript.innerHTML) || (sourceScript.innerHTML.indexOf("setupTableAjax") == -1) ) { //use source script src or innerHTML as its key; will be used to match target script key var sourceKey = sourceScript.src ? sourceScript.src : sourceScript.innerHTML ? sourceScript.innerHTML : null; if (!scriptsAdded[sourceKey]) { scriptsAdded[sourceKey] = "true"; wclajax_debug("replaceScriptsInDocument : Adding script(" + j + ") : " + scriptToString(sourceScript)); if (sourceScript.innerHTML.indexOf("contextMenuShow") == -1) { // create new script to replace existing script in DOM var newScript = createNewScriptBasedOn(sourceScript); var targetScripts = targetElement.getElementsByTagName('script'); var readded = false; if (targetScripts != null && targetScripts.length > 0) { wclajax_debug("replaceScriptsInDocument : target scripts [" + targetScripts.length + "]"); //loop over every script found in the target container to find the script we want to replace for ( var k = 0; !readded && k < targetScripts.length; k++) { var targetScript = targetScripts[k]; try { //use target script src or innerHTML as its key; will be used to match DOM script key var targetKey = targetScript.src ? targetScript.src : targetScript.innerHTML ? targetScript.innerHTML : null; //wclajax_debug("replaceScriptsInDocument : "+k+": targetKey == sourceKey ? "+( targetKey == sourceKey )); // if we find the script already in the target container, replace it with the new script if ( targetKey == sourceKey ) { var targetParent = targetScript.parentNode; //be sure to replace existing script with new script (rather than remove and //append); we do this because sourceScripts appears to be a reference to the //list of scripts (removing a script from a parent removes it from sourceScripts //list and appending the new script adds it to the end of sourceScripts, causing //some script to not be processed and others processed more than once) targetParent.replaceChild(newScript, targetScript); readded = true; wclajax_debug("replaceScriptsInDocument : replaced"); } } catch (scriptError) { wclajax_debugErr("replaceScriptsInDocument: Error re-adding script(" + k + "): " + scriptToString(targetScript)); wclajax_debugErr("replaceScriptsInDocument: Error name [" + scriptError.name + "] message [" + scriptError.message + "]"); } } wclajax_debug("replaceScriptsInDocument : readded ["+readded+"]"); } // if we didn't find the script in the target container, add it (should never happen) if (!readded) { wclajax_debug("replaceScriptsInDocument: !!! added !!!"); targetElement.appendChild(newScript); } } } else { wclajax_debug("replaceScriptsInDocument : Skipping script [" + sourceKey + "]"); skipped++; } } else { wclajax_debug("replaceScriptsInDocument : Will add script later [" + sourceScript.innerHTML + "]"); ajaxTables[ajaxTables.length] = sourceScript.innerHTML; } //previousScript = sourceScript.innerHTML; } catch (scriptError) { wclajax_debugErr("Error adding script(" + j + "): " + scriptToString(sourceScript)); wclajax_debugErr("Error name [" + scriptError.name + "] message [" + scriptError.message + "]"); } } if (skipped > 0) { wclajax_debug("replaceScriptsInDocument : skipped [" + skipped + "]"); } workMapList = null; } wclajax_debug("<- replaceScriptsInDocument"); } function addScriptsToDocument(sourceElement, targetElement, onlyAjax) { var scriptContent = sourceElement.getElementsByTagName('script'); wclajax_debug("-> addScriptsToDocument: scriptContent.length ["+(scriptContent != null ? scriptContent.length : 0)+"] onlyAjax ["+onlyAjax+"]"); if (scriptContent != null && scriptContent.length > 0) { var scriptsAdded = new Array(); var skipped = 0; var newScript; var numberScripts = scriptContent.length; wclajax_debug("addScriptsToDocument : New scripts [" + scriptContent.length + "]"); for ( var j = 0; j < numberScripts; j++) { if(onlyAjax && scriptContent[j].getAttribute("runOnAjax") == null){ wclajax_debug("addScriptsToDocument : !runOnAjax Skipping " + (scriptContent[j].src ? scriptContent[j].src : scriptContent[j].innerHTML ? scriptContent[j].innerHTML : null)); continue; } try { // If the script is the setupTableAjax script save it for later // so it won't flash the page. if ((!WClient.isBrowserInternetExplorer()) || (!scriptContent[j].innerHTML) || (scriptContent[j].innerHTML .indexOf("setupTableAjax") == -1)) { var scriptKey = scriptContent[j].src ? scriptContent[j].src : scriptContent[j].innerHTML ? scriptContent[j].innerHTML : null; if (!scriptsAdded[scriptKey]) { scriptsAdded[scriptKey] = "true"; wclajax_debug("addScriptsToDocument : Adding script(" + j + ") : type [" + (scriptContent[j].type ? scriptContent[j].type : "") + "] lang [" + (scriptContent[j].lang ? scriptContent[j].lang : "") + "] language [" + (scriptContent[j].language ? scriptContent[j].language : "") + "] src [" + (scriptContent[j].src ? scriptContent[j].src : "") + "] html [" + (scriptContent[j].innerHTML ? scriptContent[j].innerHTML : "") + "]"); newScript = document.createElement('script'); if (scriptContent[j].type) newScript.type = scriptContent[j].type; if (scriptContent[j].lang) newScript.lang = scriptContent[j].lang; if (scriptContent[j].language) newScript.language = scriptContent[j].language; if (scriptContent[j].src) newScript.src = scriptContent[j].src; // IE doesn't allow the innerHTML to be set. // if (scriptContent[j].innerHTML) newScript.innerHTML = // scriptContent[j].innerHTML; if (scriptContent[j].innerHTML) newScript.text = scriptContent[j].innerHTML; // Unfortunately this doesn't work... //documentHead.appendChild(scriptContent[j]); if (scriptContent[j].innerHTML .indexOf("contextMenuShow") == -1) { targetElement.appendChild(newScript); } } else { wclajax_debug("addScriptsToDocument : Skipping script [" + scriptKey + "]"); skipped++; } } else { wclajax_debug("addScriptsToDocument : Will add script later [" + scriptContent[j].innerHTML + "]"); ajaxTables[ajaxTables.length] = scriptContent[j].innerHTML; } //previousScript = scriptContent[j].innerHTML; } catch (scriptError) { wclajax_debugErr("Error adding script(" + j + ") : type [" + (scriptContent[j].type ? scriptContent[j].type : "") + "] lang [" + (scriptContent[j].lang ? scriptContent[j].lang : "") + "] language [" + (scriptContent[j].language ? scriptContent[j].language : "") + "] src [" + (scriptContent[j].src ? scriptContent[j].src : "") + "] html [" + (scriptContent[j].innerHTML ? scriptContent[j].innerHTML : "") + "]"); wclajax_debugErr("Error name [" + scriptError.name + "] message [" + scriptError.message + "]"); } } if (skipped > 0) { wclajax_debug("addScriptsToDocument : skipped [" + skipped + "]"); } } wclajax_debug("<- addScriptsToDocument"); } function addSetupTableAjaxScripts() { if (WClient.isBrowserInternetExplorer()) { wclajax_debug("addSetupTableAjaxScripts : num scripts [" + ajaxTables.length + "]"); var extraScriptContainer = document .getElementById('WCL_AJAX_TABLE_SCRIPT_CONTAINER'); if (!extraScriptContainer) { // Create a container for the scripts. extraScriptContainer = document.createElement('DIV'); document.body.appendChild(extraScriptContainer); extraScriptContainer.setAttribute("id", "WCL_AJAX_TABLE_SCRIPT_CONTAINER"); } var addSetupTableAjax = true; var existingScripts = extraScriptContainer .getElementsByTagName('SCRIPT'); // Add the current scripts to the container. for ( var index = 0; index < ajaxTables.length; ++index) { // See if we already have this script. if ((existingScripts != null) && (existingScripts.length > 0)) { for ( var existingIndex = 0; existingIndex < existingScripts.length; existingIndex++) { if (existingScripts[existingIndex].innerHTML == ajaxTables[index]) { addSetupTableAjax = false; break; } } } if (addSetupTableAjax) { var newScript = document.createElement('script'); newScript.type = "text/javascript"; newScript.text = ajaxTables[index]; wclajax_debug("addSetupTableAjaxScripts : Adding [" + ajaxTables[index] + "]"); extraScriptContainer.appendChild(newScript); } } } } function updateAjaxDivs(tempContent, updateForm, updateParams, responseText) { var anyDivs = null; var doAgain = true; var addExtra = true; var result = true; wclajax_debug("-> updateAjaxDivs"); // If the response indicates the portlet threw an exception, disregard this // ajax // update and rerender the entire page //Speed improvements: // don't reference innerHTML property of tempContent repeatedly // use regular expressions instead of indexOf var tempContent_innerHTML = tempContent.innerHTML; var puRe = new RegExp("This portlet is unavailable"); var acRe = new RegExp("wcl_ajax_container"); if ( tempContent != null && tempContent_innerHTML.length > 0 && puRe.test(tempContent_innerHTML) ) { doAgain = false; addExtra = false; result = false; wclajax_debug("Detected a problem displaying portlet, so redisplaying page without ajax"); startRefreshRequest(updateForm ,updateParams, 'NO'); } else if (tempContent != null && tempContent_innerHTML.length > 0 && !acRe.test(tempContent_innerHTML) ) { // The response does not contain an ajax container but has size // a 302 redirect might have occurred or the user's session has expired // just update and render the page returned doAgain = false; addExtra = false; result = true; wclajax_debug("The response does not contain an ajax container but has size"); if (!handleLoginPortlet(responseText)) { //if responseText contains a BODY tag, update and render the page //returned, otherwise abort var bodyRe = new RegExp(" 0) { oldDisplay = oldContainer.childNodes[0].style.display; oldContainer.childNodes[0].style.display='none'; } } catch (hideError) { wclajax_debugErr("Got an error hiding old content [" + hideError.name + "] [" + hideError.message + "]"); } } */ // Arg, update the forms here for Firefox so you can't // see the updates happen. if (WClient.isBrowserMozilla()) { inputData.updateInputs(oldContent, newContent); } // IE8 fix: need to mark scripts in newContent before replacing // oldContent or scripts inside AJAX_CONTAINERS will not get executed // if IE8, mark scripts now (non IE8 scripts marked later) if ( WClient.isBrowserInternetExplorer() && (WClient.isBrowserVersion8Up() || WClient.isCompatibilityView()) ) { // mark scripts as runOnAjax, so we'll know they're new and only them need to be executed markScriptsFromAjax(newContent); } wclajax_debug("Adding child"); try { oldContainer.appendChild(newContent); // fix IE8 standards view bug: added content is not // visible upon insertion into DOM unless we replace its // outerHTML with its outerHTML if ( WClient.isBrowserInternetExplorer() && WClient.isBrowserVersion8Up() ) { //need to reset the element innerHTML because it somehow //gets reset after setting its outerHTML var newContent_innerHTML = newContent.innerHTML; newContent.outerHTML = newContent.outerHTML; newContent.innerHTML = newContent_innerHTML; newContent_innerHTML = null; } // bind forms/anchors with ISC 7.5 if( (typeof PortletLink != 'undefined') && (typeof PortletLink.hookAnchors != 'undefined') ) { PortletLink.hookAnchors(newContent); PortletLink.hookForms(newContent); } } catch (addError) { wclajax_debugErr("Got an error adding new content: " + addError.toString()); } // Arg, update the forms here for IE so that the // checkbox update will work. // The checkboxes need to be in the document so that we // can set checked. if (WClient.isBrowserInternetExplorer()) { inputData.updateInputs(oldContent, newContent); } wclajax_debug("Removing child"); try { // if ( WClient.isBrowserMozilla() && oldContainer.childNodes.length == 1 ) { // // Add failed so unhide the old content // oldContainer.childNodes[0].style.display=oldDisplay; // } else { // Remove the old content and any scripts we added. while (oldContainer.childNodes.length > 1) { var removed = oldContainer .removeChild(oldContainer.childNodes[0]); if (WClient.isBrowserInternetExplorer() || WClient.isBrowserFirefox()) { removed.outerHTML=" "; } // } } } catch (removeError) { wclajax_debugErr("Got an error removing old content [" + removeError.name + "] [" + removeError.message + "]"); } // IE8 fix: if not IE8, mark scripts now (IE8 scripts marked earlier) if ( !WClient.isBrowserInternetExplorer() || !(WClient.isBrowserVersion8Up() || WClient.isCompatibilityView()) ) { // mark scripts as runOnAjax, so we'll know they're new and only them need to be executed markScriptsFromAjax(newContent); } // Now add any scripts that were in the response because // IE removes them when we do innerHTML = responseText. if (WClient.isBrowserInternetExplorer()) { addScriptsToDocument(newContent, oldContainer, false); } else { //ODT A7325 - AJAX response is text that is used to define the innerHTML of handleStateChange's //tempContent, because the tempContent node is created via innerHTML, its script tags are not //executed. To workaround this, we replace all script elements found in the DOM that are also //found in the reponse with new script elements based on them. This should have no effective //change on the script change, but it will force the browser to execute these scripts. replaceScriptsInDocument(newContent, oldContainer, false); } // Redo this processing as we could have nested AJAX content //avoid doAgain processing if TD doesn't contain an wcl_ajax_container var childDivs = newContent.getElementsByTagName("DIV"); for (var j = 0; j < childDivs.length && doAgain == false; j++) { if (childDivs[j].getAttribute("wcl_ajax_container") == "true") { doAgain = true; } } if ( doAgain == false ) { //divs in array (including div at index i were removed), //so decrement i to pick up next unprocessed DIV i = i - 1; } } else if ((oldContent == null) && (newId.substring(0, 3) == "PG_")) { // The response does contain an ajax container but is // not the same // container the request as originated from. The request // might have // generated a new page or a 302 redirect might have // occurred or the // user's session has expired just update and render the // page returned wclajax_debug("Response contains new content so display the new page"); doAgain = false; addExtra = false; result = true; // Update the document with what we got in the response. document.body.innerHTML = getHeadlessResponseText(responseText); // mark scripts in new page to ensure they get executed markScriptsFromAjax(document.body); // Now add any scripts that were in the response because // IE removes them when we do innerHTML = response. addScriptsToDocument(document.body, document.body, false); if (WClient.isBrowserInternetExplorer()) { // Since this is a new page let's scroll to the top. window.scroll(0, 0); } break; } } } } } if (addExtra) { // Add any scripts that were outside of any AJAX containers. var extraScripts = tempContent.getElementsByTagName('script'); if (extraScripts != null && extraScripts.length > 0) { wclajax_debug("Adding extra scripts that were not in an AJAX container"); // Remove the container that holds the scripts so we can start over. var extraScriptContainer = document .getElementById('WCL_AJAX_SCRIPT_CONTAINER'); if (extraScriptContainer) { extraScriptContainer.parentNode .removeChild(extraScriptContainer); } // Create the container to hold the scripts. extraScriptContainer = document.createElement('div'); document.body.appendChild(extraScriptContainer); extraScriptContainer .setAttribute("id", "WCL_AJAX_SCRIPT_CONTAINER"); // Now add the scripts to this container. addScriptsToDocument(tempContent, extraScriptContainer, true); } } wclajax_debug("<- updateAjaxDivs"); return result; } function markScriptsFromAjax(sourceElement){ scripts = sourceElement.getElementsByTagName('script'); for(var i=0; i< scripts.length; i++){ if ( scripts[i].getAttribute("runOnAjax") != "FALSE" ) { scripts[i].setAttribute("runOnAjax", "TRUE"); } } } function handleRequestErrorDojo(error) { wclajax_debug("-> handleRequestErrorDojo"); if ( error && error.response && error.response.status != 0 ) { wclajax_debug(" handleRequestErrorDojo: error.response.status ["+error.response.status+"]"); var reterr = document.getElementById('RETRIEVAL_ERR'); if (reterr) { reterr.style.display = 'block'; if (!WClient.isBrowserMozilla()) { reterr.style.height = document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight; reterr.style.width = document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth; reterr.style.zoom = 1; } else { reterr.style.height = document.body.scrollHeight; reterr.style.width = document.body.scrollWidth; } reterr.style.left = "0px"; reterr.setAttribute('aria-label', reterr.getAttribute('label')); reterr.setAttribute('aria-labelledby', 'RETRIEVAL_ERR'); reterr.setAttribute("role", "alertdialog"); reterr.setAttribute("onClick", "hideRequestErrorDojoDialog()"); } var retimg = document.getElementById('RETRIEVAL_ERR_IMG'); if (retimg) { retimg.style.display = 'block'; retimg.setAttribute('aria-label', retimg.getAttribute('label')); retimg.setAttribute('aria-labelledby', 'RETRIEVAL_ERR_IMG'); retimg.setAttribute("role", "alertdialog"); retimg.setAttribute("onClick", "hideRequestErrorDojoDialog()"); } window.document.body.style.cursor = "auto"; wclajax_debug("WCL/DoJo Request Error - HTTP status code: ", error.response.status); isAJAXOutstanding=false; } wclajax_debug("<- handleRequestErrorDojo"); return error; } function hideRequestErrorDojoDialog() { var reterr = document.getElementById('RETRIEVAL_ERR'); if (reterr) { reterr.style.display = 'none'; reterr.removeAttribute('aria-label'); reterr.removeAttribute('aria-labelledby'); reterr.removeAttribute("role"); reterr.removeAttribute("onClick"); } var retimg = document.getElementById('RETRIEVAL_ERR_IMG'); if (retimg) { retimg.style.display = 'none'; retimg.removeAttribute('aria-label'); retimg.removeAttribute('aria-labelledby'); retimg.removeAttribute("role"); retimg.removeAttribute("onClick"); } } var END_OF_INPUT = -1; var base64Chars = new Array( 'A','B','C','D','E','F','G','H', 'I','J','K','L','M','N','O','P', 'Q','R','S','T','U','V','W','X', 'Y','Z','a','b','c','d','e','f', 'g','h','i','j','k','l','m','n', 'o','p','q','r','s','t','u','v', 'w','x','y','z','0','1','2','3', '4','5','6','7','8','9','+','/' ); //*************************************************************** var reverseBase64Chars = new Array(); for (var i=0; i < base64Chars.length; i++){ reverseBase64Chars[base64Chars[i]] = i; } var base64Str; var base64Count; function setBase64Str(str){ base64Str = str; base64Count = 0; } function readReverseBase64(){ if (!base64Str) return END_OF_INPUT; while (true){ if (base64Count >= base64Str.length) return END_OF_INPUT; var nextCharacter = base64Str.charAt(base64Count); base64Count++; if (reverseBase64Chars[nextCharacter]){ return reverseBase64Chars[nextCharacter]; } if (nextCharacter == 'A') return 0; } return END_OF_INPUT; } function ntos(n){ n=n.toString(16); if (n.length == 1) n="0"+n; n="%"+n; return unescape(n); } function decodeBase64(str){ setBase64Str(str); var result = ""; var inBuffer = new Array(4); var done = false; while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){ inBuffer[2] = readReverseBase64(); inBuffer[3] = readReverseBase64(); result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4)); if (inBuffer[2] != END_OF_INPUT){ result += ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2)); if (inBuffer[3] != END_OF_INPUT){ result += ntos((((inBuffer[2] << 6) & 0xff) | inBuffer[3])); } else { done = true; } } else { done = true; } } return result; } //*************************************************************************** function webBrowserLookUp(data) { //navigator.appName == "Netscape" if(navigator.appName.indexOf("Netscape") == -1) { writeFileIE(data); }else { writeFileNS(data); //writeFileNSTest(); } } function handleExportData(response) { var exportedData = getExportedData(response); exportedData = decodeBase64(exportedData); webBrowserLookUp(exportedData); return response; } function getExportedData(response) { var tempContent = document.createElement("div"); tempContent.setAttribute("id","ServerDataResponse"); wclajax_debug("Reading in response"); tempContent.innerHTML = response; var divs = tempContent.getElementsByTagName('div'); var doAgain = true; var div = null; for (var i = 0; i < divs.length && doAgain == true; i++) { if (divs[i].getAttribute("id") == "EXPORTED_DATA") { div = divs[i]; doAgain = false; } } return div.innerHTML; } function writeFileIE(str) { SaveFrame.document.write( str ); SaveFrame.document.execCommand('SaveAs',null,'test.csv'); } function writeFileNS(str) { var priv1 = "UniversalXPConnect"; var priv2 = "UniversalFileRead"; var privilegeGranted = true; var runtimeError = ''; try { netscape.security.PrivilegeManager.enablePrivilege (priv1); netscape.security.PrivilegeManager.enablePrivilege (priv2); } catch(e) { alert(e); privilegeGranted = false; runtimeError = "Extended privileges are not granted by user"; } finally { } if (privilegeGranted) { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes['@mozilla.org/filepicker;1'].createInstance(nsIFilePicker); fp.init(window, 'Save File As...', nsIFilePicker.modeSave); fp.defaultString = "test.csv"; fp.appendFilters(fp.filterAll); var res = fp.show(); if ( res == nsIFilePicker.returnOK ) { var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); outputStream.init( fp.file, 0x04 | 0x08,777, 0 ); var result = outputStream.write( str, str.length ); outputStream.close(); } } } function handleStateChange(response) { try { wclajax_debug("-> handleStateChange: IE ["+WClient.isBrowserInternetExplorer()+"]"); var startTime = new Date(); // Reset the ajax tables list. ajaxTables = new Array(); // Save the refresh form. var previousForm = refreshForm; var previousParams = refreshParams; // window.status = ""; var tempContent = document.createElement("div"); tempContent.setAttribute("id", "ServerResponse"); // Get references to WCL scripts from response var responseScriptReferences = getScriptReferences(response.text); addScriptsToHead(responseScriptReferences); if (WClient.isBrowserFirefox()) { responseScriptReferences = null; } // Get scripts from the response HEAD and put them in the doc HEAD. var responseHead = getResponseHeadElement(response.text); addScriptsToHead(responseHead); addStylesToHead(responseHead); addLinksToHead(responseHead); if (WClient.isBrowserFirefox()) { responseHead = null; } if ( typeof debugWcl == "function" ) { debugWcl("-> handleStateChange: response = "); debugWcl(response.text, "", true, true); } wclajax_debug("Reading in response"); tempContent.innerHTML = response.text; //remove bothersome scripts from response head var scriptContent = tempContent.getElementsByTagName('script'); if ( scriptContent != null ) { for (var j = 0; j < scriptContent.length; j++) { try { if ( scriptContent[j].src ) { if ( scriptContent[j].src.indexOf("WUtilities.js") != -1 || scriptContent[j].src.indexOf("utilities.js") != -1 ) { //remove WUtilties.js node from ajax update; prevent loss of onresize actions //remove utilties.js node from ajax update; prevent resetting of last user interaction timer tempContent.removeChild(scriptContent[j]); j = j - 1; //decrement j to account for shift in array } else if ( ( (typeof visibleMenu_ != "undefined") && (scriptContent[j].src.indexOf("context_ns6.js") != -1) ) || ( (typeof visibleMenu_ != "undefined") && (scriptContent[j].src.indexOf("context_ie.js") != -1) && WClient.isBrowserInternetExplorer() && WClient.isBrowserVersion8Up() ) ) { //if a visibleMenu_ is defined and context_ns6.js exists, remove //context_ns6.js script tag from the tempContent, as to not freeze //possible context menus. Note this a temp fix that will leave an //outdated context menu displayed and is only needed until WCL properly //handles AJAX updates of displayed context/popup menus. tempContent.removeChild(scriptContent[j]); j = j - 1; //decrement j to account for shift in array } } } catch(e) { } } } //wclajax_debugHtml(tempContent.innerHTML); wclajax_debug("Done reading in response"); // Mark any input components as ok to update. inputData.markInputs(tempContent); // Now let's look in the response from the server if (updateAjaxDivs(tempContent, previousForm, previousParams, response.text)) { addSetupTableAjaxScripts(); callRunScripts(); } if (WClient.isBrowserFirefox()) { tempContent.innerHTML = ""; inputData.initialize(); ajaxTables = null; } // remove OVERRIDE_FOCUS attributes lingering from previous ajax updates removeOverrideFocusAttributes(); isAJAXOutstanding = false; wclajax_debug("<- handleStateChange : time to process AJAX request [" + (new Date().getTime() - startTime.getTime()) + "]"); } catch (err) { wclajax_debugErr("Got an error [" + err.name + "] [" + err.message + "]"); wclajax_debugErr(err.toString()); } window.document.body.style.cursor = "auto"; return response.text; } function removeOverrideFocusAttributes() { document.querySelectorAll(`[${OVERRIDE_FOCUS}]`) .forEach((element) => element.removeAttribute(OVERRIDE_FOCUS)); } function createHandleStateChange (focusElementId) { // if not given an element to focus, use existing callback as-is if (!focusElementId) { return handleStateChange; } // If given an element to focus, first handle the response as usual. Then focus on the element (if it still exists) // and set client-side-only OVERRIDE_FOCUS attribute referenced by wcl.js' focusFirstInput and hwmca's defaultButton.js return function(response) { handleStateChange(response); const focusElement = document.getElementById(focusElementId); if (focusElement) { focusElement.setAttribute(OVERRIDE_FOCUS, 'true'); focusElement.focus(); } } } function handleRefreshStateChange(response) { try { wclajax_debug("handleRefreshStateChange"); //window.status = ""; // Reset the ajax tables list. ajaxTables = new Array(); // wclajax_debugHtml(response.text); // Get scripts from the response HEAD and put them in the doc // HEAD. var responseHead = getResponseHeadElement(response.text); addScriptsToHead(responseHead); if (WClient.isBrowserFirefox()) { responseHead = null; } if (!handleLoginPortlet(response.text)) { // Update the document with what we got in the response. document.body.innerHTML = getHeadlessResponseText(response.text); // Now add any scripts that were in the response because // IE removes them when we do innerHTML = response. addScriptsToDocument(document.body, document.body, false); addSetupTableAjaxScripts(); callRunScripts(); if (WClient.isBrowserInternetExplorer()) { // Since this is a new page let's scroll to the top. window.scroll(0, 0); } } // remove OVERRIDE_FOCUS attributes lingering from previous ajax updates removeOverrideFocusAttributes(); if (WClient.isBrowserFirefox()) { ajaxTables = null; } isAJAXOutstanding = false; } catch (err) { wclajax_debugErr("Got an error refreshing [" + err.name + "] [" + err.message + "]"); } window.document.body.style.cursor = "auto"; } function restoreLoginPortlet(response) { try { wclajax_debug("handleLoginRestore"); // wclajax_debugHtml(response.text); var restore = response.text.indexOf("title_alt_restore.gif"); var hrefStart = response.text.substring(0,restore).lastIndexOf("href='") + "href='".length; var hrefEnd = response.text.substring(hrefStart).indexOf("'") + hrefStart; var restoreHref = response.text.substring(hrefStart, hrefEnd); wclajax_debug("restoreLoginPortlet : restore href [" + restoreHref + "]"); window.location = restoreHref; } catch (err) { wclajax_debugErr("Got an error restoring login portlet [" + err.name + "] [" + err.message + "]"); window.location = null; } } function callRunScripts() { // Javascript files that get added to the document do not get loaded // in IE until the page is loaded. This means that during the // addScriptsToDocument function if a js file is added and then a // function is called from that file it will not run (popup menus // call contextMenuSetIcons in context_ie.js). Let's add an image to // the end of the document so that when it's finished loading we can // run all the scripts again so that they are run successfully. if (document.images.length > 0) { var refreshImage = document.createElement('img'); refreshImage.onload = runScripts; refreshImage.src = document.images[document.images.length - 1].src; refreshImage.width = '0'; refreshImage.height = '0'; refreshImage.setAttribute("alt", ""); document.body.appendChild(refreshImage); } else { setTimeout("runScripts()", 3000); } } /** * Check for duplicate scripts * * @param script * @param evaled */ function dupeScript(script, evaled){ for(var i=0;i 0) { for (var j = 0; j < anyScripts.length; j++) { try { wclajax_debug(" runScripts: run script(" + j + ") : " + scriptToString(anyScripts[j])); // We don't need to eval the context menu buildMenu functions. // The setupTableAjax scripts are run during updateAjaxDivs. if ((anyScripts[j].innerHTML) && (anyScripts[j].getAttribute("runOnAjax") == "TRUE") && (anyScripts[j].innerHTML .indexOf("function buildMenu") == -1)) { if (previousScript == null || anyScripts[j].innerHTML != previousScript) { wclajax_debugHtml(anyScripts[j].innerHTML); if(anyScripts[j].innerHTML.indexOf("//buildMenu_") != -1){ anyScripts[j].innerHTML = anyScripts[j].innerHTML .substring(2, anyScripts[j].innerHTML.length); eval(anyScripts[j].innerHTML); } else if (anyScripts[j].innerHTML.indexOf('hmcAddLoadEvent(') != -1) { wclajax_debug(" runScripts: run script(" + j + ") : hmcAddLoadEvent"); var hmconloadString = anyScripts[j].innerHTML hmconloadString = hmconloadString.replace(/hmcAddLoadEvent/g, "hmcExecuteFunction"); if(!dupeScript(hmconloadString, evaled)) { eval(hmconloadString); evaled.push(hmconloadString); } } else { wclajax_debug(" runScripts: run script(" + j + ") : eval"); eval(anyScripts[j].innerHTML); } } else { skipped++; } anyScripts[j].removeAttribute("runOnAjax"); previousScript = anyScripts[j].innerHTML; } //if it was script showing popup clear script if(anyScripts[j].innerHTML.indexOf("contextMenuShow") != -1) { anyScripts[j].text = ""; } } catch (runError) { wclajax_debugErr("Got an error running script [" + runError.name + "] [" + runError.message + "]"); } } if (skipped > 0) { wclajax_debug("runScripts : skipped [" + skipped + "]"); } } wclajax_debug("runScripts : time to run scripts [" + (new Date().getTime() - startTime.getTime()) + "]"); setTimeout("runOnloads();", 0); } function runOnloads() { // Run any images onloads that did not get run. var images = document.getElementsByTagName('img'); var numImages = images.length; wclajax_debug("runOnloads : images [" + numImages + "]"); var current = null; var onloadString = null; for (var x = 0; x < numImages; ++x) { if (images[x].onload) { onloadString = null; current = images[x].onload.toString(); if (WClient.isBrowserMozilla()) { if (current.indexOf('function onload(event)') == 0) { onloadString = current.substring(24, (current.length - 2)); } } else { if (current.indexOf('function anonymous()') == 0) { onloadString = current.substring(23, (current.length - 2)); } } wclajax_debug("runOnloads : onload [" + onloadString + "]"); // if ((onloadString != null) && // ((onloadString.indexOf('WOverview.') != -1) || // (onloadString.indexOf('WImageViewport.') != -1) || // (onloadString.indexOf('WToggleButton.') != -1))) { wclajax_debug("runOnloads : rerunning onload [" + onloadString + "]"); eval(onloadString); //} } } } function FormsData() { var formsData = new Array(); var inputList = new Array(); var changeList = new Array(); var typeList = new Array(); this.initialize = initialize; this.markInputs = markInputs; this.updateInputs = updateInputs; this.addField = addField; this.getField = getField; this.reset = reset; this.markInput = markInput; function initialize() { this.reset(); var fieldList = document.getElementsByTagName("input"); for (var i = 0; i < fieldList.length; i++) { this.addField(fieldList.item(i), "input"); } var textAreaList = document.getElementsByTagName("textarea"); for (var i = 0; i < textAreaList.length; i++) { this.addField(textAreaList.item(i), "textarea"); } var selectList = document.getElementsByTagName("select"); for (var i = 0; i < selectList.length; i++) { this.addField(selectList.item(i), "select"); } } function addField(input, type) { if ((input != null) && (input.id != null) && (input.id != "") && (input.name != null) && (input.name != "") && ((type != "input") || (input.type != "hidden"))) { // See if we already have this input. var newInput = this.getField(input); if (newInput == null) { newInput = new FormField(); formsData[formsData.length] = newInput; } newInput.update(input, type); } } function markInputs(docElement) { var changeType = 0; var fieldList = docElement.getElementsByTagName("input"); for (var i = 0; i < fieldList.length; i++) { this.markInput(fieldList, i, fieldList.item(i).type); } var textAreaList = docElement.getElementsByTagName("textarea"); for (var i = 0; i < textAreaList.length; i++) { this.markInput(textAreaList, i, "textarea"); } var selectList = docElement.getElementsByTagName("select"); for (var i = 0; i < selectList.length; i++) { this.markInput(selectList, i, "select"); } } function markInput(fields, index, type) { // 0: ID was not found in saved data. // 1: Input was found and was the same. // 2: Server value was different from saved. if (type != null) { type = type.toLowerCase(); } var changed = 0; var input = fields.item(index); // Get the original input of this name. var num = formsData.length; for ( var i = 0; i < num; ++i) { if ((formsData[i].getName() == input.name) && (formsData[i].getType() == type)) { if (type == "radio") { if (!formsData[i].tested) { // Need to check all the radios to see if the server // changed anything. var match = true; var numFields = fields.length; var numValues = formsData[i].values.length; // wclajax_debug("markInput : testing radio buttons [" + // formsData[i].getName() + "]"); for ( var x = 0; x < numFields && match; ++x) { if (fields[x].type == "radio" && fields[x].name == formsData[i].getName()) { match = false; for (j = 0; j < numValues && !match; ++j) { if ((formsData[i].values[j] == fields[x].value) && (formsData[i].checks[j] == fields[x].checked) && (formsData[i].ids[j] == fields[x].id)) { match = true; formsData[i].matched[j] = match; } } } } if (match) { // wclajax_debug("markInput : all radio buttons from // response are in original page"); // See if all the original checks were marked to // tell if there were any original // that were left out of the server response. for (j = 0; j < numValues && match; ++j) { if (!formsData[i].matched[j]) { // wclajax_debug("markInput : radio button was not // in server response [" + // formsData[i].values[j] + "]"); // Found an entry that was not in the // response. match = false; } } // Save this info for later so we don't have to do // that junk again! formsData[i].passed = match; } formsData[i].tested = true; } changed = (formsData[i].passed ? 1 : 2); // wclajax_debug("markInput : name [" + input.name + "] type [" + // type + "] changed [" + changed + "]"); } else if ((type == "checkbox") && (input.id == formsData[i].getId())) { changed = ((formsData[i].value == input.value && formsData[i].checked == input.checked) ? 1 : 2); // wclajax_debug("markInput : name [" + input.name + "] type [" + // type + "] changed [" + changed + "]"); } else if ((type == "text" || type == "password" || type == "textarea") && (input.id == formsData[i].getId())) { changed = ((formsData[i].value == input.value) ? 1 : 2); // wclajax_debug("markInput : name [" + input.name + "] type [" + // type + "] changed [" + changed + "]"); } else if ((type == "select") && (input.id == formsData[i].getId())) { // Make sure all of the options are the same. var match = true; var numOptions = input.options.length; // wclajax_debug("markInput : name [" + formsData[i].getId() + "] // selections [" + numOptions + "]"); for ( var z = 0; z < numOptions && match; ++z) { if ((input.options[z].value != formsData[i].values[z]) || (input.options[z].text != formsData[i].selections[z]) || (input.options[z].selected != formsData[i].selected[z])) { match = false; } } changed = match ? 1 : 2; // wclajax_debug("markInput : name [" + input.name + "] type [" + // type + "] changed [" + changed + "]"); } //break; } } if (changed > 0) { // wclajax_debug("markInput : field changed so saving name [" + input.name + // "] id [" + input.id + "] type [" + type + "] changed [" + changed // + "]"); inputList[inputList.length] = input; changeList[changeList.length] = changed; typeList[typeList.length] = type; } } function updateInputs(oldContent, newContent) { var num = inputList.length; for ( var index = 0; index < num; ++index) { try { var oldInput = document.getElementById(inputList[index].id); // wclajax_debug("updateInputs : processing input [" + // inputList[index].id + "]"); if ((typeList[index] == "text" || typeList[index] == "password" || typeList[index] == "textarea") && (oldInput.value != inputList[index].value) && (changeList[index] == 1)) { // wclajax_debug("updateInputs : updating [" + inputList[index].id + // "] [" + inputList[index].name + "] type [" + // typeList[index] + "] text [" + oldInput.value + "]"); inputList[index].value = oldInput.value; } else if ((typeList[index] == "checkbox") && (oldInput.checked != inputList[index].checked) && (changeList[index] == 1)) { // wclajax_debug("updateInputs : updating [" + inputList[index].id + // "] [" + inputList[index].name + "] type [" + // typeList[index] + "] checked [" + oldInput.checked + // "]"); inputList[index].checked = oldInput.checked; } else if ((typeList[index] == "radio") && (oldInput.checked != inputList[index].checked) && (changeList[index] == 1)) { // wclajax_debug("updateInputs : updating [" + inputList[index].id + // "] [" + inputList[index].name + "] type [" + // typeList[index] + "] checked [" + oldInput.checked + // "]"); inputList[index].checked = oldInputs.checked; } else if (typeList[index] == "select") { if (changeList[index] == 1) { // wclajax_debug("updateInputs : updating [" + // inputList[index].id + "] [" + inputList[index].name + // "] type [" + typeList[index] + "] selected [" + // oldInput.value + "]"); for ( var i = 0; i < oldInput.length; ++i) { inputList[index].options[i].selected = oldInput.options[i].selected; } } else if (changeList[index] == 2) { // wclajax_debug("updateInputs : resetting [" + // inputList[index].id + "] [" + inputList[index].name + // "] type [" + typeList[index] + "]"); //KR - commented code causes reseting selectionBox/comboBox and //this causes loss of visible information about changed selections //recieved from the server //bug:46030 // if ((inputList[index].type != null) // && (inputList[index].type == "select-multiple")) { // inputList[index].selectedIndex = -1; // } else { // inputList[index].selectedIndex = 0; // } } } } catch (inputError) { wclajax_debugErr("Error updating input " + inputList[index].id + " [" + inputError.name + "] message [" + inputError.message + "]"); } } } function getField(input) { var result = null; var num = formsData.length; for ( var i = 0; i < num; ++i) { if (formsData[i].equals(input)) { result = formsData[i]; break; } } return result; } function reset() { formsData = new Array(); inputList = new Array(); changeList = new Array(); typeList = new Array(); } } function FormField() { var id; var type; var name; this.getId = getId; this.getType = getType; this.getName = getName; this.update = update; this.equals = equals; function getId() { return id; } function getType() { return type; } function getName() { return name; } function update(input, type) { if (type != null) { type = type.toLowerCase(); } if (type == "input") { type = input.type; } if ((type == "text") || (type == "password") || (type == "textarea")) { setData(input.id, type, input.name); this.value = input.value; } else if (type == "checkbox") { setData(input.id, type, input.name); this.value = input.value; this.checked = input.checked; } else if (type == "radio") { setData(input.id, type, input.name); if (this.values == null) { this.values = new Array(); this.checks = new Array(); this.matched = new Array(); this.ids = new Array(); } var numValues = this.values.length; this.values[numValues] = input.value; this.checks[numValues] = input.checked; this.ids[numValues] = input.id; this.matched[numValues] = false; this.tested = false; this.passed = false; } else if (type == "select") { setData(input.id, type, input.name); this.values = new Array(); this.selections = new Array(); this.selected = new Array(); var numSelections = input.options.length; for ( var i = 0; i < numSelections; ++i) { this.values[i] = input.options[i].value; this.selections[i] = input.options[i].text; this.selected[i] = input.options[i].selected; } } } function setData(fieldId, fieldType, fieldName) { id = fieldId; type = fieldType; name = fieldName; } function equals(field) { var result = false; if ((field.type != null) && (field.type == "radio")) { // Group radio buttons by name. result = (field.name == name); } else { result = ((field.id == id) && (field.name == name)); } return result; } } /** * Debug functions and variables. * Uses Dojo firebug debugging console. */ var wclajax_debugOn = false; function wclajax_debug(msg) { if (wclajax_debugOn == true) { console.log(msg); } /* Uncomment to test a table with a specific aria-label (useful in tasks that display multiple tables). Enable by defining traceAriaLabel at the top. else if (traceID === null || msg.indexOf(traceID) !== -1) { if (traceID === null && msg.indexOf('traceID = ') !== -1) { var matches = msg.match(/traceID = (\w+)/); if (matches && matches.length == 2) { var divID = matches[1]; if (divID) { var tdID = divID.replace(/^\w\w(_.*)/, "TD$1"); if (tdID) { var td = document.getElementById(tdID); if (td && td.getAttribute("aria-label") === traceAriaLabel) { traceID = divID.replace(/^\w\w_(.*)/, "$1"); console.log("FOUND traceID: "+traceID); } } } } } if (traceID !== null && msg.indexOf(traceID) !== -1) { console.log(msg); } } */ if ( typeof debugWcl == 'function' ) { debugWcl(msg); } } function wclajax_debugErr(msg) { if (wclajax_debugOn == true) { console.error(msg); } if ( typeof debugWcl == 'function' ) { debugWcl(msg, "red"); } } function wclajax_debugInfo(msg) { if (wclajax_debugOn == true) { console.info(msg); } } function wclajax_debugHtml(msg) { if (wclajax_debugOn == true) { console.log(msg); } } function wclajax_debugWarn(msg){ if (wclajax_debugOn == true){ console.warn(msg); } } function getActionString(form){ var actionString; // TG: AJAX in Portlets if(form.getAttribute("AJAX_ACTION") != null){ actionString = form.getAttribute("AJAX_ACTION"); }else{ actionString = form.action; } return actionString; } // @auiml - begin - the following enhancement is need so that auiml can // support WCL ajax function addAuimlTransactionSupport(actionString, inputFields){ var transactionIndex = actionString.indexOf("WnTransaction="); if (transactionIndex != -1) { wclajax_debugInfo("found transaction in action"); // There is a transaction in the action so get the real value from // parameters. var currentTransaction = null; var transIndex = inputFields.indexOf("WnTransaction="); if (transIndex != -1) { var endTransIndex = inputFields.substring(transIndex).indexOf("&"); if (endTransIndex != -1) { currentTransaction = inputFields.substring(transIndex + 14, transIndex + endTransIndex); } else { currentTransaction = inputFields.substring(transIndex + 14); } } wclajax_debugInfo("Current transaction [" + currentTransaction + "]"); if (currentTransaction != null) { var endIndex = actionString.substring(transactionIndex) .indexOf("&"); if (endIndex != -1) { var endAction = actionString.substring(transactionIndex + endIndex); actionString = actionString.substring(0, transactionIndex) + "WnTransaction=" + currentTransaction + endAction; } else { actionString = actionString.substring(0, transactionIndex) + "WnTransaction=" + currentTransaction; } } } else { wclajax_debugInfo("no transaction in action"); } return actionString; }