Search.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. @private
  14. @class
  15. */
  16. cognos.Prompt.Control.Search = cognos.Prompt.Control.f_extend({
  17. f_initialize: function( v_oProps )
  18. {
  19. this._type_ = "cognos.Prompt.Control.Search";
  20. this.f_parent( v_oProps ); // call parent's initialize()
  21. this.m_sCacheDelimiter = "\n";
  22. this.f_initCompleted();
  23. },
  24. checkData: function()
  25. {
  26. this.f_parent(); // call parent's checkData
  27. var v_aPV = ( this.m_oChoices ? this.m_oChoices.f_getPV() : this.f_getPV() );
  28. var values = ( v_aPV && v_aPV.length > 0 );
  29. if ( this.isRequired() && !values )
  30. {
  31. this.m_bValid = false;
  32. this.checkFail();
  33. }
  34. else
  35. {
  36. this.m_bValid = true;
  37. this.checkPass();
  38. }
  39. if (this.m_bValid)
  40. {
  41. this.cacheControlValue(this._type_);
  42. }
  43. return this.m_bValid;
  44. },
  45. clearValues: function()
  46. {
  47. this.f_parent();
  48. this.f_clearResults();
  49. },
  50. f_drawCompleted: function()
  51. {
  52. // We keep a reference to the parent function.
  53. var v_fnParent = this.f_parent;
  54. var v_oResults = this.m_oResults;
  55. if ( v_oResults )
  56. {
  57. v_oResults.f_drawCompleted();
  58. }
  59. // call parent's checkData using saved reference.
  60. this.f_parent = v_fnParent;
  61. this.f_parent();
  62. var v_inputId = this.f_getId("swsInput");
  63. var v_input = this.$( v_inputId );
  64. if ( typeof Search_DisableEnterKeyAutoSubmit != K_PRMT_sUNDEFINED && Search_DisableEnterKeyAutoSubmit !== true )
  65. {
  66. PRMTUtils.f_addEvent( v_input, "keydown", this.f_keyDownHandler.bind(this) );
  67. }
  68. if ( G_IsBidiEnabled && this["@contentTextDirection"] )
  69. {
  70. PRMTUtils.f_addEvent( v_input, "keyup", this.f_keyUpHandler.bind(this) );
  71. }
  72. var v_elImg = this.$( this.f_getId("imgAdvancedArrow") );
  73. if (v_elImg)
  74. {
  75. var v_td = v_elImg.parentNode;
  76. if ( this[K_PRMT_sATTR_DISABLED] )
  77. {
  78. v_td.setAttribute( "disabled", "disabled" );
  79. }
  80. else
  81. {
  82. var v_elContainer = this.$( this.f_getId("idAdvancedOptions") );
  83. PRMTUtils.f_addEvent( v_elImg.parentNode, "click", this.f_toggleOptions.bind(this) );
  84. }
  85. }
  86. var v_btnSearch = this.$( this.f_getId("searchButton") );
  87. PRMTUtils.f_addEvent( v_btnSearch, "click", this.f_search.bind(this) );
  88. this.f_setDefaultSelection();
  89. if ( G_IsBidiEnabled && this["@contentTextDirection"] ) {
  90. v_input.style.direction = PRMT_BidiUtils.getTextDirection(v_input.value, this["@contentTextDirection"]);
  91. }
  92. // link a11y label if it exists using FOR
  93. var v_a11yLabel = this.$( this.f_getId("PRMT_LBL_") );
  94. if ( v_a11yLabel && !v_a11yLabel.getAttribute("for")) {
  95. v_a11yLabel.setAttribute("for", v_inputId);
  96. }
  97. this.processAriaRequired();
  98. // focus Search and Select control editbox and searchButton
  99. var oCV = this.f_getCV();
  100. if (oCV && typeof oCV.getCurrentPromptControlFocus == K_PRMT_sFUNCTION){
  101. if (this["@name"] == oCV.getCurrentPromptControlFocus()) {
  102. var v_input = this.$( v_inputId );
  103. v_input.focus();
  104. oCV.setCurrentPromptControlFocus(null);
  105. }
  106. if (this["@name"] + "_searchButtonfocus" == oCV.getCurrentPromptControlFocus()) {
  107. v_btnSearch.focus();
  108. oCV.setCurrentPromptControlFocus(null);
  109. }
  110. }
  111. }
  112. });
  113. /**
  114. * If the prompt value is Required add the tag aria-required to the right element
  115. *
  116. See {@link cognos.Prompt.Control.addValues} for more info.
  117. @param {cognos.Value[]}
  118. @return {void}
  119. */
  120. cognos.Prompt.Control.Search.prototype.processAriaRequired = function( ) {
  121. if ( !this.isMulti() ) {
  122. if (this.m_oResults.isRequired()) {
  123. this.m_oResults.setAriaRequired();
  124. }
  125. }
  126. };
  127. /**
  128. See {@link cognos.Prompt.Control.addValues} for more info.
  129. @param {cognos.Value[]}
  130. @return {void}
  131. */
  132. cognos.Prompt.Control.Search.prototype.addValues = function( aValues )
  133. {
  134. if (this.m_oChoices)
  135. {
  136. this.m_oChoices.addValues( aValues );
  137. }
  138. else
  139. {
  140. var v_iLimit = ( this.isMulti() ? aValues.length : 1);
  141. this.cachedResults = this.buildCachedResults();
  142. for (var v_idx = 0; v_idx < v_iLimit; v_idx++)
  143. {
  144. var v_oValue = aValues[v_idx];
  145. this.f_addResults( v_oValue[K_PRMT_sUSE], v_oValue[K_PRMT_sDISPLAY], true );
  146. }
  147. delete this.cachedResults;
  148. this.cachedResults = null;
  149. // We need to enforce Bidi text direction
  150. if ( G_IsBidiEnabled && this["@contentTextDirection"] ) {
  151. this.m_oResults.f_drawCompleted();
  152. }
  153. }
  154. };
  155. /**
  156. @private
  157. @return {void}
  158. */
  159. cognos.Prompt.Control.Search.prototype.buildCachedResults = function()
  160. {
  161. var cache = {};
  162. var v_aOptions = this.m_oResults.m_elPrompt.options;
  163. for (var i = 0; i < v_aOptions.length; i++) {
  164. var v_opt = v_aOptions[i];
  165. cache[ v_opt.value + this.m_sCacheDelimiter + v_opt.getAttribute("dv") ] = v_opt;
  166. }
  167. return cache;
  168. };
  169. /**
  170. @private
  171. @return {void}
  172. */
  173. cognos.Prompt.Control.Search.prototype.f_addResults = function(v_sUse, v_sDisplay, v_bSelected)
  174. {
  175. var v_opt = (this.cachedResults ? this.cachedResults[v_sUse + this.m_sCacheDelimiter + v_sDisplay] : this.f_getOption( v_sUse, v_sDisplay ));
  176. if ( !v_opt )
  177. {
  178. v_opt = new Option( v_sDisplay, v_sUse );
  179. v_opt.setAttribute("dv", v_sDisplay );
  180. var v_elOptions = this.m_oResults.m_elPrompt.options;
  181. v_elOptions[v_elOptions.length] = v_opt;
  182. if (this.cachedResults) {
  183. this.cachedResults[v_sUse + this.m_sCacheDelimiter + v_sDisplay] = v_opt;
  184. }
  185. }
  186. if ( v_bSelected )
  187. {
  188. v_opt.selected = true;
  189. }
  190. };
  191. /**
  192. @private
  193. @return {void}
  194. */
  195. cognos.Prompt.Control.Search.prototype.f_clearResults = function()
  196. {
  197. var v_oResults = this.m_oResults;
  198. if ( v_oResults )
  199. {
  200. v_oResults = v_oResults.m_elPrompt;
  201. while (v_oResults.hasChildNodes()) {
  202. v_oResults.removeChild(v_oResults.firstChild);
  203. }
  204. }
  205. };
  206. /**
  207. Sets the JavaScript references used by custom scripts based on generated code from Blaring and before.
  208. (Custom Scripts Workaround)
  209. @private
  210. @return {void}
  211. */
  212. cognos.Prompt.Control.Search.prototype.f_CSW_init = function()
  213. {
  214. this.f_CSW_createJSObject( "search" );
  215. };
  216. /**
  217. @private
  218. @param {C_PromptElement} v_el Container.
  219. @return {void}
  220. */
  221. cognos.Prompt.Control.Search.prototype.f_drawInput = function( v_el )
  222. {
  223. var v_sPrefix = K_PRMT_sEMPTY;
  224. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0,"role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_el );
  225. var v_tbd = $CE( "tbody", {}, v_tbl );
  226. var v_tr = $CE( "tr", {}, v_tbd );
  227. var v_inputId = this.f_getId( "swsInput" );
  228. var v_td = $CE( "td", {"class": "clsControlLabel pc"}, v_tr );
  229. var v_keywordsLabel = $CE( "label", { "for": v_inputId }, v_td );
  230. v_keywordsLabel.f_appendText( this[K_PRMT_LABEL_SEARCH_KEYWORDS] );
  231. v_tr = $CE( "tr", {}, v_tbd );
  232. v_td = $CE( "td", {"class": "clsDialogIntroduction pi"}, v_tr );
  233. var v_descId = this.f_getId( "swsInputDesc" );
  234. v_td = $CE( "div", {"id": v_descId}, v_td );
  235. v_td.f_appendText(this[K_PRMT_LABEL_SEARCH_INSTRUCTIONS_TEXT]);
  236. // Search criteria & button
  237. v_tr = $CE( "tr", {}, v_tbd );
  238. v_td = $CE( "td", {}, v_tr );
  239. var v_tblCriteria = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_td );
  240. var v_tbdCriteria = $CE( "tbody", {}, v_tblCriteria );
  241. v_tr = $CE( "tr", {}, v_tbdCriteria );
  242. v_td = $CE( "td", {}, v_tr );
  243. var v_ipt = $CE( "input", {
  244. "id": v_inputId,
  245. "type": "text",
  246. "name": v_sPrefix + "_searchValue",
  247. "class": "clsSwsEditBox",
  248. "aria-describedby" : v_descId,
  249. "aria-required" : (this.isRequired() ? "true" : "false"),
  250. "onkeydown": "return (event.keyCode!=13);",
  251. "value": ( typeof this["@searchValue"] != K_PRMT_sUNDEFINED ? this["@searchValue"] : K_PRMT_sEMPTY )
  252. }, v_td );
  253. this.f_setStyle( v_ipt, "swsEditBox" );
  254. v_td = $CE( "td", {nowrap:"nowrap"}, v_tr );
  255. var v_btn = $CE( "button", {
  256. "type": "button",
  257. "name": this.f_getId("searchButton"),
  258. "id": this.f_getId("searchButton"),
  259. "class": "clsPromptButton",
  260. "onMouseOver": "this.className = 'clsPromptButtonOver';",
  261. "onMouseOut": "this.className = 'clsPromptButton';"
  262. }, v_td );
  263. this.f_setStyle( v_btn, "swsSearchButton" );
  264. if ( this[K_PRMT_sATTR_DISABLED] )
  265. {
  266. v_ipt.f_setProperty( "disabled", "disabled" );
  267. v_btn.f_setProperty( "disabled", "disabled" );
  268. }
  269. v_btn.f_appendText( this[K_PRMT_LABEL_SEARCH_BTN_LABEL] );
  270. var v_img = $CE( "img", {
  271. "src": this.m_sSkin + "/prompting/images/prompt_search.gif",
  272. "name": this.f_getId( "imgBusy" ),
  273. "id": this.f_getId( "imgBusy" ),
  274. "alt": K_PRMT_sEMPTY,
  275. "border": "0",
  276. "height": "16",
  277. "width": "15",
  278. "align": "top"
  279. }, v_btn );
  280. // options links
  281. v_tr = $CE( "tr", {}, v_tbd );
  282. v_td = $CE( "td", {"vAlign": "top", "class": "clsOptions pe", "style": "padding:3px;"}, v_tr );
  283. var v_fieldSet = $CE( "fieldset", {"style":"border:0; margin-top:3px; margin-left:0px; padding:0px"}, v_td );
  284. var v_optionsContainerId = this.f_getId("idAdvancedOptions");
  285. var v_optionsLegendId = this.f_getId("idSearchOptionsLegend");
  286. var v_legend = $CE( "legend", {"id": v_optionsLegendId, "aria-controls": v_optionsContainerId, "role": "button", "aria-expanded": false}, v_fieldSet );
  287. var v_linksSpan = $CE( "span", { "style": "padding:0px; margin: 0px;"}, v_legend );
  288. // Use a link, to be a tab stop.
  289. var v_a = $CE( "a", { "class": "clsLink pl", "href": "javascript:;", "onclick": "document.location.hash='';" }, v_linksSpan );
  290. v_a.f_appendText( this[K_PRMT_LABEL_SEARCH_OPTIONS_TEXT] );
  291. var v_sCustomDir = cssParser( this["@style"], "direction", true );
  292. var v_sFinalDir = ((v_sCustomDir == "ltr" || v_sCustomDir == "rtl") ? v_sCustomDir : PRMT_BidiUtils.lookupDirection(this.$( this.f_getId(this.m_sDivPrefix) )));
  293. v_img = $CE( "img", {
  294. "id": this.f_getId("imgAdvancedArrow"),
  295. "class" : "clsSearchOptionsExpand",
  296. "src": this.m_sSkin + "/prompting/images/blank.gif",
  297. "border": "0",
  298. "alt": K_PRMT_sEMPTY,
  299. "align": "top",
  300. "style": (v_sFinalDir == "rtl" ? "margin-right: 5px" : "margin-left: 5px")
  301. }, v_linksSpan );
  302. // Options
  303. var v_div = $CE( "div", {"class": "clsSwsOptions pe"}, v_fieldSet );
  304. this.m_bShowOptions = ( this["@showOptions"] === true );
  305. var v_tblOptions = $CE( "table", {
  306. "id": v_optionsContainerId,
  307. "border": K_PRMT_DEBUG_TABLEBORDER,
  308. "style": ( this.m_bShowOptions ? K_PRMT_sEMPTY : "display:none" ),
  309. "role":K_PRMT_ARIA_ROLE_PRESENTATION
  310. }, v_div );
  311. var v_tbdOptions = $CE( "tbody", {}, v_tblOptions );
  312. var v_nStyle = this.getChildByName("swsOptions");
  313. var v_sOptionStyle = ( v_nStyle && v_nStyle["@style"] ? v_nStyle["@style"] : K_PRMT_sEMPTY );
  314. this.f_drawOption( v_tbdOptions, "swsStartAny", PMT_SSM_STARTANY, v_sOptionStyle, ( !this["@matchAnywhere"] && !this["@matchAll"] ) );
  315. this.f_drawOption( v_tbdOptions, "swsStartAll", PMT_SSM_STARTALL, v_sOptionStyle, ( !this["@matchAnywhere"] && this["@matchAll"] ) );
  316. this.f_drawOption( v_tbdOptions, "swsMatchAny", PMT_SSM_CONTAINANY, v_sOptionStyle, ( this["@matchAnywhere"] && !this["@matchAll"] ) );
  317. this.f_drawOption( v_tbdOptions, "swsMatchAll", PMT_SSM_CONTAINALL, v_sOptionStyle, ( this["@matchAnywhere"] && this["@matchAll"] ) );
  318. this.f_drawOption( v_tbdOptions, "swsCaseInsensitive", PMT_SSM_CASEINSENSITIVE, "padding-top:10px;" + v_sOptionStyle, this["@caseInsensitiveIsDefault"], true );
  319. if ( this["@noResultsFound"] )
  320. {
  321. $CE("div", {
  322. "style": "margin: 5px;white-space:nowrap;",
  323. "tabindex": "0"
  324. }, v_el).f_appendText( PMT_SSM_NORESULTSFOUND );
  325. }
  326. };
  327. /**
  328. @private
  329. @param {C_PromptElement} v_el Container.
  330. @param {C_PromptElement} v_tdLayout Container.
  331. @return {void}
  332. */
  333. cognos.Prompt.Control.Search.prototype.f_drawResultList = function( v_el, v_tdLayout )
  334. {
  335. var v_sel = $CE( "select", {
  336. "id": this.f_getId(K_PRMT_sSV_PREFIX),
  337. "size": 3,
  338. "aria-required" : (this.isRequired() ? "true" : "false"),
  339. "multiple": "multiple"
  340. }, v_tdLayout );
  341. var v_oSV = {};
  342. v_oSV._type_ = null;
  343. v_oSV.n = "selectValue";
  344. v_oSV["@selectValueUI"] = "listBox";
  345. v_oSV["@required"] = ( this.isRequired() && !this.isMulti() );
  346. v_oSV["@multiSelect"] = this["@multiSelect"];
  347. v_oSV[K_PRMT_sATTR_DISABLED] = this[K_PRMT_sATTR_DISABLED];
  348. v_oSV["@style"] = cssParser(this["@style"], "color,font,text,direction");
  349. v_oSV["@contentTextDirection"] = this["@contentTextDirection"];
  350. if ( this.isMulti() )
  351. {
  352. v_oSV["@listSize"] = 9;
  353. }
  354. v_oSV._id_ = this.f_getId();
  355. v_oSV.m_bIsAComponent = true;
  356. v_oSV.m_oOwner = this;
  357. v_oSV[K_PRMT_LABEL_RESULTS_SELECT_ALL] = this[K_PRMT_LABEL_RESULTS_SELECT_ALL];
  358. v_oSV[K_PRMT_LABEL_RESULTS_DESELECT_ALL] = this[K_PRMT_LABEL_RESULTS_DESELECT_ALL];
  359. v_oSV[K_PRMT_LABEL_DESELECT] = this[K_PRMT_LABEL_DESELECT];
  360. var v_oResultsList = new cognos.Prompt.Control.SelectValue( v_oSV );
  361. var v_sListStyle = this.f_getStyleForNode("swsResultsListbox");
  362. if ( v_sListStyle )
  363. {
  364. v_oResultsList["@listStyle"] = v_sListStyle;
  365. }
  366. if (typeof SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST == K_PRMT_sUNDEFINED || !SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST)
  367. {
  368. v_oResultsList["@style"] += ";width:200px;";
  369. }
  370. var v_elResults =v_oResultsList.f_drawInput( v_el );
  371. this.m_oResults = v_oResultsList;
  372. };
  373. /**
  374. Renders the layout of the control: position lists, adornments and control inputs.
  375. @private
  376. @param {C_PromptElement} v_trLayout Container for this control.
  377. @return {C_PromptElement}
  378. */
  379. cognos.Prompt.Control.Search.prototype.f_drawLayout = function( v_trLayout )
  380. {
  381. var v_tdLayout = $CE( "td", {}, v_trLayout );
  382. var v_oPrompt = this.f_drawInput( v_tdLayout );
  383. var v_tbl = $CE( "table", {"border": K_PRMT_DEBUG_TABLEBORDER, "cellPadding":0, "cellSpacing":0, "role":K_PRMT_ARIA_ROLE_PRESENTATION}, v_tdLayout );
  384. if ( this[K_PRMT_sATTR_DISABLED] )
  385. {
  386. v_tbl.f_setProperty( "disabled", "disabled" );
  387. }
  388. var v_tbd = $CE( "tbody", {}, v_tbl );
  389. var v_tr = $CE( "tr", {}, v_tbd );
  390. var v_resultListId = this.f_getId(K_PRMT_sSV_PREFIX);
  391. if ( this.isMulti() )
  392. {
  393. var v_td1 = $CE( "td", {}, v_tr );
  394. var v_div1 = $CE( "div", {"vAlign":"top", "class": "clsControlLabel pc"}, v_td1 );
  395. var v_choiceLabel = $CE( "label", { "for": v_resultListId }, v_div1 );
  396. v_choiceLabel.f_appendText( this[K_PRMT_LABEL_SEARCH_RESULTS_TEXT] );
  397. var v_sDivStyle = this.f_getStyleForNode( "swsResultsHeader" );
  398. if ( v_sDivStyle )
  399. {
  400. v_div1.f_setProperty( "style", v_sDivStyle );
  401. }
  402. this.f_drawResultList( v_td1, v_tdLayout );
  403. if ( cssParser( this["@style"], "width" ) )
  404. {
  405. v_td1.f_setProperty( "width", "100%" );
  406. v_tbl.f_setProperty( "width", "100%" );
  407. v_td.f_setProperty( "width", "100%" );
  408. }
  409. var v_oChoices = new C_Choices( this );
  410. v_oChoices["@listSize"] = 9;
  411. var v_aMO = this.f_getCV().multipleObserverArray;
  412. if (v_aMO) {
  413. v_aMO.push( v_oChoices );
  414. }
  415. if (typeof SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST == K_PRMT_sUNDEFINED || !SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST)
  416. {
  417. v_oChoices["@listWidth"] = "200px";
  418. }
  419. var v_sListStyle = this.f_getStyleForNode( "swsChoicesListbox" );
  420. if ( v_sListStyle )
  421. {
  422. v_oChoices["@listStyle"] = v_sListStyle;
  423. }
  424. v_oChoices.F_Draw( v_tr );
  425. this.m_oChoices = v_oChoices;
  426. }
  427. else
  428. {
  429. var v_td1 = $CE( "td", {"vAlign":"top", "class": "clsControlLabel pc"}, v_tr );
  430. if ( this.isRequired() && !this["@hideAdornments"] )
  431. {
  432. var v_imgReq = $CE( "img", {
  433. "src": this.m_sSkin + "/prompting/images/icon_required.gif",
  434. "class": "clsErrorRequired",
  435. "vAlign": "top",
  436. "height": 10,
  437. "width": 10,
  438. "border": 0
  439. }, v_td1);
  440. }
  441. var v_choiceLabel = $CE( "label", { "for": v_resultListId }, v_td1 );
  442. v_choiceLabel.f_appendText( this[K_PRMT_LABEL_CHOICES] );
  443. v_tr = $CE( "tr", {}, v_tbd );
  444. v_td1 = $CE( "td", {}, v_tr );
  445. this.f_drawResultList( v_td1, v_tdLayout );
  446. }
  447. this.m_elPrompt = v_oPrompt;
  448. return (v_oPrompt);
  449. };
  450. /**
  451. Render Search option.
  452. @private
  453. @param {HTMLtlement} v_tbd Container (Table).
  454. @param {String} v_sIdPrefix
  455. @param {String} v_sText Text in the UI for this option
  456. @param {String} v_sOptionStyle
  457. @param {boolean} [v_bChecked]
  458. @param {boolean} [v_bCheckBox]
  459. @return {void}
  460. */
  461. cognos.Prompt.Control.Search.prototype.f_drawOption = function( v_tbd, v_sIdPrefix, v_sText, v_sOptionStyle, v_bChecked, v_bCheckBox )
  462. {
  463. var v_tr = $CE( "tr", {}, v_tbd );
  464. var v_td = $CE( "td", {
  465. "class": "clsSwsOptions pe",
  466. "style": v_sOptionStyle,
  467. "vAlign": "top"
  468. }, v_tr );
  469. var v_sID = this.f_getId( v_sIdPrefix );
  470. var v_className = (v_bCheckBox ? K_PRMT_CSS_CHECKBOX : K_PRMT_CSS_RADIOBUTTON);
  471. if (v_bChecked) {
  472. v_className = (v_bCheckBox ? K_PRMT_CSS_CHECKBOX_CHECKED : K_PRMT_CSS_RADIOBUTTON_CHECKED);
  473. }
  474. var v_optionDiv = $CE( "div", {"class": v_className}, v_td );
  475. var v_oInputAttrib = {
  476. "type": ( v_bCheckBox ? "checkbox" : "radio" ),
  477. "name": ( v_bCheckBox ? "swsCaseInsensitive" : this.f_getId( "swsOption" ) ),
  478. "id": v_sID,
  479. "class": "dijitCheckBoxInput"
  480. };
  481. if (!v_bCheckBox) {
  482. v_oInputAttrib.onclick = "return PRMTUtils.f_updateRadioButtons(this);";
  483. v_oInputAttrib.onkeypress = "return PRMTUtils.f_updateRadioButtons(this);";
  484. } else {
  485. v_oInputAttrib.onclick = "return PRMTUtils.F_OnChange(event, this);";
  486. v_oInputAttrib.onkeypress = "return PRMTUtils.F_OnChange(event, this);";
  487. }
  488. v_oInputAttrib.onFocus = "PRMTUtils.f_SearchOptionOnFocus(this)";
  489. v_oInputAttrib.onBlur = "PRMTUtils.f_SearchOptionOnBlur(this)";
  490. var v_ipt = $CE( "input", v_oInputAttrib, v_optionDiv);
  491. if ( this[K_PRMT_sATTR_DISABLED] )
  492. {
  493. v_ipt.f_setProperty( "disabled", "true" );
  494. }
  495. if ( v_bChecked )
  496. {
  497. v_ipt.f_setProperty( "checked", "checked" );
  498. }
  499. var v_td = $CE( "td", {
  500. "class": "clsSwsOptions pe",
  501. "style": v_sOptionStyle,
  502. "nowrap": "nowrap"
  503. }, v_tr );
  504. var v_label = $CE( "label", {"for": v_sID}, v_td );
  505. v_label.f_appendText( v_sText );
  506. };
  507. /**
  508. @private
  509. @return {void}
  510. */
  511. cognos.Prompt.Control.Search.prototype.f_keyDownHandler = function()
  512. {
  513. var v_lastEvt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );
  514. if ( v_lastEvt && v_lastEvt.keyCode == 13 )
  515. {
  516. // set Search and Select control name for focus
  517. var oCV = this.f_getCV();
  518. if (oCV && oCV.setCurrentPromptControlFocus && typeof oCV.setCurrentPromptControlFocus == K_PRMT_sFUNCTION)
  519. {
  520. oCV.setCurrentPromptControlFocus(this["@name"]);
  521. }
  522. this.f_search();
  523. }
  524. };
  525. /**
  526. @private
  527. @return {void}
  528. */
  529. cognos.Prompt.Control.Search.prototype.f_keyUpHandler = function(evt)
  530. {
  531. PRMT_BidiUtils.fixInputDirection(evt.target ? evt.target : evt.srcElement, this["@contentTextDirection"], 'true');
  532. };
  533. /**
  534. @private
  535. @return {HTML object} null if no results.
  536. */
  537. cognos.Prompt.Control.Search.prototype.f_getOption = function( v_sUse, v_sDisplay )
  538. {
  539. var v_aOptions = this.m_oResults.m_elPrompt.options;
  540. for (var i = 0; i < v_aOptions.length; i++)
  541. {
  542. var v_opt = v_aOptions[i];
  543. if ( v_sUse == v_opt.value && v_sDisplay == v_opt.getAttribute("dv") )
  544. {
  545. return v_opt;
  546. }
  547. }
  548. return null;
  549. };
  550. /**
  551. @private
  552. @return {cognos.Value[]} null if no results.
  553. */
  554. cognos.Prompt.Control.Search.prototype.f_getPV = function()
  555. {
  556. var v_oResults = this.m_oResults;
  557. var v_aPV = [];
  558. if ( v_oResults )
  559. {
  560. v_aPV = v_oResults.f_getPV();
  561. }
  562. return v_aPV;
  563. };
  564. /**
  565. @private
  566. @return {object}
  567. */
  568. cognos.Prompt.Control.Search.prototype.f_getSearchOptions = function()
  569. {
  570. var v_oSearchOptions = {};
  571. var v_oInput = this.$( this.f_getId( "swsInput" ) );
  572. if ( v_oInput )
  573. {
  574. var v_sValue = v_oInput.value;
  575. var v_sName = ( this["@name"] ? this["@name"] : "" );
  576. if ( v_sValue )
  577. {
  578. v_oSearchOptions["_sws_"+ v_sName + "_searchValue"] = v_sValue;
  579. v_oSearchOptions["_sws_"+ v_sName + "_showOptions"] = this.m_bShowOptions;
  580. v_oSearchOptions["_sws_"+ v_sName + "_submit"] = true;
  581. } else
  582. {
  583. v_oSearchOptions["_sws_"+ v_sName + "_searchValue"] = "";
  584. v_oSearchOptions["_sws_"+ v_sName + "_submit"] = true;
  585. }
  586. var v_oCaseInsensitive = this.$( this.f_getId( "swsCaseInsensitive" ) );
  587. var v_oStartAll = this.$( this.f_getId( "swsStartAll" ) );
  588. var v_oMatchAny = this.$( this.f_getId( "swsMatchAny" ) );
  589. var v_oMatchAll = this.$( this.f_getId( "swsMatchAll" ) );
  590. v_oSearchOptions["_sws_"+ v_sName + "_matchAnywhere"] = (v_oMatchAny && v_oMatchAny.checked) || (v_oMatchAll && v_oMatchAll.checked);
  591. v_oSearchOptions["_sws_"+ v_sName + "_matchAll"] = (v_oStartAll && v_oStartAll.checked) || (v_oMatchAll && v_oMatchAll.checked);
  592. v_oSearchOptions["_sws_"+ v_sName + "_caseInsensitive"] = (v_oCaseInsensitive && v_oCaseInsensitive.checked);
  593. v_oSearchOptions["_sws_"+ this["@parameter"]] = this.f_getXMLOptionValues();
  594. }
  595. return v_oSearchOptions;
  596. };
  597. /**
  598. * Get the search results options in XML format
  599. *
  600. */
  601. cognos.Prompt.Control.Search.prototype.f_getXMLOptionValues = function()
  602. {
  603. var v_aOptionXml = ['<selectOption', ' useValue="',K_PRMT_sEMPTY,'" displayValue="',K_PRMT_sEMPTY,'" />'];
  604. var result = "<selectOptions>";
  605. if (this.m_oResults) {
  606. var v_aSO = this.f_getChildByTagName( "selectOptions" );
  607. if ( v_aSO && v_aSO.c && v_aSO.c.length )
  608. {
  609. for ( var i = 0; i < v_aSO.c.length; i++ )
  610. {
  611. v_aOptionXml[2] = sDecodeU003( v_aSO.c[i]["@useValue"] );
  612. v_aOptionXml[4] = sDecodeU003( v_aSO.c[i]["@displayValue"] );
  613. result += v_aOptionXml.join(K_PRMT_sEMPTY);
  614. }
  615. }
  616. }
  617. result += "</selectOptions>";
  618. return result;
  619. }
  620. /**
  621. Return the style attribute for this control (@style).
  622. @private
  623. @param {v_sNode} v_sNode name of the node.
  624. @return {String} CSS string
  625. */
  626. cognos.Prompt.Control.Search.prototype.f_getStyleForNode = function( v_sNode )
  627. {
  628. var v_sStyle = null;
  629. var v_nStyle = this.getChildByName(v_sNode);
  630. if ( v_nStyle && v_nStyle["@style"] )
  631. {
  632. v_sStyle = v_nStyle["@style"];
  633. }
  634. return v_sStyle;
  635. };
  636. /**
  637. @private
  638. @return {void}
  639. */
  640. cognos.Prompt.Control.Search.prototype.f_search = function()
  641. {
  642. // set Search and Select prompt name for search button focus
  643. var v_lastEvt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );
  644. if ( v_lastEvt && v_lastEvt.type == "click" )
  645. {
  646. var oCV = this.f_getCV();
  647. if (oCV && oCV.setCurrentPromptControlFocus && typeof oCV.setCurrentPromptControlFocus == K_PRMT_sFUNCTION)
  648. {
  649. oCV.setCurrentPromptControlFocus( this["@name"] + "_searchButtonfocus");
  650. }
  651. }
  652. var v_img = this.$( this.f_getId( "imgBusy" ) );
  653. if ( v_img )
  654. {
  655. v_img.setAttribute( "src", this.m_sSkin + "/prompting/images/prompt_search_ani.gif" );
  656. }
  657. this.f_clearResults();
  658. //prevent the single select search from sending
  659. //the user's choice to the server when the user
  660. //has pressed search
  661. if ( this["@multiSelect"] == false )
  662. {
  663. this.m_bSubmitChoices = false;
  664. }
  665. // allow overriding of default search functionality
  666. if (this["@searchFunction"])
  667. {
  668. eval(this["@searchFunction"] + "();");
  669. }
  670. else
  671. {
  672. // get the search options for all search controls to repopulate them
  673. var v_oSearchOptions = [];
  674. var v_aReportControls = this.f_getCV().preProcessControlArray;
  675. if (v_aReportControls) {
  676. var kCount = v_aReportControls.length;
  677. for ( var k=0; k < kCount; k++ ) {
  678. if (v_aReportControls[k].f_getSearchOptions) {
  679. var tmp = v_aReportControls[k].f_getSearchOptions();
  680. for (var opt in tmp) {
  681. v_oSearchOptions[opt] = tmp[opt];
  682. }
  683. }
  684. }
  685. }
  686. // set parameters name for the _searchParameter variable
  687. v_oSearchOptions["_searchParameter"] = this["@parameter"];
  688. v_oSearchOptions["_promptIdBasedNames"] = true;
  689. v_oSearchOptions["_promptControl"] = K_ACTION_SEARCH;
  690. var oCV = this.f_getCV();
  691. if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION) {
  692. var oReq = new ViewerDispatcherEntry(oCV);
  693. oReq.addFormField("ui.action", K_ACTION_FORWARD);
  694. for (var v_opt in v_oSearchOptions)
  695. {
  696. oReq.addFormField( v_opt, v_oSearchOptions[ v_opt ] );
  697. }
  698. oCV.submitPromptValues(oReq);
  699. }
  700. else
  701. {
  702. // No Cognos Viewer object, use the <form>, like SetPromptMethod and SetPromptControl do.
  703. var frm = document.forms[0];
  704. if (frm)
  705. {
  706. for (var v_opt in v_oSearchOptions)
  707. {
  708. genHiddenInputHTML( frm.name, v_opt, v_oSearchOptions[ v_opt ] );
  709. }
  710. }
  711. SetPromptMethod(K_ACTION_FORWARD);
  712. SetPromptControl(K_ACTION_SEARCH);
  713. }
  714. }
  715. };
  716. /**
  717. @private
  718. @return {void}
  719. */
  720. cognos.Prompt.Control.Search.prototype.f_setDefaultSelection = function()
  721. {
  722. if (!this.m_oResults) {return;}
  723. var v_aSO = this.f_getChildByTagName( "selectOptions" );
  724. if ( v_aSO && v_aSO.c && v_aSO.c.length )
  725. {
  726. this.cachedResults = this.buildCachedResults();
  727. for ( var i = 0; i < v_aSO.c.length; i++ )
  728. {
  729. var v_sUse = sDecodeU003( v_aSO.c[i]["@useValue"] );
  730. var v_sDisplay = sDecodeU003( v_aSO.c[i]["@displayValue"] );
  731. this.f_addResults( v_sUse, v_sDisplay, v_aSO.c[i]["@selected"] );
  732. }
  733. delete this.cachedResults;
  734. this.cachedResults = null;
  735. // We need to enforce Bidi text direction
  736. if ( G_IsBidiEnabled && this["@contentTextDirection"] ) {
  737. this.m_oResults.f_drawCompleted();
  738. }
  739. }
  740. v_aSO = this.f_getChildByTagName( "selectChoices" );
  741. if ( !this.isMulti() && v_aSO && v_aSO.c && v_aSO.c.length )
  742. {
  743. this.cachedResults = this.buildCachedResults();
  744. for ( var i = 0; i < v_aSO.c.length; i++ )
  745. {
  746. var v_sUse = sDecodeU003( v_aSO.c[i]["@useValue"] );
  747. var v_sDisplay = sDecodeU003( v_aSO.c[i]["@displayValue"] );
  748. this.f_addResults( v_sUse, v_sDisplay, true );
  749. }
  750. delete this.cachedResults;
  751. this.cachedResults = null;
  752. // We need to enforce Bidi text direction
  753. if ( G_IsBidiEnabled && this["@contentTextDirection"] ) {
  754. this.m_oResults.f_drawCompleted();
  755. }
  756. }
  757. };
  758. /**
  759. @private
  760. @param {cognos.Value[]} v_oPV
  761. @return {void}
  762. */
  763. cognos.Prompt.Control.Search.prototype.f_setPV = function( v_oPV )
  764. {
  765. if ( this.m_oChoices )
  766. {
  767. this.m_oChoices.f_setPV( v_oPV );
  768. }
  769. this.m_oResults.f_setPV( v_oPV );
  770. };
  771. /**
  772. @private
  773. @param {C_PromptElement} v_el Element to update.
  774. @[aram {String} v_sNode Node with @style attribute.
  775. @return {void}
  776. */
  777. cognos.Prompt.Control.Search.prototype.f_setStyle = function( v_el, v_sNode )
  778. {
  779. var v_sStyle = this.f_getStyleForNode( v_sNode );
  780. if ( v_sStyle )
  781. {
  782. v_el.f_setProperty( "style", v_sStyle );
  783. }
  784. };
  785. /**
  786. Show/hide the advanced search options.
  787. @private
  788. @return {void}
  789. */
  790. cognos.Prompt.Control.Search.prototype.f_toggleOptions = function()
  791. {
  792. var v_elContainer = this.$( this.f_getId("idAdvancedOptions") );
  793. var v_elImg = this.$( this.f_getId("imgAdvancedArrow") );
  794. //show the dialog if not already visible
  795. if ( v_elContainer )
  796. {
  797. var v_optionsLegend = this.$( this.f_getId("idSearchOptionsLegend") );
  798. if (v_elContainer.style.display != "none")
  799. {
  800. v_elContainer.style.display = "none";
  801. v_elImg.className = "clsSearchOptionsExpand";
  802. this.m_bShowOptions = false;
  803. v_optionsLegend.setAttribute("aria-expanded", false);
  804. }
  805. else
  806. {
  807. v_elContainer.style.display = K_PRMT_sEMPTY;
  808. v_elImg.className = "clsSearchOptionsCollapse";
  809. this.m_bShowOptions = true;
  810. v_optionsLegend.setAttribute("aria-expanded", true);
  811. }
  812. }
  813. };
  814. var C_Search = cognos.Prompt.Control.Search; // Keep old reference for backward compatibility with custom scripts.