Commit a1a10a1d9c9b5e0483da4329f684fc80ce07ffd0

Authored by Neil Blakey-Milner
1 parent 5828f728

Add "Match" capability to the OptionTransfer code.

SF Tracker:	1060116
Submitted by:	Stefano Ciancio (sciancio)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2978 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js
... ... @@ -469,4 +469,48 @@ function OptionTransfer(l,r) {
469 469 this.setAutoSort=OT_setAutoSort;
470 470 this.init=OT_init;
471 471 this.update=OT_update;
  472 + this.sortSelectMatch=OT_sortSelectMatch;
  473 +}
  474 +
  475 +
  476 +
  477 +// -------------------------------------------------------------------
  478 +// sortSelectMatch(select_object, pattern)
  479 +// Pass this function a SELECT object and the options will be sorted
  480 +// matching pattern string. It select also matching options
  481 +// -------------------------------------------------------------------
  482 +function OT_sortSelectMatch(obj, pattern) {
  483 +
  484 + sortSelect(obj);
  485 +
  486 + var o = new Array();
  487 + // Store original array in "o"
  488 + if (obj.options==null) { return; }
  489 + for (var i=0; i<obj.options.length; i++){
  490 + o[o.length] = new Option(obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
  491 + }
  492 +
  493 + // Match / NoMatch Array
  494 + match = new Array();
  495 + nomatch = new Array();
  496 + for (var i=0; i<o.length; i++){
  497 +
  498 + if (o[i].text.toLowerCase().indexOf(pattern.toLowerCase())!=-1) {
  499 + match[match.length] = new Option(o[i].text, o[i].value, o[i].defaultSelected, true);
  500 + } else {
  501 + nomatch[nomatch.length] = new Option(o[i].text, o[i].value, o[i].defaultSelected, false);
  502 + }
  503 + }
  504 +
  505 + // Now rewrite sorted array
  506 + for (var i=0; i<match.length; i++){
  507 + obj.options[i] = new Option(match[i].text, match[i].value, match[i].defaultSelected, match[i].selected);
  508 + }
  509 +
  510 + for (var i=0; i<nomatch.length; i++){
  511 + obj.options[i+match.length] = new Option(nomatch[i].text, nomatch[i].value, nomatch[i].defaultSelected, nomatch[i].selected);
  512 + }
  513 +
  514 + return;
  515 +
472 516 }
... ...