control.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2020
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. @fileOverview Managing Prompts.
  14. @namespace cognos.Prompt
  15. */
  16. /**
  17. @class Prompting Control. Refers to elements in the User Interface used to manipulate values associated to a parameter. There can be one or many controls associated to a parameter.
  18. */
  19. cognos.Prompt.Control = new Class({});
  20. cognos.Prompt.Control.isElementInList = function(elem,list)
  21. {
  22. var aElements = list.split(K_PRMT_TREE_CACHE_LIST_SEP);
  23. var bIsInList = false;
  24. for (var i = 0; i < aElements.length; i++)
  25. {
  26. if (aElements[i] == elem)
  27. {
  28. bIsInList = true;
  29. break;
  30. }
  31. }
  32. return bIsInList;
  33. };
  34. /**
  35. @private
  36. @return {void}
  37. */
  38. cognos.Prompt.Control.prototype.f_initialize = function( v_oProps )
  39. {
  40. // set the default for the customizable labels
  41. // C_Choices labels
  42. this[K_PRMT_LABEL_CHOICES] = (this._type_ == "cognos.Prompt.Control.Search" && !this.isMulti()? PMT_UIM_CHOICE : PMT_UIM_CHOICES);
  43. this[K_PRMT_LABEL_INSERT] = PMT_UIM_INSERT;
  44. this[K_PRMT_LABEL_REMOVE] = PMT_UIM_REMOVE;
  45. this[K_PRMT_LABEL_CHOICES_SELECT_ALL] = PMT_UIM_SELECTALL;
  46. this[K_PRMT_LABEL_CHOICES_DESELECT_ALL] = PMT_UIM_DESELECTALL;
  47. this[K_PRMT_LABEL_RESULTS_SELECT_ALL] = PMT_UIM_SELECTALL;
  48. this[K_PRMT_LABEL_RESULTS_DESELECT_ALL] = PMT_UIM_DESELECTALL;
  49. //range
  50. this[K_PRMT_LABEL_RANGE_FROM] = PMT_RNG_FROM;
  51. this[K_PRMT_LABEL_RANGE_TO] = PMT_RNG_TO;
  52. // the following attr can be overriden by the subclass
  53. this[K_PRMT_LABEL_RANGE_LOWEST] = this[K_PRMT_LABEL_RANGE_LOWEST] ? this[K_PRMT_LABEL_RANGE_LOWEST] : PMT_RNG_LOWEST_VALUE;
  54. this[K_PRMT_LABEL_RANGE_HIGHEST] = this[K_PRMT_LABEL_RANGE_HIGHEST] ? this[K_PRMT_LABEL_RANGE_HIGHEST] : PMT_RNG_HIGHEST_VALUE;
  55. // search
  56. this[K_PRMT_LABEL_SEARCH_KEYWORDS] = PMT_SSM_KEYWORDSLABEL;
  57. this[K_PRMT_LABEL_SEARCH_INSTRUCTIONS_TEXT] = PMT_SSM_KEYWORDTIP;
  58. this[K_PRMT_LABEL_SEARCH_BTN_LABEL] = PMT_SSM_SEARCH;
  59. this[K_PRMT_LABEL_SEARCH_OPTIONS_TEXT] = PMT_SSM_OPTIONS;
  60. this[K_PRMT_LABEL_SEARCH_RESULTS_TEXT] = PMT_SSM_SEARCHRESULTS;
  61. // selectValue
  62. this[K_PRMT_LABEL_DESELECT] = PMT_UIM_DESELECT;
  63. // interval
  64. this[K_PRMT_LABEL_INTERVAL_DAYS] = PMT_SIC_DAYS;
  65. this[K_PRMT_LABEL_INTERVAL_HOURS] = PMT_SIC_HOURS;
  66. this[K_PRMT_LABEL_INTERVAL_MINUTES] = PMT_SIC_MINUTES;
  67. this[K_PRMT_LABEL_INTERVAL_SECONDS] = PMT_SIC_SECONDS;
  68. this[K_PRMT_LABEL_INTERVAL_MILLISECONDS] = PMT_SIC_MILLISECONDS;
  69. if ( v_oProps )
  70. {
  71. Object.f_extend( this, v_oProps );
  72. }
  73. this.f_decodeProperty("@parameter");
  74. this.f_decodeProperty("@name");
  75. // this.m_oSubmit is the hidden <input> used to submit (POST) prompt values (<selectChoices...>)
  76. this.m_oSubmit = null;
  77. this.m_sDivPrefix = "PRMT_";
  78. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  79. this.m_elPrompt = null;
  80. this.m_imgError = null;
  81. this.m_oChoices = null;
  82. this.m_fValidator = null;
  83. this.m_bisValidationON = false;
  84. this.m_bisGetValuesCall = false;
  85. this.m_sImgErrorOn = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  86. this.m_sImgErrorOnRTL = this.m_sSkin + "/prompting/images/error_timed_small_rtl.gif";
  87. this.m_sImgErrorOff = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  88. if ( !this["@submitType"] )
  89. {
  90. this["@submitType"] = K_PRMT_sXML;
  91. }
  92. this.m_bValid = false;
  93. this.m_dicStrings = {
  94. 'lowest': PMT_RNG_LOWEST_VALUE,
  95. 'highest': PMT_RNG_HIGHEST_VALUE
  96. };
  97. };
  98. cognos.Prompt.Control.prototype.clearSubmit = function()
  99. {
  100. this.m_oSubmit.value = K_PRMT_sEMPTY;
  101. };
  102. /**
  103. Triggers verification routine. Used after modifying a selection for example.
  104. @private
  105. @return {boolean} <i>true</i> if verification passed. <i>false</i> otherwise.
  106. */
  107. cognos.Prompt.Control.prototype.checkData = function()
  108. {
  109. if ( this.m_oRangeControl )
  110. {
  111. this.m_oRangeControl.checkData();
  112. }
  113. // custom validation through the JS API
  114. if (this.m_fValidator && (typeof this.m_fValidator == K_PRMT_sFUNCTION) && !this.m_bisValidationON) {
  115. this.m_bisValidationON = true;
  116. this.m_bValid = this.m_fValidator(this.getValues());
  117. this.m_bisValidationON = false;
  118. }
  119. var v_bPass = this.m_bValid;
  120. if ( v_bPass )
  121. {
  122. this.checkPass();
  123. }
  124. else
  125. {
  126. this.checkFail();
  127. }
  128. if ( this.m_oOwner )
  129. {
  130. this.m_oOwner.checkData();
  131. }
  132. if (v_bPass && (this._type_ != "cognos.Prompt.Control.Search") &&
  133. (this._type_ != "cognos.Prompt.Control.Time"))
  134. {
  135. this.cacheControlValue(this._type_);
  136. }
  137. return v_bPass;
  138. };
  139. /**
  140. Update UI to show this control as invalid.
  141. @private
  142. @return {void}
  143. */
  144. cognos.Prompt.Control.prototype.checkFail = function()
  145. {
  146. var v_elWidget = this.f_getErrorWidget();
  147. if ( v_elWidget )
  148. {
  149. PRMTUtils.f_addClass( v_elWidget, "clsTextWidgetParseError" );
  150. // Date control is made in CDatePickerIE5 CDatePicker_checkDateFail
  151. if ( !(this._type_ == "cognos.Prompt.Control.Date") ) {
  152. var v_errorMsg = (this.isEmpty() ? PMT_UIM_MISSING_VALUE : PMT_UIM_INVALID_INPUT );
  153. var v_oPrompt = this.m_elPrompt;
  154. var v_sPromptId = this.f_getId();
  155. var v_sPromptSkin = this.m_sSkin;
  156. window.setTimeout(function () { PRMTUtils.f_showARIAFail(v_oPrompt, v_sPromptId,v_sPromptSkin, v_errorMsg); },0);
  157. }
  158. }
  159. if ( !this["@hideAdornments"] && this.m_imgError && this.m_imgError.getAttribute("src") != this.m_sImgErrorOn && this.m_imgError.getAttribute("src") != this.m_sImgErrorOnRTL)
  160. {
  161. var v_el = (this.m_elRangeContainer ? this.m_elRangeContainer : $( this.f_getId(this.m_sDivPrefix) ));
  162. var v_sCustomDir = cssParser( this["@style"], "direction", true );
  163. var v_sFinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(v_el));
  164. this.m_imgError.setAttribute( "src", ( v_sFinalDir == "rtl" ) ? this.m_sImgErrorOnRTL : this.m_sImgErrorOn);
  165. }
  166. this.notify(gFAIL, this);
  167. };
  168. /**
  169. Update UI to show this control as valid.
  170. @private
  171. @return {void}
  172. */
  173. cognos.Prompt.Control.prototype.checkPass = function()
  174. {
  175. var v_elWidget = this.f_getErrorWidget();
  176. if ( v_elWidget )
  177. {
  178. PRMTUtils.f_removeClass( v_elWidget, "clsTextWidgetParseError" );
  179. // Date control is made in CDatePickerIE5 CDatePicker_checkDatePass
  180. if ( !(this._type_ == "cognos.Prompt.Control.Date") ) {
  181. PRMTUtils.f_showARIAPass(this.m_elPrompt, this.f_getId());
  182. }
  183. }
  184. if ( this.m_oErrorFeedback )
  185. {
  186. PRMTUtils.f_removeClass( this.m_oErrorFeedback, this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsFeedbackWidgetParseError" );
  187. }
  188. if ( !this["@hideAdornments"] && this.m_imgError && this.m_imgError.getAttribute("src") != this.m_sImgErrorOff )
  189. {
  190. this.m_imgError.setAttribute( "src", this.m_sImgErrorOff );
  191. }
  192. this.notify(gPASS, this);
  193. };
  194. /**
  195. Update UI to show this control as required.
  196. @private
  197. @return {void}
  198. */
  199. cognos.Prompt.Control.prototype.checkRequired = function()
  200. {
  201. if ( this.isRequired() )
  202. {
  203. if ( this.m_oChoices && this.m_oChoices.m_elRequired )
  204. {
  205. if ( this.m_oChoices.F_IsEmpty() ) {
  206. PRMTUtils.f_addClass( this.m_oChoices.m_elRequired, this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsTextWidgetParseError" );
  207. }
  208. else {
  209. PRMTUtils.f_removeClass( this.m_oChoices.m_elRequired, this.m_sErrorFeedbackClass );
  210. PRMTUtils.f_removeClass( this.m_oChoices.m_elRequired, "clsTextWidgetParseError" );
  211. }
  212. }
  213. }
  214. };
  215. /**
  216. Set the aria-required tag to an element.
  217. @private
  218. @return {void}
  219. */
  220. cognos.Prompt.Control.prototype.setAriaRequired = function(v_inputEl) {
  221. if (this.isRequired() && v_inputEl) {
  222. v_inputEl.setAttribute("aria-required", true);
  223. }
  224. };
  225. cognos.Prompt.Control.prototype.getWebContentRoot = function()
  226. {
  227. var v_sWebContentRoot = "..";
  228. var v_oCV = (this.f_getCV ? this.f_getCV() : null);
  229. if (v_oCV && v_oCV.getWebContentRoot) {
  230. v_sWebContentRoot = v_oCV.getWebContentRoot();
  231. }
  232. return v_sWebContentRoot;
  233. };
  234. /**
  235. [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control.
  236. Return values:<ul>
  237. <li><b>-1</b> if v_oValue is lower than current value.</li>
  238. <li><b>0</b> if v_oValue is matching current value.</li>
  239. <li><b>1</b> if v_oValue is higher than current value.</li></ul>
  240. @private
  241. @return {Integer} Always returns 1.
  242. */
  243. cognos.Prompt.Control.prototype.f_compare = function( v_oValue )
  244. {
  245. PRMTUtils.f_error( "PRMT_0006", "f_compare() not implemented! [" + this._type_ + "]");
  246. return 1;
  247. };
  248. /**
  249. Kicks off the control UI rendering in the container.
  250. @private
  251. @return {void}
  252. */
  253. cognos.Prompt.Control.prototype.f_draw = function()
  254. {
  255. var v_el = $( this.f_getId(this.m_sDivPrefix) );
  256. if ( !v_el )
  257. {
  258. PRMTUtils.f_error( "PRMT_0000", "f_draw():: Can't find " + this.f_getId(this.m_sDivPrefix) );
  259. return;
  260. }
  261. if (PRMTUtils.f_isHighContrast()) {
  262. v_el.className = v_el.className + " clsPrompt_a11y";
  263. }
  264. var v_customVAlign = cssParser( this["@style"], "vertical-align", true );
  265. if ( v_customVAlign ) {
  266. v_el.style.verticalAlign = v_customVAlign;
  267. }
  268. var v_sCustomDir = cssParser( this["@style"], "direction", true );
  269. var v_sFinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(v_el));
  270. if ( v_sFinalDir == "rtl" ) {
  271. v_el.style.textAlign = "right";
  272. }
  273. else {
  274. v_el.style.textAlign = "left";
  275. }
  276. var v_tblLayout = $CE( "table", {
  277. "border": K_PRMT_DEBUG_TABLEBORDER,
  278. "cellPadding": 0,
  279. "cellSpacing": 0,
  280. "role":K_PRMT_ARIA_ROLE_PRESENTATION,
  281. "style": (window.ie?"display:inline-table;vertical-align:top;":"") + cssParser( this["@style"], gsCSS_DEFAULT_STYLE )
  282. });
  283. if ( cssParser( this["@style"], "width" ) && this.n != "selectValue" )
  284. {
  285. v_tblLayout.f_setProperty( "width", "100%" );
  286. }
  287. if ( this[K_PRMT_sATTR_DISABLED] )
  288. {
  289. v_tblLayout.f_appendClass( K_PRMT_sCLS_DISABLED );
  290. }
  291. var v_tbdLayout = $CE( "tbody", {}, v_tblLayout );
  292. var v_trLayout = $CE( "tr", {}, v_tbdLayout );
  293. this.f_drawLayout( v_trLayout );
  294. var v_sCSSFloat = cssParser( this["@style"], "float", true );
  295. if ( v_sCSSFloat )
  296. {
  297. v_el.style.styleFloat = v_sCSSFloat; //IE
  298. v_el.style.cssFloat = v_sCSSFloat; // Firefox
  299. }
  300. var v_sHTML = this.f_drawParameterValueHolder() + v_tblLayout.f_getHTML();
  301. v_el.innerHTML = ( v_sHTML );
  302. if ( !this.m_oSubmit )
  303. {
  304. this.f_setFormSubmit();
  305. }
  306. if ( this.m_elPrompt && this.disabled )
  307. {
  308. this.m_elPrompt.f_setProperty( "disabled", "disabled" );
  309. }
  310. this.f_drawCompleted();
  311. };
  312. /**
  313. Renders the adornments for errors and required.
  314. @private
  315. @param {HTMLelement} v_el Container for this control.
  316. @param {boolean} [v_bSkipRequired] Skips rendering of the required flag. Used when controls are set as children of another control (like in ranges). The parent control will handle the 'Required' UI.
  317. @return {C_PromptElement}
  318. */
  319. cognos.Prompt.Control.prototype.f_drawAdornments = function( v_el, v_bSkipRequired )
  320. {
  321. var v_td0 = $CE( "td", {"vAlign": "top", "width": "10px"}, v_el );
  322. if ( this["@hideAdornments"] )
  323. {
  324. // This function shouldn't be called when @hideAdornments is set to true, but to preserve some
  325. // layout formatting (like in ranges), we are using blank image as spacers.
  326. var v_img = $CE( "img", {
  327. "src": this.m_sSkin + "/prompting/images/spacer.gif",
  328. "height": 10,
  329. "width": 10,
  330. "border": 0
  331. }, v_td0);
  332. if ( !this.m_bIsAComponent )
  333. {
  334. // class clsErrorRequired adds padding, which we don't want when the control is a component of an other control.
  335. // (ie. Time in a DateTime, text box in a range control...)
  336. v_img.f_setProperty( "class", "clsErrorRequired" );
  337. }
  338. }
  339. else
  340. {
  341. var v_tblReq = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "width":10, "height":20, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td0 );
  342. var v_tbdReq = $CE( "tbody", {}, v_tblReq );
  343. if ( this.isRequired() && !v_bSkipRequired )
  344. {
  345. var v_trReq = $CE( "tr", {}, v_tbdReq);
  346. var v_tdReq = $CE( "td", {"vAlign":"top"}, v_trReq);
  347. var v_imgReq = $CE( "img", {
  348. "src": this.m_sSkin + "/prompting/images/icon_required.gif",
  349. "class": "clsErrorRequired",
  350. "vAlign": "top",
  351. "height": 10,
  352. "width": 10,
  353. "border": 0,
  354. "alt": ""
  355. }, v_tdReq);
  356. }
  357. var v_trError = $CE( "tr", {}, v_tbdReq );
  358. var v_tdError = $CE( "td", {"vAlign":"top"}, v_trError );
  359. $CE( "img", {
  360. "id": this.f_getId( K_PRMT_sIMG_ERROR_PREFIX ),
  361. "src": this.m_sSkin + "/prompting/images/error_timed_small_off.gif",
  362. "class": "clsErrorRequired",
  363. "vAlign": "top",
  364. "height": 10,
  365. "width": 10,
  366. "border": 0,
  367. "alt": ""
  368. }, v_tdError);
  369. }
  370. return v_td0;
  371. };
  372. /**
  373. [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control.
  374. @private
  375. @param {C_PromptElement} v_el Container.
  376. @return {void}
  377. */
  378. cognos.Prompt.Control.prototype.f_drawInput = function( v_el )
  379. {
  380. alert( "cognos.Prompt.Control::f_drawInput" );
  381. };
  382. /**
  383. Renders the layout of the control: position lists, adornments and control inputs.
  384. @private
  385. @param {C_PromptElement} v_trLayout Container for this control.
  386. @return {C_PromptElement}
  387. */
  388. cognos.Prompt.Control.prototype.f_drawLayout = function( v_trLayout )
  389. {
  390. var v_oPrompt = null;
  391. if ( this.isMulti() )
  392. {
  393. var v_td1 = $CE( "td", {"vAlign":"top", "class": "clsControlLabel pc"}, v_trLayout );
  394. if ( !this.f_isRange() && !this.m_bHasLabel )
  395. {
  396. v_td1.f_appendChild( "&nbsp;<br>" );
  397. if ( this["@showCondition"])
  398. {
  399. // Add a empty (invisible) select, to fix alignment.
  400. var v_sel = $CE( "select", {"style":"margin-bottom:5px;visibility:hidden;"}, v_td1 );
  401. var v_opt = $CE( "option", {"value":"null"}, v_sel);
  402. v_opt.f_appendText( "x" );
  403. }
  404. }
  405. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0}, v_td1 );
  406. var v_tbd = $CE( "tbody", {}, v_tbl );
  407. var v_tr = $CE( "tr", {}, v_tbd );
  408. if ( !(this["@hideAdornments"] || this.m_bSkipAdornments) )
  409. {
  410. this.f_drawAdornments( v_tr, true );
  411. }
  412. var v_td = $CE( "td", {}, v_tr );
  413. if ( cssParser( this["@style"], "width" ) )
  414. {
  415. v_td1.f_setProperty( "width", "100%" );
  416. v_tbl.f_setProperty( "width", "100%" );
  417. v_td.f_setProperty( "width", "100%" );
  418. }
  419. v_oPrompt = this.f_drawInput( v_td );
  420. this.setAriaRequired();
  421. this.m_oChoices = new C_Choices( this );
  422. var v_aMO = this.f_getCV().multipleObserverArray;
  423. if (v_aMO) {
  424. v_aMO.push( this.m_oChoices );
  425. }
  426. this.m_oChoices.F_Draw( v_trLayout );
  427. }
  428. else
  429. {
  430. if ( !(this["@hideAdornments"] || this.m_bSkipAdornments) )
  431. {
  432. this.f_drawAdornments( v_trLayout );
  433. }
  434. v_oPrompt = this.f_drawInput( $CE( "td", {}, v_trLayout ) );
  435. }
  436. this.m_elPrompt = v_oPrompt;
  437. return (v_oPrompt);
  438. };
  439. /**
  440. [Abstract] This function should be overriden by any sub-classes of cognos.Prompt.Control.
  441. @private
  442. @return {void}
  443. */
  444. cognos.Prompt.Control.prototype.f_getPV = function()
  445. {
  446. PRMTUtils.f_error( "PRMT_0004", "f_getPV() not implemented! [" + this._type_ + "]");
  447. };
  448. /**
  449. Return a localized string.
  450. @private
  451. @param {String} v_sKey Key for the localized string.
  452. @return {String} Returns the value associated with the key. If no value, return the key.
  453. */
  454. cognos.Prompt.Control.prototype.f_getString = function( v_sKey )
  455. {
  456. var v_s = this.m_dicStrings[v_sKey];
  457. if ( typeof v_s == K_PRMT_sUNDEFINED )
  458. {
  459. v_s = v_sKey;
  460. }
  461. return v_s;
  462. };
  463. /**
  464. Returns the last validity state. It doesn't check the data first. Call checkData() before if required.
  465. @private
  466. @return {boolean}
  467. */
  468. cognos.Prompt.Control.prototype.getValid = function()
  469. {
  470. return ( this.m_oChoices ? this.m_oChoices.f_getValid() : this.m_bValid );
  471. };
  472. /**
  473. Return the first element matching the tag name in the control.
  474. @private
  475. @param {String} v_sTag Tag name.
  476. @return {HTMLelement[]} Null if not found.
  477. */
  478. cognos.Prompt.Control.prototype.f_getChildByTagName = function( v_sTag )
  479. {
  480. var v_oPrompt = this;
  481. var v_oChild = null;
  482. if ( v_oPrompt.c && v_oPrompt.c.length )
  483. {
  484. for ( var v_idx = 0; v_idx < v_oPrompt.c.length; v_idx++ )
  485. {
  486. if ( v_oPrompt.c[ v_idx ].n == v_sTag )
  487. {
  488. v_oChild = v_oPrompt.c[ v_idx ];
  489. if ( !(v_oChild && v_oChild.c && v_oChild.c.length > 0) )
  490. {
  491. // clear v_oChild, <selectChoices> is empty
  492. v_oChild = null;
  493. }
  494. // Stop after the first find, we should have only one node called 'selectChoices'.
  495. break;
  496. }
  497. }
  498. }
  499. return v_oChild;
  500. };
  501. /**
  502. Return the &lt;selectChoices&gt; node.
  503. @private
  504. @return {HTMLelement} Null if not found.
  505. */
  506. cognos.Prompt.Control.prototype.getSelectChoices = function()
  507. {
  508. return ( this.f_getChildByTagName( "selectChoices" ) );
  509. };
  510. /**
  511. By default, returns true if one or more value are returned by the control.
  512. @private
  513. @return {boolean} Always false.
  514. */
  515. cognos.Prompt.Control.prototype.hasValue = function()
  516. {
  517. var v_aPV = this.f_getPV();
  518. return ( v_aPV && v_aPV.length > 0 );
  519. };
  520. /**
  521. * By default, returns true if the control does not return any value.
  522. *
  523. * @private
  524. * @return {boolean}
  525. */
  526. cognos.Prompt.Control.prototype.isEmpty = function()
  527. {
  528. return !this.hasValue();
  529. };
  530. /**
  531. Query Studio feature only.
  532. @private
  533. @return {boolean}
  534. */
  535. cognos.Prompt.Control.prototype.isExclusive = function()
  536. {
  537. var v_sel = $( this.f_getId("oExcludeSelectedValues") );
  538. return ( v_sel && v_sel.options && v_sel.options[1] && v_sel.options[1].selected ? true : false );
  539. };
  540. /**
  541. Check if multi-selection if enabled.
  542. @private
  543. @return {boolean} <i>true</i> if this control accepts multiple selections.
  544. */
  545. cognos.Prompt.Control.prototype.isMulti = function()
  546. {
  547. return ( this["@multiSelect"] === true );
  548. };
  549. /**
  550. Check if this is a range control.
  551. @private
  552. @return {boolean}
  553. */
  554. cognos.Prompt.Control.prototype.f_isRange = function()
  555. {
  556. return ( this["@range"] === true );
  557. };
  558. /**
  559. Check if this control needs to have a selection to be valid.
  560. @private
  561. @return {boolean} <i>true</i> if this control is satisfied.
  562. */
  563. cognos.Prompt.Control.prototype.isRequired = function()
  564. {
  565. return ( this["@required"] === true );
  566. };
  567. /**
  568. Check if this control is valid, i.e. ready to submit.
  569. @private
  570. @return {boolean} <i>true</i> if this control has a valid selection.
  571. */
  572. cognos.Prompt.Control.prototype.isValid = function()
  573. {
  574. this.checkData();
  575. return (this.m_bValid===true);
  576. };
  577. /**
  578. @private
  579. @param {integer} iState
  580. @param {object} oNotifier
  581. @return {void}
  582. */
  583. cognos.Prompt.Control.prototype.notify = function(iState, oNotifier)
  584. {
  585. var v_oCV = this.f_getCV();
  586. if (v_oCV && typeof v_oCV.notify == K_PRMT_sFUNCTION)
  587. {
  588. v_oCV.notify(iState, oNotifier);
  589. }
  590. };
  591. /**
  592. @private
  593. @return {String} XML
  594. */
  595. cognos.Prompt.Control.prototype.preProcess = function()
  596. {
  597. if ( !this.m_oSubmit )
  598. {
  599. PRMTUtils.f_error( "PRMT_0005", "preProcess():: No m_oSubmit defined. [" + this._type_ + "]");
  600. return;
  601. }
  602. var v_aPV = ( this.m_oChoices ? this.m_oChoices.f_getPV() : this.f_getPV() );
  603. var v_sXML = null;
  604. if ( v_aPV && typeof v_aPV == K_PRMT_sOBJECT )
  605. {
  606. v_sXML = cognos.Value.toXML(v_aPV);
  607. }
  608. else if ( typeof v_aPV == K_PRMT_sSTRING )
  609. {
  610. v_sXML = v_aPV;
  611. }
  612. if ( v_sXML === null )
  613. {
  614. v_sXML = K_PRMT_sEMPTY;
  615. }
  616. addSelectChoices( this.m_oSubmit, v_sXML );
  617. return (v_sXML);
  618. };
  619. /**
  620. @private
  621. @return {void}
  622. */
  623. cognos.Prompt.Control.prototype.removeSelectedChoices = function()
  624. {
  625. var iFirstSelection = null;
  626. if (typeof this.m_oLstChoices == K_PRMT_sOBJECT)
  627. {
  628. iFirstSelection = this.m_oLstChoices.selectedIndex;
  629. }
  630. if (typeof iFirstSelection != "number")
  631. {
  632. return;
  633. }
  634. if (iFirstSelection != -1)
  635. {
  636. for (var idxSelection = this.m_oLstChoices.options.length-1; idxSelection > -1 ; idxSelection--)
  637. {
  638. if (this.m_oLstChoices.options[idxSelection].selected)
  639. {
  640. this.m_oLstChoices.options[idxSelection] = null;
  641. }
  642. }
  643. }
  644. else
  645. {
  646. var sPrompt_Select_Item_First = "sPrompt_Select_Item_First";
  647. if (typeof PMT_UIM_sPrompt_Select_Item_First == K_PRMT_sSTRING)
  648. {
  649. sPrompt_Select_Item_First = PMT_UIM_sPrompt_Select_Item_First;
  650. }
  651. PRMTUtils.f_error("PRMT_0001", sPrompt_Select_Item_First);
  652. }
  653. this.checkData();
  654. };
  655. /**
  656. @private
  657. @param {String} sId New Id.
  658. @return {void}
  659. */
  660. cognos.Prompt.Control.prototype.setCVId = function(sId)
  661. {
  662. if (typeof sId == K_PRMT_sSTRING && sId !== K_PRMT_sEMPTY & sId != K_PRMT_sUNDEFINED)
  663. {
  664. this.m_sCVId = sId;
  665. }
  666. };
  667. /**
  668. Query Studio feature only.
  669. @private
  670. @param {boolean} v_bExclusive
  671. @return {void}
  672. */
  673. cognos.Prompt.Control.prototype.setExclusive = function( v_bExclusive )
  674. {
  675. var v_sel = $( this.f_getId("oExcludeSelectedValues") );
  676. if ( v_sel && v_sel.options )
  677. {
  678. var v_idx = ( v_bExclusive ? 1 : 0 );
  679. if ( v_sel.options[v_idx] ) {
  680. v_sel.options[v_idx].selected = true;
  681. }
  682. }
  683. };
  684. /**
  685. @private
  686. @return {void}
  687. */
  688. cognos.Prompt.Control.prototype.f_setFormSubmit = function()
  689. {
  690. var v_frm = this.f_CSW_GetForm();
  691. var sParamName = this.getParameterName();
  692. if (v_frm)
  693. {
  694. this.m_oSubmit = v_frm.elements[ sParamName ];
  695. }
  696. if (this.m_oSubmit) {
  697. this.m_oSubmit.value = K_PRMT_sEMPTY;
  698. }
  699. else
  700. {
  701. if ( document.readyState && document.readyState != "complete" )
  702. {
  703. // Need DOM ready for IE.
  704. setTimeout( this.f_setFormSubmit.bind(this), 100 );
  705. return;
  706. }
  707. this.m_oSubmit = PRMTUtils.f_createElement( "input", {"name": sParamName, "type":"hidden", "value":K_PRMT_sEMPTY}, v_frm );
  708. }
  709. };
  710. /**
  711. Modifies the selection of the control.
  712. @private
  713. @param {ParameterValues[]} Array of parameter values (cognos.SingleValue or cognos.RangeValue). If the control doesn't accept multiple selections, only the first value will be considered.
  714. @return {void}
  715. */
  716. cognos.Prompt.Control.prototype.setParameterValues = function( v_aParmValueItems )
  717. {
  718. var v_oChoiceControl = this.m_oChoices;
  719. if ( v_oChoiceControl )
  720. {
  721. v_oChoiceControl.F_SelectAll();
  722. v_oChoiceControl.F_Remove();
  723. for ( var v_idx = 0; v_idx < v_aParmValueItems.length; v_idx++ )
  724. {
  725. v_oChoiceControl.F_AddPV( v_aParmValueItems[ v_idx ] );
  726. }
  727. v_oChoiceControl.checkData();
  728. }
  729. else if (v_aParmValueItems.length)
  730. {
  731. this.f_setPV( v_aParmValueItems[0] );
  732. }
  733. };
  734. /**
  735. Finish drawing, set events.
  736. @private
  737. @return {void}
  738. */
  739. cognos.Prompt.Control.prototype.f_drawCompleted = function()
  740. {
  741. if ( this.m_oChoices )
  742. {
  743. this.m_oChoices.F_DrawCompleted();
  744. }
  745. var img = $( this.f_getId(K_PRMT_sIMG_ERROR_PREFIX) );
  746. if ( img )
  747. {
  748. this.m_imgError = img;
  749. }
  750. if ( !this.m_oRangeControl )
  751. {
  752. this.f_setSelectChoices();
  753. }
  754. if (window.JsUnitException)
  755. {
  756. this.checkData();
  757. }
  758. else
  759. {
  760. // 575695 - Need to call checkData() in a different thread.
  761. // We can't just call checkData() through setTimeout, JsUnit tests will fail.
  762. setTimeout( this.checkData.bind(this), 20 );
  763. }
  764. if (typeof SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS != K_PRMT_sUNDEFINED && SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS && typeof this.f_CSW_init == K_PRMT_sFUNCTION)
  765. {
  766. this.f_CSW_init();
  767. }
  768. };
  769. /**
  770. Set up event callbacks for this control. Supported events: <tt>onChange</tt>, <tt>onFail</tt>, <tt>onValid</tt>, <tt style="color:red">onLoad?</tt>.
  771. @param {String} evt Event type
  772. @param {function} fct The Javascript function used as callback.
  773. @return {void}
  774. @example Change the background to red when control's selection is invalid: <br/>
  775. &nbsp;&nbsp;ctrl.addEvent( "<tt>onFail</tt>", <tt>function() {
  776. <br/>&nbsp;&nbsp;&nbsp;&nbsp;var ctrl = cognos.Report.getReport().prompt.getControlByName('X');
  777. <br/>&nbsp;&nbsp;&nbsp;&nbsp;ctrl.setStyle("background-color:red;");
  778. <br/>&nbsp;&nbsp;}</tt> );
  779. */
  780. cognos.Prompt.Control.prototype.addEvent = function(evt, fct) {};
  781. /**
  782. If the control doesn't support multiple values, only the first one will be considered.
  783. @param {cognos.Value[]} aValues New values to use for this control.
  784. @return {void}
  785. */
  786. cognos.Prompt.Control.prototype.addValues = function( aValues )
  787. {
  788. var v_iLimit = ( this.isMulti() ? aValues.length : 1);
  789. for (var v_idx = 0; v_idx < v_iLimit; v_idx++)
  790. {
  791. this.f_setPV( aValues[v_idx] );
  792. if ( this.m_oChoices ) {
  793. this.m_oChoices.F_Insert();
  794. }
  795. }
  796. this.checkData();
  797. };
  798. /**
  799. If the control doesn't support multiple values, only the first one will be considered.
  800. @param {cognos.Value[]} aValues New values to use for this control.
  801. @return {void}
  802. */
  803. cognos.Prompt.Control.prototype.setValues = function( aValues )
  804. {
  805. this.clearValues();
  806. this.addValues(aValues);
  807. };
  808. /**
  809. Change the validation function for controls. Returning <tt>false</tt> will update control's UI to indicate there is a validation error and will disable the <tt>Insert</tt> button when used in a multi-selection scenario.
  810. @param {function} oFct A function that would take the user input as parameter and must return a boolean value.
  811. @return {void}
  812. @example
  813. // Make sure we have a valid Postal Code (ie. A1A 1A1)
  814. textBox.setValidator(
  815. function (sInput) {
  816. var rePostalCodeFormat = new RegExp( "[a-z][0-9][a-z] [0-9][a-z][0-9]", "gi" );
  817. if ( rePostalCodeFormat.test(sInput) ) {
  818. return true;
  819. }
  820. return false;
  821. }
  822. );
  823. */
  824. cognos.Prompt.Control.prototype.setValidator = function(oFct) {
  825. this.m_fValidator = oFct;
  826. };
  827. /**
  828. Traps whether the user has pressed the delete key in the choices box. [IE specific]
  829. @private
  830. @param {Integer} iKeyCode
  831. @return {void}
  832. */
  833. cognos.Prompt.Control.prototype.catchDeleteKey = function(iKeyCode)
  834. {
  835. //catch the Delete key code
  836. if (iKeyCode == 46 && typeof this.remove == K_PRMT_sFUNCTION)
  837. {
  838. this.remove(this.m_oLstChoices);
  839. }
  840. };
  841. /**
  842. Clear (or deselect) all values for this control.
  843. @return {void}
  844. */
  845. cognos.Prompt.Control.prototype.clearValues = function()
  846. {
  847. if ( this.m_oChoices )
  848. {
  849. this.m_oChoices.F_SelectAll();
  850. this.m_oChoices.F_Remove();
  851. }
  852. };
  853. /**
  854. Adds a javascript reference using 'prefix' and this control's name (Custom Scripts Workaround).
  855. @private
  856. @param {String} v_sPrefix Prefix of the 'input' control to use in the formWarpRequest
  857. @param {HTMLElement} v_obj HTML element to set to v_sName. If missing, using this.m_elPrompt.
  858. @return {object} The newly associated object, incidently 'this'.
  859. */
  860. cognos.Prompt.Control.prototype.f_CSW_createJSObject = function( v_sPrefix, v_obj )
  861. {
  862. if ( this["@name"] )
  863. {
  864. var v_sName = v_sPrefix + this["@name"];
  865. window[v_sName] = (v_obj ? v_obj : this);
  866. return (window[v_sName]);
  867. }
  868. return null;
  869. };
  870. /**
  871. Set the value of an input in the FormWarpRequest form. Adds the reference if missing.
  872. (Custom Scripts Workaround)
  873. @private
  874. @return {HTMLelement} The 'FormWarpRequest' element.
  875. */
  876. cognos.Prompt.Control.prototype.f_CSW_GetForm = function()
  877. {
  878. var v_doc = document;
  879. var v_sFWR = "formWarpRequest";
  880. var v_f = v_doc[v_sFWR + this.f_getCVId()];
  881. if ( !v_f && v_doc[v_sFWR] )
  882. {
  883. v_f = v_doc[v_sFWR];
  884. v_doc[v_sFWR].submit = f_CSW_tryCVPromptAction;
  885. }
  886. return v_f;
  887. };
  888. /**
  889. Set the value of an input in the FormWarpRequest form. Adds the reference if missing (Custom Scripts Workaround).
  890. @private
  891. @param {String} v_sPrefix Prefix of the 'input' control to use in the formWarpRequest
  892. @param {HTMLElement} [v_el] HTML element to set to v_sName. If missing, using this.m_elPrompt.
  893. @return {void}
  894. */
  895. cognos.Prompt.Control.prototype.f_CSW_SetFormElement = function(v_sPrefix, v_el)
  896. {
  897. if ( this["@name"] )
  898. {
  899. var v_sName = v_sPrefix + this["@name"];
  900. var v_f = this.f_CSW_GetForm();
  901. if ( v_f )
  902. {
  903. v_f[v_sName] = ( v_el ? v_el : this.m_elPrompt );
  904. }
  905. if (this.m_sCSW_rangeSuffix)
  906. {
  907. // Used to fix references in ranges
  908. v_sName = v_sPrefix + this.m_sCSW_rangeSuffix + this["@name"];
  909. window[v_sName] = ( v_el ? v_el : this.m_elPrompt );
  910. if ( v_f ) {
  911. v_f[v_sName] = window[v_sName];
  912. }
  913. }
  914. if ( this["@parameter"] )
  915. {
  916. v_sName = "p_" + this["@parameter"];
  917. if ( !v_f[v_sName] )
  918. {
  919. v_f[v_sName] = this.m_oSubmit;
  920. }
  921. }
  922. }
  923. };
  924. /**
  925. Checks and decodes a property if necessary (U003 encoding for < and >).
  926. @private
  927. @param {String} v_sPropertyName The property name we need to decode.
  928. @return {void}
  929. */
  930. cognos.Prompt.Control.prototype.f_decodeProperty = function(v_sPropertyName)
  931. {
  932. if ( typeof this[v_sPropertyName] == K_PRMT_sSTRING )
  933. {
  934. this[v_sPropertyName] = sDecodeU003( this[v_sPropertyName] );
  935. }
  936. };
  937. /**
  938. Generates a hidden input field to store parameter values in the UI.
  939. @private
  940. @return {C_PromptElement}
  941. */
  942. cognos.Prompt.Control.prototype.f_drawParameterValueHolder = function()
  943. {
  944. var v_sHiddenInput = "";
  945. var v_sCVID = this.f_getCVId();
  946. var v_frm = $("formWarpRequest" + v_sCVID);
  947. if ( v_frm && v_frm.elements && !v_frm.elements[this.getParameterName()] )
  948. {
  949. var v_hidden = $CE( "input", {
  950. "type": "hidden",
  951. "name": this.getParameterName()
  952. });
  953. v_sHiddenInput = v_hidden.f_getHTML();
  954. }
  955. return v_sHiddenInput;
  956. };
  957. /**
  958. @private
  959. @return {CCognosViewer}
  960. */
  961. cognos.Prompt.Control.prototype.f_getCV = function()
  962. {
  963. var oRetVal = window;
  964. if (typeof this.m_oCV == K_PRMT_sOBJECT)
  965. {
  966. oRetVal = this.m_oCV;
  967. }
  968. else
  969. {
  970. try {
  971. oRetVal = eval("oCV" + this.f_getCVId());
  972. if (typeof oRetVal == K_PRMT_sOBJECT)
  973. {
  974. this.m_oCV = oRetVal;
  975. }
  976. }
  977. catch (e)
  978. {
  979. oRetVal = window;
  980. }
  981. }
  982. return oRetVal;
  983. };
  984. /**
  985. @private
  986. @return {void}
  987. */
  988. cognos.Prompt.Control.prototype.f_setPromptManager = function(oPromptManager)
  989. {
  990. this.m_oPromptManager = oPromptManager;
  991. }
  992. /**
  993. @private
  994. @return {PromptManager}
  995. */
  996. cognos.Prompt.Control.prototype.f_getPromptManager = function()
  997. {
  998. return this.m_oPromptManager;
  999. }
  1000. cognos.Prompt.Control.prototype.f_isBUX = function(){
  1001. var v_oCV = this.f_getCV();
  1002. return (typeof v_oCV == K_PRMT_sOBJECT && v_oCV.isBux? true :false);
  1003. };
  1004. cognos.Prompt.Control.prototype.getGateway = function()
  1005. {
  1006. var v_sGateway = document.location.pathname;
  1007. var v_oCV = (this.f_getCV ? this.f_getCV() : null);
  1008. if (v_oCV && v_oCV.getGateway) {
  1009. v_sGateway = v_oCV.getGateway();
  1010. }
  1011. return v_sGateway;
  1012. };
  1013. /**
  1014. @private
  1015. @return {String}
  1016. */
  1017. cognos.Prompt.Control.prototype.f_getCVId = function()
  1018. {
  1019. return this.CVId;
  1020. };
  1021. /**
  1022. Retrieves the control's ID based on its id, name or parameter properties.
  1023. @private
  1024. @return {String}
  1025. */
  1026. cognos.Prompt.Control.prototype.f_getControlId = function()
  1027. {
  1028. var v_sId = K_PRMT_sEMPTY;
  1029. if ( this._id_ )
  1030. {
  1031. v_sId = this._id_;
  1032. }
  1033. else if ( this.id )
  1034. {
  1035. v_sId = this.id;
  1036. }
  1037. else if ( this["@parameter"] )
  1038. {
  1039. v_sId = this["@parameter"];
  1040. }
  1041. else if ( this.name )
  1042. {
  1043. v_sId = this.name;
  1044. }
  1045. return v_sId;
  1046. };
  1047. /**
  1048. Return the error widget for this control.
  1049. @private
  1050. @return {HTMLelement}
  1051. */
  1052. cognos.Prompt.Control.prototype.f_getErrorWidget = function()
  1053. {
  1054. var v_elWidget = this.m_elPrompt;
  1055. // When control is a Text inside a Interval, use self for showing errors, otherwise use its parent.
  1056. // It means the border will be under the control (as opposed to be the control's border in case of intervals).
  1057. if ( !(this.m_oOwner && this.m_oOwner.n == "selectInterval") && v_elWidget && v_elWidget.parentNode )
  1058. {
  1059. v_elWidget = v_elWidget.parentNode;
  1060. }
  1061. return v_elWidget;
  1062. };
  1063. /**
  1064. Returns the ID for this control.
  1065. @private
  1066. @param {String} [v_sPrefix] Prefix to add to the ID/name.
  1067. @return {String} Prompt Control ID.
  1068. */
  1069. cognos.Prompt.Control.prototype.f_getId = function( v_sPrefix )
  1070. {
  1071. return ( (v_sPrefix ? v_sPrefix : K_PRMT_sEMPTY) + this.f_getControlId() );
  1072. };
  1073. /**
  1074. Called after initialisation is completed and initiate the contol rendering.
  1075. @private
  1076. @return {void}
  1077. */
  1078. cognos.Prompt.Control.prototype.f_initCompleted = function()
  1079. {
  1080. if ( !this.m_oRangeControl && !this.m_bIsAComponent )
  1081. {
  1082. this.f_draw();
  1083. }
  1084. };
  1085. /**
  1086. @private
  1087. @return {void}
  1088. */
  1089. cognos.Prompt.Control.prototype.f_setPV = function()
  1090. {
  1091. PRMTUtils.f_log( "PRMT_0003", "f_setPV() is not implemented for this class. [" + this._type_ + "]");
  1092. };
  1093. /**
  1094. @private
  1095. @return {void}
  1096. */
  1097. cognos.Prompt.Control.prototype.f_setSelectChoices = function()
  1098. {
  1099. var v_oSC = this.getSelectChoices();
  1100. var v_oPV = null;
  1101. if ( v_oSC )
  1102. {
  1103. if ( this.m_oChoices )
  1104. {
  1105. if ( v_oSC.c && v_oSC.c.length > 0){
  1106. this.m_oChoices.f_setSelectChoices(v_oSC.c);
  1107. }
  1108. }
  1109. else if ( !this.m_bIsAComponent )
  1110. {
  1111. this.f_setPV( cognos.Value.getValue( v_oSC ) );
  1112. }
  1113. }
  1114. };
  1115. /**
  1116. Finds a HTML element contained in this control.
  1117. @private
  1118. @param {String} v_sName Name of the HTML element.
  1119. @return {HTMLelement}
  1120. */
  1121. cognos.Prompt.Control.prototype.getChildByName = function( v_sName )
  1122. {
  1123. var v_oChild = null;
  1124. if ( this.c )
  1125. {
  1126. for (var v_idxChild = 0; v_idxChild < this.c.length; v_idxChild++)
  1127. {
  1128. if ( this.c[v_idxChild].n == v_sName )
  1129. {
  1130. v_oChild = this.c[v_idxChild];
  1131. break;
  1132. }
  1133. }
  1134. }
  1135. return v_oChild;
  1136. };
  1137. /**
  1138. Returns the control's name, set in Report Studio.
  1139. @return {String}
  1140. */
  1141. cognos.Prompt.Control.prototype.getName = function()
  1142. {
  1143. return ( typeof this["@name"] == K_PRMT_sUNDEFINED ? null : this["@name"] );
  1144. };
  1145. /**
  1146. Returns the parameter associated to this control.
  1147. @return {cognos.Prompt.Parameter}
  1148. */
  1149. cognos.Prompt.Control.prototype.getParameter = function() {};
  1150. /**
  1151. Returns the name of the parameter associated to this control.
  1152. @private
  1153. @return {String} Parameter name
  1154. */
  1155. cognos.Prompt.Control.prototype.getParameterName = function()
  1156. {
  1157. var sParamName = "p_" + this["@parameter"];
  1158. if ( this.suppressExtraPromptNames )
  1159. {
  1160. sParamName = sParamName.substring(1);
  1161. }
  1162. return sParamName;
  1163. };
  1164. /**
  1165. Returns the parameter values selected in this control.
  1166. @private
  1167. @return {ParameterValues[]} Array of parameter values (cognos.SingleValue or cognos.RangeValue).
  1168. */
  1169. cognos.Prompt.Control.prototype.getParameterValues = function()
  1170. {
  1171. return ( this.m_oChoices ? this.m_oChoices.getParameterValues() : this.f_getPV() );
  1172. };
  1173. /**
  1174. @private
  1175. @return {HTMLelement[]}
  1176. */
  1177. cognos.Prompt.Control.prototype.getSelectOptions = function()
  1178. {
  1179. if ( !this.m_aSO )
  1180. {
  1181. this.m_aSO = this.getChildByName("selectOptions");
  1182. if (this.m_aSO && this.m_aSO.c)
  1183. {
  1184. this.m_aSO = this.m_aSO.c;
  1185. }
  1186. }
  1187. return (this.m_aSO);
  1188. };
  1189. /**
  1190. Returns the current value for the control. Always returns an array for simplicity, even if single select and/or there is only one value selected.
  1191. See {@link cognos.Value} for the format of the returned values.
  1192. @return {cognos.Value[]}
  1193. @example <ul>
  1194. <li>Text box prompt (single): <tt>[ {use: "Smith", display: "Smith"} ]</tt></li>
  1195. <li>Select prompt (multiple): <tt>[ {use: "CAN", display: "Canada"}, {use: "JPN", display: "Japan"} ]</tt></li>
  1196. <li>Tree prompt (multiple): <tt>[ {use: "[Americas].[Canada]", display: "Canada"}, {use: "[Asia].[Japan]", display: "Japan"} ]</tt></li>
  1197. </ul>
  1198. */
  1199. cognos.Prompt.Control.prototype.getValues = function(v_allOptions)
  1200. {
  1201. this.m_bisGetValuesCall = true;
  1202. var v_aValues = ( this.m_oChoices ? this.m_oChoices.getValues() : this.f_getPV(true,v_allOptions) );
  1203. if ( !(v_aValues instanceof Array) ) {
  1204. if (v_aValues) {
  1205. v_aValues = [v_aValues];
  1206. }
  1207. else {
  1208. v_aValues = [];
  1209. }
  1210. }
  1211. this.m_bisGetValuesCall = false;
  1212. return v_aValues;
  1213. };
  1214. /**
  1215. Returns the name of the parameter associated to this control.
  1216. @private
  1217. @return {Object} cascadeOn Parameter
  1218. */
  1219. cognos.Prompt.Control.prototype.getCascadeOnParameter = function()
  1220. {
  1221. var result = null;
  1222. var v_promptManager = this.f_getPromptManager();
  1223. if(this["@cascadeOn"]){
  1224. var v_cascadeParamName = "p_" + this["@cascadeOn"];
  1225. result = v_promptManager.getParameterByName(v_cascadeParamName);
  1226. }
  1227. return result;
  1228. };
  1229. cognos.Prompt.Control.prototype.getTracking = function()
  1230. {
  1231. var tracking_info = K_PRMT_sEMPTY;
  1232. var oCV = this.f_getCV();
  1233. if (oCV && typeof oCV.getTracking == K_PRMT_sFUNCTION)
  1234. {
  1235. tracking_info = oCV.getTracking();
  1236. }
  1237. else
  1238. {
  1239. // can't find tracking in CCognosViewer, trying with a form
  1240. var oForm = document.getElementById("formWarpRequest" + this.f_getCVId());
  1241. if (!oForm) {
  1242. oForm = document.getElementById("formWarpRequest");
  1243. }
  1244. if (oForm) {
  1245. if (typeof oForm.m_tracking != K_PRMT_sUNDEFINED) {
  1246. tracking_info = oForm.m_tracking.value;
  1247. }
  1248. else if (typeof oForm.tracking != K_PRMT_sUNDEFINED) {
  1249. tracking_info = oForm.tracking.value;
  1250. }
  1251. else if (typeof tracking != K_PRMT_sUNDEFINED) {
  1252. tracking_info = tracking;
  1253. }
  1254. }
  1255. }
  1256. return tracking_info;
  1257. };
  1258. cognos.Prompt.Control.prototype.cacheControlValue = function (sType)
  1259. {
  1260. if (SYSTEMPROPERTY_TREE_CACHE_ENABLED)
  1261. {
  1262. var sTracking = this.getTracking();
  1263. if (sTracking.length == 0) return;
  1264. var selectDateTimeControl = this.getCachedDateTimePromptNames(sTracking);
  1265. if (selectDateTimeControl != null)
  1266. {
  1267. if (cognos.Prompt.Control.isElementInList(this.getName(),selectDateTimeControl))
  1268. {
  1269. // this is a DateTime control
  1270. if (sType != "cognos.Prompt.Control.DateTime")
  1271. {
  1272. // getting a notification of a "has-a" control so ignore
  1273. return;
  1274. }
  1275. }
  1276. }
  1277. // to avoid recursion DateTime control where attempt to get value calls checkData
  1278. if ((typeof cognos.Prompt.Control.prototype.cacheControlValue.running != 'undefined') && cognos.Prompt.Control.prototype.cacheControlValue.running)
  1279. {
  1280. return;
  1281. }
  1282. else
  1283. {
  1284. cognos.Prompt.Control.prototype.cacheControlValue.running = true;
  1285. }
  1286. if (this.cacheUseValue(sTracking))
  1287. {
  1288. this.cachePromptName(sTracking);
  1289. }
  1290. cognos.Prompt.Control.prototype.cacheControlValue.running = false;
  1291. }
  1292. };
  1293. cognos.Prompt.Control.prototype.getUseValues = function()
  1294. {
  1295. var sValues = "";
  1296. var v_aValues = this.getValues();
  1297. if (v_aValues)
  1298. {
  1299. for (var j = 0; j < v_aValues.length; j++)
  1300. {
  1301. var v_oValue = v_aValues[j];
  1302. sValues += v_oValue["use"];
  1303. }
  1304. }
  1305. return sValues
  1306. };
  1307. cognos.Prompt.Control.prototype.cacheDateTimeControlName = function (sTracking)
  1308. {
  1309. var sCacheKey = this.generateUniqueDateTimeKey(sTracking);
  1310. this.cacheControlName(sTracking,sCacheKey);
  1311. };
  1312. cognos.Prompt.Control.prototype.cacheControlName = function (sTracking,sCacheKey)
  1313. {
  1314. var sPreviousValue = window.sessionStorage.getItem(sCacheKey);
  1315. var bAddToList = true;
  1316. if (sPreviousValue != null)
  1317. {
  1318. if (sPreviousValue.length != 0)
  1319. {
  1320. // only add if name is not already in list
  1321. bAddToList = !cognos.Prompt.Control.isElementInList(this.getName(), sPreviousValue);
  1322. if (bAddToList) {
  1323. sPreviousValue += K_PRMT_TREE_CACHE_LIST_SEP;
  1324. }
  1325. }
  1326. if (bAddToList) {
  1327. sPreviousValue += this.getName();
  1328. }
  1329. }
  1330. else
  1331. {
  1332. sPreviousValue = this.getName();
  1333. }
  1334. if (bAddToList) {
  1335. this.saveToSessionStorage(sCacheKey,sPreviousValue,sTracking);
  1336. }
  1337. };
  1338. cognos.Prompt.Control.prototype.cacheUseValue = function (sTracking)
  1339. {
  1340. var bReturnValue = false;
  1341. var sValues = this.getUseValues();
  1342. if (sValues && sValues.length > 0)
  1343. {
  1344. var sCacheKey = this.generateUniqueValueKey(sTracking);
  1345. this.saveToSessionStorage(sCacheKey,sValues,sTracking);
  1346. bReturnValue = true;
  1347. }
  1348. return bReturnValue;
  1349. };
  1350. cognos.Prompt.Control.prototype.cachePromptName = function (sTracking)
  1351. {
  1352. var sCacheKey = this.generateUniquePromptKey(sTracking);
  1353. this.cacheControlName(sTracking,sCacheKey);
  1354. };
  1355. cognos.Prompt.Control.prototype.saveToSessionStorage = function(sCacheKey, sValue, sTrackingInfo)
  1356. {
  1357. // save tracking so we can clear our entries
  1358. if (!sTrackingInfo)
  1359. {
  1360. sTrackingInfo = this.getTracking();
  1361. }
  1362. var sPreviousValue = "";
  1363. sPreviousValue = window.sessionStorage.getItem(K_PRMT_TREE_CACHE_TRACKING);
  1364. if (!sPreviousValue)
  1365. {
  1366. this.writeToSessionStorage(K_PRMT_TREE_CACHE_TRACKING,sTrackingInfo);
  1367. }
  1368. else
  1369. {
  1370. if (!cognos.Prompt.Control.isElementInList(sTrackingInfo, sPreviousValue))
  1371. {
  1372. sPreviousValue += K_PRMT_TREE_CACHE_LIST_SEP;
  1373. sPreviousValue += sTrackingInfo;
  1374. // add tracking info
  1375. this.writeToSessionStorage(K_PRMT_TREE_CACHE_TRACKING,sPreviousValue);
  1376. }
  1377. }
  1378. this.writeToSessionStorage(sCacheKey, sValue);
  1379. };
  1380. cognos.Prompt.Control.prototype.writeToSessionStorage = function(key, value, bNoRetryWhenFull)
  1381. {
  1382. if ((key == null) || (value == null)) return;
  1383. if ((key == "") || (value == "")) return;
  1384. try
  1385. {
  1386. window.sessionStorage.setItem(key,value);
  1387. }
  1388. catch(e)
  1389. {
  1390. if (!bNoRetryWhenFull)
  1391. {
  1392. this.cleanCacheValues();
  1393. this.saveToSessionStorage(key,value,true);
  1394. }
  1395. }
  1396. };
  1397. cognos.Prompt.Control.prototype.cleanCacheValues = function()
  1398. {
  1399. if (SYSTEMPROPERTY_TREE_CACHE_ENABLED)
  1400. {
  1401. try
  1402. {
  1403. var sKnownTrackingIds =
  1404. window.sessionStorage.getItem(K_PRMT_TREE_CACHE_TRACKING);
  1405. var aTrackingIds = sKnownTrackingIds.split(K_PRMT_TREE_CACHE_LIST_SEP);
  1406. for (var i = 0; i < aTrackingIds.length; i++)
  1407. {
  1408. var sTrackingId = aTrackingIds[i];
  1409. // build key for prompt names
  1410. var sCacheKeyPromptNames = K_PRMT_TREE_CACHE_NAMES + sTrackingId;
  1411. var sSavedPromptNames = window.sessionStorage.getItem(sCacheKeyPromptNames);
  1412. var aPromptNames = sSavedPromptNames.split(K_PRMT_TREE_CACHE_LIST_SEP);
  1413. for (var j = 0; j < aPromptNames.length; j++)
  1414. {
  1415. var sPromptName = aPromptNames[j];
  1416. // delete the display value
  1417. var sPromptDisplayKey = K_PRMT_TREE_CACHE_VALUES + sTrackingId + sPromptName;
  1418. window.sessionStorage.removeItem(sPromptDisplayKey);
  1419. }
  1420. // delete the prompt names
  1421. window.sessionStorage.removeItem(sCacheKeyPromptNames);
  1422. // delete the DateTime prompt names
  1423. sCacheKeyPromptNames = K_PRMT_TREE_CACHE_SELECTDATETIME + sTrackingId;
  1424. window.sessionStorage.removeItem(sCacheKeyPromptNames);
  1425. }
  1426. // delete the tracking ids
  1427. window.sessionStorage.removeItem(K_PRMT_TREE_CACHE_TRACKING);
  1428. }
  1429. catch(e)
  1430. {
  1431. }
  1432. }
  1433. };
  1434. cognos.Prompt.Control.prototype.getCachedDateTimePromptNames = function(sTracking)
  1435. {
  1436. var sCacheKey = K_PRMT_TREE_CACHE_SELECTDATETIME + sTracking;
  1437. var promptNames = window.sessionStorage.getItem(sCacheKey);
  1438. return promptNames;
  1439. };
  1440. cognos.Prompt.Control.prototype.getCachedPromptNames = function(sTracking)
  1441. {
  1442. var sCacheKey = K_PRMT_TREE_CACHE_NAMES + sTracking;
  1443. var promptNames = window.sessionStorage.getItem(sCacheKey);
  1444. return promptNames;
  1445. };
  1446. cognos.Prompt.Control.prototype.getCachedDisplayValues = function (sTracking, sPrmtName)
  1447. {
  1448. var sCacheKey = K_PRMT_TREE_CACHE_VALUES + sTracking + sPrmtName;
  1449. var sPromptValues = window.sessionStorage.getItem(sCacheKey);
  1450. return sPromptValues;
  1451. };
  1452. cognos.Prompt.Control.prototype.generateUniqueDateTimeKey = function(sTracking)
  1453. {
  1454. return K_PRMT_TREE_CACHE_SELECTDATETIME + sTracking;
  1455. };
  1456. cognos.Prompt.Control.prototype.generateUniqueValueKey = function(sTracking)
  1457. {
  1458. return K_PRMT_TREE_CACHE_VALUES + sTracking + this.getName();
  1459. };
  1460. cognos.Prompt.Control.prototype.generateUniquePromptKey = function(sTracking)
  1461. {
  1462. return K_PRMT_TREE_CACHE_NAMES + sTracking;
  1463. };
  1464. /**
  1465. Sets a property for one control. Each control will defined what property they are 'listening' to.
  1466. For examaple: This is to be able to set 'caseInsensitive' option for a Search control.
  1467. Supported properties: <small>[defined by the type of controls]</small>
  1468. @param {String} sName Property name.
  1469. @param {object} oValue Can be a string, number, boolean, object.
  1470. @return {void}
  1471. @example <ul>
  1472. <li>ctrl.setProperty( "<tt>caseInsensitive</tt>", <tt>true</tt> );</li>
  1473. <li>ctrl.setProperty( "<tt>searchType</tt>", "<tt>startsWith</tt>" );</li>
  1474. </ul>
  1475. */
  1476. cognos.Prompt.Control.prototype.setProperty = function(sName, oValue) {};
  1477. /**
  1478. Overrides CSS style for a control. The control will decide which part of it is updated based on the style passed in.
  1479. For example: You can't specify the width of the text box a date control here, setting the width will resize the whole calendar.
  1480. Supported styles:
  1481. <tt>background</tt>(-*),
  1482. <tt>border</tt>(-*),
  1483. <tt>color</tt>,
  1484. <tt>display</tt>,
  1485. <tt>font</tt>(-*),
  1486. <tt>height</tt> <small>(absolute sizes)</small>,
  1487. <tt>overflow</tt>,
  1488. <tt>text-decoration</tt>,
  1489. <tt>text-transform</tt>,
  1490. <tt>visibility</tt>,
  1491. <tt>width</tt> <small>(absolute sizes)</small>.
  1492. @param {String} sStyle CSS string.
  1493. @return {void}
  1494. @example <ul>
  1495. <li>ctrl.setStyle( "<tt>display:none</tt>" );</li>
  1496. <li>ctrl.setStyle( "<tt>border:1px solid blue;background-color:yellow;</tt>" );</li>
  1497. </ul>
  1498. */
  1499. cognos.Prompt.Control.prototype.setStyle = function(sStyle) {};
  1500. /**
  1501. The following function is included for the Cognos Mobile case, where the MooTools Javascript framework
  1502. has also defined a function $( id ), which has a document context that is not able to find the element in the DOM.
  1503. Mobile will be upgrading MooTools in their next release, and their $( id ) method is aliased in later version when
  1504. a $ function already exists. So once the upgrade is done, this code will be able to be removed.
  1505. @private
  1506. @param id - identifier for the element being requested
  1507. @return the element requested, or null
  1508. */
  1509. cognos.Prompt.Control.prototype.$ = function(id) {
  1510. var v_el = $( id );
  1511. if(!v_el){
  1512. v_el = document.getElementById(id);
  1513. }
  1514. return v_el;
  1515. };
  1516. var C_PromptControl = cognos.Prompt.Control; // Keep old reference for backward compatibility with custom scripts.