1 /********************************************************************************
2 * include/philter.js : philter javascript functions
5 * This file is part of the philter distribution
6 * Copyright: See COPYING files that comes with this distribution
7 ********************************************************************************/
9 function text_onfocus(object
,val
) {
10 if(object
.value
== val
)
14 function text_onblur(object
,val
) {
15 if(object
.value
== '')
19 function cleanChilds(Node
, nbChilds
) {
20 while(Node
.childNodes
.length
>nbChilds
)
21 Node
.removeChild(Node
.childNodes
[nbChilds
]);
24 /********** ORDER FORM FUNCTIONS **********/
27 form
= document
.forms
['order'];
28 select
= form
.elements
['order[select]'];
30 if(select
.selectedIndex
>1) {
31 i
= select
.selectedIndex
;
32 value1
= select
.options
[i
].value
;
33 text1
= select
.options
[i
].text
;
34 value2
= select
.options
[i
-1].value
;
35 text2
= select
.options
[i
-1].text
;
37 select
.options
[i
] = new Option(text2
,value2
,false,false);
38 select
.options
[i
-1] = new Option(text1
,value1
,false,false);
39 select
.selectedIndex
= i
-1;
41 form
.elements
['order['+value1
+']'].value
= i
-1;
42 form
.elements
['order['+value2
+']'].value
= i
;
47 form
= document
.forms
['order'];
48 select
= form
.elements
['order[select]'];
50 if(select
.selectedIndex
>0 && select
.selectedIndex
<select
.length
-1) {
51 i
= select
.selectedIndex
;
52 value1
= select
.options
[i
].value
;
53 text1
= select
.options
[i
].text
;
54 value2
= select
.options
[i
+1].value
;
55 text2
= select
.options
[i
+1].text
;
57 select
.options
[i
] = new Option(text2
,value2
,false,false);
58 select
.options
[i
+1] = new Option(text1
,value1
,false,false);
59 select
.selectedIndex
= i
+1;
61 form
.elements
['order['+value1
+']'].value
= i
+1;
62 form
.elements
['order['+value2
+']'].value
= i
;
66 function order_submit(obj
) {
67 if(obj
.name
== 'order[submit]')
68 obj
.form
.elements
['order[action]'].value
= 'submit';
69 if(obj
.name
== 'order[delete]')
70 obj
.form
.elements
['order[action]'].value
= 'delete';
74 /********** RULE FORM GLOBALS **********/
76 var matches_list
= new Array();
77 var matches_func
= new Array();
79 var actions_list
= new Array()
80 var actions_func
= new Array();
82 var mail_pool
= new Array();
83 var filter
= new Array();
90 /********** RULE.ACTION FORM FUNCTIONS **********/
92 function createActionSelect(data
,base
) {
94 var select
= document
.createElement("select");
95 select
.name
= base
+'[0]';
97 for(i
=0, j
=0; i
<actions_list
.length
; i
++)
99 select
.options
[j
++] = new Option(actions_list
[i
],i
,false,(data
==i
));
101 select
.setAttribute("onchange", "changeRow(this,actions_func)");
103 if(select
.selectedIndex
<0)
104 select
.selectedIndex
= 0;
108 function createActionRow(Node
,data
) {
109 var div
= document
.createElement("div");
110 div
.className
= 'row';
111 div
.name
= 'rule[actions]['+actions_i
+']';
113 Node
.appendChild(div
);
115 var del
= document
.createElement("input");
116 del
.setAttribute("type", "submit");
117 del
.setAttribute("value", "Del");
118 del
.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
119 div
.appendChild(del
);
121 div
.appendChild(document
.createTextNode(" "));
123 var select
= createActionSelect(data
[0],div
.name
);
124 div
.appendChild(select
);
126 actions_func
[select
.options
[select
.selectedIndex
].value
](div
,data
);
129 function newAction() {
130 createActionRow(document
.all
['actions_row'], 0);
133 /********** RULE.MATCH FORM FUNCTIONS **********/
135 function createMatchSelect(data
,base
) {
137 var select
= document
.createElement("select");
138 select
.name
= base
+'[0]';
140 for(i
=0, j
=0; i
<matches_list
.length
; i
++)
142 select
.options
[j
++] = new Option(matches_list
[i
],i
,false,(data
==i
));
144 select
.setAttribute("onchange", "changeRow(this,matches_func)");
146 if(select
.selectedIndex
<0)
147 select
.selectedIndex
= 0;
151 function createMatchRow(Node
,data
) {
152 var div
= document
.createElement("div");
153 div
.className
= 'row';
154 div
.name
= 'rule[matches]['+actions_i
+']';
156 Node
.appendChild(div
);
158 var del
= document
.createElement("input");
159 del
.setAttribute("type", "submit");
160 del
.setAttribute("value", "Del");
161 del
.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
162 div
.appendChild(del
);
164 div
.appendChild(document
.createTextNode(" "));
166 var select
= createMatchSelect(data
[0],div
.name
);
167 div
.appendChild(select
);
169 matches_func
[select
.options
[select
.selectedIndex
].value
](div
,data
);
172 function newMatch() {
173 createMatchRow(document
.all
['matches_row'], 0);
176 /********** RULE FORM FUNCTIONS **********/
178 function changeRow(sel
, funcs
) {
179 var row
= sel
.parentNode
;
181 funcs
[sel
.options
[sel
.selectedIndex
].value
](row
,0);
184 function createRuleForm() {
186 var sel
= document
.all
['order[select]'];
187 var index
= sel
.options
[sel
.selectedIndex
].value
;
189 actions_i
= matches_i
= 0;
190 current_rule
= filter
[index
];
192 document
.all
['rule[id]'].value
= index
;
193 document
.all
['rule[name]'].value
= current_rule
.name
;
194 document
.all
['rule[all]'][1-current_rule
.all
].checked
= true;
195 document
.all
['rule[block]'].checked
= current_rule
.block
;
197 var mr
= document
.all
['matches_row'];
199 for(i
=0; i
<current_rule
.matches
.length
; i
++)
200 createMatchRow(mr
, current_rule
.matches
[i
]);
202 var ar
= document
.all
['actions_row'];
204 for(i
=0; i
<current_rule
.actions
.length
; i
++)
205 createActionRow(ar
, current_rule
.actions
[i
]);
208 /********************************************************************************
210 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
211 ********************************************************************************/