Commit 365499e10b6c4e4397d2aaae386f21faeeef1c64

Authored by Neil Blakey-Milner
1 parent b110d291

Moved to thirdpartyjs/


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4356 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js deleted
1   -// ===================================================================
2   -// Author: Matt Kruse <matt@mattkruse.com>
3   -// WWW: http://www.mattkruse.com/
4   -//
5   -// NOTICE: You may use this code for any purpose, commercial or
6   -// private, without any further permission from the author. You may
7   -// remove this notice from your final code if you wish, however it is
8   -// appreciated by the author if at least my web site address is kept.
9   -//
10   -// You may *NOT* re-distribute this code in any way except through its
11   -// use. That means, you can include it in your product, or your web
12   -// site, or any other form where the code is actually being used. You
13   -// may not put the plain javascript up on your site for download or
14   -// include it in your javascript libraries for download.
15   -// If you wish to share this code with others, please just point them
16   -// to the URL instead.
17   -// Please DO NOT link directly to my .js files from your site. Copy
18   -// the files to your server and use them there. Thank you.
19   -// ===================================================================
20   -
21   -
22   -/* SOURCE FILE: selectbox.js */
23   -
24   -// -------------------------------------------------------------------
25   -// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
26   -// This is a general function used by the select functions below, to
27   -// avoid code duplication
28   -// -------------------------------------------------------------------
29   -function selectUnselectMatchingOptions(obj,regex,which,only) {
30   - if (window.RegExp) {
31   - if (which == "select") {
32   - var selected1=true;
33   - var selected2=false;
34   - }
35   - else if (which == "unselect") {
36   - var selected1=false;
37   - var selected2=true;
38   - }
39   - else {
40   - return;
41   - }
42   - var re = new RegExp(regex);
43   - for (var i=0; i<obj.options.length; i++) {
44   - if (re.test(obj.options[i].text)) {
45   - obj.options[i].selected = selected1;
46   - }
47   - else {
48   - if (only == true) {
49   - obj.options[i].selected = selected2;
50   - }
51   - }
52   - }
53   - }
54   - }
55   -
56   -// -------------------------------------------------------------------
57   -// selectMatchingOptions(select_object,regex)
58   -// This function selects all options that match the regular expression
59   -// passed in. Currently-selected options will not be changed.
60   -// -------------------------------------------------------------------
61   -function selectMatchingOptions(obj,regex) {
62   - selectUnselectMatchingOptions(obj,regex,"select",false);
63   - }
64   -// -------------------------------------------------------------------
65   -// selectOnlyMatchingOptions(select_object,regex)
66   -// This function selects all options that match the regular expression
67   -// passed in. Selected options that don't match will be un-selected.
68   -// -------------------------------------------------------------------
69   -function selectOnlyMatchingOptions(obj,regex) {
70   - selectUnselectMatchingOptions(obj,regex,"select",true);
71   - }
72   -// -------------------------------------------------------------------
73   -// unSelectMatchingOptions(select_object,regex)
74   -// This function Unselects all options that match the regular expression
75   -// passed in.
76   -// -------------------------------------------------------------------
77   -function unSelectMatchingOptions(obj,regex) {
78   - selectUnselectMatchingOptions(obj,regex,"unselect",false);
79   - }
80   -
81   -// -------------------------------------------------------------------
82   -// sortSelect(select_object)
83   -// Pass this function a SELECT object and the options will be sorted
84   -// by their text (display) values
85   -// -------------------------------------------------------------------
86   -function sortSelect(obj) {
87   - var o = new Array();
88   - if (obj.options==null) { return; }
89   - for (var i=0; i<obj.options.length; i++) {
90   - o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
91   - }
92   - if (o.length==0) { return; }
93   - o = o.sort(
94   - function(a,b) {
95   - if ((a.text+"") < (b.text+"")) { return -1; }
96   - if ((a.text+"") > (b.text+"")) { return 1; }
97   - return 0;
98   - }
99   - );
100   -
101   - for (var i=0; i<o.length; i++) {
102   - obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
103   - }
104   - }
105   -
106   -// -------------------------------------------------------------------
107   -// selectAllOptions(select_object)
108   -// This function takes a select box and selects all options (in a
109   -// multiple select object). This is used when passing values between
110   -// two select boxes. Select all options in the right box before
111   -// submitting the form so the values will be sent to the server.
112   -// -------------------------------------------------------------------
113   -function selectAllOptions(obj) {
114   - for (var i=0; i<obj.options.length; i++) {
115   - obj.options[i].selected = true;
116   - }
117   - }
118   -
119   -// -------------------------------------------------------------------
120   -// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
121   -// This function moves options between select boxes. Works best with
122   -// multi-select boxes to create the common Windows control effect.
123   -// Passes all selected values from the first object to the second
124   -// object and re-sorts each box.
125   -// If a third argument of 'false' is passed, then the lists are not
126   -// sorted after the move.
127   -// If a fourth string argument is passed, this will function as a
128   -// Regular Expression to match against the TEXT or the options. If
129   -// the text of an option matches the pattern, it will NOT be moved.
130   -// It will be treated as an unmoveable option.
131   -// You can also put this into the <SELECT> object as follows:
132   -// onDblClick="moveSelectedOptions(this,this.form.target)
133   -// This way, when the user double-clicks on a value in one box, it
134   -// will be transferred to the other (in browsers that support the
135   -// onDblClick() event handler).
136   -// -------------------------------------------------------------------
137   -function moveSelectedOptions(from,to) {
138   - // Unselect matching options, if required
139   - if (arguments.length>3) {
140   - var regex = arguments[3];
141   - if (regex != "") {
142   - unSelectMatchingOptions(from,regex);
143   - }
144   - }
145   - // Move them over
146   - for (var i=0; i<from.options.length; i++) {
147   - var o = from.options[i];
148   - if (o.selected) {
149   - to.options[to.options.length] = new Option( o.text, o.value, false, false);
150   - }
151   - }
152   - // Delete them from original
153   - for (var i=(from.options.length-1); i>=0; i--) {
154   - var o = from.options[i];
155   - if (o.selected) {
156   - from.options[i] = null;
157   - }
158   - }
159   - if ((arguments.length<3) || (arguments[2]==true)) {
160   - sortSelect(from);
161   - sortSelect(to);
162   - }
163   - from.selectedIndex = -1;
164   - to.selectedIndex = -1;
165   - }
166   -
167   -// -------------------------------------------------------------------
168   -// copySelectedOptions(select_object,select_object[,autosort(true/false)])
169   -// This function copies options between select boxes instead of
170   -// moving items. Duplicates in the target list are not allowed.
171   -// -------------------------------------------------------------------
172   -function copySelectedOptions(from,to) {
173   - var options = new Object();
174   - for (var i=0; i<to.options.length; i++) {
175   - options[to.options[i].text] = true;
176   - }
177   - for (var i=0; i<from.options.length; i++) {
178   - var o = from.options[i];
179   - if (o.selected) {
180   - if (options[o.text] == null || options[o.text] == "undefined") {
181   - to.options[to.options.length] = new Option( o.text, o.value, false, false);
182   - }
183   - }
184   - }
185   - if ((arguments.length<3) || (arguments[2]==true)) {
186   - sortSelect(to);
187   - }
188   - from.selectedIndex = -1;
189   - to.selectedIndex = -1;
190   - }
191   -
192   -// -------------------------------------------------------------------
193   -// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
194   -// Move all options from one select box to another.
195   -// -------------------------------------------------------------------
196   -function moveAllOptions(from,to) {
197   - selectAllOptions(from);
198   - if (arguments.length==2) {
199   - moveSelectedOptions(from,to);
200   - }
201   - else if (arguments.length==3) {
202   - moveSelectedOptions(from,to,arguments[2]);
203   - }
204   - else if (arguments.length==4) {
205   - moveSelectedOptions(from,to,arguments[2],arguments[3]);
206   - }
207   - }
208   -
209   -// -------------------------------------------------------------------
210   -// copyAllOptions(select_object,select_object[,autosort(true/false)])
211   -// Copy all options from one select box to another, instead of
212   -// removing items. Duplicates in the target list are not allowed.
213   -// -------------------------------------------------------------------
214   -function copyAllOptions(from,to) {
215   - selectAllOptions(from);
216   - if (arguments.length==2) {
217   - copySelectedOptions(from,to);
218   - }
219   - else if (arguments.length==3) {
220   - copySelectedOptions(from,to,arguments[2]);
221   - }
222   - }
223   -
224   -// -------------------------------------------------------------------
225   -// swapOptions(select_object,option1,option2)
226   -// Swap positions of two options in a select list
227   -// -------------------------------------------------------------------
228   -function swapOptions(obj,i,j) {
229   - var o = obj.options;
230   - var i_selected = o[i].selected;
231   - var j_selected = o[j].selected;
232   - var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
233   - var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
234   - o[i] = temp2;
235   - o[j] = temp;
236   - o[i].selected = j_selected;
237   - o[j].selected = i_selected;
238   - }
239   -
240   -// -------------------------------------------------------------------
241   -// moveOptionUp(select_object)
242   -// Move selected option in a select list up one
243   -// -------------------------------------------------------------------
244   -function moveOptionUp(obj) {
245   - // If > 1 option selected, do nothing
246   - var selectedCount=0;
247   - for (i=0; i<obj.options.length; i++) {
248   - if (obj.options[i].selected) {
249   - selectedCount++;
250   - }
251   - }
252   - if (selectedCount!=1) {
253   - return;
254   - }
255   - // If this is the first item in the list, do nothing
256   - var i = obj.selectedIndex;
257   - if (i == 0) {
258   - return;
259   - }
260   - swapOptions(obj,i,i-1);
261   - obj.options[i-1].selected = true;
262   - }
263   -
264   -// -------------------------------------------------------------------
265   -// moveOptionDown(select_object)
266   -// Move selected option in a select list down one
267   -// -------------------------------------------------------------------
268   -function moveOptionDown(obj) {
269   - // If > 1 option selected, do nothing
270   - var selectedCount=0;
271   - for (i=0; i<obj.options.length; i++) {
272   - if (obj.options[i].selected) {
273   - selectedCount++;
274   - }
275   - }
276   - if (selectedCount != 1) {
277   - return;
278   - }
279   - // If this is the last item in the list, do nothing
280   - var i = obj.selectedIndex;
281   - if (i == (obj.options.length-1)) {
282   - return;
283   - }
284   - swapOptions(obj,i,i+1);
285   - obj.options[i+1].selected = true;
286   - }
287   -
288   -// -------------------------------------------------------------------
289   -// removeSelectedOptions(select_object)
290   -// Remove all selected options from a list
291   -// (Thanks to Gene Ninestein)
292   -// -------------------------------------------------------------------
293   -function removeSelectedOptions(from) {
294   - for (var i=(from.options.length-1); i>=0; i--) {
295   - var o=from.options[i];
296   - if (o.selected) {
297   - from.options[i] = null;
298   - }
299   - }
300   - from.selectedIndex = -1;
301   - }
302   -
303   -
304   -/* SOURCE FILE: OptionTransfer.js */
305   -
306   -/*
307   -OptionTransfer.js
308   -Last Modified: 11/18/2002
309   -
310   -DESCRIPTION: This widget is used to easily and quickly create an interface
311   -where the user can transfer choices from one select box to another. For
312   -example, when selecting which columns to show or hide in search results.
313   -This object adds value by automatically storing the values that were added
314   -or removed from each list, as well as the state of the final list.
315   -
316   -COMPATABILITY: Should work on all Javascript-compliant browsers.
317   -
318   -USAGE:
319   -// Create a new OptionTransfer object. Pass it the field names of the left
320   -// select box and the right select box.
321   -var ot = new OptionTransfer("from","to");
322   -
323   -// Optionally tell the lists whether or not to auto-sort when options are
324   -// moved. By default, the lists will be sorted.
325   -ot.setAutoSort(true);
326   -
327   -// Optionally set the delimiter to be used to separate values that are
328   -// stored in hidden fields for the added and removed options, as well as
329   -// final state of the lists. Defaults to a comma.
330   -ot.setDelimiter("|");
331   -
332   -// These functions assign the form fields which will store the state of
333   -// the lists. Each one is optional, so you can pick to only store the
334   -// new options which were transferred to the right list, for example.
335   -// Each function takes the name of a HIDDEN or TEXT input field.
336   -
337   -// Store list of options removed from left list into an input field
338   -ot.saveRemovedLeftOptions("removedLeft");
339   -// Store list of options removed from right list into an input field
340   -ot.saveRemovedRightOptions("removedRight");
341   -// Store list of options added to left list into an input field
342   -ot.saveAddedLeftOptions("addedLeft");
343   -// Store list of options radded to right list into an input field
344   -ot.saveAddedRightOptions("addedRight");
345   -// Store all options existing in the left list into an input field
346   -ot.saveNewLeftOptions("newLeft");
347   -// Store all options existing in the right list into an input field
348   -ot.saveNewRightOptions("newRight");
349   -
350   -// IMPORTANT: This step is required for the OptionTransfer object to work
351   -// correctly.
352   -// Add a call to the BODY onLoad="" tag of the page, and pass a reference to
353   -// the form which contains the select boxes and input fields.
354   -BODY onLoad="ot.init(document.forms[0])"
355   -
356   -// ADDING ACTIONS INTO YOUR PAGE
357   -// Finally, add calls to the object to move options back and forth, either
358   -// from links in your page or from double-clicking the options themselves.
359   -// See example page, and use the following methods:
360   -ot.transferRight();
361   -ot.transferAllRight();
362   -ot.transferLeft();
363   -ot.transferAllLeft();
364   -
365   -
366   -NOTES:
367   -1) Requires the functions in selectbox.js
368   -
369   -*/
370   -function OT_transferLeft() { moveSelectedOptions(this.right,this.left,this.autoSort); this.update(); }
371   -function OT_transferRight() { moveSelectedOptions(this.left,this.right,this.autoSort); this.update(); }
372   -function OT_transferAllLeft() { moveAllOptions(this.right,this.left,this.autoSort); this.update(); }
373   -function OT_transferAllRight() { moveAllOptions(this.left,this.right,this.autoSort); this.update(); }
374   -function OT_saveRemovedLeftOptions(f) { this.removedLeftField = f; }
375   -function OT_saveRemovedRightOptions(f) { this.removedRightField = f; }
376   -function OT_saveAddedLeftOptions(f) { this.addedLeftField = f; }
377   -function OT_saveAddedRightOptions(f) { this.addedRightField = f; }
378   -function OT_saveNewLeftOptions(f) { this.newLeftField = f; }
379   -function OT_saveNewRightOptions(f) { this.newRightField = f; }
380   -function OT_update() {
381   - var removedLeft = new Object();
382   - var removedRight = new Object();
383   - var addedLeft = new Object();
384   - var addedRight = new Object();
385   - var newLeft = new Object();
386   - var newRight = new Object();
387   - for (var i=0;i<this.left.options.length;i++) {
388   - var o=this.left.options[i];
389   - newLeft[o.value]=1;
390   - if (typeof(this.originalLeftValues[o.value])=="undefined") {
391   - addedLeft[o.value]=1;
392   - removedRight[o.value]=1;
393   - }
394   - }
395   - for (var i=0;i<this.right.options.length;i++) {
396   - var o=this.right.options[i];
397   - newRight[o.value]=1;
398   - if (typeof(this.originalRightValues[o.value])=="undefined") {
399   - addedRight[o.value]=1;
400   - removedLeft[o.value]=1;
401   - }
402   - }
403   - if (this.removedLeftField!=null) { this.removedLeftField.value = OT_join(removedLeft,this.delimiter); }
404   - if (this.removedRightField!=null) { this.removedRightField.value = OT_join(removedRight,this.delimiter); }
405   - if (this.addedLeftField!=null) { this.addedLeftField.value = OT_join(addedLeft,this.delimiter); }
406   - if (this.addedRightField!=null) { this.addedRightField.value = OT_join(addedRight,this.delimiter); }
407   - if (this.newLeftField!=null) { this.newLeftField.value = OT_join(newLeft,this.delimiter); }
408   - if (this.newRightField!=null) { this.newRightField.value = OT_join(newRight,this.delimiter); }
409   - }
410   -function OT_join(o,delimiter) {
411   - var val; var str="";
412   - for(val in o){
413   - if (str.length>0) { str=str+delimiter; }
414   - str=str+val;
415   - }
416   - return str;
417   - }
418   -function OT_setDelimiter(val) { this.delimiter=val; }
419   -function OT_setAutoSort(val) { this.autoSort=val; }
420   -function OT_init(theform) {
421   - this.form = theform;
422   - if(!theform[this.left]){alert("OptionTransfer init(): Left select list does not exist in form!");return false;}
423   - if(!theform[this.right]){alert("OptionTransfer init(): Right select list does not exist in form!");return false;}
424   - this.left=theform[this.left];
425   - this.right=theform[this.right];
426   - for(var i=0;i<this.left.options.length;i++) {
427   - this.originalLeftValues[this.left.options[i].value]=1;
428   - }
429   - for(var i=0;i<this.right.options.length;i++) {
430   - this.originalRightValues[this.right.options[i].value]=1;
431   - }
432   - if(this.removedLeftField!=null) { this.removedLeftField=theform[this.removedLeftField]; }
433   - if(this.removedRightField!=null) { this.removedRightField=theform[this.removedRightField]; }
434   - if(this.addedLeftField!=null) { this.addedLeftField=theform[this.addedLeftField]; }
435   - if(this.addedRightField!=null) { this.addedRightField=theform[this.addedRightField]; }
436   - if(this.newLeftField!=null) { this.newLeftField=theform[this.newLeftField]; }
437   - if(this.newRightField!=null) { this.newRightField=theform[this.newRightField]; }
438   - this.update();
439   - }
440   -// -------------------------------------------------------------------
441   -// OptionTransfer()
442   -// This is the object interface.
443   -// -------------------------------------------------------------------
444   -function OptionTransfer(l,r) {
445   - this.form = null;
446   - this.left=l;
447   - this.right=r;
448   - this.autoSort=true;
449   - this.delimiter=",";
450   - this.originalLeftValues = new Object();
451   - this.originalRightValues = new Object();
452   - this.removedLeftField = null;
453   - this.removedRightField = null;
454   - this.addedLeftField = null;
455   - this.addedRightField = null;
456   - this.newLeftField = null;
457   - this.newRightField = null;
458   - this.transferLeft=OT_transferLeft;
459   - this.transferRight=OT_transferRight;
460   - this.transferAllLeft=OT_transferAllLeft;
461   - this.transferAllRight=OT_transferAllRight;
462   - this.saveRemovedLeftOptions=OT_saveRemovedLeftOptions;
463   - this.saveRemovedRightOptions=OT_saveRemovedRightOptions;
464   - this.saveAddedLeftOptions=OT_saveAddedLeftOptions;
465   - this.saveAddedRightOptions=OT_saveAddedRightOptions;
466   - this.saveNewLeftOptions=OT_saveNewLeftOptions;
467   - this.saveNewRightOptions=OT_saveNewRightOptions;
468   - this.setDelimiter=OT_setDelimiter;
469   - this.setAutoSort=OT_setAutoSort;
470   - this.init=OT_init;
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   -
516   - }