Project

General

Profile

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

    
5
        Copyright (C) 2005 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

    
35
  var IntOrIp;
36
	var enabledSel = form['servers[]'];
37
	var disabledSel = form['serversdisabled[]'];
38
	if (form.type.selectedIndex == 0)
39
	    IntOrIp = form.ipaddr;
40
	else
41
	    IntOrIp = form.iface;
42

    
43
	if (form.type.selectedIndex == 1) {
44
		if (!form.monitorip.value) {
45
			alert("Monitor IP Required First!");
46
			return true;
47
		}
48
	}
49

    
50
	var ServerPort = IntOrIp.value;
51
	if(form.type.selectedIndex == 0)
52
		var ServerPort = IntOrIp.value;
53
	else
54
		var ServerPort = IntOrIp.value + "|" + form.monitorip.value;
55
	form['servers[]'].options[form['servers[]'].options.length] = new Option(ServerPort,ServerPort);
56
}
57

    
58

    
59
function AllServers(id, selectAll) {
60
   var opts = document.getElementById(id).getElementsByTagName('option');
61
   for (i = 0; i < opts.length; i++)
62
   {
63
       opts[i].selected = selectAll;
64
   }
65
}
66

    
67

    
68
function RemoveServerFromPool(form, field)
69
{
70
	var theSel = form[field];
71
	var selIndex = theSel.selectedIndex;
72
	if (selIndex != -1) {
73
		for(i=theSel.length-1; i>=0; i--)
74
		{
75
			if(theSel.options[i].selected)
76
			{
77
				theSel.options[i] = null;
78
			}
79
		}
80
		if (theSel.length > 0) {
81
			theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
82
		}
83
	}
84
}
85

    
86
function addOption(theSel, theText, theValue)
87
{
88
	var newOpt = new Option(theText, theValue);
89
	var selLength = theSel.length;
90
	theSel.options[selLength] = newOpt;
91
}
92

    
93
function deleteOption(theSel, theIndex)
94
{ 
95
	var selLength = theSel.length;
96
	if(selLength>0)
97
	{
98
		theSel.options[theIndex] = null;
99
	}
100
}
101

    
102
function moveOptions(theSelFrom, theSelTo)
103
{
104
	var selLength = theSelFrom.length;
105
	var selectedText = new Array();
106
	var selectedValues = new Array();
107
	var selectedCount = 0;
108

    
109
	var i;
110

    
111
	// Find the selected Options in reverse order
112
	// and delete them from the 'from' Select.
113
	for(i=selLength-1; i>=0; i--)
114
	{
115
		if(theSelFrom.options[i].selected)
116
		{
117
			selectedText[selectedCount] = theSelFrom.options[i].text;
118
			selectedValues[selectedCount] = theSelFrom.options[i].value;
119
			deleteOption(theSelFrom, i);
120
			selectedCount++;
121
		}
122
	}
123

    
124
	// Add the selected text/values in reverse order.
125
	// This will add the Options to the 'to' Select
126
	// in the same order as they were in the 'from' Select.
127
	for(i=selectedCount-1; i>=0; i--)
128
	{
129
		addOption(theSelTo, selectedText[i], selectedValues[i]);
130
	}
131
}
132

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

    
135
function up(obj) {
136
	var sel = new Array();
137
	for (var i=0; i<obj.length; i++) {
138
		if (obj[i].selected == true) {
139
			sel[sel.length] = i;
140
		}
141
	}
142
	for (i in sel) {
143
		if (sel[i] != 0 && !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
}
154

    
155
function down(obj) {
156
	var sel = new Array();
157
	for (var i=obj.length-1; i>-1; i--) {
158
		if (obj[i].selected == true) {
159
			sel[sel.length] = i;
160
		}
161
	}
162
	for (i in sel) {
163
		if (sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {
164
			var tmp = new Array(obj[sel[i]+1].text, obj[sel[i]+1].value);
165
			obj[sel[i]+1].text = obj[sel[i]].text;
166
			obj[sel[i]+1].value = obj[sel[i]].value;
167
			obj[sel[i]].text = tmp[0];
168
			obj[sel[i]].value = tmp[1];
169
			obj[sel[i]+1].selected = true;
170
			obj[sel[i]].selected = false;
171
		}
172
	}
173
}
(98-98/189)