source: trunk/expressoMail1_2/js/filter.js @ 197

Revision 197, 17.9 KB checked in by niltonneto, 16 years ago (diff)

Ticket #147: Revisão da internacionalização
Ticket #152: Melhoria no Fora de Escritório
Implementação da funcao write_msg com a opção de não apagar aviso.
Implementação da funcao clean_msg para limpar aviso.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1function charCounter(form)
2{
3        if (form.value.length >= 300) {
4                alert(get_lang("You have exceeded the number of allowed characters"));
5                return false;
6        }
7
8}
9
10        function cfilter(){
11
12                this.mode_in   = "";
13                this.rulest              = new Array;
14                this.out_officeR = "";
15                this.out_officeF = false;
16                this.email_deny  = new Array;
17                this.ac_form     = "";
18                this.ind                 = "";
19                this.email_deny  = new Array;
20                this.email_ld    = "";
21                this.values = new Array("",
22                                        ",checkBox1",
23                                        ",select_size=1",
24                                        ",checkBox1,select_size=1",
25                                        ",select_rules=1",
26                                        ",checkBox1,select_rules=1",                           
27                                        ",select_size=1,select_rules=1",                               
28                                        ",checkBox1,select_size=1,select_rules=1",
29                                        ",checkBox2",                           
30                                        ",checkBox1,checkBox2",                         
31                                        ",checkBox2,select_size=1",
32                                        ",ckeckBox1,checkBox2,select_size=1",
33                                        ",checkBox2,select_rules=1",                                                                                                                                                           
34                                        ",checkBox1,checkBox2,select_rules=1",                         
35                                        ",checkBox2,select_size=1,select_rules=1",                             
36                                        ",checkBox1,checkBox2,select_size=1,select_rules=1");
37               
38        }
39       
40        cfilter.prototype.load_rules = function(){
41                var _this = this;
42                if(_this.rulest.length == 0){
43                        var handler_sieve = function(data){
44                                if(data.rule.length > 0){
45                                        for(var i=0 ; i < data.rule.length; i++){
46                                                _this.rulest[_this.rulest.length] = data.rule[i];
47                                        }
48                                }
49                                _this.out_officeR = data.vacation[0];
50                                _this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
51                                if(data.mode.length > 0){_this.mode_in = data.mode[0];}
52                        }
53                        if(Element('form_status') != null)
54                                Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
55                        cExecute("$this.ScriptS.init_a",handler_sieve);
56                        _this.get_email();
57            }
58        }
59       
60        cfilter.prototype.form_m = function(){
61                Element('form_body').innerHTML = "";
62                Element('form_buttons').style.display = '';
63                filters.mount_list();
64                this.ac_form = "";             
65        }
66       
67        cfilter.prototype.form_out = function(){
68                Element('form_body').innerHTML = "";
69                Element('form_body').innerHTML = this.forms_();
70                Element('div_vacation').style.display = "";
71                this.ac_form = "old_out";               
72                this.r_rules_out();             
73        }
74       
75        cfilter.prototype.form_r = function(pos){
76                Element('form_body').innerHTML = "";
77                Element('form_body').innerHTML = this.forms_();
78                Element('div_rule').style.display = "";
79                this.ac_form = "old_rule";
80                this.ind = pos;
81                this.r_rules_form(pos);
82        }
83       
84        cfilter.prototype.get_email = function(){
85                var _this = this;
86                var handler_get_email = function(data){
87                        _this.email_ld = data ? data : "";
88                }
89                cExecute("$this.user.get_email",handler_get_email);
90        }
91       
92        cfilter.prototype.sel_boxes = function(){
93                var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
94                if(document.getElementById("select_mailboxes") != null){
95                        var sel_nm = document.getElementById("select_mailboxes");
96                        if(sel_nm.length > 0 ){
97                                for(var i=0; i < sel_nm.options.length; i++){
98                                        sel_nm.options[i] = null;
99                                        i--;
100                                }
101                        }
102                        for(var i=0; i < nm_folders.length; i++){
103                                if(nm_folders[i].id != "root"){
104                                        var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
105                                        sel_nm[sel_nm.length] = opt;
106                                }
107                        }
108                        sel_nm[0].selected = true;
109                }
110        }
111
112        cfilter.prototype.box_select = function(param){
113                var aux = this.BoxSelection[param].split(",");
114                var ele1 = document.getElementById(aux[0]);
115                var ele2 = document.getElementById(aux[1]);
116                var noption = "";
117                if(param == 0 || param == 1){
118                        if(ele1.selectedIndex != -1){
119                                noption = new Option(ele1.value,ele1.value,false,false);
120                                ele2.options[ele2.length] = noption;
121                                ele1.options[ele1.selectedIndex] = null;
122                                ele1.selectedIndex = 0;
123                        }
124                }
125        }
126
127        cfilter.prototype.r_rules_form = function(ind){
128               
129                // hide buttons
130                Element('form_buttons').style.display = 'none';
131
132                this.sel_boxes();
133                var aux = new Array;
134                var _this = this;
135                if(this.rulest.length == 0){
136                        return false;
137                }
138                aux = _this.rulest[ind].split("&&");
139                document.getElementById("field1").value = aux[3];
140                document.getElementById("field2").value = aux[4];
141                document.getElementById("field3").value = aux[5];
142                document.getElementById("field4").value = aux[11];                             
143               
144                switch(aux[6]){
145                        case "folder":
146                                document.getElementById("radio1").checked  = true;
147                                var name_mb = aux[7];
148                                var sel_mb = document.getElementById("select_mailboxes");
149                                for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
150                                break;
151                        case "address":
152                                document.getElementById("radio2").checked   = true;
153                                document.getElementById("field5").value         = aux[7];
154                                break;
155                        case "reject":
156                                 document.getElementById("radio3").checked  = true;
157                                 var text0 = aux[7].split("\\n");                                       
158                                 for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
159                                 break;
160                        case "discard":
161                                document.getElementById("radio4").checked       = true;
162                                break;
163                }
164                var mark_values = this.values[aux[8]].split(",");
165                for(var i=0; i < mark_values.length; i++){
166                        if( mark_values[i] == "checkBox1" || mark_values[i] == "checkBox2"){
167                                document.getElementById(mark_values[i]).checked = true;
168                        }
169                        if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
170                                var mark_val = mark_values[i].split("=");
171                                document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
172                        }
173                }
174        }
175
176        cfilter.prototype.r_rules_out = function(){
177       
178                var _this = this;
179                if(_this.out_officeR.length == 0){
180                        return false;
181                }
182               
183                // hide buttons
184                Element('form_buttons').style.display = 'none';
185       
186                var aux = _this.out_officeR.split("&&");
187                var days   = aux[1];
188                var emails = aux[2];
189                var mens   = aux[3];           
190                var p_emails = new Array;
191                var d_emails = new Array;
192                               
193                var p_aux = emails.split(", ");
194                for(var i=0; i < p_aux.length; i++){
195                        p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
196                        p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
197                }
198                for(var i=0; i < _this.email_ld.length; i++){
199                        d_emails[i] = _this.email_ld[i];
200                }
201
202                diff = function(vet, comp){
203                        var sel1 = new Array;
204                        for(var i=0; i < vet.length; i++){
205                                for(var j=0; j < comp.length; j++){
206                                        if(vet[i] == comp[j]){
207                                                comp.splice(j,1);
208                                                j--;
209                                        }
210                                }
211                        }
212                };     
213                diff(p_emails,d_emails);
214                var text    = mens.split("\\n");
215                for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
216                for(var i=0; i < _this.email_ld.length; i++){
217                        d_emails[i] = _this.email_ld[i];
218                }
219
220        }
221
222        cfilter.prototype.forms_ = function(){
223                        var form   = "";
224                        form       = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
225                                                 "<tr><td colspan='2'><input type='checkBox' id='checkBox1' name='checkb'>"+get_lang('Also check message against next rule') + "</td></tr>"+
226                                                 "<tr><td colspan='2'><input type='checkBox' id='checkBox2' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
227                                                 "<tr><td colspan='2'><hr size='1' width='100%'></td></tr><tr>"+
228                                                 "<td rowspan='4' width='20%'>"+get_lang('Coincident')+"<br><select id='select_rules' name='select_rules'>"+
229                                                 "<option value='0'>"+get_lang("with all")+"</option><option value='1'>"+get_lang("with some")+"</option>"+
230                                                 "</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+
231                                                 "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+
232                                                 "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+
233                                                 "</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
234                                                 "<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+                                         
235                                                 "</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
236                                                 "</tr><tr><td colspan='2'><hr size='1' width='100%'></td></tr>"+
237                                                 "</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
238                                                 "<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
239                                                 "<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
240                                                 "</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
241                                                 "<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
242                                                 "</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
243                                                 "<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
244                                                 "</tr><tr><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
245                                                 "</tr></table></div><div id='div_vacation' style='display:none'>"+
246                                                 "<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
247                                                 "<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
248                                                 //"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
249                                                 "<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
250                                                 "</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>"+
251                                                 "<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
252                                                 "<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";                                           
253                return form;
254        }
255
256        cfilter.prototype.enabled_disabled = function(param){
257
258                // Rules
259                if(Element("rule_0") != null){
260                        for(var i=0; i < this.rulest.length; i++){
261                                if(Element("rule_"+i).checked){
262                                        var aux_rul = this.rulest[i].split("&&");
263                                        if(aux_rul[2] != param){
264                                                aux_rul[2] = param;                                     
265                                                var rl = "";
266                                                for(var j=0; j < aux_rul.length; j++){
267                                                        rl += aux_rul[j] + "&&";
268                                                }
269                                                rl = rl.substr(0,(rl.length - 2));
270                                                this.rulest[i] = rl;                                   
271                                        }
272                                }
273                        }
274                }
275                // Out Office
276                if(Element("out_0") != null){
277                        if(Element("out_0").checked){
278                                var aux_out = this.out_officeR.split("&&");
279                                if(param == "ENABLED")
280                                        aux_out[4] = "on ";
281                                else
282                                        aux_out[4] = "off";
283                                var out = "";
284                                for(var i=0; i < aux_out.length; i++){
285                                        out += aux_out[i] + "&&";
286                                }                               
287                                out = out.substr(0,(out.length - 2));
288                                this.out_officeR = out;
289                        }
290                }
291                this.reload_rules();
292        }
293       
294        cfilter.prototype.new_rule = function(email){
295
296                if(this.email_deny.length > 0){
297                        for(var i=0 ; i < this.email_deny.length; i++){
298                                if(this.email_deny[i] == email){
299                                        alert(get_lang("Sender blocked!"));
300                                        return false;
301                                }
302                        }
303                }
304
305                // Verifica Email
306                var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
307        if(!emailReg.test(email)){
308                        alert(get_lang("Inform a valid e-mail!"));
309                        return false;
310                }
311
312                this.load_rules();
313                if(confirm(get_lang("Do you want to block this e-mail?"))){
314                        new_r = "&&ENABLED&&" + email + "&&&&&&discard&&&&0&&&&&&0";
315                        setTimeout("filter.e_newrule('" + new_r + "')",2000);           
316                        this.email_deny.push(email);
317                        write_msg(get_lang("The sender was blocked"));                                                 
318                }
319        }
320       
321        cfilter.prototype.e_newrule = function(nw_rule){
322
323                var new_rl = "";
324                if(this.rulest.length == 0){
325                        new_rl = "#rule&&1" + nw_rule;
326                }else{
327                        var aux = this.rulest[this.rulest.length -1 ].split("&&");
328                        new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
329                }
330                this.rulest.push(new_rl);
331                this.saved_all();
332        }
333       
334        cfilter.prototype.delete_r = function(){
335       
336                // rule
337                var _this = this;
338                if(Element("rule_0") != null){
339                        for(var i=0; i < _this.rulest.length; i++){
340                                if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
341                        }
342                        for(var i=0; i < _this.rulest.length; i++){
343                                if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
344                        }
345                }
346       
347                if(_this.rulest.length > 0){
348                        var cont = parseInt(1);
349                        for(var i=0; i < _this.rulest.length ; i++){
350                                var n_rulest = _this.rulest[i].split("&&");
351                                n_rulest[1] = cont;
352                                cont = cont + parseInt(2);
353                                var aux = "";
354                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
355                                aux = aux.substr(0,(aux.length - 2));
356                                _this.rulest[i] = aux;
357                        }
358                }
359                // out office
360                if(Element("out_0") != null){
361                        if(Element("out_0").checked){_this.out_officeR =''; _this.out_officeF = false;}
362                }
363                _this.reload_rules();
364        }
365       
366        cfilter.prototype.reload_rules = function(){
367                this.saved_all();
368                Element('form_body').innerHTML = "";
369                this.load_rules();
370               
371                if(this.out_officeF){
372                        write_msg(get_lang("Attention, you are in out of office mode."), true);
373                }else {
374                        clean_msg();
375                        this.out_officeF = false;
376                }
377                filters.mount_list();
378        }
379
380        cfilter.prototype.saved_rules = function(){
381
382                var mount_rule = "";
383                var form = this.ac_form.split("_");
384                var n_rule = "";
385
386                if(form[1] == "rule"){
387                        mount_rule = "#rule&&";
388                        if(form[0] == "new"){
389                                n_rule = "1&&";
390                                if(this.rulest.length > 0){
391                                        aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
392                                        n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
393                                }
394                                mount_rule += n_rule + "ENABLED&&";
395                        }else{
396                                n_rule = this.rulest[this.ind].split("&&");
397                                mount_rule += n_rule[1] + "&&";
398                                mount_rule += n_rule[2] + "&&";
399                        }
400
401                        if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "")
402                        {
403                                alert(get_lang("Define some criterion to the fields From, To and Subject with more than 3 characters!"));
404                                return false;
405                        }
406
407                        if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){
408                                alert(get_lang("Define some criterion to the fields From, To and Subject with more than 3 characters!"));
409                                return false;
410                        }
411                       
412                        for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";}
413                        var v_checked = false;
414                        if(Element("radio1").checked){
415                                mount_rule += "folder&&";
416                                var sel_nameBox = Element("select_mailboxes");
417                                for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
418                                v_checked = true;
419                        }
420                        if(Element("radio2").checked){
421                                mount_rule += "address&&";
422                                if(Element("field5").value == ""){
423                                        alert(get_lang("Inform a forwarding e-mail!"));
424                                        return false;
425                                }else{
426                                        var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
427                                if(emailReg.test(Element("field5").value)){
428                                                mount_rule += Element("field5").value + "&&";
429                                        }else{
430                                                alert(get_lang("Inform a valid e-mail!"));
431                                                return false;
432                                        }
433                                }
434                                v_checked = true;
435                        }
436                        if(Element("radio3").checked){
437                                mount_rule += "reject&&";
438                                if(Element("field6").value == ""){
439                                        alert(get_lang("Inform a text for rejection!"));
440                                        return false;
441                                }else{
442                                        mount_rule += Element("field6").value + "&&";
443                                }
444                                v_checked = true;
445                        }                               
446                        if(Element("radio4").checked){
447                                mount_rule += "discard&&&&";
448                                v_checked = true;
449                        }
450                        if(!v_checked){
451                                alert(get_lang("No option marked!"));
452                                return false;
453                        }
454                        var opts = "";
455                        if(Element("checkBox1").checked == true){opts += ",checkBox1";}
456                        if(Element("checkBox2").checked == true){opts += ",checkBox2";}
457                        if(Element("select_size").options[1].selected == true){opts += ",select_size=1";}
458                        if(Element("select_rules").options[1].selected == true){opts += ",select_rules=1";}
459                        for(var i=0; i < this.values.length; i++){if(this.values[i] == opts){mount_rule += i + "&&";}}
460                        mount_rule += "&&&&";
461                        if(LTrim(Element("field4").value) != ""){
462                                mount_rule += LTrim(Element("field4").value);
463                        }else{
464                                mount_rule += 0;
465                        }
466                        if(form[0] == "new")
467                                this.rulest[this.rulest.length] = mount_rule;
468                        else
469                                this.rulest[this.ind] = mount_rule;
470                }else{
471                        mount_rule = "";
472                        var fld_emails = this.email_ld; // Get first email of list!
473                        var fld_men        = Element("field8");
474                        mount_rule = "#vacation&&";
475                        mount_rule += "1&&";
476                        mount_rule += "\"" + fld_emails + "\", ";                       
477                        mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
478                        mount_rule += "&&";
479                        mount_rule += fld_men.value + "&&on";
480                        if(LTrim(fld_men.value) == ""){
481                                alert(get_lang("Inform a message!"));
482                                return false;
483                        }
484                        this.out_officeR = mount_rule;
485                }
486                Element('form_buttons').style.display = '';
487                this.reload_rules();
488        }
489
490        cfilter.prototype.close_frm= function(){
491                filters.filter_Sh['window_ffilter_ccform'].close();
492        }
493       
494        cfilter.prototype.saved_all = function(){
495                var aux_rul = "";
496                var _this = this;
497                if(_this.rulest.length > 0){
498                        for(var i=0; i < _this.rulest.length; i++){
499                                var aux = _this.rulest[i].split("&&");                         
500                                aux_rul += "_begin_##";
501                                for(var j=0 ; j < aux.length; j++){
502                                        if( (j +1) > aux.length){aux_rul += url_encode(aux[j]);}
503                                        else{aux_rul += url_encode(aux[j]) + "##";}
504                                }       
505                                aux_rul += "_end_\n";
506                        }
507                }
508                if(_this.out_officeR.length > 0){
509                                var aux = _this.out_officeR.split("&&");                               
510                                aux_rul += "_begin_##";
511                                for(var j=0 ; j < aux.length; j++){
512                                        if( (j +1) > aux.length){aux_rul += url_encode(aux[j]);}
513                                        else{aux_rul += url_encode(aux[j]) + "##";}
514                                }       
515                                aux_rul += "_end_\n";
516                                _this.out_officeF = (aux[4].replace("\n","") == "off") ? false : true;
517                }
518                var h_filter = function(data){
519                        if(data != "Ok"){alert("Erro : \n" + data);}
520                }
521                var args   = "$this.ScriptS.rec_rules";
522                var params = "arfilter="+aux_rul;
523                cExecute(args,h_filter,params);
524        }
525
526// build object
527   var filter;
528   filter = new cfilter();
Note: See TracBrowser for help on using the repository browser.