Project

General

Profile

Download (4.38 KB) Statistics
| Branch: | Tag: | Revision:
1
/*
2
        pool.js
3
        part of pfSense (http://www.pfsense.com/)
4

    
5
        Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
6
        All rights reserved.
7

    
8
        Redistribution and use in source and binary forms, with or without
9
        modification, are permitted provided that the following conditions are met:
10

    
11
        1. Redistributions of source code must retain the above copyright notice,
12
           this list of conditions and the following disclaimer.
13

    
14
        2. Redistributions in binary form must reproduce the above copyright
15
           notice, this list of conditions and the following disclaimer in the
16
           documentation and/or other materials provided with the distribution.
17

    
18
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
        POSSIBILITY OF SUCH DAMAGE.
28
*/
29

    
30
/* Add server to virtual server pool
31
 * operates on whatever form is passed to it
32
 */
33
function AddServerToPool(form) {
34
	var ServerPort = form.ipaddr.value;
35
	form['servers[]'].options[form['servers[]'].options.length] = new Option(ServerPort,ServerPort);
36
}
37

    
38

    
39
function AllServers(id, selectAll) {
40
   var opts = document.getElementById(id).getElementsByTagName('option');
41
   for (i = 0; i < opts.length; i++)
42
   {
43
       opts[i].selected = selectAll;
44
   }
45
}
46

    
47

    
48
function RemoveServerFromPool(form, field)
49
{
50
	var theSel = form[field];
51
	var selIndex = theSel.selectedIndex;
52
	if (selIndex != -1) {
53
		for(i=theSel.length-1; i>=0; i--)
54
		{
55
			if(theSel.options[i].selected)
56
			{
57
				theSel.options[i] = null;
58
			}
59
		}
60
		if (theSel.length > 0) {
61
			theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
62
		}
63
	}
64
}
65

    
66
function addOption(theSel, theText, theValue)
67
{
68
	var newOpt = new Option(theText, theValue);
69
	var selLength = theSel.length;
70
	theSel.options[selLength] = newOpt;
71
}
72

    
73
function deleteOption(theSel, theIndex)
74
{ 
75
	var selLength = theSel.length;
76
	if(selLength>0)
77
	{
78
		theSel.options[theIndex] = null;
79
	}
80
}
81

    
82
function moveOptions(theSelFrom, theSelTo)
83
{
84
	var selLength = theSelFrom.length;
85
	var selectedText = new Array();
86
	var selectedValues = new Array();
87
	var selectedCount = 0;
88

    
89
	var i;
90

    
91
	// Find the selected Options in reverse order
92
	// and delete them from the 'from' Select.
93
	for(i=selLength-1; i>=0; i--)
94
	{
95
		if(theSelFrom.options[i].selected)
96
		{
97
			selectedText[selectedCount] = theSelFrom.options[i].text;
98
			selectedValues[selectedCount] = theSelFrom.options[i].value;
99
			deleteOption(theSelFrom, i);
100
			selectedCount++;
101
		}
102
	}
103

    
104
	// Add the selected text/values in reverse order.
105
	// This will add the Options to the 'to' Select
106
	// in the same order as they were in the 'from' Select.
107
	for(i=selectedCount-1; i>=0; i--)
108
	{
109
		addOption(theSelTo, selectedText[i], selectedValues[i]);
110
	}
111
}
112

    
113
// functions up() and down() modified from http://www.babailiica.com/js/sorter/
114

    
115
function up(obj) {
116
	var sel = new Array();
117
	for (var i=0; i<obj.length; i++) {
118
		if (obj[i].selected == true) {
119
			sel[sel.length] = i;
120
		}
121
	}
122
	for (i in sel) {
123
		if (sel[i] != 0 && !obj[sel[i]-1].selected) {
124
			var tmp = new Array(obj[sel[i]-1].text, obj[sel[i]-1].value);
125
			obj[sel[i]-1].text = obj[sel[i]].text;
126
			obj[sel[i]-1].value = obj[sel[i]].value;
127
			obj[sel[i]].text = tmp[0];
128
			obj[sel[i]].value = tmp[1];
129
			obj[sel[i]-1].selected = true;
130
			obj[sel[i]].selected = false;
131
		}
132
	}
133
}
134

    
135
function down(obj) {
136
	var sel = new Array();
137
	for (var i=obj.length-1; i>-1; i--) {
138
		if (obj[i].selected == true) {
139
			sel[sel.length] = i;
140
		}
141
	}
142
	for (i in sel) {
143
		if (sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {
144
			var tmp = new Array(obj[sel[i]+1].text, obj[sel[i]+1].value);
145
			obj[sel[i]+1].text = obj[sel[i]].text;
146
			obj[sel[i]+1].value = obj[sel[i]].value;
147
			obj[sel[i]].text = tmp[0];
148
			obj[sel[i]].value = tmp[1];
149
			obj[sel[i]+1].selected = true;
150
			obj[sel[i]].selected = false;
151
		}
152
	}
153
}
(115-115/210)