// Licensed Materials - Property of IBM // // IBM Cognos Products: pps // // (C) Copyright IBM Corp. 2005, 2017 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. //this JavaScript file provides a layer of abstraction over the browser specific //xml comunication controls. function dataItem(name, value) { this.name = name; this.value = value; } function dataCollection() { var dataArray = new Array(); this.addItem = function(name, value) { dataArray[dataArray.length] = new dataItem(name,value); } this.getDataArray = function() { return dataArray; } } //Static public variables xmlCommunicator.prototype.STATUS_SUCCESS = 1; xmlCommunicator.prototype.STATUS_FAILED = 0; xmlCommunicator.prototype.STATUS_ASYNC_SENT = 2; xmlCommunicator.prototype.MODE_POST = 0; xmlCommunicator.prototype.MODE_GET = 1; //Class xmlCommunicator function xmlCommunicator (admCommandHandler) { //Constructor var mode = this.MODE_POST; var ACH = admCommandHandler; var xmlResponse = null; var textResponse = null; var requestSuccess = false; var requestInProgress = false; function returnSuccess(transport) { if (requestInProgress) { returnSuccessBlocking(transport); requestInProgress = false; ACH.requestCompleted(); //Inform the adminCommands layer that a request has completed } } function returnFailure(transport) { if (requestInProgress) { returnFailureBlocking(transport); requestInProgress = false; ACH.requestCompleted(); //Inform the adminCommands layer that a request has completed } } function returnException(e) { if (requestInProgress) { returnExceptionBlocking(e); requestInProgress = false; ACH.requestCompleted(); //Inform the adminCommands layer that a request has completed } } function returnSuccessBlocking(transport) { requestSuccess = true; xmlResponse = transport.responseXml; textResponse = transport.responseText; //In Firefoxm it's possible to have gotten a valid XML document, but not have it parsed. //So here is a workaround if (textResponse && !xmlResponse) { if (typeof (DOMParser) != "undefined") { xmlResponse = (new DOMParser()).parseFromString(textResponse,"text/xml"); } } } function returnFailureBlocking(transport) { requestSuccess = false; xmlResponse = null; textResponse = null; } function returnExceptionBlocking(e) { requestSuccess = false; xmlResponse = null; textResponse = null; } //Public methods this.setMode = function (theMode) { mode = theMode; } this.GetXMLResponse = function() { return xmlResponse; } this.GetTextResponse = function() { return textResponse; } this.requestSuceeded = function() { return requestSuccess; } this.sendRequest = function(dataArray, isBlocking) { if (requestInProgress) { return this.STATUS_FAILED; } else { requestInProgress = true; var requestProps = {}; requestProps.method = (mode == this.MODE_POST)? "post" : "get"; //requestProps.parameters = {}; var sPostBody = ""; for (var i = 0; i < dataArray.length; i++) { if (i) sPostBody += "&"; sPostBody += dataArray[i].name; sPostBody += "="; sPostBody += _F_Strings.urlEncode(dataArray[i].value); //requestProps.parameters[dataArray[i].name] = dataArray[i].value; } requestProps.postBody = sPostBody; requestProps.asynchronous = !(isBlocking); requestProps.onSuccess = (isBlocking)? returnSuccessBlocking : returnSuccess; requestProps.onFailure = (isBlocking)? returnFailureBlocking : returnFailure; requestProps.onException = (isBlocking)? returnExceptionBlocking : returnException; new _F_Ajax.Request("$CGI$", requestProps); if (isBlocking) { if (requestSuccess) return this.STATUS_SUCCESS; else return this.STATUS_FAILED; } else return this.STATUS_ASYNC_SENT; } } }