C_Choices.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2018
  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. function C_Choices( v_oPrompt )
  13. {
  14. this.m_oPrompt = v_oPrompt;
  15. this.m_selList = null;
  16. this.m_tpl_optionHTML = ['<option value="','','" display="','','" pvxml="','','" pvJSON="','','" style="white-space:pre"','','>','','</option>'];
  17. };
  18. /**
  19. See {@link cognos.Prompt.Control.addValues} for more info.
  20. @param {cognos.Value[]}
  21. @return {void}
  22. */
  23. C_Choices.prototype.addValues = function( aValues )
  24. {
  25. for (var v_idx = 0; v_idx < aValues.length; v_idx++)
  26. {
  27. this.F_AddPV( aValues[v_idx] );
  28. }
  29. };
  30. /**
  31. @private
  32. @return {void}
  33. */
  34. C_Choices.prototype.checkData = function()
  35. {
  36. this.f_updateWidth();
  37. var v_ef = this.m_oErrorFeedback;
  38. if ( v_ef )
  39. {
  40. var v_sClass = ( this.m_sErrorFeedbackClass ? this.m_sErrorFeedbackClass : "clsFeedbackWidgetParseError" );
  41. if ( this.m_oPrompt.isRequired() && this.F_IsEmpty() )
  42. {
  43. PRMTUtils.f_addClass( v_ef, v_sClass );
  44. PRMTUtils.f_showARIAFail(this.m_selList, this.f_getId(), this.m_oPrompt.m_sSkin, PMT_UIM_MISSING_VALUE, K_PRMT_ALERT_CHOICES_SUFFIX);
  45. }
  46. else
  47. {
  48. PRMTUtils.f_removeClass( v_ef, v_sClass );
  49. PRMTUtils.f_showARIAPass(this.m_selList, this.f_getId(), K_PRMT_ALERT_CHOICES_SUFFIX);
  50. }
  51. }
  52. this.m_oPrompt.checkData();
  53. };
  54. /**
  55. @private
  56. @return {boolean}
  57. */
  58. C_Choices.prototype.checkInsertRemove = function()
  59. {
  60. this.f_updateButton( this.m_btnRemove, this.f_hasSelection() );
  61. var v_oP = this.m_oPrompt;
  62. this.f_updateButton( this.m_btnInsert, v_oP.hasValue() );
  63. return this.f_getValid();
  64. };
  65. /**
  66. @private
  67. @return {void}
  68. */
  69. C_Choices.prototype.f_updateButton = function(v_btn, v_bState)
  70. {
  71. if ( v_btn )
  72. {
  73. var v_oImgEl = (v_btn.firstChild && v_btn.firstChild.tagName == "IMG"? v_btn.firstChild : v_btn.childNodes[1]);
  74. var v_bInsertType = (v_btn.id.indexOf("INSERT")!= -1? true:false);
  75. var v_dir = this.m_dir;
  76. if ( v_bState && !this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
  77. {
  78. v_btn.disabled = false;
  79. v_oImgEl.className = ( (v_bInsertType && v_dir== "ltr") || (!v_bInsertType && v_dir== "rtl") ? "clsInsertImg" : "clsRemoveImg" );
  80. }
  81. else
  82. {
  83. v_btn.className = "clsInsertRemoveButton";
  84. v_btn.disabled = true;
  85. if (v_oImgEl) {
  86. v_oImgEl.className = ( (v_bInsertType && v_dir== "ltr") || (!v_bInsertType && v_dir== "rtl") ? "clsInsertImgDisabled" : "clsRemoveImgDisabled" );
  87. }
  88. }
  89. }
  90. };
  91. /**
  92. @private
  93. @return {void}
  94. */
  95. C_Choices.prototype.f_updateWidth = function()
  96. {
  97. var v_selList = this.m_selList;
  98. if ( v_selList && !this["@listWidth"] )
  99. {
  100. v_selList.style.overflow = "auto";
  101. v_selList.style.width = "auto";
  102. if ( v_selList.offsetWidth < 200 )
  103. {
  104. v_selList.style.width = "200px";
  105. }
  106. if (window.ie)
  107. {
  108. if (v_selList.parentNode && v_selList.parentNode.style)
  109. {
  110. // 560392: make sure the table's width follows the select's width
  111. v_selList.parentNode.style.width = "200px";
  112. v_selList.parentNode.style.width = "auto";
  113. }
  114. else {
  115. // 585565
  116. return;
  117. }
  118. }
  119. if (v_selList.offsetWidth < 200)
  120. {
  121. setTimeout( this.f_updateWidth.bind( this ), 100 );
  122. }
  123. }
  124. };
  125. /**
  126. @private
  127. @return {boolean}
  128. */
  129. C_Choices.prototype.F_IsEmpty = function()
  130. {
  131. if ( this.m_selList && this.m_selList.options && this.m_selList.options.length > 0 )
  132. {
  133. return false;
  134. }
  135. return true;
  136. };
  137. /**
  138. @private
  139. @return {void}
  140. */
  141. C_Choices.prototype.F_Draw = function( v_el )
  142. {
  143. this.f_drawInsertRemoveButtons( v_el );
  144. this.f_drawList( $CE( "td", {"vAlign":"top"}, v_el ) );
  145. };
  146. /**
  147. @private
  148. @return {void}
  149. */
  150. C_Choices.prototype.f_getId = function( v_sPrefix )
  151. {
  152. return ( this.m_oPrompt.f_getId( v_sPrefix ) );
  153. };
  154. /**
  155. @private
  156. @return {void}
  157. */
  158. C_Choices.prototype.F_DrawCompleted = function()
  159. {
  160. var v_btnInsert = $( this.f_getId(K_PRMT_sLIST_BUTTON_INSERT_PREFIX) );
  161. if ( v_btnInsert )
  162. {
  163. v_btnInsert.m_oEH = this;
  164. PRMTUtils.f_addEvent( v_btnInsert, "click", this.F_Insert.bind(this) );
  165. this.m_btnInsert = v_btnInsert;
  166. }
  167. var v_btnRemove = $( this.f_getId(K_PRMT_sLIST_BUTTON_REMOVE_PREFIX) );
  168. if ( v_btnRemove )
  169. {
  170. v_btnRemove.m_oEH = this;
  171. PRMTUtils.f_addEvent( v_btnRemove, "click", this.F_Remove.bind(this) );
  172. this.m_btnRemove = v_btnRemove;
  173. }
  174. var v_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
  175. if ( v_selList )
  176. {
  177. v_selList.m_oPrompt = this.m_oPrompt;
  178. PRMTUtils.f_addEvent( v_selList, "change", this.checkData.bind(this) );
  179. this.m_selList = v_selList;
  180. }
  181. // dblclick
  182. var v_resultList = $( this.f_getId(K_PRMT_sSV_PREFIX) );
  183. if ( v_resultList )
  184. {
  185. PRMTUtils.f_addEvent( v_resultList, "dblclick", this.F_Insert.bind(this) );
  186. }
  187. var v_choicesList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
  188. if ( v_choicesList )
  189. {
  190. PRMTUtils.f_addEvent( v_choicesList, "dblclick", this.F_Remove.bind(this) );
  191. }
  192. var v_link = $( this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX) );
  193. if ( v_link )
  194. {
  195. v_link.m_oEH = this;
  196. PRMTUtils.f_addEvent( v_link, "click", this.F_SelectAll.bind(this) );
  197. }
  198. var v_link = $( this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX) );
  199. if ( v_link )
  200. {
  201. v_link.m_oEH = this;
  202. PRMTUtils.f_addEvent( v_link, "click", this.F_DeselectAll.bind(this) );
  203. }
  204. this.m_oErrorFeedback = $( this.f_getId( K_PRMT_sLIST_FEEDBACK_PREFIX ) );
  205. this.checkData();
  206. if (typeof SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS != K_PRMT_sUNDEFINED && SYSTEMPROPERTY_CREATE_CUSTOM_SCRIPTS_REFS)
  207. {
  208. this.f_CSW_init();
  209. }
  210. };
  211. /**
  212. @private
  213. @return {void}
  214. */
  215. C_Choices.prototype.f_drawInsertRemoveButtons = function( v_el )
  216. {
  217. var v_iTopPadding = ( this.m_oPrompt["@showCondition"] ? 42 : 16 );
  218. var v_td0 = $CE( "td", {"vAlign": "top", "class": "clsButtonLeftRightPadding", "style":"padding-top:" + v_iTopPadding + "px"}, v_el );
  219. var v_sCustomDir = cssParser( this.m_oPrompt["@style"], "direction", true );
  220. this.m_dir = ( ( v_sCustomDir == "rtl" || PRMT_BidiUtils.lookupDirection($( this.m_oPrompt.f_getId(this.m_oPrompt.m_sDivPrefix) )) == "rtl") ? "rtl" : "ltr");
  221. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":2, "cellSpacing":0, "class":"clsInsertRemoveTable", "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td0 );
  222. var v_tbd = $CE( "tbody", {}, v_tbl );
  223. var v_tr = $CE( "tr", {}, v_tbd );
  224. var v_td = $CE( "td", {"width": "100%"}, v_tr );
  225. this.f_drawInsertButton( v_td );
  226. v_tr = $CE( "tr", {}, v_tbd );
  227. v_td = $CE( "td", {"width": "100%"}, v_tr );
  228. this.f_drawRemoveButton( v_td );
  229. };
  230. /**
  231. @private
  232. @return {void}
  233. */
  234. C_Choices.prototype.f_drawInsertButton = function( v_el )
  235. {
  236. var v_btn = $CE( "button", {
  237. "id": this.f_getId(K_PRMT_sLIST_BUTTON_INSERT_PREFIX),
  238. "type": "button",
  239. "title": PMT_UIM_INSERTTIP,
  240. "class": "clsInsertRemoveButton"
  241. }, v_el );
  242. var v_span = $CE( "span", {}, v_btn);
  243. v_span.f_appendText( this.m_oPrompt[K_PRMT_LABEL_INSERT] );
  244. var v_sImgClass = ( this.m_dir == "ltr" ? "clsInsertImg" : "clsRemoveImg" );
  245. if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
  246. {
  247. v_btn.f_setProperty( "disabled", "disabled" );
  248. v_sImgClass = ( this.m_dir == "ltr" ? "clsInsertImgDisabled" : "clsRemoveImgDisabled" );
  249. }
  250. var v_img = $CE( "img", {
  251. "src": this.m_oPrompt.m_sSkin + "/prompting/images/blank.gif",
  252. "alt": PMT_UIM_INSERTTIP,
  253. "class": v_sImgClass,
  254. "border": 0,
  255. "height": 16,
  256. "width": 16,
  257. "align": "top"
  258. }, v_btn);
  259. v_btn.f_setProperty( "onMouseOver", "this.className = 'clsInsertRemoveButtonOver';" );
  260. v_btn.f_setProperty( "onMouseOut", "this.className = 'clsInsertRemoveButton';" );
  261. return v_btn;
  262. };
  263. C_Choices.prototype.f_drawRemoveButton = function( v_el )
  264. {
  265. var v_btn = $CE( "button", {
  266. "id": this.f_getId(K_PRMT_sLIST_BUTTON_REMOVE_PREFIX),
  267. "type": "button",
  268. "title": PMT_UIM_REMOVETIP,
  269. "class": "clsInsertRemoveButton"
  270. }, v_el );
  271. var v_sImgClass = ( this.m_dir == "ltr" ? "clsRemoveImg" : "clsInsertImg" );
  272. if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
  273. {
  274. v_btn.f_setProperty( "disabled", "disabled" );
  275. v_sImgClass = ( this.m_dir == "ltr" ? "clsRemoveImgDisabled" : "clsInsertImgDisabled" );
  276. }
  277. var v_img = $CE( "img", {
  278. "src": this.m_oPrompt.m_sSkin + "/prompting/images/blank.gif", //"/prompting/images/remove.gif",
  279. "alt": PMT_UIM_REMOVETIP,
  280. "class": v_sImgClass,
  281. "border": 0,
  282. "height": 16,
  283. "width": 16,
  284. "align": "top"
  285. }, v_btn);
  286. var v_span = $CE( "span", {}, v_btn);
  287. v_span.f_appendText( this.m_oPrompt[K_PRMT_LABEL_REMOVE] );
  288. v_btn.f_setProperty( "onMouseOver", "this.className = 'clsInsertRemoveButtonOver';" );
  289. v_btn.f_setProperty( "onMouseOut", "this.className = 'clsInsertRemoveButton';" );
  290. return v_btn;
  291. };
  292. /**
  293. @private
  294. @return {void}
  295. */
  296. C_Choices.prototype.f_drawList = function( v_el )
  297. {
  298. // Caption
  299. var v_tdCaption = $CE( "div", {"class": "clsControlLabel pc"}, v_el );
  300. if ( this.m_oPrompt.isRequired() && !this.m_oPrompt["@hideAdornments"] )
  301. {
  302. $CE( "img", {"src": this.m_oPrompt.m_sSkin + "/prompting/images/icon_required.gif", "class": "clsErrorRequired", "align":"top", "height":10, "width":10, "border":0, "alt":""}, v_tdCaption );
  303. }
  304. var v_selectId = this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX);
  305. if ( this.m_oPrompt["@showCondition"] )
  306. {
  307. v_tdCaption.f_setProperty("style", "padding:0px 0px 5px 0px;");
  308. var v_captionLabel = $CE( "label", { "for": v_selectId }, v_tdCaption );
  309. v_captionLabel.f_appendText( PMT_UIM_CONDITION );
  310. v_captionLabel.f_appendChild( "<br/>" );
  311. var v_select = $CE( "select", { "id": this.f_getId("oExcludeSelectedValues") }, v_tdCaption );
  312. var v_opt = $CE( "option", { "value": "false" }, v_select );
  313. v_opt.f_appendText( PMT_UIM_SHOWONLY );
  314. v_opt = $CE( "option", { "value": "true" }, v_select );
  315. v_opt.f_appendText( PMT_UIM_DONOTSHOW );
  316. }
  317. else
  318. {
  319. var v_captionLabel = $CE( "label", { "for": v_selectId }, v_tdCaption );
  320. v_captionLabel.f_appendText( this.m_oPrompt[K_PRMT_LABEL_CHOICES] );
  321. }
  322. // Select box to show selected values
  323. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_el );
  324. var v_tbd = $CE( "tbody", {}, v_tbl );
  325. var v_trSelect = $CE( "tr", {}, v_tbd );
  326. var v_tdSelect = $CE( "td", {"vAlign":"top"}, v_trSelect );
  327. var v_select = $CE( "select", {
  328. "id": v_selectId,
  329. "size": ( this["@listSize"] ? this["@listSize"] : 7),
  330. "multiple": "multiple",
  331. "class": "clsListControl pv",
  332. "role": "listbox",
  333. "aria-multiselectable": "true"
  334. }, v_tdSelect );
  335. if ( this.m_oPrompt.isRequired() )
  336. {
  337. v_select.f_setProperty("aria-required","true");
  338. }
  339. // Combine @style && @listStyle, @listStyle is used by the Search control.
  340. var v_sListStyle = cssParser( this.m_oPrompt["@style"], 'color,font,text' );
  341. if ( this["@listStyle"] )
  342. {
  343. v_sListStyle = ( v_sListStyle ? v_sListStyle : K_PRMT_sEMPTY ) + this["@listStyle"];
  344. }
  345. if ( this["@listWidth"] )
  346. {
  347. v_sListStyle = ( v_sListStyle ? v_sListStyle + ";" : K_PRMT_sEMPTY ) + "width:" + this["@listWidth"];
  348. }
  349. if ( v_sListStyle )
  350. {
  351. v_sListStyle = cssParser( v_sListStyle, 'background,color,font,text,height,width' );
  352. v_select.f_setProperty( "style", v_sListStyle );
  353. }
  354. // Feedback for non-valid lists
  355. var v_trFB = $CE( "tr", {}, v_tbd );
  356. var v_tdFB = $CE( "td", {}, v_trFB );
  357. var v_divFB = $CE( "div", {
  358. "id": this.f_getId( K_PRMT_sLIST_FEEDBACK_PREFIX ),
  359. "class": "clsFeedbackWidget",
  360. "style": "min-width:200px; width:100%;"
  361. }, v_tdFB );
  362. var v_imgFB = $CE( "img", {
  363. "class": "clsFeedbackSpacer",
  364. "src": this.m_oPrompt.m_sSkin + "/prompting/images/spacer.gif",
  365. "alt": K_PRMT_sEMPTY,
  366. "width": "100%",
  367. "height": 3
  368. }, v_divFB);
  369. // Links to select/deselect all
  370. var v_trLinks = $CE( "tr", {}, v_tbd );
  371. var v_sCustomDir = cssParser( this.m_oPrompt["@style"], "direction", true );
  372. var v_FinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection($( this.m_oPrompt.f_getId(this.m_oPrompt.m_sDivPrefix) )));
  373. var v_sAlignStyle = ( ( v_FinalDir == "rtl" ) ? "left" : "right");
  374. var v_tdLinks = $CE( "td", {"align": v_sAlignStyle}, v_trLinks );
  375. // draw selectAll and deselectAll button-links
  376. if ( this.m_oPrompt[K_PRMT_sATTR_DISABLED] )
  377. {
  378. v_select.f_setProperty( "disabled", "disabled" );
  379. var v_spanProps = {
  380. "class": "clsLink",
  381. "style": "text-decoration:underline;color: #CCCCCC"
  382. };
  383. var v_span = $CE( "span", v_spanProps, v_tdLinks );
  384. v_span.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL]);
  385. v_tdLinks.f_appendText( K_PRMT_sSP );
  386. v_span = $CE( "span", v_spanProps, v_tdLinks );
  387. v_span.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL]);
  388. }
  389. else
  390. {
  391. var v_a1 = $CE("a", {
  392. "id": (v_sAlignStyle == "right") ? this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX) : this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX),
  393. "href": "javascript:;",
  394. "onclick": "document.location.hash='';",
  395. "class": "clsLink pl"
  396. }, v_tdLinks );
  397. v_a1.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] );
  398. v_tdLinks.f_appendText( K_PRMT_sSP );
  399. var v_a2 = $CE( "a", {
  400. "id": (v_sAlignStyle == "right") ? this.f_getId(K_PRMT_sLIST_LINK_DESELECT_PREFIX) : this.f_getId(K_PRMT_sLIST_LINK_SELECT_PREFIX),
  401. "href": "javascript:;",
  402. "onclick": "document.location.hash='';",
  403. "class": "clsLink pl"
  404. }, v_tdLinks );
  405. v_a2.f_appendText( (v_sAlignStyle == "right") ? this.m_oPrompt[K_PRMT_LABEL_CHOICES_DESELECT_ALL] : this.m_oPrompt[K_PRMT_LABEL_CHOICES_SELECT_ALL]);
  406. }
  407. };
  408. /**
  409. * formate unformated dates provided to use from report server
  410. **/
  411. C_Choices.prototype.formatDefaultDateChoice = function(dateChoice, calType) {
  412. var dateArray = dateChoice.replace("T","-").split("-");
  413. if (dateArray.length >= 3){
  414. var tmpDate = new Date(dateArray[0],dateArray[1] - 1,dateArray[2]);
  415. return getFormatDate(tmpDate,calType);
  416. }
  417. return null;
  418. };
  419. /**
  420. update display type attributes for items that report server does not gives us one
  421. **/
  422. C_Choices.prototype.f_fixDisplayValues = function(item, iType){
  423. if (item && item[K_PRMT_sUSE] && !item[K_PRMT_sDISPLAY]) {
  424. item[K_PRMT_sATTR_DISPLAY_VALUE] = this.formatDefaultDateChoice(item[K_PRMT_sATTR_USE_VALUE], iType);
  425. item[K_PRMT_sDISPLAY] = this.formatDefaultDateChoice(item[K_PRMT_sUSE], iType);
  426. }
  427. };
  428. /**
  429. * Set selection
  430. */
  431. C_Choices.prototype.f_setSelectChoices = function(v_oSelChoices)
  432. {
  433. if ( v_oSelChoices && this.m_selList )
  434. {
  435. var uniqueSet = {};
  436. // build the HTML string for the new options, preallocate the array
  437. var v_newOptions = new Array(v_oSelChoices.length);
  438. var v_len = v_oSelChoices.length;
  439. var v_item = null;
  440. var v_sUse = null;
  441. for ( var i = 0; i < v_len; i++ ){
  442. v_item = v_oSelChoices[ i ];
  443. v_item = cognos.Value.getValue(v_item);
  444. //have to manually parse this as the value returned by report server is inexcplicably unformated
  445. if (this.m_oPrompt.n == "selectDate"){
  446. if (v_item.f_isRange()){
  447. this.f_fixDisplayValues(v_item.start, this.m_oPrompt.m_oFrom.m_oControl.m_iType);
  448. this.f_fixDisplayValues(v_item.end, this.m_oPrompt.m_oFrom.m_oControl.m_iType);
  449. } else {
  450. this.f_fixDisplayValues(v_item, this.m_oPrompt.m_oControl.m_iType);
  451. }
  452. }
  453. // Skip duplicated
  454. v_sUse = this.f_getUseValueRO(v_item);
  455. if (!uniqueSet[v_sUse]) {
  456. v_newOptions[i] = this.f_generateOptionHTMLFromValue( v_item );
  457. uniqueSet[v_sUse] = 1;
  458. }
  459. }
  460. var v_sNewOpString = v_newOptions.join('');
  461. if (window.ie) {
  462. var sOuter = this.m_selList.outerHTML;
  463. var sNew = sOuter.replace(/<\/select\s*>\s*$/i, K_PRMT_sEMPTY) + v_sNewOpString + '<' + '/' + 'SELECT>';
  464. this.m_selList.outerHTML = sNew;
  465. // reset the object attributes and events
  466. this.m_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
  467. this.m_selList.m_oPrompt = this.m_oPrompt;
  468. PRMTUtils.f_addEvent( this.m_selList, "change", this.checkData.bind(this) );
  469. } else {
  470. this.m_selList.innerHTML += v_sNewOpString;
  471. }
  472. }
  473. this.checkData();
  474. };
  475. /*
  476. * Read Only get Use value
  477. */
  478. C_Choices.prototype.f_getUseValueRO = function(v_Value) {
  479. var v_sUseMember = v_Value['use'];
  480. var v_sUse = v_Value.f_getUse();
  481. if (v_Value['use'] != v_sUseMember) {
  482. if (typeof v_sUseMember == K_PRMT_sUNDEFINED) {
  483. delete v_Value['use'];
  484. } else {
  485. v_Value['use'] = v_sUseMember;
  486. }
  487. }
  488. return v_sUse;
  489. };
  490. /**
  491. @private
  492. @return {void}
  493. */
  494. C_Choices.prototype.F_DeselectAll = function()
  495. {
  496. if ( this.m_selList )
  497. {
  498. this.m_selList.selectedIndex = -1;
  499. for (var i = 0; i < this.m_selList.options.length; i++)
  500. {
  501. this.m_selList.options[i].selected = false;
  502. }
  503. //In IE10, the selected items still appear selected until the list box gets focus
  504. this.m_selList.focus();
  505. this.m_selList.blur();
  506. }
  507. this.checkInsertRemove();
  508. };
  509. /**
  510. @desc Build the string for one SELECT option for the given parameter
  511. @private
  512. @return {String} Object that hold the option data
  513. */
  514. C_Choices.prototype.f_generateOptionHTML = function( v_oPV )
  515. {
  516. v_oPV = cognos.Value.getValue(v_oPV);
  517. return this.f_generateOptionHTMLFromValue(v_oPV);
  518. };
  519. /**
  520. @desc Build the string for one SELECT option for the given parameter
  521. from already pre-processed value
  522. @private
  523. @return {String} Object that hold the option data
  524. */
  525. C_Choices.prototype.f_generateOptionHTMLFromValue = function( v_oPV )
  526. {
  527. var v_sJSON = cognos.Value.toJSON( v_oPV );
  528. var v_sUse = v_oPV.f_getUse();
  529. if ( G_IsBidiEnabled && this.m_oPrompt["@contentTextDirection"] )
  530. {
  531. v_oPV.contentTextDir = this.m_oPrompt["@contentTextDirection"];
  532. }
  533. var v_sDisplay = sHtmlEncode(v_oPV.f_getDisplay());
  534. var v_sXML = cognos.Value.toXML( v_oPV );
  535. /*
  536. Building an HTML option from the array template, which has the following structure. The variables follow the notation: v_VarName
  537. <option value=" (0)
  538. v_sUse (1)
  539. "display=" (2)
  540. v_sDisplay (3)
  541. " pvxml=" (4)
  542. v_sSafeXML (5)
  543. " pvJSON=" (6)
  544. v_sJSON (7)
  545. " style="white-space:pre" (8)
  546. [selected] (9)
  547. > (10)
  548. v_sDisplay (11)
  549. </option> (12)
  550. */
  551. this.m_tpl_optionHTML[1] = v_sUse;
  552. this.m_tpl_optionHTML[3] = v_sDisplay;
  553. this.m_tpl_optionHTML[5] = v_sXML.f_xmlSafe();
  554. this.m_tpl_optionHTML[7] = v_sJSON.replace(K_PRMT_reQU, K_PRMT_sQU_encoded);
  555. this.m_tpl_optionHTML[9] = v_oPV["@selected"]? ' selected' : '';
  556. this.m_tpl_optionHTML[11] = ( G_IsBidiEnabled && this.m_oPrompt["@contentTextDirection"] ? PRMT_BidiUtils.enforceBidiDirection(v_sDisplay, this.m_oPrompt["@contentTextDirection"]) : v_sDisplay);
  557. result = this.m_tpl_optionHTML.join('');
  558. return result;
  559. };
  560. /**
  561. Returns the parameter values selected in this control.
  562. @private
  563. @return {ParmValueItem[]} Array of parameter values (ParmValueItem and derived classes).
  564. */
  565. C_Choices.prototype.getParameterValues = function()
  566. {
  567. var v_aPV = [];
  568. var v_opt = null;
  569. var v_selList = this.m_selList;
  570. if ( v_selList.options && v_selList.options.length > 0 )
  571. {
  572. for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
  573. {
  574. v_opt = v_selList.options[v_iIdx];
  575. var v_sJSON = v_opt.getAttribute("pvJSON");
  576. if ( v_sJSON ) {
  577. var v_oVal = cognos.Value.getValue( eval("v=" + v_sJSON) );
  578. v_aPV.push( v_oVal );
  579. }
  580. }
  581. };
  582. return v_aPV;
  583. };
  584. /**
  585. @private
  586. @return {void}
  587. */
  588. C_Choices.prototype.f_getPV = function()
  589. {
  590. var v_selList = this.m_selList;
  591. var v_aPV = [];
  592. var v_opt = null;
  593. var v_sXML = K_PRMT_sEMPTY;
  594. var v_sUse = K_PRMT_sEMPTY;
  595. var v_sDisplay = K_PRMT_sEMPTY;
  596. if ( v_selList && v_selList.options && v_selList.options.length > 0 )
  597. {
  598. for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
  599. {
  600. v_opt = v_selList.options[v_iIdx];
  601. v_aPV.push( v_opt.getAttribute("pvXML") );
  602. }
  603. };
  604. return v_aPV;
  605. };
  606. //get the validity without checking the data first
  607. C_Choices.prototype.f_getValid = function()
  608. {
  609. return (!this.m_oPrompt.isRequired() || (this.m_selList && this.m_selList.options && this.m_selList.options.length > 0) );
  610. };
  611. /**
  612. @private
  613. @return {void}
  614. */
  615. C_Choices.prototype.f_hasSelection = function()
  616. {
  617. return ( this.m_selList && this.m_selList.selectedIndex >= 0 );
  618. };
  619. /**
  620. @private
  621. @return {void}
  622. */
  623. C_Choices.prototype.F_Contains = function( v_oPV )
  624. {
  625. if ( this.m_selList && this.m_selList.options && this.m_selList.options.length )
  626. {
  627. var v_sXML = cognos.Value.toXML( v_oPV );
  628. for ( var i = 0; i < this.m_selList.options.length; i++ )
  629. {
  630. if ( this.m_selList.options[i].getAttribute("pvXML") == v_sXML )
  631. {
  632. return true;
  633. }
  634. }
  635. }
  636. return false;
  637. };
  638. /**
  639. @private
  640. @return {void}
  641. */
  642. C_Choices.prototype.F_AddPV = function( v_oPV )
  643. {
  644. // Don't add it if it's already there
  645. if ( this.F_Contains( v_oPV ) )
  646. {
  647. return;
  648. }
  649. v_oPV = cognos.Value.getValue(v_oPV);
  650. var v_sJSON = cognos.Value.toJSON( v_oPV );
  651. var v_sUse = v_oPV.f_getUse();
  652. var v_sDisplay = v_oPV.f_getDisplay();
  653. var v_sXML = cognos.Value.toXML( v_oPV );
  654. var v_opt = PRMTUtils.f_createElement( "option", {"value": v_sUse, "display": v_sDisplay, "pvXML": v_sXML, "pvJSON": v_sJSON, "style": "white-space:pre"}, this.m_selList );
  655. if ( v_oPV["@selected"] )
  656. {
  657. v_opt["selected"] = "selected";
  658. }
  659. v_opt["pv"] = v_oPV;
  660. PRMTUtils.f_addText( v_opt, v_sDisplay );
  661. };
  662. /**
  663. @private
  664. @return {void}
  665. */
  666. C_Choices.prototype.F_Insert = function()
  667. {
  668. if ( this.m_oPrompt )
  669. {
  670. var v_oPV = this.m_oPrompt.f_getPV();
  671. if ( this.m_selList && v_oPV )
  672. {
  673. if ( !v_oPV.length ) { v_oPV = [ v_oPV] ; } // cast into an array
  674. // build the HTML string for the new options, preallocate the array
  675. var v_newOptions = new Array(v_oPV.length);
  676. for ( var v_idx = 0; v_idx < v_oPV.length; v_idx++ )
  677. {
  678. // Skip duplicated
  679. if (! this.F_Contains( v_oPV[ v_idx ] ) )
  680. {
  681. v_newOptions[v_idx] = this.f_generateOptionHTML( v_oPV[ v_idx ] );
  682. }
  683. }
  684. var v_sNewOpString = v_newOptions.join('');
  685. if (window.ie)
  686. {
  687. var sOuter = this.m_selList.outerHTML;
  688. var sNew = sOuter.replace(/<\/select\s*>\s*$/i, K_PRMT_sEMPTY) + v_sNewOpString + '<' + '/' + 'SELECT>';
  689. this.m_selList.outerHTML = sNew;
  690. // reset the object attributes and events
  691. this.m_selList = $( this.f_getId(K_PRMT_sLIST_BOX_SELECT_PREFIX) );
  692. this.m_selList.m_oPrompt = this.m_oPrompt;
  693. PRMTUtils.f_addEvent( this.m_selList, "change", this.checkData.bind(this) );
  694. }
  695. else
  696. {
  697. this.m_selList.innerHTML += v_sNewOpString;
  698. }
  699. }
  700. if ( this.m_oPrompt && typeof this.m_oPrompt.f_clear == K_PRMT_sFUNCTION )
  701. {
  702. this.m_oPrompt.f_clear();
  703. }
  704. }
  705. this.checkData();
  706. };
  707. /**
  708. @private
  709. @return {void}
  710. */
  711. C_Choices.prototype.F_Remove = function()
  712. {
  713. if ( this.m_selList )
  714. {
  715. for (var i = this.m_selList.options.length-1; i >= 0; i--)
  716. {
  717. if ( this.m_selList.options[i].selected )
  718. {
  719. PRMTUtils.f_removeElement( this.m_selList.options[i] );
  720. }
  721. }
  722. }
  723. this.checkData();
  724. };
  725. /**
  726. @private
  727. @return {void}
  728. */
  729. C_Choices.prototype.F_SelectAll = function()
  730. {
  731. if ( this.m_selList )
  732. {
  733. for (var i = 0; i < this.m_selList.options.length; i++)
  734. {
  735. this.m_selList.options[i].selected = true;
  736. }
  737. }
  738. this.checkInsertRemove();
  739. };
  740. /*
  741. @private
  742. @desc Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
  743. (Custom Scripts Workaround)
  744. */
  745. C_Choices.prototype.f_CSW_init = function()
  746. {
  747. var v_sPrefix = null;
  748. var v_oPrompt = this.m_oPrompt;
  749. if (v_oPrompt)
  750. {
  751. switch( v_oPrompt.n )
  752. {
  753. case "selectInterval": v_sPrefix = "multipleIntervalPicker"; break;
  754. case "textBox": v_sPrefix = "multipleText"; break;
  755. case "selectDate": v_sPrefix = "multipleDatePicker"; break;
  756. case "selectDateTime": v_sPrefix = "multipleDateTimePicker"; break;
  757. case "selectTime": v_sPrefix = "multipleTimePicker"; break;
  758. }
  759. if ( v_sPrefix )
  760. {
  761. this.f_CSW_createJSObject( v_sPrefix );
  762. }
  763. }
  764. };
  765. /**
  766. @private
  767. @return {object} The newly associated object, incidently 'this'.
  768. @desc Adds a javascript reference using 'prefix' and this control's name.
  769. (Custom Scripts Workaround)
  770. */
  771. C_Choices.prototype.f_CSW_createJSObject = function( v_sPrefix )
  772. {
  773. var v_oPrompt = this.m_oPrompt;
  774. if ( v_oPrompt && v_oPrompt["@name"] )
  775. {
  776. var v_sName = v_sPrefix + v_oPrompt["@name"];
  777. if ( !window[v_sName] )
  778. {
  779. window[v_sName] = this;
  780. }
  781. return (window[v_sName]);
  782. }
  783. return null;
  784. };
  785. /**
  786. 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.
  787. See {@link cognos.Value} for the format of the returned values.
  788. @return {cognos.Value[]}
  789. @example <ul>
  790. <li>Text box prompt (single): <tt>[ {use: "Smith", display: "Smith"} ]</tt></li>
  791. <li>Select prompt (multiple): <tt>[ {use: "CAN", display: "Canada"}, {use: "JPN", display: "Japan"} ]</tt></li>
  792. <li>Tree prompt (multiple): <tt>[ {use: "[Americas].[Canada]", display: "Canada"}, {use: "[Asia].[Japan]", display: "Japan"} ]</tt></li>
  793. </ul>
  794. */
  795. C_Choices.prototype.getValues = function()
  796. {
  797. var v_aValues = [];
  798. var v_sJSON = null;
  799. var v_selList = this.m_selList;
  800. if ( v_selList != null && v_selList.options && v_selList.options.length > 0 )
  801. {
  802. for ( var v_iIdx = 0; v_iIdx < v_selList.options.length; v_iIdx++ )
  803. {
  804. v_sJSON = v_selList.options[v_iIdx].getAttribute("pvJSON");
  805. if ( v_sJSON ) {
  806. v_aValues.push( eval("v=" + v_sJSON) );
  807. }
  808. }
  809. };
  810. return v_aValues;
  811. };