123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Viewer
- *| (C) Copyright IBM Corp. 2001, 2012, 2013
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- function AsynchJSONRequest(gateway, webContentRoot) {
- // initialize the base class
- AsynchJSONRequest.baseConstructor.call(this, gateway, webContentRoot);
- this.m_jsonResponse = null;
- }
- // set up the base class
- AsynchJSONRequest.prototype = new AsynchRequest();
- AsynchJSONRequest.baseConstructor = AsynchRequest;
- AsynchJSONRequest.prototype.getJSONResponseObject = function() {
- if(this.m_jsonResponse == null) {
- if(this.getResponseHeader("Content-type").indexOf("application/json") != -1) {
- var text = this.getResponseText();
- if(text != null) {
- var validJson = this.removeInvalidCharacters(text);
- this.m_jsonResponse = eval("(" + validJson + ")");
- }
- }
- }
- return this.m_jsonResponse;
- };
- AsynchJSONRequest.prototype.getTracking = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.tracking;
- }
- return "";
- };
- AsynchJSONRequest.prototype.getConversation = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.conversation;
- }
- return "";
- };
- AsynchJSONRequest.prototype.getAsynchStatus = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.status;
- }
- return "unknown";
- };
- AsynchJSONRequest.prototype.getPrimaryAction = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.primaryAction;
- }
- return "";
- };
- AsynchJSONRequest.prototype.getActionState = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.actionState;
- }
- return "";
- };
- AsynchJSONRequest.prototype.getDebugLogs = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.debugLogs;
- }
- return "";
- };
- AsynchJSONRequest.prototype.isRAPWaitTrue = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return (jsonResponse.rapWait === "true");
- }
- return false;
- };
- AsynchJSONRequest.prototype.getRAPRequestCache = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- var requestCache = jsonResponse.rapRequestCache;
- if (requestCache !== null && typeof requestCache != "undefined" ) {
- return requestCache;
- }
- }
- return null;
- };
- AsynchJSONRequest.prototype.getMainConversation = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.mainConversation;
- }
- return null;
- };
- AsynchJSONRequest.prototype.getMainTracking = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse) {
- return jsonResponse.mainTracking;
- }
- return null;
- };
- AsynchJSONRequest.prototype.getResult = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse && jsonResponse.json) {
- var validJson = this.removeInvalidCharacters(jsonResponse.json);
- return eval("(" + validJson + ")");
- }
- return null;
- };
- AsynchJSONRequest.prototype.removeInvalidCharacters = function(text) {
- if (text) {
- text = text.replace(/(\n|\r|\t)+/g,"");//characters throw exception in eval
- }
- return text;
- };
- AsynchJSONRequest.prototype.getPromptHTMLFragment = function() {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse && jsonResponse.promptHTMLFragment) {
- return jsonResponse.promptHTMLFragment;
- }
- return "";
- };
- AsynchJSONRequest.prototype.constructFaultEnvelope = function() {
- if(this.m_soapFault == null) {
- var jsonResponse = this.getJSONResponseObject();
- if(jsonResponse.status == "fault") {
- this.m_soapFault = XMLBuilderLoadXMLFromString(jsonResponse.fault);
- }
- }
- return this.m_soapFault;
- };
- AsynchJSONRequest.prototype.construct = function() {
- var asynchRequest = new AsynchJSONRequest(this.m_gateway, this.m_webContentRoot);
- asynchRequest.setCallbacks(this.m_callbacks);
- if (this.getFormFields().exists("cv.responseFormat")) {
- asynchRequest.addFormField("cv.responseFormat", this.getFormField("cv.responseFormat"));
- }
- else {
- asynchRequest.addFormField("cv.responseFormat", "asynchJSON");
- }
-
- return asynchRequest;
- };
|