CSearch.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2011
  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. CSearch.js
  14. This script is used to provide interactivity for the selectWithSearch prompt component.
  15. */
  16. //Constructor to create a selectWithSearch component
  17. // oSubmit: the control used to submit values to the server
  18. // oLstResults: the results list box
  19. // oLstChoices: the choices list box
  20. // oForm: the form
  21. // oSearchBox: the type in search box
  22. // oImgSearch: the search icon, used for animation
  23. // sRef: the name of this object
  24. // oShowOptions: the object that will show/hide the options
  25. // oMatchAnywhere: starts with / contains
  26. // oMatchAll: and / or
  27. // bRequired: boolean, specify if user input is required
  28. // sSubmitType: 'default' will submit as a standard form
  29. // 'XML' will convert the submission to XML and submit
  30. // bMultiple: boolean, specify whether multiple values are allowed or not
  31. // oSubmitFlag: a hidden variable used to tell the server whether this control has submitted a search
  32. // oSelectOptions: a hidden variable used to resupply the search results to the server
  33. // oResultsSizer: object used to resize the results list box
  34. // oChoicesSizer: object used to resize the choices list box
  35. // oSearchButton: the search button
  36. // oInsertButton: the insert button
  37. // oRemoveButton: the remove button
  38. // sSearchFuntion:
  39. // sParameterName: name of the parameter to send in the _searchParameter.
  40. function CSearch(oSubmit, oLstResults, oLstChoices, oForm, oSearchBox, oImgSearch, sRef, oShowOptions, oMatchAnywhere, oMatchAll, bRequired, sSubmitType, oErrorFeedback, bMultiple, oSubmitFlag, oSelectOptions, oResultsSizer, oChoicesSizer, oSearchButton, oInsertButton, oRemoveButton, sSearchFunction, sParameterName, sCVId)
  41. {
  42. this.setCVId(sCVId);
  43. this.m_oSubmit = oSubmit;
  44. this.m_oForm = oForm;
  45. this.m_oSearchBox = oSearchBox;
  46. this.m_oLstResults = oLstResults;
  47. this.m_oLstChoices = oLstChoices;
  48. this.m_oSelectOptions = oSelectOptions;
  49. this.m_bRequired = bRequired;
  50. this.m_bValid = false;
  51. this.m_sSubmitType = sSubmitType;
  52. this.m_oErrorFeedback = oErrorFeedback;
  53. this.m_sErrorFeedbackClass = "clsFeedbackWidgetParseErrorArrowLeft";
  54. this.m_sRef = sRef;
  55. // the promptId is the ref without CV's ID.
  56. this.m_sPromptId = this.m_sRef.replace(new RegExp(sCVId + "$"), K_PRMT_sEMPTY);
  57. this.m_oShowOptions = oShowOptions;
  58. this.m_oMatchAnywhere = oMatchAnywhere;
  59. this.m_oMatchAll = oMatchAll;
  60. this.m_sSearchFunction = sSearchFunction;
  61. this.m_sParameterName = sParameterName;
  62. if (oSearchButton)
  63. {
  64. this.m_oSearchButton = oSearchButton;
  65. }
  66. if (oInsertButton)
  67. {
  68. this.m_oInsertButton = oInsertButton;
  69. }
  70. if (oRemoveButton)
  71. {
  72. this.m_oRemoveButton = oRemoveButton;
  73. }
  74. if (bMultiple)
  75. {
  76. this.m_bMultiple = bMultiple;
  77. }
  78. else
  79. {
  80. this.m_bMultiple = false;
  81. }
  82. //skin folder
  83. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  84. this.m_oImgSearch = oImgSearch;
  85. this.imgBusyTrue = new Image();
  86. this.imgBusyTrue.src = this.m_sSkin + "/prompting/images/prompt_search_ani.gif";
  87. this.imgBusyFalse = new Image();
  88. this.imgBusyFalse.src = this.m_sSkin + "/prompting/images/prompt_search.gif";
  89. this.m_oImgErrorFalse= new Image();
  90. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  91. this.m_oImgErrorTrue = new Image();
  92. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  93. this.m_oSubmitFlag = oSubmitFlag;
  94. this.checkData();
  95. this.stopAnimateSearchIcon();
  96. this.m_bSubmitChoices = true;
  97. //resize the list to content if necessary
  98. if (this.m_sRef)
  99. {
  100. if ((oResultsSizer))
  101. {
  102. this.m_oResultsSizer = oResultsSizer;
  103. this.m_oResultsTester = new Object();
  104. this.m_oResultsTester.m_bSizeAvailable = false;
  105. this.m_oResultsTester.m_iResizeTestCounter = 0;
  106. this.m_iIntervalResults = window.setInterval ('search'+ this.m_sRef +'.testResize(search'+ this.m_sRef +'.m_oResultsSizer, search'+ this.m_sRef +'.m_oLstResults, search'+ this.m_sRef +'.m_oResultsTester,search'+ this.m_sRef +'.m_iIntervalResults)',250);
  107. }
  108. if(oChoicesSizer)
  109. {
  110. this.m_oChoicesSizer = oChoicesSizer;
  111. this.m_oChoicesTester = new Object();
  112. this.m_oChoicesTester.m_bSizeAvailable = false;
  113. this.m_oChoicesTester.m_iResizeTestCounter = 0;
  114. this.m_iIntervalChoices = window.setInterval ('search'+ this.m_sRef +'.testResize(search'+ this.m_sRef +'.m_oChoicesSizer, search'+ this.m_sRef +'.m_oLstChoices, search'+ this.m_sRef +'.m_oChoicesTester,search'+ this.m_sRef +'.m_iIntervalChoices)',250);
  115. }
  116. }
  117. //check status of characters (for compatibility with IME)
  118. this.m_bFirstInput = true;
  119. this.m_iCheckStatusInterval = window.setInterval ('search'+ this.m_sRef +'.checkSearchButtonState()', 1000);
  120. //check the state of the search button
  121. this.checkSearchButtonState();
  122. var sDefaultWidth = "200px";
  123. if (typeof SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST != K_PRMT_sUNDEFINED && SYSTEMPROPERTY_CSEARCH_AUTO_RESIZE_RESULT_LIST === true)
  124. {
  125. sDefaultWidth = "auto";
  126. }
  127. this.m_oLstResults.style.width = sDefaultWidth;
  128. this.m_oLstChoices.style.width = sDefaultWidth;
  129. //check the states of the insert and remove buttons
  130. this.update();
  131. }
  132. CSearch.prototype = new CPromptControl();
  133. //select all items
  134. function CSearch_selectAll(col)
  135. {
  136. for (var i=0; i < col.options.length; i++)
  137. {
  138. col.options[i].selected = true;
  139. }
  140. //check the states of the insert and remove buttons
  141. this.checkInsertRemove();
  142. }
  143. //remove selection from all items
  144. function CSearch_deSelectAll(col)
  145. {
  146. for (var i=0; i < col.options.length; i++)
  147. {
  148. col.options[i].selected = false;
  149. }
  150. //check the states of the insert and remove buttons
  151. this.checkInsertRemove();
  152. }
  153. //perform any special processing for the server.
  154. //this function will wrap all list items in XML.
  155. //This is required for cases where the unselected items need
  156. //to be submitted too.
  157. function CSearch_preProcess()
  158. {
  159. //prepare form for submission
  160. var i=0;
  161. if (this.m_sSubmitType == K_PRMT_sXML)
  162. {
  163. var sURLValues = K_PRMT_sEMPTY;
  164. if ((this.m_oLstChoices.options.length > 0) && (this.m_bSubmitChoices == true))
  165. {
  166. if (this.m_bMultiple == true)
  167. {
  168. for(i = 0; i <this.m_oLstChoices.options.length; i ++)
  169. {
  170. sURLValues += '<selectOption';
  171. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[i].text) +'"';
  172. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[i].value) + '"';
  173. if (this.m_oLstChoices.options[i].selected == true)
  174. {
  175. sURLValues += ' selected="true" />';
  176. }
  177. else
  178. {
  179. sURLValues += ' selected="false" />';
  180. }
  181. }
  182. }
  183. else
  184. {
  185. if (this.m_oLstChoices.selectedIndex != -1)
  186. {
  187. sURLValues += '<selectOption';
  188. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[this.m_oLstChoices.selectedIndex].text) +'"';
  189. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[this.m_oLstChoices.selectedIndex].value) + '"';
  190. sURLValues += ' selected="true" />';
  191. }
  192. }
  193. }
  194. addSelectChoices(this.m_oSubmit, sURLValues);
  195. if (this.m_oForm && this.m_oForm.elements && typeof this.m_oForm.elements['p_' + this.m_sRef] == K_PRMT_sOBJECT)
  196. {
  197. addSelectChoices(this.m_oForm.elements['p_' + this.m_sRef], sURLValues);
  198. }
  199. if((this.m_oSelectOptions) && (this.m_oSubmitFlag != true))
  200. {
  201. this.processResults();
  202. }
  203. }
  204. else
  205. {
  206. //select all the choices so they can be submitted with the form
  207. //if this is a multiple select search
  208. if (this.m_oLstResults != this.m_oLstChoices)
  209. {
  210. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  211. {
  212. this.m_oLstChoices.options[i].selected = true;
  213. }
  214. }
  215. }
  216. }
  217. //Prepare search results
  218. // <selectOptions>
  219. // <selectOption displayValue="Canada" useValue="4" selected="true"/>
  220. // <selectOption displayValue="Australia" useValue="16" selected="false"/>
  221. // </selectOptions>
  222. function CSearch_processResults()
  223. {
  224. var sURLValues = "<selectOptions>";
  225. if (this.m_oLstResults.options.length > 0)
  226. {
  227. for(var i = 0; i <this.m_oLstResults.options.length; i ++)
  228. {
  229. sURLValues += '<selectOption';
  230. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstResults.options[i].text) +'"';
  231. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstResults.options[i].value) + '"';
  232. if (this.m_oLstResults.options[i].selected == true)
  233. {
  234. sURLValues += ' selected="true" />';
  235. }
  236. else
  237. {
  238. sURLValues += ' selected="false" />';
  239. }
  240. }
  241. }
  242. sURLValues += "</selectOptions>";
  243. this.m_oSelectOptions.value = sURLValues;
  244. }
  245. //insert values from the picker control
  246. function CSearch_insert(fromCol, toCol)
  247. {
  248. //check to see if anything is selected
  249. if (fromCol.selectedIndex != -1 && fromCol.options[fromCol.selectedIndex].value > K_PRMT_sEMPTY)
  250. {
  251. for (var i=0; i < fromCol.options.length; i++)
  252. {
  253. if ( fromCol.options[i].selected == true && !this.contains( toCol.options, fromCol.options[i] ) )
  254. {
  255. toCol.options[toCol.options.length] = new Option(fromCol.options[i].text, fromCol.options[i].value, false, false);
  256. }
  257. }
  258. }
  259. this.update();
  260. return false;
  261. }
  262. function CSearch_contains( aOptions, oOption )
  263. {
  264. if ( aOptions && oOption )
  265. {
  266. var sText = oOption.text;
  267. var sValue = oOption.value;
  268. for (var i=0; i < aOptions.length; i++)
  269. {
  270. if ( aOptions[i].text == sText && aOptions[i].value == sValue )
  271. {
  272. return true;
  273. }
  274. }
  275. }
  276. return false;
  277. }
  278. //remove selections from the list of choices
  279. function CSearch_remove(col)
  280. {
  281. if (col.selectedIndex != -1)
  282. {
  283. var i=0;
  284. for (i=col.options.length-1; i > -1 ; i--)
  285. {
  286. if (col.options[i].selected == true)
  287. {
  288. col.options[i]=null;
  289. }
  290. }
  291. }
  292. this.update();
  293. }
  294. //show the search in progress animation
  295. function CSearch_busyTrue(oImg)
  296. {
  297. //oImg.src = this.imgBusyTrue.src + '?' + Math.random();
  298. //TODO
  299. //the animation is being overidden by the submit
  300. //oImg.src = this.imgBusyTrue.src + '?' + Math.random();
  301. }
  302. //turn the search progress off
  303. function CSearch_busyFalse(oImg)
  304. {
  305. oImg.src = this.imgBusyFalse.src;
  306. }
  307. //toggle the busy search progress state on
  308. function CSearch_busy()
  309. {
  310. this.busyTrue(document.images['imgBusy']);
  311. }
  312. //start the search animation
  313. //mark the search control for submission
  314. function CSearch_startAnimateSearchIcon()
  315. {
  316. //tell the server to search after the form is submitted
  317. if (this.m_oSubmitFlag)
  318. {
  319. this.m_oSubmitFlag.value = "true";
  320. }
  321. this.m_oImgSearch.src = this.imgBusyTrue.src;
  322. }
  323. function CSearch_stopAnimateSearchIcon()
  324. {
  325. this.m_oImgSearch.src = this.imgBusyFalse.src;
  326. }
  327. //show/hide the advanced search options
  328. function CSearch_toggleAdvanced(objId,imgId)
  329. {
  330. var oIdAdvancedOptions = document.getElementById(objId);
  331. var oimgAdvancedArrow = document.getElementById(imgId);
  332. //show the dialog if not already visible
  333. if (oIdAdvancedOptions.style.display != "none")
  334. {
  335. oIdAdvancedOptions.style.display = "none";
  336. oimgAdvancedArrow.src = this.m_sSkin + "/prompting/images/prompt_option_expand.gif";
  337. if (this.m_oShowOptions)
  338. {
  339. this.m_oShowOptions.value="false";
  340. }
  341. }
  342. else
  343. {
  344. oIdAdvancedOptions.style.display = "inline";
  345. oimgAdvancedArrow.src = this.m_sSkin + "/prompting/images/prompt_option_collapse.gif";
  346. if (this.m_oShowOptions)
  347. {
  348. this.m_oShowOptions.value="true";
  349. }
  350. }
  351. }
  352. //change the configuration of the advanced search options
  353. function CSearch_setOptions(sMatchAnywhere,sMatchAll)
  354. {
  355. this.m_oMatchAnywhere.value = sMatchAnywhere;
  356. this.m_oMatchAll.value = sMatchAll;
  357. }
  358. //validate the input into the control
  359. function CSearch_checkData()
  360. {
  361. if (this.m_oLstResults != this.m_oLstChoices)
  362. {
  363. if ((this.m_bRequired == true) && (this.m_oLstChoices.options.length === 0))
  364. {
  365. this.m_bValid = false;
  366. this.checkFail();
  367. return false;
  368. }
  369. else
  370. {
  371. this.m_bValid = true;
  372. this.checkPass();
  373. return true;
  374. }
  375. }
  376. else
  377. {
  378. if ((this.m_bRequired == true) && ((this.m_oLstChoices.options.length === 0) || (this.m_oLstChoices.selectedIndex == -1)))
  379. {
  380. this.m_bValid = false;
  381. this.checkFail();
  382. return false;
  383. }
  384. else
  385. {
  386. this.m_bValid = true;
  387. this.checkPass();
  388. return true;
  389. }
  390. }
  391. }
  392. //submit the prompt control
  393. function CSearch_startSearch()
  394. {
  395. this.startAnimateSearchIcon();
  396. while (this.m_oLstResults.hasChildNodes()) {
  397. this.m_oLstResults.removeChild(this.m_oLstResults.firstChild);
  398. }
  399. //prevent the single select search from sending
  400. //the user's choice to the server when the user
  401. //has pressed search
  402. if (this.m_bMultiple == false)
  403. {
  404. this.m_bSubmitChoices = false;
  405. }
  406. // allow overriding of default search functionality
  407. if (this.m_sSearchFunction != K_PRMT_sEMPTY)
  408. {
  409. eval(this.m_sSearchFunction + "();");
  410. }
  411. else
  412. {
  413. var oCV = this.getCV();
  414. if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION) {
  415. var oReq = new ViewerDispatcherEntry(oCV);
  416. oReq.addFormField("ui.action", K_ACTION_FORWARD);
  417. // regular expression to remove CV's ID from the input names.
  418. var reStripCVID = new RegExp("_sws_" + this.m_sRef);
  419. // regular expression to match this search control.
  420. var reThisSwsInput = new RegExp("sws.*" + this.m_sRef);
  421. for (var i in this.m_oForm.elements)
  422. {
  423. var oInput = this.m_oForm.elements[i];
  424. if (typeof oInput == K_PRMT_sOBJECT && oInput && oInput.name && oInput.value)
  425. {
  426. if (oInput.name.match(reThisSwsInput))
  427. {
  428. var sName = oInput.name;
  429. sName = sName.replace(reStripCVID, "_sws_" + this.m_sPromptId);
  430. oReq.addFormField(sName, oInput.value);
  431. }
  432. }
  433. }
  434. // set parameter name for the _searchParameter variable
  435. oReq.addFormField("_searchParameter", this.m_sParameterName);
  436. oReq.addFormField("_promptIdBasedNames", "true");
  437. oReq.addFormField("_promptControl", K_ACTION_SEARCH);
  438. oCV.submitPromptValues(oReq);
  439. }
  440. else
  441. {
  442. SetPromptMethod(K_ACTION_FORWARD);
  443. SetPromptControl(K_ACTION_SEARCH);
  444. }
  445. }
  446. }
  447. //determine whether to enable or disable
  448. //the search button. If the text box is empty
  449. //then the search should be disabled.
  450. function CSearch_checkSearchButtonState()
  451. {
  452. if (this.m_oSearchButton)
  453. {
  454. if (this.m_oSearchBox.value == K_PRMT_sEMPTY)
  455. {
  456. this.m_oSearchButton.className = "clsPromptButton";
  457. this.disableSearchButton();
  458. }
  459. else
  460. {
  461. this.enableSearchButton();
  462. if (this.m_bFirstInput == true)
  463. {
  464. this.m_bFirstInput = false;
  465. window.clearInterval(this.m_checkStatusInterval);
  466. }
  467. }
  468. }
  469. }
  470. //enable the search button
  471. function CSearch_enableSearchButton()
  472. {
  473. this.m_oSearchButton.disabled = false;
  474. }
  475. //disable the search button
  476. function CSearch_disableSearchButton()
  477. {
  478. this.m_oSearchButton.disabled = true;
  479. }
  480. //this function is used to submit the page if the user
  481. //presses the Enter key while in a field
  482. function CSearch_catchSearch(evt)
  483. {
  484. var oEvent = (evt) ? evt : ((event) ? event : null);
  485. //catch the Enter key code
  486. if (oEvent && oEvent.keyCode == 13 && typeof Search_DisableEnterKeyAutoSubmit != K_PRMT_sUNDEFINED && Search_DisableEnterKeyAutoSubmit !== true)
  487. {
  488. if (this.m_oSearchButton)
  489. {
  490. if (this.m_oSearchBox.value != K_PRMT_sEMPTY)
  491. {
  492. this.startSearch();
  493. }
  494. }
  495. else
  496. {
  497. this.startSearch();
  498. }
  499. if (typeof oEvent.stopPropagation == K_PRMT_sFUNCTION) { oEvent.stopPropagation(); }
  500. if (typeof oEvent.preventDefault == K_PRMT_sFUNCTION) { oEvent.preventDefault(); }
  501. oEvent.cancelBubble = true;
  502. return false;
  503. }
  504. }
  505. //catch the backspace key
  506. //some browsers (IE5.5 don't capture this event)
  507. function CSearch_keyPress(sKeyCode)
  508. {
  509. if (sKeyCode=='8')
  510. {
  511. //check the data that has been typed in
  512. this.checkSearchButtonState();
  513. }
  514. return true;
  515. }
  516. //enable and disable the insert and remove buttons
  517. //based on what the user has selected
  518. function CSearch_checkInsertRemove()
  519. {
  520. if (this.m_oInsertButton)
  521. {
  522. if (this.m_oLstResults.selectedIndex == -1)
  523. {
  524. this.m_oInsertButton.disabled = true;
  525. this.m_oInsertButton.className = "clsInsertRemoveButton";
  526. }
  527. else
  528. {
  529. this.m_oInsertButton.disabled = false;
  530. }
  531. }
  532. if (this.m_oRemoveButton)
  533. {
  534. if (this.m_oLstChoices.selectedIndex == -1)
  535. {
  536. this.m_oRemoveButton.disabled = true;
  537. this.m_oRemoveButton.className = "clsInsertRemoveButton";
  538. }
  539. else
  540. {
  541. this.m_oRemoveButton.disabled = false;
  542. }
  543. }
  544. }
  545. //wait until the size of the list box is known
  546. //then trigger a resize -- used in conjunction with an interval
  547. function CSearch_testResize(oSizer, oLst, oTester, iInterval)
  548. {
  549. if (oTester.m_bSizeAvailable == false)
  550. {
  551. if (oSizer.width != 0 || oTester.m_iResizeTestCounter < 100)
  552. {
  553. oTester.m_bSizeAvailable = true;
  554. }
  555. else
  556. {
  557. oTester.m_iResizeTestCounter++;
  558. }
  559. }
  560. else
  561. {
  562. window.clearInterval(iInterval);
  563. }
  564. }
  565. //add a value to the list via javascript
  566. function CSearch_add(sDisplayValue, sInsertText)
  567. {
  568. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
  569. this.checkData();
  570. //check the states of the insert and remove buttons
  571. this.checkInsertRemove();
  572. }
  573. //add an item to the list without any checking by the control
  574. //this method provides an efficient way to add items, but
  575. //the update() method should be called to clean up the control
  576. //when finished adding
  577. function CSearch_addNoUpdate(sText, sValue, type, sel)
  578. {
  579. sText = sDecodeU003( sText );
  580. sValue = sDecodeU003( sValue );
  581. var iIndex = 0;
  582. if (type == "result")
  583. {
  584. if (sel == true) {
  585. iIndex = this.m_oLstResults.options.length;
  586. this.m_oLstResults.options[iIndex] = new Option(sText, sValue, true, true);
  587. // IE bug : Need to reselect the option, otherwise IE selects the previous one.
  588. this.m_oLstResults.options[iIndex].selected = true;
  589. }
  590. else {
  591. this.m_oLstResults.options[this.m_oLstResults.options.length] = new Option(sText, sValue, false, false);
  592. }
  593. }
  594. else
  595. {
  596. if (sel == true) {
  597. iIndex = this.m_oLstChoices.options.length;
  598. this.m_oLstChoices.options[iIndex] = new Option(sText, sValue, true, true);
  599. // IE bug : Need to reselect the option, otherwise IE selects the previous one.
  600. this.m_oLstChoices.options[iIndex].selected = true;
  601. }
  602. else {
  603. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sText, sValue, false, false);
  604. }
  605. }
  606. }
  607. function CSearch_addOptions(aOptions)
  608. {
  609. var sDisplayValue, sUseValue, sType, bSel;
  610. if (aOptions instanceof Array)
  611. {
  612. for (var idxOption = 0; idxOption < aOptions.length; idxOption++)
  613. {
  614. var aOpt = aOptions[idxOption];
  615. if (aOpt && aOpt.length)
  616. {
  617. sDisplayValue = (aOpt.length > 0 ? aOpt[0] : K_PRMT_sEMPTY);
  618. sUseValue = (aOpt.length > 1 ? aOpt[1] : K_PRMT_sEMPTY);
  619. bSel = (aOpt.length > 2 ? aOpt[2] : false);
  620. sType = (aOpt.length > 3 ? aOpt[3] : null);
  621. this.addNoUpdate(sDisplayValue, sUseValue, sType, bSel);
  622. }
  623. }
  624. this.update();
  625. }
  626. }
  627. //clean up the control
  628. function CSearch_update()
  629. {
  630. this.checkData();
  631. //check the states of the insert and remove buttons
  632. this.checkInsertRemove();
  633. CPromptControl_updateSelectWidth( this.m_oLstChoices );
  634. CPromptControl_updateSelectWidth( this.m_oLstResults );
  635. }
  636. //Prototypes to assign methods to new instances of the object
  637. CSearch.prototype.selectAll = CSearch_selectAll;
  638. CSearch.prototype.deSelectAll = CSearch_deSelectAll;
  639. CSearch.prototype.preProcess = CSearch_preProcess;
  640. CSearch.prototype.remove = CSearch_remove;
  641. CSearch.prototype.insert = CSearch_insert;
  642. CSearch.prototype.contains = CSearch_contains;
  643. CSearch.prototype.busyTrue = CSearch_busyTrue;
  644. CSearch.prototype.busyFalse = CSearch_busyFalse;
  645. CSearch.prototype.busy = CSearch_busy;
  646. CSearch.prototype.toggleAdvanced = CSearch_toggleAdvanced;
  647. CSearch.prototype.setOptions = CSearch_setOptions;
  648. CSearch.prototype.checkData = CSearch_checkData;
  649. CSearch.prototype.startAnimateSearchIcon = CSearch_startAnimateSearchIcon;
  650. CSearch.prototype.stopAnimateSearchIcon = CSearch_stopAnimateSearchIcon;
  651. CSearch.prototype.startSearch = CSearch_startSearch;
  652. CSearch.prototype.processResults = CSearch_processResults;
  653. CSearch.prototype.checkSearchButtonState = CSearch_checkSearchButtonState;
  654. CSearch.prototype.enableSearchButton = CSearch_enableSearchButton;
  655. CSearch.prototype.disableSearchButton = CSearch_disableSearchButton;
  656. CSearch.prototype.catchSearch = CSearch_catchSearch;
  657. CSearch.prototype.keyPress = CSearch_keyPress;
  658. CSearch.prototype.checkInsertRemove = CSearch_checkInsertRemove;
  659. CSearch.prototype.testResize = CSearch_testResize;
  660. CSearch.prototype.add = CSearch_add;
  661. CSearch.prototype.addNoUpdate = CSearch_addNoUpdate;
  662. CSearch.prototype.addOptions = CSearch_addOptions;
  663. CSearch.prototype.update = CSearch_update;