Commit | Line | Data |
---|---|---|
dd8de1ec PH |
1 | /******************************************************************************** |
2 | * include/philter.js : philter javascript functions | |
3 | * ------------------ | |
4 | * | |
5 | * This file is part of the philter distribution | |
6 | * Copyright: See COPYING files that comes with this distribution | |
7 | ********************************************************************************/ | |
8 | ||
9 | function text_onfocus(object,val) { | |
10 | if(object.value == val) | |
11 | object.value = ''; | |
12 | } | |
13 | ||
14 | function text_onblur(object,val) { | |
15 | if(object.value == '') | |
16 | object.value = val; | |
17 | } | |
18 | ||
19 | function cleanChilds(Node, nbChilds) { | |
20 | while(Node.childNodes.length>nbChilds) | |
21 | Node.removeChild(Node.childNodes[nbChilds]); | |
22 | } | |
23 | ||
242c14dc | 24 | function getElement(obj) { |
693b6ec6 PH |
25 | if(document.getElementById) |
26 | return document.getElementById(obj); | |
3e328a2d | 27 | if(document.all) |
693b6ec6 | 28 | return document.all[obj]; |
1b874dc4 | 29 | return false; |
0aa1a917 PH |
30 | } |
31 | ||
0eb037c8 | 32 | function del_onclick(val) { |
5ae3e923 | 33 | if(window.confirm(del_q_i18n)) { |
0eb037c8 PH |
34 | getElement('emailsDel').value = val; |
35 | document.forms['emails'].submit(); | |
4956445b | 36 | } |
01f3d5ec PH |
37 | } |
38 | ||
dd8de1ec PH |
39 | /********** ORDER FORM FUNCTIONS **********/ |
40 | ||
41 | function order_up() { | |
42 | form = document.forms['order']; | |
242c14dc | 43 | select = getElement('orderSelect'); |
dd8de1ec PH |
44 | |
45 | if(select.selectedIndex>1) { | |
46 | i = select.selectedIndex; | |
47 | value1 = select.options[i].value; | |
48 | text1 = select.options[i].text; | |
49 | value2 = select.options[i-1].value; | |
50 | text2 = select.options[i-1].text; | |
51 | ||
52 | select.options[i] = new Option(text2,value2,false,false); | |
53 | select.options[i-1] = new Option(text1,value1,false,false); | |
54 | select.selectedIndex = i-1; | |
55 | ||
242c14dc PH |
56 | form.elements['order'+value1].value = i-1; |
57 | form.elements['order'+value2].value = i; | |
dd8de1ec PH |
58 | } |
59 | } | |
60 | ||
61 | function order_dn() { | |
62 | form = document.forms['order']; | |
cd37c077 | 63 | select = getElement('orderSelect'); |
dd8de1ec PH |
64 | |
65 | if(select.selectedIndex>0 && select.selectedIndex<select.length-1) { | |
66 | i = select.selectedIndex; | |
67 | value1 = select.options[i].value; | |
68 | text1 = select.options[i].text; | |
69 | value2 = select.options[i+1].value; | |
70 | text2 = select.options[i+1].text; | |
71 | ||
72 | select.options[i] = new Option(text2,value2,false,false); | |
73 | select.options[i+1] = new Option(text1,value1,false,false); | |
74 | select.selectedIndex = i+1; | |
75 | ||
242c14dc PH |
76 | form.elements['order'+value1].value = i+1; |
77 | form.elements['order'+value2].value = i; | |
dd8de1ec PH |
78 | } |
79 | } | |
80 | ||
81 | function order_submit(obj) { | |
82 | if(obj.name == 'order[submit]') | |
311c293a | 83 | obj.form.elements['order[action]'].value = 'submit'; |
dd8de1ec | 84 | if(obj.name == 'order[delete]') |
311c293a | 85 | obj.form.elements['order[action]'].value = 'delete'; |
dd8de1ec PH |
86 | obj.form.submit(); |
87 | } | |
88 | ||
89 | /********** RULE FORM GLOBALS **********/ | |
90 | ||
91 | var matches_list = new Array(); | |
92 | var matches_func = new Array(); | |
93 | ||
94 | var actions_list = new Array() | |
95 | var actions_func = new Array(); | |
96 | ||
97 | var mail_pool = new Array(); | |
98 | var filter = new Array(); | |
99 | ||
100 | var current_rule; | |
101 | ||
102 | var actions_i = 0; | |
103 | var matches_i = 0; | |
104 | ||
5ae3e923 PH |
105 | var del_i18n = 'Del'; |
106 | var del_q_i18n = 'Del'; | |
107 | ||
dd8de1ec PH |
108 | /********** RULE.ACTION FORM FUNCTIONS **********/ |
109 | ||
0eb037c8 | 110 | function createActionSelect(div,data) { |
dd8de1ec PH |
111 | var i,j; |
112 | var select = document.createElement("select"); | |
8294c7d2 | 113 | var sel = 0; |
0eb037c8 | 114 | select.name = div.name+'[0]'; |
dd8de1ec | 115 | |
0eb037c8 PH |
116 | // OG: must insert select node before creating options because of IE5 bug |
117 | div.appendChild(select); | |
8294c7d2 PH |
118 | for(i=0, j=0; i<actions_list.length; i++) { |
119 | if(data==i) sel = j; | |
120 | if(actions_list[i]) select.options[j++] = new Option(actions_list[i],i,false,(data==i)); | |
121 | } | |
dd8de1ec | 122 | |
8294c7d2 PH |
123 | select.selectedIndex = sel; |
124 | select.onchange = function () { changeRow(this,actions_func); }; | |
125 | ||
dd8de1ec PH |
126 | return select; |
127 | } | |
128 | ||
129 | function createActionRow(Node,data) { | |
130 | var div = document.createElement("div"); | |
dd8de1ec PH |
131 | div.name = 'rule[actions]['+actions_i+']'; |
132 | actions_i++; | |
133 | Node.appendChild(div); | |
134 | ||
135 | var del = document.createElement("input"); | |
136 | del.setAttribute("type", "submit"); | |
5ae3e923 | 137 | del.setAttribute("value", del_i18n); |
8294c7d2 | 138 | del.onclick = function () { del.parentNode.parentNode.removeChild(del.parentNode); }; |
dd8de1ec PH |
139 | div.appendChild(del); |
140 | ||
141 | div.appendChild(document.createTextNode(" ")); | |
142 | ||
0eb037c8 | 143 | var select = createActionSelect(div,data[0]); |
dd8de1ec PH |
144 | |
145 | actions_func[select.options[select.selectedIndex].value](div,data); | |
146 | } | |
147 | ||
148 | function newAction() { | |
693b6ec6 | 149 | createActionRow(getElement('actionsRow'), [-1]); |
dd8de1ec PH |
150 | } |
151 | ||
152 | /********** RULE.MATCH FORM FUNCTIONS **********/ | |
153 | ||
0eb037c8 | 154 | function createMatchSelect(div,data) { |
dd8de1ec PH |
155 | var i,j; |
156 | var select = document.createElement("select"); | |
8294c7d2 | 157 | var sel = 0; |
0eb037c8 | 158 | select.name = div.name+'[0]'; |
dd8de1ec | 159 | |
0eb037c8 PH |
160 | // OG: must insert select node before creating options because of IE5 bug |
161 | div.appendChild(select); | |
8294c7d2 PH |
162 | for(i=0, j=0; i<matches_list.length; i++) { |
163 | if(data==i) sel = j; | |
164 | if(matches_list[i]) select.options[j++] = new Option(matches_list[i],i,false,(data==i)); | |
165 | } | |
dd8de1ec | 166 | |
8294c7d2 PH |
167 | select.selectedIndex = sel; |
168 | select.onchange = function () { changeRow(this,matches_func); }; | |
dd8de1ec | 169 | |
dd8de1ec PH |
170 | return select; |
171 | } | |
172 | ||
173 | function createMatchRow(Node,data) { | |
174 | var div = document.createElement("div"); | |
dd8de1ec PH |
175 | div.name = 'rule[matches]['+actions_i+']'; |
176 | actions_i++; | |
177 | Node.appendChild(div); | |
178 | ||
179 | var del = document.createElement("input"); | |
180 | del.setAttribute("type", "submit"); | |
5ae3e923 | 181 | del.setAttribute("value", del_i18n); |
8294c7d2 | 182 | del.onclick = function () { del.parentNode.parentNode.removeChild(del.parentNode); }; |
dd8de1ec PH |
183 | div.appendChild(del); |
184 | ||
185 | div.appendChild(document.createTextNode(" ")); | |
186 | ||
0eb037c8 | 187 | var select = createMatchSelect(div,data[0]); |
dd8de1ec PH |
188 | |
189 | matches_func[select.options[select.selectedIndex].value](div,data); | |
190 | } | |
191 | ||
192 | function newMatch() { | |
693b6ec6 | 193 | createMatchRow(getElement('matchesRow'), [-1]); |
dd8de1ec PH |
194 | } |
195 | ||
196 | /********** RULE FORM FUNCTIONS **********/ | |
197 | ||
198 | function changeRow(sel, funcs) { | |
199 | var row = sel.parentNode; | |
200 | cleanChilds(row,3); | |
201 | funcs[sel.options[sel.selectedIndex].value](row,0); | |
202 | } | |
203 | ||
204 | function createRuleForm() { | |
205 | var i; | |
242c14dc | 206 | var sel = getElement('orderSelect'); |
dd8de1ec PH |
207 | var index = sel.options[sel.selectedIndex].value; |
208 | ||
209 | actions_i = matches_i = 0; | |
210 | current_rule = filter[index]; | |
211 | ||
242c14dc PH |
212 | getElement('ruleId').value = index; |
213 | getElement('ruleName').value = current_rule.name; | |
693b6ec6 | 214 | var c = (current_rule.all ? '1' : '0'); |
242c14dc PH |
215 | getElement('ruleAll'+c).checked = true; |
216 | getElement('ruleBlock').checked = current_rule.block; | |
dd8de1ec | 217 | |
693b6ec6 | 218 | var mr = getElement('matchesRow'); |
dd8de1ec PH |
219 | cleanChilds(mr,0); |
220 | for(i=0; i<current_rule.matches.length; i++) | |
221 | createMatchRow(mr, current_rule.matches[i]); | |
222 | ||
693b6ec6 | 223 | var ar = getElement('actionsRow'); |
dd8de1ec PH |
224 | cleanChilds(ar,0); |
225 | for(i=0; i<current_rule.actions.length; i++) | |
226 | createActionRow(ar, current_rule.actions[i]); | |
227 | } | |
228 | ||
229 | /******************************************************************************** | |
230 | * $Id$ | |
231 | * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: | |
232 | ********************************************************************************/ |