rsPromptHandler.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /*
  2. IBM Confidential
  3. OCO Source Materials
  4. IBM Cognos Products: rs
  5. (C) Copyright IBM Corp. 2018, 2020
  6. The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office.
  7. */
  8. define( ['bi/authoring/utils/pat/rsLaunchParameters',
  9. 'bi/authoring/utils/U_Blocker',
  10. 'bi/authoring/utils/U_Object',
  11. 'bi/authoring/utils/U_ClearableTimeout'],
  12. function(rsLaunchParameters, U_Blocker, U_Object, U_ClearableTimeout) {
  13. var rsPromptHandler = {};
  14. //
  15. ///**
  16. // * @private
  17. // */
  18. rsPromptHandler.k_iPollPromptWindow = 1000;
  19. ///**
  20. // * @private
  21. // */
  22. //G_BusServer.m_aLogonListeners = [];
  23. ///**
  24. // * @private
  25. // */
  26. rsPromptHandler.m_oPromptListeners = {};
  27. ///**
  28. // * @private
  29. // */
  30. rsPromptHandler.m_oPromptWindows = {};
  31. /**
  32. * @private
  33. */
  34. rsPromptHandler.m_iPromptId = 0;
  35. //G_BusServer.M_bUseReportServiceConsumerMode = false;
  36. //
  37. ///**
  38. // * @private
  39. // */
  40. //G_BusServer.f_setParameterValues = function(v_sParameterValues)
  41. //{
  42. // this.m_sParameterValues = v_sParameterValues;
  43. // this.m_docParameterValues = null;
  44. //};
  45. //
  46. //G_BusServer.F_GetParameterValuesNode = function()
  47. //{
  48. // if (!this.m_docParameterValues)
  49. // {
  50. // this.m_docParameterValues = this.f_parseParameterValues(this.m_sParameterValues);
  51. // }
  52. //
  53. // return this.m_docParameterValues.documentElement;
  54. //};
  55. //
  56. ///**
  57. // * convert parameters from xml to json
  58. // *
  59. // * <bus:parameterValues>
  60. // * <item xsi:type="bus:parameterValue">
  61. // * <bus:name xsi:type="xs:string">Parameter1</bus:name>
  62. // * <bus:value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:parmValueItem[1]">
  63. // * <item xsi:type="bus:simpleParmValueItem">
  64. // * <bus:inclusive xsi:type="xs:boolean">true</bus:inclusive>
  65. // * <bus:display xsi:type="xs:string">BugShield Lotion</bus:display>
  66. // * <bus:use xsi:type="xs:string">BugShield Lotion</bus:use>
  67. // * </item>
  68. // * </bus:value>
  69. // * </item>
  70. // * </bus:parameterValues>
  71. // *
  72. // * [
  73. // * {
  74. // * "name": "Parameter1",
  75. // * "value": [
  76. // * {
  77. // * "inclusive": true,
  78. // * "use": "BugShield Lotion",
  79. // * "display": "BugShield Lotion",
  80. // * "type": "simpleParmValueItem"
  81. // * }
  82. // * ]
  83. // * }
  84. // * ]
  85. // *
  86. // */
  87. //G_BusServer.F_GetParameterValuesJson = function()
  88. //{
  89. // var v_nParameters = G_BusServer.F_GetParameterValuesNode();
  90. // var v_nlParamItems = v_nParameters.selectNodes("./item"), v_nParamItem;
  91. // var v_nlValues, v_nValue, v_nValueItem;
  92. // var v_aParams = [], v_oParam, v_oValue, v_oItem, v_sDisplay;
  93. //
  94. // for (var v_iIdx = 0; v_iIdx < v_nlParamItems.length; v_iIdx++)
  95. // {
  96. // v_nParamItem = v_nlParamItems.item(v_iIdx);
  97. //
  98. // v_oParam = {
  99. // name: U_Node.F_GetText(v_nParamItem.selectSingleNode("./bus:name")),
  100. // value: []
  101. // };
  102. //
  103. // v_nValue = v_nParamItem.selectSingleNode("./bus:value");
  104. // v_nlValues = v_nValue.selectNodes("./item");
  105. // var v_aItems = [];
  106. //
  107. // for (var v_iValue = 0; v_iValue < v_nlValues.length; v_iValue++)
  108. // {
  109. // v_nValueItem = v_nlValues.item(v_iValue);
  110. //
  111. // v_oValue = {
  112. // type: v_nValueItem.getAttribute("xsi:type").split(":").pop(),
  113. // inclusive: v_nValueItem.selectSingleNode("./bus:inclusive[text()='true']") ? true : false
  114. // };
  115. //
  116. // switch (v_oValue.type)
  117. // {
  118. // case "simpleParmValueItem":
  119. // v_aItems.push({
  120. // xmlNode: v_nValueItem,
  121. // jsonObj: v_oValue
  122. // });
  123. // break;
  124. //
  125. // case "boundRangeParmValueItem":
  126. // v_oValue.start = {};
  127. // v_aItems.push({
  128. // xmlNode: v_nValueItem.selectSingleNode("./bus:start"),
  129. // jsonObj: v_oValue.start
  130. // });
  131. //
  132. // v_oValue.end = {};
  133. // v_aItems.push({
  134. // xmlNode: v_nValueItem.selectSingleNode("./bus:end"),
  135. // jsonObj: v_oValue.end
  136. // });
  137. // break;
  138. //
  139. // case "unboundedStartRangeParmValueItem":
  140. // v_oValue.end = {};
  141. // v_aItems.push({
  142. // xmlNode: v_nValueItem.selectSingleNode("./bus:end"),
  143. // jsonObj: v_oValue.end
  144. // });
  145. // break;
  146. //
  147. // case "unboundedEndRangeParmValueItem":
  148. // v_oValue.start = {};
  149. // v_aItems.push({
  150. // xmlNode: v_nValueItem.selectSingleNode("./bus:start"),
  151. // jsonObj: v_oValue.start
  152. // });
  153. // break;
  154. //
  155. // case "hierarchicalParmValueItem":
  156. // // The spec is invalid, but we need to render it anyway
  157. // G_Debug.F_Print("'hierarchicalParmValueItem' type is not handled.");
  158. // break;
  159. // }
  160. //
  161. // for (var v_iItem = 0; v_iItem < v_aItems.length; v_iItem++)
  162. // {
  163. // v_oItem = v_aItems[v_iItem];
  164. //
  165. // v_oItem.jsonObj.type = v_oItem.xmlNode.getAttribute("xsi:type").split(":").pop();
  166. // v_oItem.jsonObj.inclusive = v_oItem.xmlNode.selectSingleNode("./bus:inclusive[text()='true']") ? true : false;
  167. // v_oItem.jsonObj.use = U_Node.F_GetText(v_oItem.xmlNode.selectSingleNode("bus:use"));
  168. //
  169. // v_sDisplay = U_Node.F_GetText(v_oItem.xmlNode.selectSingleNode("./bus:display"));
  170. // if (v_sDisplay)
  171. // {
  172. // v_oItem.jsonObj.display = v_sDisplay;
  173. // }
  174. // }
  175. //
  176. // v_oParam.value.push(v_oValue);
  177. // }
  178. //
  179. // v_aParams.push(v_oParam);
  180. // }
  181. //
  182. // return v_aParams;
  183. //};
  184. //
  185. ///**
  186. // * @private
  187. // */
  188. //G_BusServer.f_setNoParameterValues = function()
  189. //{
  190. // /**
  191. // * @private
  192. // */
  193. // this.f_setParameterValues(
  194. // '<bus:parameterValues ' + C_BusRequest.k_sBIBusNamespaceDecl + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENC:arrayType="bus:parameterValue[]" xsi:type="SOAP-ENC:Array">' +
  195. // '</bus:parameterValues>');
  196. //};
  197. //
  198. //G_BusServer.f_setNoParameterValues();
  199. //
  200. //
  201. ///**
  202. // * @private
  203. // */
  204. //G_BusServer.m_aParametersListeners = [];
  205. //
  206. ///**
  207. // * @param {I_ServerParametersListener} v_oListener
  208. // * @type void
  209. // */
  210. //G_BusServer.F_AddParametersListener = function( v_oListener )
  211. //{
  212. // this.m_aParametersListeners.push( v_oListener );
  213. //};
  214. //
  215. ///**
  216. // * @private
  217. // */
  218. rsPromptHandler.f_getPromptId = function()
  219. {
  220. return ++this.m_iPromptId;
  221. };
  222. ///**
  223. // * Sets the CAF context id for the server.
  224. // * @param {String} v_sCafContextId CAF context id
  225. // * @type void
  226. // */
  227. //G_BusServer.F_SetCafContextId = function(v_sCafContextId)
  228. //{
  229. // this.m_sCafContextId = v_sCafContextId;
  230. //};
  231. //
  232. ///**
  233. // * @returns The CAF context id for the server.
  234. // * @type String
  235. // */
  236. //G_BusServer.F_GetCafContextId = function()
  237. //{
  238. // return this.m_sCafContextId;
  239. //};
  240. //
  241. ///**
  242. // * @private
  243. // */
  244. //G_BusServer.m_sRoutingServerGroup = "";
  245. //
  246. ///**
  247. // * This identifies the routing server group that the requests will be sent to.
  248. // * @param {String} v_sRoutingServerGroup Routing server group to use for the request.
  249. // * @type void
  250. // */
  251. //G_BusServer.F_SetCurrentReportRoutingServerGroup = function(v_sRoutingServerGroup)
  252. //{
  253. // this.m_sRoutingServerGroup = v_sRoutingServerGroup || "";
  254. //};
  255. //
  256. ///**
  257. // * @returns The router server group.
  258. // * @type String
  259. // */
  260. //G_BusServer.F_GetCurrentReportRoutingServerGroup = function()
  261. //{
  262. // return this.m_sRoutingServerGroup;
  263. //};
  264. //
  265. ///**
  266. // * @private
  267. // */
  268. //G_BusServer.f_onUserProfileAcountOK = function(v_oAccount)
  269. //{
  270. // G_BusServer.f_onLogonComplete(true);
  271. //};
  272. //
  273. ///**
  274. // * @private
  275. // */
  276. //G_BusServer.f_onUserProfileAcountFailed = function(v_oDfd, v_oXHRError, v_sTextStatus, v_sErrorThrown)
  277. //{
  278. // G_BusServer.f_onLogonComplete(false);
  279. //};
  280. //
  281. ///**
  282. // * Launches the server dialog window for logon to the bus. The application will be blocked until the window closes.
  283. // * @param {I_ServerLogonListener} v_oListener The listener for the logon.
  284. // * @returns False if the logon process could not be started.
  285. // * @type Boolean
  286. // */
  287. //G_BusServer.F_Logon = function(v_oListener, v_docResponse)
  288. //{
  289. // // Call the Glass login perspective
  290. // U_GlassUtils.F_UserProfileAcountRequest(this.f_onUserProfileAcountOK.bind(this), this.f_onUserProfileAcountFailed.bind(this));
  291. //
  292. // // After login the failing SOAP request must be done again
  293. // this.m_aLogonListeners.push(v_oListener);
  294. //
  295. // // Because the user session could have timed out, we need to clear the authenticity token so that it is renewed when next needed
  296. // this.m_sAuthenticityToken = "";
  297. //
  298. // return true;
  299. //};
  300. //
  301. ///**
  302. // * @private
  303. // * Called by portal services when logon is complete
  304. // */
  305. //function ccModalCallBack( v_sStatus )
  306. //{
  307. // G_BusServer.f_onLogonComplete( v_sStatus == "ok" );
  308. //};
  309. //
  310. ///**
  311. // * @private
  312. // */
  313. //G_BusServer.f_onLogonComplete = function(v_bSuccess)
  314. //{
  315. // //Cant send a new request on a callback from another window.
  316. // //Bugzilla Bug 249843
  317. // setTimeout(this.f_onAfterLogonComplete.bind(this, v_bSuccess), 0);
  318. //};
  319. //
  320. ///**
  321. // * @private
  322. // */
  323. //G_BusServer.f_onAfterLogonComplete = function(v_bSuccess)
  324. //{
  325. // U_Array.F_CallEach( this.m_aLogonListeners, "F_OnServerLogonComplete", v_bSuccess );
  326. // this.m_aLogonListeners.length = 0;
  327. //};
  328. //
  329. ///**
  330. // * @type void
  331. // */
  332. //G_BusServer.F_Logoff = function()
  333. //{
  334. // var v_oBusRequest = new C_BusRequest( null, C_BusRequest.K_sSOAPAction_contentManagerService, "<bus:logoff/>" );
  335. // v_oBusRequest.F_Send();
  336. // // need to clear out the authenticityToken on logoff so next request can generate the new and correct one.
  337. // this.m_sAuthenticityToken = "";
  338. //};
  339. //
  340. ///**
  341. // * @param {XMLDocument} v_docSOAPResponse
  342. // * @type Boolean
  343. // */
  344. //G_BusServer.F_AuthenticationRequired = function( v_docSOAPResponse )
  345. //{
  346. // var v_nBIBusHeader = v_docSOAPResponse.selectSingleNode( "/SOAP-ENV:Envelope/SOAP-ENV:Header/bus:biBusHeader" );
  347. //
  348. // if (v_nBIBusHeader && v_nBIBusHeader.selectSingleNode(".//*[local-name() = 'errorCodeString' and text() = 'camAuthUserRecoverable']" ) )
  349. // {
  350. // return v_nBIBusHeader.selectSingleNode( ".//bus:promptInfo | .//promptInfo" ) != null;
  351. // }
  352. // return false;
  353. //};
  354. //
  355. ///**
  356. // * @param {XMLDocument} v_docSOAPResponse
  357. // * @type Boolean
  358. // */
  359. //G_BusServer.F_RequiresServerPrompting = function( v_docSOAPResponse )
  360. //{
  361. // return Boolean( v_docSOAPResponse && v_docSOAPResponse.selectSingleNode( "/SOAP-ENV:Envelope/SOAP-ENV:Body/*/bus:result/bus:details/item[bus:status='prompting']" ) );
  362. //};
  363. rsPromptHandler.f_createSoapPromptLaunchParameters = function(v_docSOAPResponse, v_fnOkCallback)
  364. {
  365. return this.f_createPromptLaunchParameters(v_docSOAPResponse, null, v_fnOkCallback);
  366. };
  367. /**
  368. * Launches the interactive viewer for response prompting, then passes the final response to callback function.
  369. * @param {XMLDocument} v_docSOAPResponse
  370. * @param {Function} v_fnOkCallback
  371. */
  372. rsPromptHandler.f_createPromptLaunchParameters = function(v_docSOAPResponse, v_oRequest, v_fnOkCallback)
  373. {
  374. var v_oLaunchParameters = {
  375. promptFnOkCallback: v_fnOkCallback,
  376. reportXML: null
  377. };
  378. if (v_docSOAPResponse)
  379. {
  380. v_oLaunchParameters.promptSOAPResponse = ( new XMLSerializer() ).serializeToString( v_docSOAPResponse );
  381. }
  382. if (v_oRequest)
  383. {
  384. v_oLaunchParameters.promptRequest = v_oRequest;
  385. }
  386. return v_oLaunchParameters;
  387. };
  388. rsPromptHandler.f_createRestPromptLaunchParameters = function(v_oRequest, v_fnOkCallback)
  389. {
  390. return this.f_createPromptLaunchParameters(null, v_oRequest, v_fnOkCallback);
  391. };
  392. /**
  393. * @private
  394. See WO 2397
  395. The pdsState object will contains these properties:
  396. ccs_cbdata the callback client state sent to promptDataSource.xts.
  397. clientContext the parameter sent to promptDataSource.xts. (Formerly the 4th parameter 'clientContext' of the callback function)
  398. conversation the conversation used in promptDataSource.xts's SOAP request. (Formerly the 3rd parameter of the callback function)
  399. parameters contains the paremeter values collected by the promptDataSource.xts. (Formerly the 1st parameter of the callback function)
  400. state the state of response returned promptDataSource.xts's SOAP request (OK, Cancel, Error). (Formerly the 2nd parameter 'response' of the callback function)
  401. tracking the tracking info used in prompDataSource.xts's SOAP request. (Formerly the 5th parameter of the callback function)
  402. */
  403. rsPromptHandler.f_prompting_OkCallback = function(v_sPromptId, v_oResponse, v_oAttachments, v_sParameters, v_oOpener)
  404. {
  405. var pdsState =
  406. {
  407. "v_sClientContext": v_sPromptId,
  408. "response": v_oResponse,
  409. "attachments": v_oAttachments,
  410. "parameters": v_sParameters,
  411. "opener": v_oOpener
  412. };
  413. var v_oOpener = null;
  414. if ( pdsState.state != "Cancel" )
  415. {
  416. if (pdsState.parameters)
  417. {
  418. // Save parameter values used to generate the response.
  419. //G_BusServer.F_AddParameterValues( pdsState.parameters );
  420. }
  421. if (this.m_oPromptListeners[pdsState.v_sClientContext].F_SetPromptCallbackResponse)
  422. {
  423. this.m_oPromptListeners[pdsState.v_sClientContext].F_SetPromptCallbackResponse( pdsState.response, pdsState.attachments );
  424. }
  425. v_oOpener = pdsState.opener;
  426. }
  427. var v_sClientContext = pdsState.v_sClientContext;
  428. if ( !v_sClientContext )
  429. {
  430. //G_Debug.F_Print("Error: Prompting returned with no client context. Will attempt to inform any listener that can be found");
  431. for ( var s in this.m_oPromptWindows )
  432. {
  433. v_sClientContext = s;
  434. }
  435. }
  436. if ( this.m_iLastPromptTimeoutId )
  437. {
  438. U_ClearableTimeout.F_Clear( this.m_iLastPromptTimeoutId );
  439. this.m_iLastPromptTimeoutId = null;
  440. }
  441. //Cant send a new request on a callback from another window.
  442. //Bugzilla Bug 249843
  443. setTimeout( function(v_sClientContext) {
  444. this.f_fireOnPromptingComplete(v_sClientContext);
  445. // Close opener after the call above to ensure parameters
  446. // are still defined while they are being processed during the callback.
  447. if (v_oOpener)
  448. {
  449. v_oOpener.close();
  450. }
  451. }.bind(rsPromptHandler, v_sClientContext), 0);
  452. delete this.m_oPromptWindows[v_sClientContext];
  453. if ( U_Object.F_IsEmpty(this.m_oPromptWindows) )
  454. {
  455. U_Blocker.F_HideEventBlocker();
  456. }
  457. else
  458. {
  459. //set the focus to another prompt window.
  460. for ( var s in this.m_oPromptWindows )
  461. {
  462. this.m_oPromptWindows[s].focus();
  463. break;
  464. }
  465. }
  466. };
  467. //G_BusServer.F_ProcessPromptContext = function( v_oPromptContext, v_oRequest )
  468. //{
  469. // // If the prompt was cancelled (using a prompt button) then v_oRequest will be null
  470. // var v_docSOAPResponse = v_oRequest ? v_oRequest.F_GetResponse() : null;;
  471. //
  472. // var v_sParameters = null;
  473. // if (v_docSOAPResponse && !v_oPromptContext.requestType)
  474. // {
  475. // // Extract parameters from response so that they can be added to current parameter values.
  476. // var v_nParameters = v_docSOAPResponse.selectSingleNode("/SOAP-ENV:Envelope/SOAP-ENV:Body//bus:details/*[@xsi:type='bus:asynchDetailParameterValues']/bus:parameters");
  477. // v_sParameters = this.f_responseParametersToParameterValues( v_nParameters );
  478. // }
  479. //
  480. // if (v_oPromptContext.promptRequest && v_docSOAPResponse)
  481. // {
  482. // var v_sOrigUrl = v_oPromptContext.promptRequest.url;
  483. // // Make REST call to transform SOAP response into REST JSON response
  484. // v_oPromptContext.promptRequest.type = "POST";
  485. // v_oPromptContext.promptRequest.url += "/promptResults";
  486. // v_oPromptContext.promptRequest.data = U_Node.F_GetXml( v_docSOAPResponse );
  487. // v_oPromptContext.promptRequest.contentType = "text/xml";
  488. // Application.GlassContext.services.ajax.ajax(v_oPromptContext.promptRequest)
  489. // .done( function( v_oResponseData, v_sStatus, v_oXHR )
  490. // {
  491. // // Restore URL so we can call delete on it latter.
  492. // v_oPromptContext.promptRequest.url = v_sOrigUrl;
  493. // this.f_processPromptContextResponse( v_oPromptContext, v_oResponseData, null, v_sParameters );
  494. // }.bind(this)
  495. // )
  496. // //.fail(??)
  497. // ;
  498. // }
  499. // else
  500. // {
  501. // var v_oAttachments = v_oRequest ? v_oRequest.F_GetAttachments() : null;
  502. // this.f_processPromptContextResponse( v_oPromptContext, v_docSOAPResponse, v_oAttachments, v_sParameters );
  503. // }
  504. //};
  505. //
  506. //G_BusServer.f_processPromptContextResponse = function( v_oPromptContext, v_oResponse, v_oAttachments, v_sParameters )
  507. //{
  508. // if (v_oPromptContext.requestType == "collectParameterValues")
  509. // {
  510. // if (v_oResponse)
  511. // {
  512. // v_oPromptContext.promptFnOkCallback(G_BusServer.F_GetParameterValuesJson());
  513. // }
  514. // Application.F_CloseCurrentPerspective(undefined, function() {
  515. // try
  516. // {
  517. // v_oPromptContext.promptOpener.close();
  518. // }
  519. // catch(e)
  520. // {
  521. // // do nothing
  522. // }
  523. // });
  524. // }
  525. // else
  526. // {
  527. // // Closing opener is done in callback AFTER values are processed.
  528. // v_oPromptContext.promptFnOkCallback(v_oResponse, v_oAttachments, v_sParameters, v_oPromptContext.promptOpener);
  529. // }
  530. //};
  531. //
  532. //G_BusServer.F_ReleasePromptContext = function( v_oPromptContext )
  533. //{
  534. // if (v_oPromptContext && v_oPromptContext.promptRequest)
  535. // {
  536. // v_oPromptContext.promptRequest.type = "DELETE";
  537. // if (v_oPromptContext.promptRequest.data)
  538. // {
  539. // delete v_oPromptContext.promptRequest.data;
  540. // }
  541. // Application.GlassContext.services.ajax.ajax(v_oPromptContext.promptRequest);
  542. //
  543. // // Clear main report conversation so we don't release it since the delete above will handle it on the server.
  544. // // ensures that this conversation doesn't get released in our shutdown code that releases all shared conversations.
  545. // C_BusConversation.F_UnShareConversation( C_BusRequest.K_sMainReportConversation );
  546. // }
  547. //};
  548. /**
  549. * Launches the server dialog window for prompting. The application will be blocked until the window closes.
  550. * @param {I_ServerPromptingListener} v_oListener The listener for the prompting.
  551. * @param {XMLDocument} v_docSOAPResponse
  552. * @param {Object} v_oGlassContext The Glass context instance
  553. * @returns False if the prompting process could not be started.
  554. * @type Boolean
  555. */
  556. rsPromptHandler.F_DoPrompting = function(v_oListener, v_docSOAPResponse, v_oGlassContext)
  557. {
  558. var v_sPromptId = this.f_getPromptId();
  559. var v_frmPrompting, v_sUrl, v_oLaunchParameters;
  560. v_oLaunchParameters = this.f_createSoapPromptLaunchParameters(v_docSOAPResponse, this.f_prompting_OkCallback.bind(this, v_sPromptId));
  561. v_oLaunchParameters.promptOutputPages = v_oListener.getOutputPages(v_docSOAPResponse);
  562. var v_oContext = {
  563. urlMap: {
  564. perspective: "authoring",
  565. isViewer: true,
  566. UIProfile: "Titan",
  567. promptResponse: "promptPage",
  568. ui_appbar: false,
  569. ui_navbar: false,
  570. launchParametersKey: rsLaunchParameters.Store(v_oLaunchParameters)
  571. }
  572. };
  573. v_sUrl = v_oGlassContext.getUrl(v_oContext);
  574. return this.f_launchPrompt( v_oListener, v_sUrl, v_frmPrompting, v_oLaunchParameters, v_sPromptId );
  575. };
  576. rsPromptHandler.f_onPromptBlockerMouseDown = function()
  577. {
  578. for ( var s in this.m_oPromptWindows )
  579. {
  580. this.m_oPromptWindows[s].focus();
  581. return;
  582. }
  583. //Shouldn't get here, but just in case.
  584. U_Blocker.F_HideEventBlocker();
  585. // ? G_Debug.F_Print("f_onPromptBlockerMouseDown: blocker was up, yet no prompt window");
  586. };
  587. rsPromptHandler.f_launchPrompt = function( v_oListener, v_sUrl, v_frmPrompting, v_oLaunchParameters, v_sPromptId )
  588. {
  589. // ? this.f_setNoParameterValues();
  590. //show blocker above dialogs
  591. var v_elBlocker = U_Blocker.F_ShowEventBlocker( 1000000 );
  592. v_elBlocker.onmousedown = this.f_onPromptBlockerMouseDown.bind(this);
  593. this.m_oPromptListeners[v_sPromptId] = v_oListener;
  594. this.m_oPromptWindows[v_sPromptId] = window.open( v_sUrl, (v_frmPrompting ? v_frmPrompting.target : "_blank"), "directories=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=yes,top=100,left=100,height=600,width=1000" );
  595. if ( !Boolean( this.m_oPromptWindows[v_sPromptId] ) )
  596. {
  597. U_Blocker.F_HideEventBlocker();
  598. return false;
  599. }
  600. this.m_oPromptWindows[v_sPromptId].focus();
  601. if (v_frmPrompting)
  602. {
  603. v_frmPrompting.submit();
  604. }
  605. if (v_oLaunchParameters)
  606. {
  607. v_oLaunchParameters.promptOpener = this.m_oPromptWindows[v_sPromptId];
  608. }
  609. // when window closes call I_ServerPromptingListener.protype.F_OnServerPromptingComplete = function()
  610. this.m_iLastPromptTimeoutId = U_ClearableTimeout.F_Create( this.f_checkPromptingWindowState.bind(this, v_sPromptId), this.k_iPollPromptWindow );
  611. return true;
  612. };
  613. ///**
  614. // * @private
  615. // */
  616. ///**
  617. // * @private
  618. // */
  619. rsPromptHandler.f_checkPromptingWindowState = function( v_sPromptId )
  620. {
  621. this.m_iLastPromptTimeoutId = null;
  622. if ( this.m_oPromptWindows[v_sPromptId] )
  623. {
  624. // Permission denied error occurs intermittently on IE 6 if window is closed (Bug 550790)
  625. var v_bWindowClosed = false;
  626. try
  627. {
  628. v_bWindowClosed = this.m_oPromptWindows[v_sPromptId].closed;
  629. }
  630. catch ( e )
  631. {
  632. v_bWindowClosed = true;
  633. }
  634. if ( v_bWindowClosed )
  635. {
  636. delete this.m_oPromptWindows[v_sPromptId];
  637. if ( U_Object.F_IsEmpty(this.m_oPromptWindows) )
  638. {
  639. U_Blocker.F_HideEventBlocker();
  640. }
  641. else
  642. {
  643. //set the focus to another prompt window.
  644. for ( var s in this.m_oPromptWindows )
  645. {
  646. this.m_oPromptWindows[s].focus();
  647. break;
  648. }
  649. }
  650. //Cant send a new request on a callback from another window.
  651. //Bugzilla Bug 249843
  652. setTimeout(this.f_fireOnPromptingComplete.bind(this, v_sPromptId), 0);
  653. }
  654. else
  655. {
  656. this.m_iLastPromptTimeoutId = U_ClearableTimeout.F_Create( this.f_checkPromptingWindowState.bind(this, v_sPromptId), this.k_iPollPromptWindow );
  657. }
  658. }
  659. //else the callback was fired
  660. };
  661. /**
  662. * The window that loaded this module is closing.
  663. * Close any currently open prompt windows.
  664. */
  665. rsPromptHandler.f_OnUnLoad = function( v_fOnUnLoad )
  666. {
  667. for (var v_sPromptId in this.m_oPromptWindows)
  668. {
  669. // Permission denied error occurs intermittently on IE 6 if window is closed (Bug 550790)
  670. var v_bWindowClosed = false;
  671. try
  672. {
  673. v_bWindowClosed = this.m_oPromptWindows[v_sPromptId].closed;
  674. }
  675. catch ( e )
  676. {
  677. v_bWindowClosed = true;
  678. }
  679. if (!v_bWindowClosed)
  680. {
  681. try {
  682. this.m_oPromptWindows[v_sPromptId].close();
  683. }
  684. catch(e) {}
  685. }
  686. delete this.m_oPromptWindows[v_sPromptId];
  687. }
  688. if (v_fOnUnLoad)
  689. {
  690. v_fOnUnLoad();
  691. }
  692. };
  693. //
  694. ///**
  695. // * @type Array
  696. // */
  697. //G_BusServer.F_GetScriptableParameter = function( v_sParameter )
  698. //{
  699. // var v_aParameters = [];
  700. // var d = this.f_parseParameterValues( this.m_sParameterValues );
  701. // if ( d )
  702. // {
  703. // var nl = d.documentElement.selectNodes( v_sParameter ? "item[bus:name=" + U_String.F_ToXPathString( v_sParameter ) + "]" : "item" );
  704. // var v_iLength = nl.length;
  705. // for ( var i = 0; i < v_iLength; i++ )
  706. // {
  707. // var v_nParameter = nl.item( i );
  708. // var v_aValues = [];
  709. // var v_oParameter = { "parameter" : v_nParameter.selectSingleNode( "bus:name" ).text, "values" : v_aValues };
  710. // v_aParameters.push( v_oParameter );
  711. // var v_nlValues = v_nParameter.selectNodes( "bus:value/item" );
  712. // var v_iValuesLength = v_nlValues.length;
  713. // for ( var j = 0; j < v_iValuesLength; j++ )
  714. // {
  715. // var v_nValueItem = v_nlValues.item( j );
  716. // if ( v_nValueItem.selectSingleNode( "bus:start | bus:end" ) )
  717. // {
  718. // var v_nStarUse = v_nValueItem.selectSingleNode( "bus:start/bus:use" );
  719. // var v_nStartDisplay = v_nValueItem.selectSingleNode( "bus:start/bus:display" );
  720. // var v_nEndUse = v_nValueItem.selectSingleNode( "bus:end/bus:use" );
  721. // var v_nEndDisplay = v_nValueItem.selectSingleNode( "bus:end/bus:display" );
  722. // v_aValues.push( new C_ScriptableParameterRangeValue( v_nStarUse ? v_nStarUse.text : null, v_nStartDisplay ? v_nStartDisplay.text : null, v_nEndUse ? v_nEndUse.text : null, v_nEndDisplay ? v_nEndDisplay.text : null ) );
  723. // }
  724. // else
  725. // {
  726. // var v_nUse = v_nValueItem.selectSingleNode( "bus:use" );
  727. // var v_nDisplay = v_nValueItem.selectSingleNode( "bus:display" );
  728. // v_aValues.push( new C_ScriptableParameterValue( v_nUse ? v_nUse.text : null, v_nDisplay ? v_nDisplay.text : null ) );
  729. // }
  730. // }
  731. // }
  732. // }
  733. // return v_aParameters;
  734. //};
  735. //
  736. ///**
  737. // * @type String
  738. // */
  739. //G_BusServer.F_GetParameterValues = function()
  740. //{
  741. // return this.m_sParameterValues;
  742. //};
  743. //
  744. ///**
  745. // * @type void
  746. // * @param {String} v_sParameterValues XML for the parameters element
  747. // * @returns True if the parameter values were updated, False otherwise
  748. // * @type Boolean
  749. // */
  750. //G_BusServer.F_SetParameterValues = function(v_sParameterValues)
  751. //{
  752. // var v_sNewParams = v_sParameterValues.replace(/bus:parameters(\W)/g, "bus:parameterValues$1");
  753. // var v_docNewParams = this.f_parseParameterValues( v_sNewParams );
  754. // var v_docOldParams = this.f_parseParameterValues( this.m_sParameterValues );
  755. //
  756. // if ( v_docNewParams && v_docOldParams && U_Node.F_GetXml( v_docNewParams.documentElement ) != U_Node.F_GetXml( v_docOldParams.documentElement ) )
  757. // {
  758. // this.f_setParameterValues(v_sNewParams);
  759. // this.F_fireOnParametersChange();
  760. // return true;
  761. // }
  762. // return false;
  763. //};
  764. //
  765. //G_BusServer.f_responseParametersToParameterValues = function( v_nParameters )
  766. //{
  767. // var v_sParameterValues = U_Node.F_GetXml( v_nParameters );
  768. // // v_nParameters is the <bus:parameters> node from asynchDetailParameterValues in the SOAP response.
  769. // // However, m_sParameterValues is used as the SOAP representation of the parameterValues parameter in SOAP requests
  770. // // e.g. run( object, parameterValues, options )
  771. // // We must therefore rename the root element from parameters to parameterValues
  772. // var v_sNewParams = v_sParameterValues.replace(/bus:parameters(\W)/g, "bus:parameterValues$1");
  773. // return v_sNewParams;
  774. //};
  775. //
  776. //G_BusServer.F_SetSOAPParameterValues = function(v_nParameters)
  777. //{
  778. // if (v_nParameters)
  779. // {
  780. // this.f_setParameterValues(this.f_responseParametersToParameterValues( v_nParameters ));
  781. // }
  782. //};
  783. //
  784. //G_BusServer.f_parseParameterValues = function( v_sParameterValues )
  785. //{
  786. // var d = U_XML.F_LoadValidXML( v_sParameterValues );
  787. // U_XML.F_SetSelectionNamespaces( d, 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + C_BusRequest.k_sBIBusNamespaceDecl );
  788. // return d;
  789. //};
  790. //
  791. ///**
  792. // * @type void
  793. // * @param {String} v_sParameterValues XML to add to the parameters element
  794. // * @returns True if the parameter values were updated, False otherwise
  795. // * @type Boolean
  796. // */
  797. //G_BusServer.F_AddParameterValues = function( v_sParameterValues )
  798. //{
  799. // var v_docNewParams = this.f_parseParameterValues( v_sParameterValues );
  800. // var v_docCurrentParams = this.f_parseParameterValues( this.m_sParameterValues );
  801. //
  802. // if ( v_docNewParams && v_docCurrentParams )
  803. // {
  804. // var v_nRoot = v_docCurrentParams.documentElement;
  805. // var nl = v_docNewParams.documentElement.selectNodes( "item" );
  806. // var v_iLength = nl.length;
  807. // for ( var i = 0; i < v_iLength; i++ )
  808. // {
  809. // var v_nNewParameter = nl.item( i );
  810. // var v_sName = v_nNewParameter.selectSingleNode( "bus:name" ).text;
  811. // var v_nRemovedParamter = U_XML.F_RemoveNode( v_nRoot, "item[bus:name=" + U_String.F_ToXPathString( v_sName ) + "]" );
  812. // // Credential parameters must be merged
  813. // if ( v_nRemovedParamter && ( v_sName.indexOf( "credential:" ) == 0 ) )
  814. // {
  815. // var v_nRemovedCredential = U_XML.F_LoadString( null, v_nRemovedParamter.selectSingleNode( "bus:value/item/bus:use" ).text ).documentElement;
  816. // var v_docNewCredential = U_XML.F_LoadString( null, v_nNewParameter.selectSingleNode( "bus:value/item/bus:use" ).text );
  817. // var v_nNewCredential = v_docNewCredential.documentElement;
  818. // var v_nlRemovedCredential = v_nRemovedCredential.selectNodes( "*" );
  819. // for ( var j = 0; j < v_nlRemovedCredential.length; j++ )
  820. // {
  821. // var v_nOld = v_nlRemovedCredential.item( j );
  822. // if ( !v_nNewCredential.selectSingleNode( v_nOld.nodeName ) )
  823. // {
  824. // v_nNewCredential.appendChild( U_XML.F_ImportNode( v_docNewCredential, v_nOld ) );
  825. // }
  826. // }
  827. // var v_sNewCredential = U_Node.F_GetXml( v_nNewCredential );
  828. // v_nNewParameter.selectSingleNode( "bus:value/item/bus:use" ).text = v_sNewCredential;
  829. // v_nNewParameter.selectSingleNode( "bus:value/item/bus:display" ).text = v_sNewCredential;
  830. // }
  831. // v_nRoot.appendChild( v_nNewParameter );
  832. // }
  833. // return this.F_SetParameterValues( U_Node.F_GetXml( v_docCurrentParams ) );
  834. // }
  835. // return false;
  836. //};
  837. //
  838. ///**
  839. // * @type void
  840. // * @param {String} v_sParameterValues XML for the parameters element
  841. // * @returns True if the parameter values were updated, False otherwise
  842. // * @type Boolean
  843. // */
  844. //G_BusServer.F_SetInitialParameterValues = function( v_sParameterValues )
  845. //{
  846. // this.m_sInitialParameterValues = v_sParameterValues;
  847. // return this.F_SetParameterValues( v_sParameterValues );
  848. //};
  849. //
  850. ///**
  851. // * @type void
  852. // */
  853. //G_BusServer.F_RestoreToInitialParameterValues = function()
  854. //{
  855. // if ( this.m_sInitialParameterValues )
  856. // {
  857. // this.F_SetParameterValues( this.m_sInitialParameterValues );
  858. // }
  859. // else
  860. // {
  861. // this.F_ClearParameterValues();
  862. // }
  863. //};
  864. //
  865. ///**
  866. // * @type Boolean
  867. // */
  868. //G_BusServer.F_HasParameterValues = function()
  869. //{
  870. // var v_nParams = this.F_GetParameterValuesNode();
  871. // return ( v_nParams.childNodes.length > 0 );
  872. //};
  873. //
  874. ///**
  875. // * @type void
  876. // */
  877. //G_BusServer.F_ClearParameterValues = function(v_bFireChange)
  878. //{
  879. // this.f_setNoParameterValues();
  880. //
  881. // if (v_bFireChange !== false)
  882. // {
  883. // this.F_fireOnParametersChange();
  884. // }
  885. //};
  886. //
  887. ///**
  888. // * @private
  889. // */
  890. //G_BusServer.F_fireOnParametersChange = function()
  891. //{
  892. // U_Array.F_CallEach( this.m_aParametersListeners, "F_OnServerParametersChange" );
  893. //};
  894. //
  895. ///**
  896. // * @private
  897. // */
  898. rsPromptHandler.f_fireOnPromptingComplete = function(v_sClientContext)
  899. {
  900. if ( this.m_oPromptListeners[v_sClientContext] && this.m_oPromptListeners[v_sClientContext].F_OnServerPromptingComplete )
  901. {
  902. this.m_oPromptListeners[v_sClientContext].F_OnServerPromptingComplete();
  903. }
  904. delete this.m_oPromptListeners[v_sClientContext];
  905. };
  906. //
  907. //G_BusServer.F_GetAuthenticityToken = function()
  908. //{
  909. // if ( !this.m_sAuthenticityToken )
  910. // {
  911. // try
  912. // {
  913. // this.m_sAuthenticityToken = ( new CAMAuthenticityTokenSession() ).generate();
  914. // }
  915. // catch ( e )
  916. // {
  917. // alert( "Exception thrown by CAMAuthenticityTokenSession" +
  918. // "\n\n Make sure you've included the camcrypto javascript files:" +
  919. // "\n camcrypto/base64.js" +
  920. // "\n camcrypto/camcryptoutil.js" +
  921. // "\n camcrypto/sha1.js" +
  922. // "\n camcrypto/authtoken1.js"
  923. // );
  924. // }
  925. // }
  926. // return this.m_sAuthenticityToken;
  927. //};
  928. //
  929. //G_BusServer.F_GetCredentialParameters = function()
  930. //{
  931. // var v_nParametersNode = G_BusServer.F_GetParameterValuesNode();
  932. // var v_nlParamItems = v_nParametersNode.selectNodes("item[starts-with(./bus:name,'credential:')]");
  933. // var v_aParams = [];
  934. //
  935. // for (var i = 0; i < v_nlParamItems.length; ++i)
  936. // {
  937. // var v_nItem = v_nlParamItems.item(i);
  938. // var v_oParam = {
  939. // name : U_Node.F_GetText(v_nItem.selectSingleNode("bus:name")),
  940. // type : U_Node.F_GetText(v_nItem.selectSingleNode("bus:value/item/@xsi:type")),
  941. // inclusive : v_nItem.selectSingleNode("bus:value/item/bus:inclusive[text()='true']") ? true : false,
  942. // values : [{
  943. // use : U_Node.F_GetText(v_nItem.selectSingleNode("bus:value/item/bus:use")),
  944. // display : U_Node.F_GetText(v_nItem.selectSingleNode("bus:value/item/bus:display"))
  945. // }]
  946. // };
  947. //
  948. // v_aParams.push(v_oParam);
  949. // }
  950. //
  951. // return v_aParams;
  952. //};
  953. /**
  954. * Launches the server dialog window for prompting. The application will be blocked until the window closes.
  955. * @param {Object} v_oListener The C_RestRequest object which prompted
  956. * @param {Object} v_oRequest The ajax request object to retrieve prompt page
  957. * @param {Object} v_oGlassContext The Glass context instance
  958. * @returns False if the prompting process could not be started.
  959. * @type Boolean
  960. */
  961. rsPromptHandler.F_DoRestPrompting = function(v_oListener, v_oRequest, v_oGlassContext)
  962. {
  963. var v_iPromptId = this.f_getPromptId();
  964. var v_oLaunchParameters = this.f_createRestPromptLaunchParameters( v_oRequest, this.f_prompting_OkCallback.bind(this, v_iPromptId) );
  965. var v_oContext = {
  966. urlMap: {
  967. perspective: "authoring",
  968. isViewer: true,
  969. UIProfile: "Titan",
  970. promptResponse: "url",
  971. ui_appbar: false,
  972. ui_navbar: false,
  973. // Uncomment following to enable debugging glass code in prompting window
  974. //debugBundles: true,
  975. launchParametersKey: rsLaunchParameters.Store(v_oLaunchParameters, true)
  976. }
  977. };
  978. var v_sUrl = v_oGlassContext.getUrl(v_oContext);
  979. return this.f_launchPrompt( v_oListener, v_sUrl, null, v_oLaunchParameters, v_iPromptId );
  980. };
  981. window.onunload = rsPromptHandler.f_OnUnLoad.bind(rsPromptHandler, window.onunload);
  982. return rsPromptHandler;
  983. });