SelectValue.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2021
  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. @file This script is used to provide interactivity for the SelectValue single and multiple select prompt components.
  14. */
  15. /**
  16. @private
  17. @class
  18. */
  19. cognos.Prompt.Control.SelectValue = cognos.Prompt.Control.f_extend({
  20. f_initialize: function( v_oProps ) {
  21. this._type_ = "cognos.Prompt.Control.SelectValue";
  22. this.f_parent( v_oProps ); // call parent's f_initialize
  23. this.m_aOptions = null;
  24. this.m_aSuperLiterals = [];
  25. this.m_currentlySelected = null;
  26. // set selectValueUI to selectUI
  27. if ( !this.selectUI )
  28. {
  29. this.selectUI = this["@selectValueUI"];
  30. }
  31. if ( this.m_oRangeControl )
  32. {
  33. this.selectUI = "dropdown";
  34. }
  35. if ( this.selectUI == "checkboxGroup" && !this.isMulti() )
  36. {
  37. this.selectUI = "radioGroup";
  38. }
  39. else if ( this.selectUI == "radioGroup" && this.isMulti() )
  40. {
  41. this.selectUI = "checkboxGroup";
  42. }
  43. else if ( this.selectUI == "dropdown" )
  44. {
  45. this["@multiSelect"] = false;
  46. }
  47. this.f_initCompleted();
  48. },
  49. checkData: function() {
  50. this.m_bValid = true;
  51. var v_bPass = this.f_parent(); // call parent's checkData
  52. if ( !v_bPass || (this.isRequired() && !this.hasValue() ))
  53. {
  54. this.m_bValid = false;
  55. this.checkFail();
  56. }
  57. else
  58. {
  59. this.m_bValid = true;
  60. this.checkPass();
  61. }
  62. return this.m_bValid;
  63. },
  64. clearValues: function() {
  65. this.f_parent();
  66. this.f_deselectAll();
  67. },
  68. singleValueSelect: function(event) {
  69. var selectedIndex = event.target.selectedIndex;
  70. var options = this.f_getOptions();
  71. var selected = options[selectedIndex];
  72. //only set aria-selected = true for valid options
  73. if (selected.hasAttribute("role") && selected.getAttribute("role") === "option") {
  74. if (this.m_currentlySelected !== null) {
  75. this.m_currentlySelected.setAttribute("aria-selected","false");
  76. }
  77. this.m_currentlySelected = selected;
  78. selected.setAttribute("aria-selected","true");
  79. } else {
  80. //if invalid option selected - clear the previously selected
  81. if (this.m_currentlySelected !== null) {
  82. this.m_currentlySelected.setAttribute("aria-selected","false");
  83. this.m_currentlySelected = null;
  84. }
  85. }
  86. },
  87. multiValueSelect: function (event) {
  88. var options = this.f_getOptions();
  89. for (let i = 0 ; i < options.length ; i++ ) {
  90. options[i].setAttribute("aria-selected",options[i].selected);
  91. }
  92. },
  93. f_drawCompleted: function() {
  94. var v_elPrompt = $( this.f_getId(K_PRMT_sSV_PREFIX) );
  95. var v_elContainer = $( this.f_getId("PRMT_SV_CONTAINER_") );
  96. if ( v_elPrompt )
  97. {
  98. var v_CPE = new C_PromptElement();
  99. var v_sStyle = this["@style"];
  100. // @listStyle is used by the search control.
  101. if ( this["@listStyle"] )
  102. {
  103. v_sStyle = (v_sStyle ? v_sStyle : K_PRMT_sEMPTY) + this["@listStyle"];
  104. }
  105. v_CPE.f_setStyle( v_elPrompt, cssParser(this["@style"], "color,font,text") + (this["@listStyle"] ? this["@listStyle"] : K_PRMT_sEMPTY) );
  106. // put it back at the right place.
  107. this.f_moveInContainer( v_elContainer, v_elPrompt );
  108. v_elPrompt.m_oPrompt = this;
  109. var v_sWidth = cssParser( v_sStyle, "width", true );
  110. if ( v_sWidth )
  111. {
  112. if ( this.m_oRangeControl && this.m_oRangeControl.isMulti() )
  113. {
  114. var p = v_elPrompt;
  115. p.style.width = "100%";
  116. var v_reTable = new RegExp("div", "i");
  117. while (p && !p.nodeName.match(v_reTable))
  118. {
  119. p.setAttribute("width", "100%");
  120. p = p.parentNode;
  121. }
  122. }
  123. else
  124. {
  125. v_elPrompt.style.width = v_sWidth;
  126. }
  127. }
  128. var v_sHeight = cssParser( v_sStyle, "height", true );
  129. if ( v_sHeight && this.selectUI != "dropdown" )
  130. {
  131. v_elPrompt.style.height = v_sHeight;
  132. v_elPrompt.style.maxHeight = "none";
  133. }
  134. if ( this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup" )
  135. {
  136. // link a11y label if it exists
  137. var v_a11yLabel = $( this.f_getId("PRMT_LBL_") );
  138. if ( v_a11yLabel ) {
  139. var v_container = $( this.f_getId("PRMT_SV_CONTAINER_") );
  140. v_container.setAttribute("aria-labelledby", this.f_getId("PRMT_LBL_"));
  141. }
  142. var v_sChildStyle = cssParser( v_sStyle, "color,font,text" );
  143. if ( v_sChildStyle )
  144. {
  145. var v_oChild = v_elPrompt.firstChild;
  146. while ( v_oChild )
  147. {
  148. v_CPE.f_setStyle( v_oChild, v_sChildStyle );
  149. v_oChild = v_oChild.nextSibling;
  150. }
  151. }
  152. }
  153. else
  154. {
  155. // link a11y label if it exists using FOR
  156. var v_a11yLabel = $( this.f_getId("PRMT_LBL_") );
  157. if ( v_a11yLabel && !v_a11yLabel.getAttribute("for")) {
  158. v_a11yLabel.setAttribute("for", this.f_getId("PRMT_SV_"));
  159. }
  160. // @listSize is used by the cognos.Prompt.Control.Search.
  161. if ( this["@listSize"] )
  162. {
  163. v_elPrompt.setAttribute( "size", this["@listSize"] );
  164. v_elPrompt.selectedIndex=-1;
  165. }
  166. else if ( this.selectUI == "listBox" )
  167. {
  168. v_elPrompt.setAttribute( "size", "11" );
  169. v_elPrompt.selectedIndex=-1;
  170. }
  171. else if ( this.selectUI == "dropdown" && !this.isMulti() && typeof this["@columnName"] == K_PRMT_sUNDEFINED)
  172. {
  173. v_elPrompt.selectedIndex=(window.isAllowEmptyStringHeaderText && !window.isAllowEmptyStringHeaderText()) ? 0 : -1;
  174. }
  175. if ( !this.isMulti() )
  176. {
  177. v_elPrompt.removeAttribute( "multiple" );
  178. v_elPrompt.setAttribute("aria-multiselectable", 'false');
  179. //REPORT-13599
  180. PRMTUtils.f_addEvent( v_elPrompt, "change", this.singleValueSelect.bind(this) );
  181. } else {
  182. v_elPrompt.setAttribute("aria-multiselectable", 'true');
  183. //REPORT-13599
  184. PRMTUtils.f_addEvent( v_elPrompt, "change", this.multiValueSelect.bind(this) );
  185. }
  186. if ( this.isRequired() )
  187. {
  188. v_elPrompt.setAttribute("aria-required", true);
  189. }
  190. }
  191. if ( typeof SYSTEMPROPERTY_CHANGE_DROPDOWN_BACKGROUNDCOLOR_ALL !== K_PRMT_sUNDEFINED
  192. && SYSTEMPROPERTY_CHANGE_DROPDOWN_BACKGROUNDCOLOR_ALL === true )
  193. {
  194. if ( this.selectUI == "listBox" || this.selectUI == "dropdown" )
  195. {
  196. var v_sBackgroundColor = cssParser( v_sStyle, "background-color", true );
  197. if ( v_sBackgroundColor )
  198. {
  199. v_elPrompt.style.backgroundColor = v_sBackgroundColor;
  200. }
  201. }
  202. }
  203. if ( this[K_PRMT_sATTR_DISABLED] )
  204. {
  205. v_elPrompt.setAttribute( "disabled", "disabled" );
  206. }
  207. PRMTUtils.f_addEvent( v_elPrompt, "change", this.f_onChange.bind(this) );
  208. // ipad quirk, Select with one option does not fire onChange, but it fires onBlur
  209. if (this.selectUI == "listBox" && PRMTUtils.f_isMobileDevice()) {
  210. PRMTUtils.f_addEvent( v_elPrompt, "blur", this.f_onBlur.bind(this) );
  211. }
  212. this.m_elPrompt = v_elPrompt;
  213. }
  214. var v_link = $( this.f_getId(K_PRMT_sSV_LINK_SELECT_PREFIX) );
  215. if ( v_link )
  216. {
  217. PRMTUtils.f_addEvent( v_link, "click", this.f_selectAll.bind(this) );
  218. }
  219. v_link = $( this.f_getId(K_PRMT_sSV_LINK_DESELECT_PREFIX) );
  220. if ( v_link )
  221. {
  222. PRMTUtils.f_addEvent( v_link, "click", this.f_deselectAll.bind(this) );
  223. }
  224. this.f_parent(); // call parent's f_drawCompleted
  225. // set the classnames
  226. if (this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup") {
  227. //set the css class to the option parent DIV
  228. var v_aOptions = this.f_getOptions();
  229. var v_iLength = v_aOptions.length;
  230. var isFirstTabIndexSet = false;
  231. for (var i = 0; i < v_iLength; i++) {
  232. var v_cb = v_aOptions[i];
  233. var v_div = v_cb.parentNode;
  234. if (v_cb.type == "checkbox") {
  235. v_div.className = (v_cb.checked ? K_PRMT_CSS_CHECKBOX_CHECKED : K_PRMT_CSS_CHECKBOX);
  236. PRMTUtils.f_addEvent( v_div, "keydown", this.f_checkboxKeyNav.bind(this) );
  237. if (!isFirstTabIndexSet) {
  238. v_cb.tabIndex = 0;
  239. isFirstTabIndexSet = true;
  240. } else {
  241. v_cb.tabIndex = -1;
  242. }
  243. } else {
  244. v_div.className = (v_cb.checked ? K_PRMT_CSS_RADIOBUTTON_CHECKED : K_PRMT_CSS_RADIOBUTTON);
  245. }
  246. PRMTUtils.f_updateElementAriaChecked(v_cb, v_cb.checked);
  247. var v_label = v_div.nextSibling;
  248. if ( G_IsBidiEnabled && v_label && this["@contentTextDirection"] ) {
  249. v_label.innerHTML = PRMT_BidiUtils.enforceBidiDirection(v_label.innerHTML, PRMT_BidiUtils.getTextDirection(v_label.firstChild.nodeValue, this["@contentTextDirection"]));
  250. }
  251. if ( this.isRequired() ) {
  252. v_cb.setAttribute("aria-required", true);
  253. }
  254. }
  255. }
  256. else {
  257. var v_aOptions = this.f_getOptions();
  258. for (var i = 0; i < v_aOptions.length; i++)
  259. {
  260. var v_elOption = v_aOptions[i];
  261. if ( G_IsBidiEnabled && v_elOption && this["@contentTextDirection"] ) {
  262. v_elOption.innerHTML = PRMT_BidiUtils.enforceBidiDirection(v_elOption.innerHTML, PRMT_BidiUtils.getTextDirection(v_elOption.firstChild.nodeValue, this["@contentTextDirection"]));
  263. }
  264. }
  265. }
  266. // FIXME: remove the hardcoded minimal width and use CSS
  267. if (!this.f_isBUX()) {
  268. setTimeout( this.f_updateSize.bind(this), 20 );
  269. }
  270. // focus Select control
  271. var oCV = this.f_getCV();
  272. if (oCV && typeof oCV.getCurrentPromptControlFocus == K_PRMT_sFUNCTION){
  273. if (this["@name"] == oCV.getCurrentPromptControlFocus()) {
  274. var v_elPrompt = $( this.f_getId(K_PRMT_sSV_PREFIX) );
  275. v_elPrompt.focus();
  276. oCV.setCurrentPromptControlFocus(null);
  277. }
  278. }
  279. }
  280. });
  281. /**
  282. * Getter for range inputId
  283. * rangeInputId used by range label to associate the label (From/To) to the input when there are not radio buttons
  284. *
  285. */
  286. cognos.Prompt.Control.SelectValue.prototype.f_getRangeInputId = function() {
  287. return (this.m_oRangeControl ? this.f_getId(K_PRMT_sSV_PREFIX) : null );
  288. }
  289. /**
  290. *
  291. Adds an option element to the list of candidates for a choice.
  292. @private
  293. @param {HTMLelement} v_option
  294. @param {cognos.Value[]} v_aSC
  295. @return {void}
  296. */
  297. cognos.Prompt.Control.SelectValue.prototype.f_addCandidateForSelection = function(v_option, v_aSC)
  298. {
  299. for (var i = 0; i < v_aSC.length; i++)
  300. {
  301. v_aSC[i].m_aCandidates.push(
  302. { "option": v_option, "score": this.f_getScore(v_aSC[i], v_option) }
  303. );
  304. }
  305. };
  306. /**
  307. Adds an option element to the list of candidates for a choice.
  308. @private
  309. @param {object} v_oMap
  310. @param {String} v_sKey
  311. @param {object} v_oValue
  312. @return {void}
  313. */
  314. cognos.Prompt.Control.SelectValue.prototype.f_addOptionInValueMap = function( v_oMap, v_sKey, v_oValue )
  315. {
  316. if (typeof(v_oValue.m_aCandidates) === K_PRMT_sUNDEFINED )
  317. {
  318. // A choice will need an array for candidates.
  319. v_oValue.m_aCandidates = [];
  320. }
  321. v_sKey = sDecodeU003( v_sKey );
  322. if ( v_oMap[v_sKey] )
  323. {
  324. v_oMap[v_sKey].push( v_oValue );
  325. }
  326. else
  327. {
  328. v_oMap[v_sKey] = [v_oValue];
  329. }
  330. };
  331. /**
  332. Select the elements which have the best match for each choice.
  333. @private
  334. @param v_oChoices The 'selectChoices' node from RSVP.
  335. @return {void}
  336. */
  337. cognos.Prompt.Control.SelectValue.prototype.f_applySelection = function(v_oChoices)
  338. {
  339. var i;
  340. var v_oCandidate = null;
  341. var v_aCandidates = null;
  342. var v_aToSelect = null;
  343. var v_iHighScore = 0;
  344. for ( var v_idx = 0; v_idx < v_oChoices.c.length; v_idx++ )
  345. {
  346. v_aCandidates = v_oChoices.c[v_idx].m_aCandidates;
  347. if (v_aCandidates && v_aCandidates.length)
  348. {
  349. v_aToSelect = [];
  350. v_iHighScore = 0;
  351. // Find candidates with highest score
  352. for (i = 0; i < v_aCandidates.length; i++)
  353. {
  354. v_oCandidate = v_aCandidates[i];
  355. if (v_oCandidate.score > v_iHighScore)
  356. {
  357. v_aToSelect = [];
  358. v_iHighScore = v_oCandidate.score;
  359. }
  360. if (v_oCandidate.score === v_iHighScore)
  361. {
  362. v_aToSelect.push(v_oCandidate.option);
  363. }
  364. }
  365. // apply selection
  366. for (i=0; i < v_aToSelect.length; i++)
  367. {
  368. v_aToSelect[i].checked = true;
  369. v_aToSelect[i].selected = true;
  370. }
  371. }
  372. }
  373. };
  374. /**
  375. Compare values. See {@link cognos.Prompt.Control#f_compare} for details.
  376. @see cognos.Prompt.Control#f_compare
  377. @private
  378. @return {Integer}
  379. */
  380. cognos.Prompt.Control.SelectValue.prototype.f_compare = function( v_oValue )
  381. {
  382. var v_iRetval = 1;
  383. if ( SYSTEMPROPERTY_REORDER_DROPDOWN_VALUES_IN_RANGES === true && v_oValue )
  384. {
  385. // f_compare is used by Ranges. We supposed we are using DROPDOWN controls.
  386. var v_iThis = this.m_elPrompt.selectedIndex;
  387. var v_iCompareTo = v_oValue.m_elPrompt.selectedIndex;
  388. if ( v_iCompareTo > v_iThis )
  389. {
  390. v_iRetval = -1;
  391. }
  392. else if ( v_iCompareTo == v_iThis )
  393. {
  394. v_iRetval = 0;
  395. }
  396. }
  397. return v_iRetval;
  398. };
  399. /**
  400. Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
  401. (Custom Scripts Workaround)
  402. @private
  403. @return {void}
  404. */
  405. cognos.Prompt.Control.SelectValue.prototype.f_CSW_init = function()
  406. {
  407. var v_sPrefix = "listBox";
  408. switch( this.selectUI )
  409. {
  410. case "checkboxGroup": v_sPrefix = "checkBoxList"; break;
  411. case "radioGroup": v_sPrefix = "radioList"; break;
  412. }
  413. var v_oPC = this.f_CSW_createJSObject( v_sPrefix );
  414. if ( v_oPC )
  415. {
  416. if (typeof v_oPC.selectAll == K_PRMT_sUNDEFINED )
  417. {
  418. v_oPC.selectAll = this.f_selectAll.bind(this);
  419. }
  420. if (typeof v_oPC.checkData == K_PRMT_sUNDEFINED )
  421. {
  422. v_oPC.checkData = this.checkData.bind(this);
  423. }
  424. }
  425. if ( this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup" )
  426. {
  427. var aChoices = document.getElementsByName( this.f_getId("pOpt_") );
  428. if (aChoices.length > 0)
  429. {
  430. if (aChoices.length == 1) {
  431. aChoices = aChoices[0];
  432. }
  433. this.f_CSW_SetFormElement("_oLstChoices", aChoices);
  434. }
  435. }
  436. else {
  437. this.f_CSW_SetFormElement("_oLstChoices");
  438. }
  439. };
  440. /**
  441. @private
  442. @param {boolean} v_bSelected
  443. @return {void}
  444. */
  445. cognos.Prompt.Control.SelectValue.prototype.f_deselectAll = function( v_bSelected )
  446. {
  447. this.f_selectAll( false );
  448. };
  449. /**
  450. Draws a deselect link inside of the container passes as a param
  451. @private
  452. @param {C_PromptElement} v_div Container
  453. @return {void}
  454. */
  455. cognos.Prompt.Control.SelectValue.prototype.f_drawDeselectLink = function( v_div )
  456. {
  457. var v_a1 = $CE("a", {
  458. "id": this.f_getId(K_PRMT_sSV_LINK_DESELECT_PREFIX),
  459. "href": "javascript:;",
  460. "onclick": "document.location.hash='';",
  461. "class": "clsLink pl"},
  462. v_div );
  463. v_a1.f_appendText( this[K_PRMT_LABEL_DESELECT] );
  464. };
  465. /**
  466. @private
  467. @param {C_PromptElement} v_el Container.
  468. @return {C_PromptElement}
  469. */
  470. cognos.Prompt.Control.SelectValue.prototype.f_drawInput = function( v_el )
  471. {
  472. var v_oInput = $( this.f_getId(K_PRMT_sSV_PREFIX) );
  473. if ( v_oInput && this.f_isHidingGroupingBox() )
  474. {
  475. PRMTUtils.f_removeClass( v_oInput, "clsCheckBoxList" );
  476. PRMTUtils.f_removeClass( v_oInput, "pv" );
  477. PRMTUtils.f_addClass( v_oInput, "clsCheckBoxHidingGroupingList" );
  478. }
  479. var v_oContainer = $CE("div", {"id": this.f_getId("PRMT_SV_CONTAINER_")}, v_el);
  480. var v_sCustomDir = cssParser( this["@style"], "direction", true );
  481. var v_FinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection($( this.f_getId(this.m_sDivPrefix) )));
  482. var v_sAlignStyle = "text-align:" + ( ( v_FinalDir == "rtl" ) ? "left" : "right");
  483. v_oContainer.f_appendText(K_PRMT_sEMPTY);
  484. switch( this.selectUI )
  485. {
  486. case "checkboxGroup":
  487. this.f_drawSelectLinks( v_el, v_sAlignStyle );
  488. break;
  489. case "radioGroup":
  490. if ( !this.isRequired() )
  491. {
  492. var v_div = $CE( "div", {style:v_sAlignStyle}, v_el );
  493. if ( this[K_PRMT_sATTR_DISABLED] )
  494. {
  495. var v_span = $CE( "span", { "class": "clsLink", "style": "text-decoration:underline;color: #CCCCCC" }, v_div );
  496. v_span.f_appendText( this[K_PRMT_LABEL_DESELECT] );
  497. }
  498. else
  499. {
  500. this.f_drawDeselectLink( v_div );
  501. }
  502. }
  503. break;
  504. case "listBox":
  505. if ( this.isMulti() )
  506. {
  507. this.f_drawSelectLinks( v_el, v_sAlignStyle );
  508. }
  509. else if ( !this.isRequired() && typeof this["@columnName"] == K_PRMT_sUNDEFINED )
  510. {
  511. var v_div = $CE( "div", {style:v_sAlignStyle}, v_el );
  512. this.f_drawDeselectLink( v_div );
  513. }
  514. break;
  515. }
  516. return v_oInput;
  517. };
  518. /**
  519. Renders the layout of the control: position lists, adornments and control inputs.
  520. @private
  521. @param {C_PromptElement} v_trLayout Container for this control.
  522. @return {C_PromptElement}
  523. */
  524. cognos.Prompt.Control.SelectValue.prototype.f_drawLayout = function( v_trLayout )
  525. {
  526. if ( !(this["@hideAdornments"] || this.m_bSkipAdornments) )
  527. {
  528. this.f_drawAdornments( v_trLayout );
  529. }
  530. var v_sWidth = cssParser(this["@style"], "width", true);
  531. // set to 100% only if already set to relative size
  532. v_sWidth = ( (/\d%/).test( v_sWidth ) ? "100%" : K_PRMT_sEMPTY );
  533. this.m_elPrompt = this.f_drawInput( $CE( "td", {"width":v_sWidth}, v_trLayout ) );
  534. this.setAriaRequired();
  535. };
  536. /**
  537. @private
  538. @param {C_PromptElement} v_el Container
  539. @return {void}
  540. */
  541. cognos.Prompt.Control.SelectValue.prototype.f_drawSelectLinks = function( v_el, v_sAlignStyle )
  542. {
  543. var v_sStyle = v_sAlignStyle;
  544. if ( typeof SYSTEMPROPERTY_SELECTVALUE_LINKS_NOWRAP !== K_PRMT_sUNDEFINED
  545. && SYSTEMPROPERTY_SELECTVALUE_LINKS_NOWRAP === true ) {
  546. v_sStyle = v_sAlignStyle + ";white-space:nowrap;padding:5px 0px 0px 0px";
  547. }
  548. var v_aSO = this.getSelectOptions();
  549. // bug 538852.1,587743,592296,593802
  550. var v_iLimitWhenToHideLinks = ( this.f_isHidingGroupingBox() ? 1 : 0);
  551. if ( (!v_aSO || v_aSO.length <= v_iLimitWhenToHideLinks) && !this.m_bIsAComponent )
  552. {
  553. v_sStyle += ";display:none";
  554. }
  555. var v_div = $CE( "div", {"style":v_sStyle}, v_el );
  556. if ( this[K_PRMT_sATTR_DISABLED] )
  557. {
  558. var v_spanProps = {
  559. "class": "clsLink",
  560. "style": "text-decoration:underline;color: #CCCCCC"
  561. };
  562. var v_span = $CE( "span", v_spanProps, v_div );
  563. v_span.f_appendText( (v_sAlignStyle == "text-align:right") ? this[K_PRMT_LABEL_RESULTS_SELECT_ALL] : this[K_PRMT_LABEL_RESULTS_DESELECT_ALL]);
  564. v_div.f_appendText( K_PRMT_sSP );
  565. v_span = $CE( "span", v_spanProps, v_div );
  566. v_span.f_appendText( (v_sAlignStyle == "text-align:right") ? this[K_PRMT_LABEL_RESULTS_DESELECT_ALL] : this[K_PRMT_LABEL_RESULTS_SELECT_ALL]);
  567. }
  568. else
  569. {
  570. var v_a1 = $CE( "a", {
  571. "id": (v_sAlignStyle == "text-align:right") ? this.f_getId(K_PRMT_sSV_LINK_SELECT_PREFIX) : this.f_getId(K_PRMT_sSV_LINK_DESELECT_PREFIX),
  572. "href": "javascript:;",
  573. "onclick": "document.location.hash='';",
  574. "class": "clsLink pl"},
  575. v_div );
  576. v_a1.m_oPrompt = this;
  577. v_a1.f_appendText( (v_sAlignStyle == "text-align:right") ? this[K_PRMT_LABEL_RESULTS_SELECT_ALL] : this[K_PRMT_LABEL_RESULTS_DESELECT_ALL] );
  578. v_div.f_appendText( K_PRMT_sSP );
  579. var v_a2 = $CE( "a", {
  580. "id": (v_sAlignStyle == "text-align:right") ? this.f_getId(K_PRMT_sSV_LINK_DESELECT_PREFIX) : this.f_getId(K_PRMT_sSV_LINK_SELECT_PREFIX),
  581. "href": "javascript:;",
  582. "onclick": "document.location.hash='';",
  583. "class": "clsLink pl"},
  584. v_div );
  585. v_a2.f_appendText( (v_sAlignStyle == "text-align:right") ? this[K_PRMT_LABEL_RESULTS_DESELECT_ALL] : this[K_PRMT_LABEL_RESULTS_SELECT_ALL]);
  586. }
  587. };
  588. /**
  589. Return an attribute for an object.
  590. @private
  591. @param {object} v_obj Object acting as dictionary.
  592. @param {String} v_sAttr Key for the value.
  593. @return (String) null if attribute don't exists, return attribute value as a string otherwise.
  594. */
  595. cognos.Prompt.Control.SelectValue.prototype.f_getAttribute = function( v_obj, v_sAttr )
  596. {
  597. var v_sValue = null;
  598. if ( typeof(v_obj[v_sAttr]) !== K_PRMT_sUNDEFINED )
  599. {
  600. v_sValue = v_obj[v_sAttr];
  601. if ( typeof(v_sValue) !== K_PRMT_sSTRING )
  602. {
  603. v_sValue = v_sValue.toString();
  604. }
  605. v_sValue = sDecodeU003( v_sValue );
  606. }
  607. return (v_sValue);
  608. };
  609. /**
  610. @private
  611. @return {array}
  612. */
  613. cognos.Prompt.Control.SelectValue.prototype.f_getOptions = function( )
  614. {
  615. var result = [];
  616. var v_elPrompt = this.m_elPrompt;
  617. if ( v_elPrompt )
  618. {
  619. switch( this.selectUI )
  620. {
  621. case "checkboxGroup":
  622. case "radioGroup":
  623. // find first checked radio or checkbox
  624. // v_elPrompt should be a div with a DIV/input for each value and a label as a second child
  625. var v_div = v_elPrompt.firstChild;
  626. var v_cbDiv = v_div == null ? null : v_div.firstChild;
  627. var v_cb = (v_cbDiv != null && v_cbDiv.firstChild && v_cbDiv.firstChild.tagName == "INPUT" ? v_cbDiv.firstChild : null);
  628. var v_lbl = v_cbDiv == null? null : v_cbDiv.nextSibling;
  629. while ( v_div && (v_cbDiv = v_div.firstChild) && (v_cb) && (v_lbl = v_cbDiv.nextSibling) )
  630. {
  631. v_cb = v_cbDiv.firstChild;
  632. result.push( v_cb );
  633. v_div = v_div.nextSibling;
  634. }
  635. break;
  636. default:
  637. // v_elPrompt should be a select control
  638. result = v_elPrompt.options;
  639. };
  640. }
  641. return result;
  642. };
  643. cognos.Prompt.Control.SelectValue.prototype.f_getOptionPV = function(v_elOption) {
  644. var v_oPV = null;
  645. var v_sUse = v_elOption.getAttribute(K_PRMT_sATTR_USE_VALUE);
  646. if (v_sUse === null)
  647. {
  648. v_sUse = v_elOption.value;
  649. }
  650. // for embedded IE 9 "feature"
  651. if (!v_sUse && v_elOption.attributes && v_elOption.attributes['value']) {
  652. v_sUse = v_elOption.attributes['value'].value;
  653. }
  654. var v_sDisplay = v_elOption.getAttribute(K_PRMT_sATTR_DISPLAY_VALUE);
  655. if (v_sDisplay === null)
  656. {
  657. v_sDisplay = v_elOption.getAttribute(K_PRMT_sDV);
  658. }
  659. var v_oPV = {"use": v_sUse, "display": v_sDisplay};
  660. if ( v_elOption.getAttribute(K_PRMT_sATTR_NULL) || v_elOption.getAttribute(K_PRMT_sNULLUSE) )
  661. {
  662. v_oPV['nil'] = true;
  663. }
  664. return v_oPV;
  665. };
  666. /**
  667. @private
  668. @return {cognos.Value[]}
  669. */
  670. cognos.Prompt.Control.SelectValue.prototype.f_getPV = function(bSkipType, v_allOptions) {
  671. var v_elPrompt = this.m_elPrompt;
  672. var v_aPV = [];
  673. var v_oPV = null;
  674. if ( v_elPrompt && ((this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup") || ( v_elPrompt.selectedIndex >= (v_elPrompt.getAttribute('hasLabel') ? 2 : 0)) || v_allOptions)) {
  675. var v_startScanOption = 0;
  676. var v_sOptionSelectAttr;;
  677. switch( this.selectUI ) {
  678. case "checkboxGroup":
  679. case "radioGroup":
  680. v_sOptionSelectAttr = "checked";
  681. break;
  682. default:
  683. // v_elPrompt should be a select control
  684. v_sOptionSelectAttr = "selected";
  685. v_startScanOption = v_elPrompt.selectedIndex;
  686. };// switch
  687. var v_bBreakAfterOne = !this.isMulti();
  688. var v_aOptions = this.f_getOptions();
  689. var v_iLength = v_aOptions.length;
  690. if (v_allOptions) {
  691. for (var i = 0; i < v_iLength; i++) {
  692. v_aPV.push( this.f_getOptionPV(v_aOptions[i]) );
  693. }
  694. } else {
  695. for (var i = v_startScanOption; i < v_iLength; i++) {
  696. if ( v_aOptions[i][v_sOptionSelectAttr] ) {
  697. v_aPV.push( this.f_getOptionPV(v_aOptions[i]) );
  698. if ( v_bBreakAfterOne ) { break; }
  699. }
  700. }
  701. }
  702. }
  703. return v_aPV;
  704. };
  705. /**
  706. Calculate a score for a option element matching a selectOption node.
  707. Scores:<ul>
  708. <li><b>3</b> if matching the 'use' and the 'display' values (Best Match).</li>
  709. <li><b>2</b> if matching only on the 'use' value.</li>
  710. <li><b>1</b> if matching only on the 'display' value.</li>
  711. <li><b>0</b> if no match.</li></ul>
  712. @private
  713. @param v_nSelectOption The selectOption node.
  714. @param v_elOption The option (UI) element.
  715. @return {Integer}
  716. */
  717. cognos.Prompt.Control.SelectValue.prototype.f_getScore = function( v_nSelectOption, v_elOption )
  718. {
  719. var v_iScore = 0;
  720. if ( this.f_getAttribute(v_nSelectOption, K_PRMT_sATTR_USE_VALUE) === v_elOption.value ) {
  721. v_iScore += 2;
  722. }
  723. if ( this.f_getAttribute(v_nSelectOption, K_PRMT_sATTR_DISPLAY_VALUE) === v_elOption.getAttribute(K_PRMT_sDV) )
  724. {
  725. v_iScore += 1;
  726. }
  727. return v_iScore;
  728. };
  729. /**
  730. Create internal hash maps for selection. One based on 'use' value and one based on 'display' value.
  731. @private
  732. @param v_oChoices The selectChoices node passed in by RSVP.
  733. @return {void}
  734. */
  735. cognos.Prompt.Control.SelectValue.prototype.f_initSelectionDictionaries = function(v_oChoices)
  736. {
  737. var v_sUse, v_sDisplay, v_nSelectOption;
  738. this.m_oMapForUseValuesAndOptions = {};
  739. this.m_oMapForDisplayValuesAndOptions = {};
  740. this.m_bSelectNulls = false;
  741. for ( var v_idx = 0; v_idx < v_oChoices.c.length; v_idx++ )
  742. {
  743. v_nSelectOption = v_oChoices.c[v_idx];
  744. v_sUse = this.f_getAttribute(v_nSelectOption, K_PRMT_sATTR_USE_VALUE);
  745. if ( v_sUse !== null )
  746. {
  747. this.f_addOptionInValueMap( this.m_oMapForUseValuesAndOptions, v_sUse, v_nSelectOption );
  748. }
  749. v_sDisplay = this.f_getAttribute(v_nSelectOption, K_PRMT_sATTR_DISPLAY_VALUE);
  750. if ( v_sDisplay !== null )
  751. {
  752. this.f_addOptionInValueMap( this.m_oMapForDisplayValuesAndOptions, v_sDisplay, v_nSelectOption );
  753. }
  754. if ( typeof( v_nSelectOption[K_PRMT_sATTR_NULL] ) !== K_PRMT_sUNDEFINED )
  755. {
  756. this.m_bSelectNulls = true;
  757. }
  758. }
  759. };
  760. /**
  761. Checks if the box around the options should be hidden or not.
  762. @private
  763. @return <i>true</i> if checkBox groups has only one option (and the property alwaysShowGroupingBox isn't set). Returns <i>false</i> otherwise.
  764. */
  765. cognos.Prompt.Control.SelectValue.prototype.f_isHidingGroupingBox = function()
  766. {
  767. var bRetVal = false;
  768. var v_aSO = this.getSelectOptions();
  769. if ( v_aSO && v_aSO.length == 1 && this.selectUI == "checkboxGroup" && !this["@alwaysShowGroupingBox"] )
  770. {
  771. bRetVal = true;
  772. }
  773. return bRetVal;
  774. };
  775. /**
  776. @private
  777. @param {HTMLelement} v_oContainer
  778. @param {HTMLelement} v_elPrompt
  779. @return {HTMLelement}
  780. */
  781. cognos.Prompt.Control.SelectValue.prototype.f_moveInContainer = function( v_oContainer, v_elPrompt )
  782. {
  783. if ( v_oContainer && v_elPrompt )
  784. {
  785. while (v_oContainer.hasChildNodes())
  786. {
  787. v_oContainer.removeChild(v_oContainer.firstChild);
  788. }
  789. if ( v_elPrompt.parentNode )
  790. {
  791. v_oContainer.appendChild( v_elPrompt.parentNode.removeChild(v_elPrompt));
  792. }
  793. else
  794. {
  795. v_oContainer.appendChild( v_elPrompt );
  796. }
  797. }
  798. return v_oContainer;
  799. };
  800. /**
  801. Event handler to handle keyboard navigation for checkboxes,
  802. using up and down arrows instead of TAB/Shift-TAB
  803. @private
  804. @return {void}
  805. */
  806. cognos.Prompt.Control.SelectValue.prototype.f_checkboxKeyNav = function(evt) {
  807. evt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );
  808. var v_oEvt = (evt || event || null);
  809. var result = false;
  810. if ( v_oEvt ) {
  811. //cancel any text selection //clearSelection();
  812. var v_optionNode = this.f_getChkBoxRow(evt);
  813. var focusDelta = 0;
  814. if ( v_oEvt.type == "keydown" ) {
  815. var keyCode = (v_oEvt.keyCode? v_oEvt.keyCode : v_oEvt.which);
  816. if (v_oEvt.altKey || keyCode == 9 || keyCode == 13 || keyCode == K_KEY_SPACE) {
  817. return true; // Browser should use this, the control does not need alt-modified keys or the TAB key
  818. }
  819. switch (keyCode)
  820. {
  821. case K_KEY_UP:
  822. focusDelta = K_PRMT_FOCUS_MOVE_UP;
  823. break;
  824. case K_KEY_DOWN:
  825. focusDelta = K_PRMT_FOCUS_MOVE_DOWN;
  826. break;
  827. default:
  828. result = true;
  829. //select ?
  830. }
  831. }
  832. if ( focusDelta != 0 ) {
  833. var nextNode = this.f_getRelativeChkbox(focusDelta, v_optionNode);
  834. if (nextNode != null && nextNode != v_optionNode) {
  835. this.f_moveFocus( v_optionNode, nextNode );
  836. }
  837. }
  838. PRMTUtils.F_StopEvent(v_oEvt);
  839. }
  840. return result;
  841. };
  842. /**
  843. * Navigate the DOM to find the DIV node that represents the checkbox row
  844. */
  845. cognos.Prompt.Control.SelectValue.prototype.f_getChkBoxRow = function(evt) {
  846. var uiNode = (evt.target || evt.srcElement || null);
  847. while ( uiNode && !(uiNode.tagName == "DIV" && uiNode.className == "clsCheckBoxRow" ) ){
  848. uiNode = uiNode.parentNode;
  849. }
  850. return uiNode;
  851. };
  852. /**
  853. * Return the next/prev checkbox row depending on the delta. If will loop when it reaches the last
  854. * element in each direction
  855. */
  856. cognos.Prompt.Control.SelectValue.prototype.f_getRelativeChkbox = function(focusDelta, node) {
  857. var result = null;
  858. var parentNode = node.parentNode;
  859. if ( focusDelta == K_PRMT_FOCUS_MOVE_DOWN ) { // Next
  860. if (parentNode.lastChild == node){
  861. result = parentNode.firstChild;
  862. } else if (node.nextSibling && node.nextSibling.className == "clsCheckBoxRow") {
  863. result = node.nextSibling;
  864. }
  865. }
  866. else if ( focusDelta == K_PRMT_FOCUS_MOVE_UP ) { //Prev
  867. if (parentNode.firstChild == node){
  868. result = parentNode.lastChild;
  869. } else if (node.previousSibling && node.previousSibling.className == "clsCheckBoxRow") {
  870. result = node.previousSibling;
  871. }
  872. }
  873. return result;
  874. };
  875. /**
  876. * Move focus for checkbox keyboard navigation
  877. */
  878. cognos.Prompt.Control.SelectValue.prototype.f_moveFocus = function(prevNode, nextNode) {
  879. if (prevNode) {
  880. prevNode.tabIndex = -1;
  881. }
  882. var v_checkbox = (nextNode && nextNode.firstChild ? nextNode.firstChild.firstChild : null) ;
  883. window.setTimeout(function () { if (v_checkbox) { v_checkbox.focus();} },0);
  884. };
  885. /**
  886. Event handler only used for the listbox in the ipad to address an
  887. ipad safari bug with a SELECT tag in a list box format
  888. @private
  889. @return {void}
  890. */
  891. cognos.Prompt.Control.SelectValue.prototype.f_onBlur = function() {
  892. var v_aOptions = this.f_getOptions();
  893. if (v_aOptions.length == 1) {
  894. v_aOptions.selectedIndex = 0;
  895. this.f_onChange();
  896. }
  897. };
  898. /**
  899. @private
  900. @return {void}
  901. */
  902. cognos.Prompt.Control.SelectValue.prototype.f_onChange = function()
  903. {
  904. this.checkData();
  905. if ( this["@autoSubmit"] && (!this.isRequired() || this.getValid()))
  906. {
  907. var oCV = this.f_getCV();
  908. var v_sAutoSubmitType = ( this["@autoCascade"] || !canSubmitPrompt(this["@parameter"], oCV) ? K_ACTION_REPROMPT : K_ACTION_PROMPT );
  909. if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION){
  910. var oReq = new ViewerDispatcherEntry(oCV);
  911. oReq.addFormField("ui.action", K_ACTION_FORWARD);
  912. oReq.addFormField("_autosubmitParameter", this["@parameter"]);
  913. oReq.addFormField("_promptControl", v_sAutoSubmitType);
  914. // set Select control name for focus
  915. oCV.setCurrentPromptControlFocus(this["@name"]);
  916. oCV.submitPromptValues(oReq);
  917. } else {
  918. SetPromptMethod(K_ACTION_FORWARD);
  919. if (document.forms[0]._autosubmitParameter) {
  920. document.forms[0]._autosubmitParameter.value = this["@parameter"];
  921. } else if (document.forms[0]) {
  922. var frm = document.forms[0];
  923. genHiddenInputHTML( frm.name, "_autosubmitParameter", this["@parameter"] );
  924. }
  925. SetPromptControl( v_sAutoSubmitType );
  926. }
  927. }
  928. };
  929. /**
  930. Checks if an option node is a valid candidate to be selected.
  931. @private
  932. @param v_elOption 'option' element in the 'select' (UI node)
  933. @return {void}
  934. */
  935. cognos.Prompt.Control.SelectValue.prototype.f_processOption = function( v_elOption )
  936. {
  937. var v_aSC;
  938. if ( v_aSC = this.m_oMapForUseValuesAndOptions[ v_elOption.value ] )
  939. {
  940. this.f_addCandidateForSelection(v_elOption, v_aSC);
  941. }
  942. if ( v_aSC = this.m_oMapForDisplayValuesAndOptions[v_elOption.getAttribute(K_PRMT_sDV)] )
  943. {
  944. this.f_addCandidateForSelection(v_elOption, v_aSC);
  945. }
  946. if ( this.m_bSelectNulls && v_elOption.getAttribute(K_PRMT_sNULLUSE) )
  947. {
  948. v_elOption.checked = true;
  949. v_elOption.selected = true;
  950. }
  951. };
  952. /**
  953. @private
  954. @param {boolean} v_bSelected
  955. @return {void}
  956. */
  957. cognos.Prompt.Control.SelectValue.prototype.f_selectAll = function( v_bSelected )
  958. {
  959. v_bSelected = ( v_bSelected !== false );
  960. var v_elPrompt = this.m_elPrompt;
  961. if ( v_elPrompt )
  962. {
  963. var v_sOptionSelectAttr = (this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup" ? "checked" : "selected");
  964. var v_aOptions = this.f_getOptions();
  965. var v_iLength = v_aOptions.length;
  966. var v_cb = null;
  967. var v_div = null;
  968. for (var i = 0; i < v_iLength; i++)
  969. {
  970. v_cb = v_aOptions[i];
  971. v_aOptions[i][v_sOptionSelectAttr] = v_bSelected;
  972. if (v_sOptionSelectAttr == "checked") {
  973. v_div = v_cb.parentNode;
  974. if (v_cb.checked) {
  975. v_div.className = (v_cb.type == "checkbox" ? K_PRMT_CSS_CHECKBOX_CHECKED : K_PRMT_CSS_RADIOBUTTON_CHECKED);
  976. }
  977. else {
  978. v_div.className = (v_cb.type == "checkbox" ? K_PRMT_CSS_CHECKBOX : K_PRMT_CSS_RADIOBUTTON);
  979. }
  980. PRMTUtils.f_updateElementAriaChecked(v_cb, v_cb.checked);
  981. } else if (v_sOptionSelectAttr == "selected") {
  982. //REPORT-13599
  983. v_aOptions[i].setAttribute("aria-selected",v_bSelected.toString());
  984. }
  985. }
  986. // fix IE SELECT single mode for DeselectAll(it does not affect FF)
  987. if ( !v_bSelected )
  988. {
  989. v_aOptions.selectedIndex = -1;
  990. }
  991. this.checkData();
  992. }
  993. };
  994. /**
  995. @private
  996. @param {cognos.Value} v_oPV
  997. @return {void}
  998. */
  999. cognos.Prompt.Control.SelectValue.prototype.f_setPV = function( v_oPV ) {
  1000. var v_elPrompt = this.m_elPrompt;
  1001. if ( v_elPrompt ) {
  1002. var v_sOptionSelectAttr = (this.selectUI == "checkboxGroup" || this.selectUI == "radioGroup" ? "checked" : "selected");
  1003. var v_aOptions = this.f_getOptions();
  1004. var v_iLength = v_aOptions.length;
  1005. for (var i = 0; i < v_aOptions.length; i++) {
  1006. var v_option = v_aOptions[i];
  1007. if ( v_option.value == v_oPV[K_PRMT_sUSE] ) {
  1008. v_option[v_sOptionSelectAttr] = true;
  1009. if (v_sOptionSelectAttr == "checked") {
  1010. v_div = v_option.parentNode;
  1011. v_div.className = (v_option.type == "checkbox" ? K_PRMT_CSS_CHECKBOX_CHECKED : K_PRMT_CSS_RADIOBUTTON_CHECKED);
  1012. }
  1013. break;
  1014. }
  1015. }
  1016. }
  1017. };
  1018. /**
  1019. @private
  1020. @param {cognos.Value[]} v_oChoices
  1021. @return {void}
  1022. */
  1023. cognos.Prompt.Control.SelectValue.prototype.f_setSelectChoices = function( v_oChoices )
  1024. {
  1025. if ( !v_oChoices )
  1026. {
  1027. v_oChoices = this.getSelectChoices();
  1028. }
  1029. var v_oPV = null;
  1030. if ( v_oChoices && v_oChoices.c && v_oChoices.c.length > 0)
  1031. {
  1032. this.f_initSelectionDictionaries(v_oChoices);
  1033. var v_elPrompt = this.m_elPrompt;
  1034. if ( v_elPrompt )
  1035. {
  1036. var v_aOptions= this.f_getOptions();
  1037. if ( v_aOptions )
  1038. {
  1039. var v_iLength = v_aOptions.length;
  1040. for (var i = 0; i < v_iLength; i++)
  1041. {
  1042. this.f_processOption(v_aOptions[i]);
  1043. }
  1044. }
  1045. }
  1046. this.f_applySelection(v_oChoices);
  1047. this.checkData();
  1048. // FIXME: remove the hardcoded minimal width and use CSS
  1049. if (!this.f_isBUX()) {
  1050. setTimeout( this.f_updateSize.bind(this), 20 );
  1051. }
  1052. }
  1053. };
  1054. /**
  1055. @private
  1056. @return {void}
  1057. */
  1058. cognos.Prompt.Control.SelectValue.prototype.f_updateSize = function()
  1059. {
  1060. if (document.readyState == "complete")
  1061. {
  1062. var v_elPrompt = this.m_elPrompt;
  1063. var v_sWidth = cssParser( this["@style"], "width", true );
  1064. if ( !v_sWidth )
  1065. {
  1066. // Setting the width to "auto" will resize the box
  1067. if ( v_elPrompt && v_elPrompt.style )
  1068. {
  1069. v_elPrompt.style.width = "auto";
  1070. if (v_elPrompt.offsetWidth < 200)
  1071. {
  1072. // the box is too small, reset the width to its previous value.
  1073. v_elPrompt.style.width = "200px";
  1074. }
  1075. }
  1076. }
  1077. // COGCQ00833069 - If it is IE and we have a horizontal scrollbar, we adjust the height to accomodate the scrollbar so that we don't end up with a vertical scrollbar.
  1078. // The original fix for COGCQ00833069 was changed to address the performance RTC defect #72240 PI46959 PROMPTS IN 10.2.2 TAKES A LONGER TIME TO LOAD
  1079. // The performance degradation was observed in 10.2.2 when compared with 10.2.1
  1080. // FireFox profiler indicates that the function f_updateSize is taking a longer time to execute in 10.2.2 and the fix for COGCQ00833069 was the only code change done between 10.2.1 and 10.2.2
  1081. // Hence, the following code is trying to avoid the multiple dereferencing and the 2nd condition (v_clientHeight < v_scrollHeight && v_scrollHeight < v_offsetHeight )is split in 2 new conditions
  1082. var v_clientHeight = v_elPrompt.clientHeight;
  1083. if ( v_clientHeight ){
  1084. var v_scrollHeight = v_elPrompt.scrollHeight;
  1085. if ( v_clientHeight < v_scrollHeight ) {
  1086. var v_offsetHeight = v_elPrompt.offsetHeight;
  1087. if ( v_scrollHeight < v_offsetHeight ){
  1088. v_elPrompt.style.height = v_offsetHeight + v_scrollHeight - v_clientHeight + "px";
  1089. }
  1090. }
  1091. }
  1092. }
  1093. else if ( document.readyState )
  1094. {
  1095. // IE is still loading the page.
  1096. // FIXME: remove the hardcoded minimal width and use CSS
  1097. if (!this.f_isBUX()) {
  1098. setTimeout(this.f_updateSize.bind(this), 100);
  1099. }
  1100. }
  1101. else
  1102. {
  1103. // Firefox, Mozilla: remove min-width if width is explicitly set in the style.
  1104. var v_sWidth = cssParser( this["@style"], "width", true );
  1105. if ( !v_sWidth )
  1106. {
  1107. var v_elPrompt = this.m_elPrompt;
  1108. if ( v_elPrompt && v_elPrompt.style )
  1109. {
  1110. v_elPrompt.style.minWidth = "200px";
  1111. v_elPrompt.style.width = "auto";
  1112. }
  1113. }
  1114. }
  1115. };
  1116. var C_SelectValue = cognos.Prompt.Control.SelectValue; // Keep old reference for backward compatibility with custom scripts.