source: sandbox/2.4.2-expresso2/expressoMail1_2/js/filter.js @ 5526

Revision 5526, 28.3 KB checked in by angelo, 12 years ago (diff)

Ticket #2490 - Campos de texto reduzidos na janela de filtros

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1
2        function charCounter(form)
3        {
4                if (form.value.length >= 300)
5                {
6                        alert(get_lang("You have exceeded the number of allowed characters"));
7                        return false;
8                }
9        }
10
11        function cfilter(){
12
13                this.criticalError = false;
14                this.mode_in   = "";
15                this.rulest              = new Array;
16                this.rulesVoip   = new Array;
17                this.out_officeR = "";
18                this.out_officeF = false;
19                this.email_deny  = new Array;
20                this.ac_form     = "";
21                this.ind                 = "";
22                this.email_deny  = new Array;
23                this.email_ld    = "";
24                this.values = new Array("",
25                                        ",checkBox1",
26                                        ",select_size=1",
27                                        ",checkBox1,select_size=1",
28                                        ",select_rules=1",
29                                        ",checkBox1,select_rules=1",
30                                        ",select_size=1,select_rules=1",
31                                        ",checkBox1,select_size=1,select_rules=1",
32                                        ",checkBox2",
33                                        ",checkBox1,checkBox2",
34                                        ",checkBox2,select_size=1",
35                                        ",ckeckBox1,checkBox2,select_size=1",
36                                        ",checkBox2,select_rules=1",
37                                        ",checkBox1,checkBox2,select_rules=1",
38                                        ",checkBox2,select_size=1,select_rules=1",
39                                        ",checkBox1,checkBox2,select_size=1,select_rules=1");
40               
41        }
42
43        cfilter.prototype.load_rules = function(posHandler, param)
44        {
45                var _this = this;
46                var cont1 = parseInt(0);
47                var cont2 = parseInt(0);
48
49                if( _this.rulest.length == 0 )
50                {
51                        var handler_sieve = function(data)
52                        {
53                                if (data.toString().indexOf('Error:') == 0)
54                                {
55                                        _this.criticalError = true;
56                                        alert(get_lang('The filters service is out of service, try again later...'));
57                                }
58                                else
59                                try{
60                                if(data.rule.length > 0){
61                                        for(var i=0 ; i < data.rule.length; i++)
62                                        {
63                                                var fields = data.rule[i].split("&&");
64                                                if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect )
65                                                        _this.rulesVoip[cont1++] = data.rule[i];
66                                                else
67                                                        _this.rulest[cont2++] = data.rule[i];
68                                        }
69                                }
70                                _this.out_officeR = data.vacation[0];
71                                _this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
72                                if(data.mode.length > 0){_this.mode_in = data.mode[0];}
73                                }
74                                catch(e){
75                                        _this.criticalError = true;
76                                        alert(get_lang('The filters service is out of service, try again later...'));
77                                }
78                                if (typeof(posHandler) == 'function') 
79                                        posHandler(param); 
80                        }
81                        if(Element('form_status') != null)
82                                Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
83                        cExecute("$this.ScriptS.init_a",handler_sieve);
84                        _this.get_email();
85            }
86        }
87       
88        cfilter.prototype.form_m = function(){
89                Element('form_body').innerHTML = "";
90                Element('form_buttons').style.display = '';
91                Element('Edit_form_buttons').style.display = 'none';
92                filters.mount_list();
93                this.ac_form = "";             
94        }
95       
96        cfilter.prototype.form_out = function(){
97                Element('form_body').innerHTML = "";
98                Element('form_body').innerHTML = this.forms_();
99                Element('div_vacation').style.display = "";
100                Element('Edit_form_buttons').style.display = 'block';
101                this.ac_form = "old_out";               
102                this.r_rules_out();             
103        }
104       
105        cfilter.prototype.form_r = function(pos,type)
106        {
107                Element('form_body').innerHTML = "";
108                Element('form_body').innerHTML = this.forms_();
109                Element('Edit_form_buttons').style.display = '';
110                Element('form_buttons').style.display = 'none';
111                this.ind = pos;         
112               
113                if( type === 'voip')
114                {
115                        this.ac_form = "old_voip";
116                        Element('div_voipFilter').style.display = "";
117                        this.r_rules_form(pos, type);   
118                }
119                else
120                {
121                        this.ac_form = "old_rule";
122                        Element('div_rule').style.display = "";
123                        this.r_rules_form(pos, type);
124                }
125        }
126       
127        cfilter.prototype.get_email = function()
128        {
129                var _this = this;
130                var handler_get_email = function(data)
131                {
132                        _this.email_ld = data ? data : "";
133                }
134                cExecute("$this.user.get_email",handler_get_email);
135        }
136       
137        cfilter.prototype.sel_boxes = function()
138        {
139                var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
140                if(document.getElementById("select_mailboxes") != null){
141                        var sel_nm = document.getElementById("select_mailboxes");
142                        if(sel_nm.length > 0 ){
143                                for(var i=0; i < sel_nm.options.length; i++){
144                                        sel_nm.options[i] = null;
145                                        i--;
146                                }
147                        }
148                        for(var i=0; i < nm_folders.length; i++){
149                                if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){
150                                        var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
151                                        sel_nm[sel_nm.length] = opt;
152                                }
153                        }
154                        sel_nm[0].selected = true;
155                }
156        }
157
158        cfilter.prototype.box_select = function(param){
159                var aux = this.BoxSelection[param].split(",");
160                var ele1 = document.getElementById(aux[0]);
161                var ele2 = document.getElementById(aux[1]);
162                var noption = "";
163                if(param == 0 || param == 1){
164                        if(ele1.selectedIndex != -1){
165                                noption = new Option(ele1.value,ele1.value,false,false);
166                                ele2.options[ele2.length] = noption;
167                                ele1.options[ele1.selectedIndex] = null;
168                                ele1.selectedIndex = 0;
169                        }
170                }
171        }
172
173        cfilter.prototype.r_rules_form = function(ind, type)
174        {
175                var fields = new Array;
176                var _this = this;
177               
178                // hide buttons
179                Element('form_buttons').style.display = 'none';
180               
181                if( type === 'voip')
182                {
183                        fields = _this.rulesVoip[ind].split("&&");
184                        document.getElementById("field9").value = fields[5];                   
185                }
186                else
187                {
188                        this.sel_boxes();
189                        if(this.rulest.length == 0){
190                                return false;
191                        }
192                        fields = _this.rulest[ind].split("&&");
193                        document.getElementById("field1").value = fields[3];
194                        document.getElementById("field2").value = fields[4];
195                        document.getElementById("field3").value = fields[5];
196                        document.getElementById("field4").value = fields[11] == 0 ? "" : fields[11];
197                       
198                        switch(fields[6]){
199                                case "folder":
200                                        document.getElementById("radio1").checked  = true;
201                                        var name_mb = fields[7];
202                                        var sel_mb = document.getElementById("select_mailboxes");
203                                        for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
204                                        break;
205                                case "address":
206                                        document.getElementById("radio2").checked   = true;
207                                        document.getElementById("field5").value         = fields[7];
208                                        break;
209                                case "reject":
210                                         document.getElementById("radio3").checked  = true;
211                                         var text0 = fields[7].split("\\n");                                   
212                                         for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
213                                         break;
214                                case "discard":
215                                        document.getElementById("radio4").checked       = true;
216                                        break;
217                                case "flagged":
218                                        document.getElementById("radio5").checked       = true;
219                                        break;
220                        }
221                        var mark_values = this.values[fields[8]].split(",");
222                        for(var i=0; i < mark_values.length; i++){
223                                if( mark_values[i] == "checkBox1" || mark_values[i] == "checkBox2"){
224                                        document.getElementById(mark_values[i]).checked = true;
225                                }
226                                if( mark_values[i] == "checkBox2"){
227                                        document.getElementById(mark_values[i]).checked = true;
228                                }
229                                if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
230                                        var mark_val = mark_values[i].split("=");
231                                        document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
232                                }
233                        }
234                }
235        }
236
237        cfilter.prototype.r_rules_out = function(){
238       
239                var _this = this;
240                if(_this.out_officeR.length == 0){
241                        return false;
242                }
243               
244                // hide buttons
245                Element('form_buttons').style.display = 'none';
246       
247                var aux = _this.out_officeR.split("&&");
248                var days   = aux[1];
249                var emails = aux[2];
250                var mens   = aux[3];           
251                var p_emails = new Array;
252                var d_emails = new Array;
253                               
254                var p_aux = emails.split(", ");
255                for(var i=0; i < p_aux.length; i++){
256                        p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
257                        p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
258                }
259                for(var i=0; i < _this.email_ld.length; i++){
260                        d_emails[i] = _this.email_ld[i];
261                }
262
263                diff = function(vet, comp){
264                        var sel1 = new Array;
265                        for(var i=0; i < vet.length; i++){
266                                for(var j=0; j < comp.length; j++){
267                                        if(vet[i] == comp[j]){
268                                                comp.splice(j,1);
269                                                j--;
270                                        }
271                                }
272                        }
273                };     
274                diff(p_emails,d_emails);
275                var text    = mens.split("\\n");
276                for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
277                for(var i=0; i < _this.email_ld.length; i++){
278                        d_emails[i] = _this.email_ld[i];
279                }
280
281        }
282
283        /*
284         * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição)
285         * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada
286         */
287        cfilter.prototype.disable_radio =  function()
288        {
289                radio4 = Element('radio4');
290                radio3 = Element('radio3');
291                cb2 = Element('checkBox2');
292                field6 = Element('field6');
293
294                if (cb2.checked)
295                {
296                        radio3.disabled = true;
297                        radio4.disabled = true;
298                        field6.disabled = true;
299
300                        if (radio3.checked)
301                        {
302                                radio3.checked = false;
303                        }
304                }
305                else
306                {
307                        radio3.disabled = false;
308                        radio4.disabled = true;
309                        field6.disabled = false;
310                }
311
312        }
313
314        cfilter.prototype.forms_ = function()
315        {
316                         var form = "";
317                                 form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
318                                                "<tr><td colspan='2'><input type='checkBox' id='checkBox1' name='checkb'>"+get_lang('Also check message against next rule') + "</td></tr>"+
319                                                //"<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio3();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
320                                                "<tr><td colspan='2'><hr size='1' width='100%'></td></tr><tr>"+
321                                         "<tr><td colspan='2'><b>"+get_lang("Criteria")+":</b></td></tr><tr>"+
322                                         "<td rowspan='4' width='20%'>"+get_lang('Find items')+":<br><select id='select_rules' name='select_rules'>"+
323                                         "<option value='1'>"+get_lang("If any criterion is met")+"</option><option value='0'>"+get_lang("If all criteria is met")+"</option>"+
324                                         "</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>"+
325                                                "</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>"+
326                                                "</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>"+
327                                                "</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
328                                                "<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+
329                                                "</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
330                                                "</tr><tr><td colspan='2'><hr size='1' width='100%'><b>"+get_lang("Action")+":</b></td></tr>"+
331                                                "</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
332                                                "<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
333                                                "<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
334                                                "<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
335                                                "</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
336                                                "<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
337                                                "</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
338                                                "<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
339                                                "</tr><tr id='tr_radio4'><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
340                                                "</tr><tr id='tr_radio5'><td colspan='2'><input type='radio' id='radio5' name='radio' value='important'>"+get_lang('Flag as important')+"</td>"+
341                                                "</tr></table></div><div id='div_vacation' style='display:none'>"+
342                                                "<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
343                                                "<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
344                                                //"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
345                                                "<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
346                                                "</tr><tr><td colspan='3'><textarea id='field8' rows='8' cols='50'></textarea></td></tr></table></div>" +
347                                                "<div id='div_voipFilter' style='display:none'>" +
348                                                "<br/><table id='table_voipFilter'>" +
349                                                "<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+
350                                                "</td></tr><tr><td width='100%'><input type='text' id='field9' size='50' maxlength='200'>" +
351                                                "</td></tr><br/></table></div>";// +
352                                                //"<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
353                                                //"<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";
354                return form;
355        }
356
357        cfilter.prototype.enabled_disabled = function(param){
358
359                // Rules
360                if(Element("rule_0") != null){
361                        for(var i=0; i < this.rulest.length; i++){
362                                if(Element("rule_"+i).checked){
363                                        var aux_rul = this.rulest[i].split("&&");
364                                        if(aux_rul[2] != param){
365                                                aux_rul[2] = param;                                     
366                                                var rl = "";
367                                                for(var j=0; j < aux_rul.length; j++){
368                                                        rl += aux_rul[j] + "&&";
369                                                }
370                                                rl = rl.substr(0,(rl.length - 2));
371                                                this.rulest[i] = rl;                                   
372                                        }
373                                }
374                        }
375                }
376                // Out Office
377                if(Element("out_0") != null){
378                        if(Element("out_0").checked){
379                                var aux_out = this.out_officeR.split("&&");
380                                if(param == "ENABLED")
381                                        aux_out[4] = "on ";
382                                else
383                                        aux_out[4] = "off";
384                                var out = "";
385                                for(var i=0; i < aux_out.length; i++){
386                                        out += aux_out[i] + "&&";
387                                }                               
388                                out = out.substr(0,(out.length - 2));
389                                this.out_officeR = out;
390                        }
391                }
392
393                // Voip
394                if(Element("voip_rule_0") != null){
395                        for(var i=0; i < this.rulesVoip.length; i++){
396                                if(Element("voip_rule_"+i).checked){
397                                        var aux_rul = this.rulesVoip[i].split("&&");
398                                        if(aux_rul[2] != param){
399                                                aux_rul[2] = param;                                     
400                                                var rl = "";
401                                                for(var j=0; j < aux_rul.length; j++){
402                                                        rl += aux_rul[j] + "&&";
403                                                }
404                                                rl = rl.substr(0,(rl.length - 2));
405                                                this.rulesVoip[i] = rl;                                 
406                                        }
407                                }
408                        }
409                }
410               
411                this.reload_rules();
412        }
413
414        cfilter.prototype.new_rule = function(email){
415       
416                var createFilter = function (param)
417                {
418                        if (filter.criticalError){
419                                alert(get_lang('The filters service is out of service, try again later...'));
420                                return false;
421                        }
422                        if(filter.rulest.length > 0){
423                                var blockedReg = new RegExp('#rule&&[0-9]+&&ENABLED&&'+param+'&&&&&&discard&&&&0&&&&&&0');
424                                for(var i=0 ; i < filter.rulest.length; i++){
425                                        if(blockedReg.test(filter.rulest[i])){
426                                                alert(get_lang("Sender blocked")+"!");
427                                                return false;
428                                        }
429                                }
430                        }                       
431               
432                       
433                        var div = document.createElement("div");
434                                div.innerHTML = '<p style="margin:10px 5px 5px 5px;">' +
435                                                                '<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>'+
436                                                                        get_lang("Do you want to block this e-mail?")+
437                                                                '</p>';
438       
439                        $(div).dialog(
440                        {
441                                resizable: false,
442                                title: get_lang('Block Sender'),
443                                position: 'center',
444                                width: 350,
445                                height:140,
446                                modal: true,
447                                buttons: [
448                                                        {
449                                                                text: get_lang("Yes"),
450                                                                click: function()
451                                                                {
452                                                                        new_r = "&&ENABLED&&" + param + "&&&&&&discard&&&&0&&&&&&0";
453                                                                 
454                                                                        if (filter.e_newrule(new_r))
455                                                                        {
456                                                                                filter.email_deny.push(new_r);
457                                                                                write_msg(get_lang("The sender was blocked"));                                                   
458                                                                        }
459                                                                        else
460                                                                        {
461                                                                                write_msg(get_lang("You have reached the maximum number of rules"));
462                                                                        }
463                                                                       
464                                                                        $( this ).dialog( "close" );
465                                                                },
466                                                                style: "margin-top: -2.1em"
467                                                        },
468                                                        {
469                                                                text: get_lang("No"),
470                                                                click: function()
471                                                                {
472                                                                        $( this ).dialog( "close" );
473                                                                },
474                                                                style: "margin-top: -2.1em"
475                                                        },
476                                                ]
477                        });
478                };
479               
480                if ( filter.rulest.length > 0 )
481                        createFilter(email);
482                else
483                        this.load_rules( createFilter, email );
484        }
485
486        cfilter.prototype.e_newrule = function(nw_rule)
487        {
488
489                var new_rl = "";
490                if (this.rulest.length >= rules_limit)
491                        return false;
492                       
493                if(this.rulest.length == 0){
494                        new_rl = "#rule&&1" + nw_rule;
495                }else{
496                        var aux = this.rulest[this.rulest.length -1 ].split("&&");
497                        new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
498                }
499                this.rulest.push(new_rl);
500                this.saved_all();
501                return true;
502        }
503       
504        cfilter.prototype.delete_r = function(){
505                // rule
506                var _this = this;
507                if(Element("rule_0") != null){
508                        for(var i=0; i < _this.rulest.length; i++){
509                                if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
510                        }
511                        for(var i=0; i < _this.rulest.length; i++){
512                                if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
513                        }
514                }
515       
516                if(_this.rulest.length > 0){
517                        var cont = parseInt(1);
518                        for(var i=0; i < _this.rulest.length ; i++){
519                                var n_rulest = _this.rulest[i].split("&&");
520                                n_rulest[1] = cont;
521                                cont = cont + parseInt(2);
522                                var aux = "";
523                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
524                                aux = aux.substr(0,(aux.length - 2));
525                                _this.rulest[i] = aux;
526                        }
527                }
528                // out office
529                if(Element("out_0") != null){
530                        if(Element("out_0").checked){
531                                _this.out_officeR ='';
532                                _this.out_officeF = false;
533                                //Save outoffice in prefs:
534                                connector.loadScript("preferences");
535                                        prefe.save("outoffice", _this.out_officeF);
536                        }
537                }
538               
539                // Voip
540                if(Element("voip_rule_0") != null){
541                        for(var i=0; i < _this.rulesVoip.length; i++){
542                                if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
543                        }
544                        for(var i=0; i < _this.rulesVoip.length; i++){
545                                if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
546                        }
547                }
548       
549                if(_this.rulesVoip.length > 0){
550                        var cont = parseInt(1);
551                        for(var i=0; i < _this.rulesVoip.length ; i++){
552                                var n_rulest = _this.rulesVoip[i].split("&&");
553                                n_rulest[1] = cont;
554                                cont = cont + parseInt(2);
555                                var aux = "";
556                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
557                                aux = aux.substr(0,(aux.length - 2));
558                                _this.rulesVoip[i] = aux;
559                        }
560                }
561               
562                _this.reload_rules();
563        }
564       
565        cfilter.prototype.reload_rules = function()
566        {
567                this.saved_all();
568                Element('form_body').innerHTML = "";
569                this.load_rules();
570
571                if(this.out_officeF)
572                {
573                        write_msg(get_lang("Attention, you are in out of office mode."), true);
574                }else{
575                        clean_msg();
576                        this.out_officeF = false;
577                }
578                filters.mount_list();
579        }
580
581        cfilter.prototype.forwardAddressValidation = function(addr) {
582            if (addr == "")
583            {
584                return true;
585            }
586            domains = sieve_forward_domains.replace(/\s/g, "").replace(/\./g, "\\.").replace(/,/g, "|");
587            domainRegexp = new RegExp("(" + domains +")$");
588            return domainRegexp.test(addr);
589        }
590
591        cfilter.prototype.saved_rules = function(){
592
593                var mount_rule = "";
594                var form = this.ac_form.split("_");
595                var n_rule = "";
596
597                if(form[1] == "rule")
598                {
599                        mount_rule = "#rule&&";
600                        if(form[0] == "new")
601                        {
602                                n_rule = "1&&";
603                                if(this.rulest.length > 0)
604                                {
605                                        aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
606                                        n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
607                                }
608                                mount_rule += n_rule + "ENABLED&&";
609                        }
610                        else
611                        {
612                                n_rule = this.rulest[this.ind].split("&&");
613                                mount_rule += n_rule[1] + "&&";
614                                mount_rule += n_rule[2] + "&&";
615                        }
616
617                        if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && LTrim(Element("field4").value).length == 0)
618                        {
619                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
620                                return false;
621                        }
622                        if((LTrim(Element("field1").value).length <= 3) && LTrim(Element("field1").value) != ""){
623                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
624                                return false;
625                        }if((LTrim(Element("field2").value).length <= 3) && LTrim(Element("field2").value) != ""){
626                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
627                                return false;
628                        }if((LTrim(Element("field3").value).length <= 3) && LTrim(Element("field3").value) != ""){
629                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
630                                return false;
631                        }
632                       
633                        if (LTrim(Element("field4").value).length > 0){
634                                var isNumero = /^\d+$/.test(Element("field4").value);
635                                if(!isNumero){
636                                        alert(get_lang("Enter a numerical value to the message size!"));
637                                        return false;                           
638                                }
639                        }
640                        for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";}
641                        var v_checked = false;
642                        if(Element("radio1").checked){
643                                if( /[^\x00-\x80]/.test( Element("select_mailboxes").value ) ) {
644                                        alert( get_lang ( 'The selected folder cotain any accented character. The filter dont work with accented folders. Please, rename the folder or choose another folder.' ) );
645                                        return false;
646                                }
647                               
648                                mount_rule += "folder&&";
649                                var sel_nameBox = Element("select_mailboxes");
650                                for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
651                                v_checked = true;
652                        }
653                        if(Element("radio2").checked){
654                            if (this.forwardAddressValidation(Element("field5").value)){
655                                mount_rule += "address&&";
656                                if(Element("field5").value == ""){
657                                        alert(get_lang("Inform a forwarding e-mail!"));
658                                        return false;
659                                }else{
660                                    if(validateEmail(Element("field5").value)){
661                                                mount_rule += Element("field5").value + "&&";
662                                        }else{
663                                                alert(get_lang("Inform a valid e-mail!"));
664                                                return false;
665                                        }
666                                }
667                                v_checked = true;
668                            }
669                            else
670                                {
671                                    alert(get_lang("You can't forward e-mails to this domain: %1", Element("field5").value.split("@")[1]));
672                                    return false;
673                                }
674                        }
675                        if(Element("radio3").checked){
676                                mount_rule += "reject&&";
677                                if(Element("field6").value == ""){
678                                        alert(get_lang("Inform a text for rejection!"));
679                                        return false;
680                                }else{
681                                        mount_rule += Element("field6").value + "&&";
682                                }
683                                v_checked = true;
684                        }                               
685                        if(Element("radio4").checked){
686                                mount_rule += "discard&&&&";
687                                v_checked = true;
688                        }
689                        if(Element("radio5").checked){
690                                mount_rule += "flagged&&&&";
691                                v_checked = true;
692                        }
693                        if(!v_checked){
694                                alert(get_lang("No option marked!"));
695                                return false;
696                        }
697                        var opts = "";
698                        if(Element("checkBox1").checked == true){
699                            opts += ",checkBox1";
700                        }
701                        if(Element("checkBox2").checked == true){
702                            opts += ",checkBox2";
703                        }
704                        if(Element("select_size").options[1].selected == true){
705                            opts += ",select_size=1";
706                        }
707                        if(Element("select_rules").options[1].selected == true){
708                            opts += ",select_rules=1";
709                        }
710                        for(var i=0; i < this.values.length; i++)
711                        {
712                            if(this.values[i] == opts)
713                            {
714                                mount_rule += i + "&&";
715                            }
716                        }
717                        mount_rule += "&&&&";
718                        if(LTrim(Element("field4").value) != "" && LTrim(Element("field4").value) >= 0){
719                                mount_rule += LTrim(Element("field4").value);
720                        }
721                        if(form[0] == "new")
722                        {
723                                this.rulest[this.rulest.length] = mount_rule;
724                        }
725                        else
726                                this.rulest[this.ind] = mount_rule;
727                }
728                else if(form[1] == "out")
729                {
730                        mount_rule = "";
731                        var fld_emails = this.email_ld; // Get first email of list!
732                        var fld_men        = Element("field8");
733                        mount_rule = "#vacation&&";
734                        mount_rule += "1&&";
735                        mount_rule += "\"" + fld_emails + "\", ";                       
736                        mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
737                        mount_rule += "&&";
738                        mount_rule += fld_men.value + "&&on";
739                        if(LTrim(fld_men.value) == ""){
740                                alert(get_lang("Message required"));
741                                return false;
742                        }
743                        else if(fld_men.value.length > 10000){
744                                alert(get_lang("Your message have %1 characters, the message needs to have less then 10000 characters",fld_men.value.length));
745                                return false;
746                        }
747                        this.out_officeR = mount_rule;
748                }
749                else if(form[1] == "voip")
750                {
751                        if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
752                        {
753                                mount_rule = "#rule&&";
754                                if(form[0] == "new")
755                                {
756                                        n_rule = "1&&";
757                                        if( this.rulesVoip.length > 0 )
758                                        {
759                                                aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
760                                                n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
761                                        }
762                                        mount_rule += n_rule + "ENABLED&&";
763                                }
764                                else
765                                {
766                                        n_rule = this.rulesVoip[this.ind].split("&&");
767                                        mount_rule += n_rule[1] + "&&";
768                                        mount_rule += n_rule[2] + "&&";
769                                }
770
771                                if ( Element("field9").value.indexOf("#") >= 0 )
772                                {
773                                        alert(get_lang('Caracter "#" is not allowed!'));
774                                        return false;
775                                }
776                               
777                                mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
778
779                                if( form[0] == "new" )
780                                {
781                                        this.rulesVoip[this.rulesVoip.length] = mount_rule;
782                                }
783                                else
784                                {
785                                        this.rulesVoip[this.ind] = mount_rule;
786                                }
787                        }
788                        else
789                        {
790                                alert( 'CAMPOS EM BRANCO !!' );
791                                return false;
792                        }
793                }
794               
795                Element('form_buttons').style.display = '';
796                Element('Edit_form_buttons').style.display = 'none';
797                this.reload_rules();
798        }
799
800        cfilter.prototype.close_frm= function()
801        {
802                filters.filter_Sh['window_ffilter_ccform'].close();
803        }
804       
805        cfilter.prototype.saved_all = function()
806        {
807                var aux_rul = "";
808                var _this = this;
809                var cont = 0;
810               
811                // Regras Gerais
812                if(_this.rulest.length > 0)
813                {
814                        for(var i=0; i < _this.rulest.length; i++)
815                        {
816                                var fieldsNormal = _this.rulest[i].split("&&");                         
817                                aux_rul += "_begin_##";
818                                for(var j=0 ; j < fieldsNormal.length; j++)
819                                {
820                                        aux_rul += url_encode(fieldsNormal[j]) + "##";
821                                        cont = parseInt(fieldsNormal[1]);                                       
822                                }       
823                                aux_rul += "_end_\n";
824                        }
825                }
826       
827                // Voip
828                if(_this.rulesVoip.length > 0)
829                {
830                        for(var i=0; i < _this.rulesVoip.length; i++)
831                        {
832                                var fieldsVoip = _this.rulesVoip[i].split("&&");
833                                aux_rul += "_begin_##";
834                                for(var j=0 ; j < fieldsVoip.length; j++)
835                                {
836                                        if(j == 1)
837                                        {
838                                                if( cont == 0 )
839                                                        cont = parseInt(1);
840                                                else
841                                                        cont = parseInt(cont) + parseInt(2);
842                                                aux_rul += cont;
843                                                aux_rul += "##";
844                                        }
845                                        else
846                                                aux_rul += url_encode(fieldsVoip[j]) + "##";
847                                }
848                                aux_rul += "_end_\n";
849                        }
850                }
851               
852                // Fora do Escritório
853                if(_this.out_officeR.length > 0)
854                {
855                                var aux = _this.out_officeR.split("&&");                               
856                                aux_rul += "_begin_##";
857                                for(var j=0 ; j < aux.length; j++)
858                                {
859                                        aux_rul += url_encode(aux[j]) + "##";                                   
860                                }       
861                                aux_rul += "_end_\n";
862                                _this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
863                                //Save outoffice in prefs:
864                                connector.loadScript("preferences");
865                                if(typeof(prefe) == 'undefined')
866                                        setTimeout("filter.saved_all();",500);
867                                else
868                                        prefe.save("outoffice", _this.out_officeF);
869                }
870               
871                var h_filter = function(data)
872                {
873                        if(data != "Ok"){alert("Erro : \n" + get_lang(data));}
874                }
875                var args   = "$this.ScriptS.rec_rules";
876                var params = "arfilter="+aux_rul;
877                if(!_this.criticalError)
878                        cExecute(args,h_filter,params);
879        }
880
881// build object
882   var filter;
883   filter = new cfilter();
Note: See TracBrowser for help on using the repository browser.