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 function getElement(obj
) {
25 if(document
.getElementById
)
26 return document
.getElementById(obj
);
28 return document
.all
[obj
];
32 function del_onclick(val
) {
33 if(window
.confirm(del_q_i18n
)) {
34 getElement('emailsDel').value
= val
;
35 document
.forms
['emails'].submit();
39 /********** ORDER FORM FUNCTIONS **********/
42 form
= document
.forms
['order'];
43 select
= getElement('orderSelect');
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
;
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;
56 form
.elements
['order'+value1
].value
= i
-1;
57 form
.elements
['order'+value2
].value
= i
;
62 form
= document
.forms
['order'];
63 select
= getElement('orderSelect');
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
;
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;
76 form
.elements
['order'+value1
].value
= i
+1;
77 form
.elements
['order'+value2
].value
= i
;
81 function order_submit(obj
) {
82 if(obj
.name
== 'order[submit]')
83 obj
.form
.elements
['order[action]'].value
= 'submit';
84 if(obj
.name
== 'order[delete]')
85 obj
.form
.elements
['order[action]'].value
= 'delete';
89 /********** RULE FORM GLOBALS **********/
91 var matches_list
= new Array();
92 var matches_func
= new Array();
94 var actions_list
= new Array()
95 var actions_func
= new Array();
97 var mail_pool
= new Array();
98 var filter
= new Array();
105 var del_i18n
= 'Del';
106 var del_q_i18n
= 'Del';
108 /********** RULE.ACTION FORM FUNCTIONS **********/
110 function createActionSelect(div
,data
) {
112 var select
= document
.createElement("select");
114 select
.name
= div
.name
+'[0]';
116 // OG: must insert select node before creating options because of IE5 bug
117 div
.appendChild(select
);
118 for(i
=0, j
=0; i
<actions_list
.length
; i
++) {
120 if(actions_list
[i
]) select
.options
[j
++] = new Option(actions_list
[i
],i
,false,(data
==i
));
123 select
.selectedIndex
= sel
;
124 select
.onchange
= function () { changeRow(this,actions_func
); };
129 function createActionRow(Node
,data
) {
130 var div
= document
.createElement("div");
131 div
.name
= 'rule[actions]['+actions_i
+']';
133 Node
.appendChild(div
);
135 var del
= document
.createElement("input");
136 del
.setAttribute("type", "submit");
137 del
.setAttribute("value", del_i18n
);
138 del
.onclick
= function () { del
.parentNode
.parentNode
.removeChild(del
.parentNode
); };
139 div
.appendChild(del
);
141 div
.appendChild(document
.createTextNode(" "));
143 var select
= createActionSelect(div
,data
[0]);
145 actions_func
[select
.options
[select
.selectedIndex
].value
](div
,data
);
148 function newAction() {
149 createActionRow(getElement('actionsRow'), [-1]);
152 /********** RULE.MATCH FORM FUNCTIONS **********/
154 function createMatchSelect(div
,data
) {
156 var select
= document
.createElement("select");
158 select
.name
= div
.name
+'[0]';
160 // OG: must insert select node before creating options because of IE5 bug
161 div
.appendChild(select
);
162 for(i
=0, j
=0; i
<matches_list
.length
; i
++) {
164 if(matches_list
[i
]) select
.options
[j
++] = new Option(matches_list
[i
],i
,false,(data
==i
));
167 select
.selectedIndex
= sel
;
168 select
.onchange
= function () { changeRow(this,matches_func
); };
173 function createMatchRow(Node
,data
) {
174 var div
= document
.createElement("div");
175 div
.name
= 'rule[matches]['+actions_i
+']';
177 Node
.appendChild(div
);
179 var del
= document
.createElement("input");
180 del
.setAttribute("type", "submit");
181 del
.setAttribute("value", del_i18n
);
182 del
.onclick
= function () { del
.parentNode
.parentNode
.removeChild(del
.parentNode
); };
183 div
.appendChild(del
);
185 div
.appendChild(document
.createTextNode(" "));
187 var select
= createMatchSelect(div
,data
[0]);
189 matches_func
[select
.options
[select
.selectedIndex
].value
](div
,data
);
192 function newMatch() {
193 createMatchRow(getElement('matchesRow'), [-1]);
196 /********** RULE FORM FUNCTIONS **********/
198 function changeRow(sel
, funcs
) {
199 var row
= sel
.parentNode
;
201 funcs
[sel
.options
[sel
.selectedIndex
].value
](row
,0);
204 function createRuleForm() {
206 var sel
= getElement('orderSelect');
207 var index
= sel
.options
[sel
.selectedIndex
].value
;
209 actions_i
= matches_i
= 0;
210 current_rule
= filter
[index
];
212 getElement('ruleId').value
= index
;
213 getElement('ruleName').value
= current_rule
.name
;
214 var c
= (current_rule
.all
? '1' : '0');
215 getElement('ruleAll'+c
).checked
= true;
216 getElement('ruleBlock').checked
= current_rule
.block
;
218 var mr
= getElement('matchesRow');
220 for(i
=0; i
<current_rule
.matches
.length
; i
++)
221 createMatchRow(mr
, current_rule
.matches
[i
]);
223 var ar
= getElement('actionsRow');
225 for(i
=0; i
<current_rule
.actions
.length
; i
++)
226 createActionRow(ar
, current_rule
.actions
[i
]);
229 /********************************************************************************
231 * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
232 ********************************************************************************/