source: sandbox/2.5.0-expresso1/expressoMail1_2/js/filter.js @ 6910

Revision 6910, 28.6 KB checked in by cristiano, 12 years ago (diff)

Ticket #2987 - Inconsistência excluindo com tela modal aberta - teclas de atalho

  • 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                open: function(event, ui)
478                {
479                    if(typeof(shortcut) != 'undefined') shortcut.disabled = true;
480                },
481                close: function(event, ui)
482                {
483                    if(typeof(shortcut) != 'undefined') shortcut.disabled = false;
484                }
485                        });
486                };
487               
488                if ( filter.rulest.length > 0 )
489                        createFilter(email);
490                else
491                        this.load_rules( createFilter, email );
492        }
493
494        cfilter.prototype.e_newrule = function(nw_rule)
495        {
496
497                var new_rl = "";
498                if (this.rulest.length >= rules_limit)
499                        return false;
500                       
501                if(this.rulest.length == 0){
502                        new_rl = "#rule&&1" + nw_rule;
503                }else{
504                        var aux = this.rulest[this.rulest.length -1 ].split("&&");
505                        new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
506                }
507                this.rulest.push(new_rl);
508                this.saved_all();
509                return true;
510        }
511       
512        cfilter.prototype.delete_r = function(){
513                // rule
514                var _this = this;
515                if(Element("rule_0") != null){
516                        for(var i=0; i < _this.rulest.length; i++){
517                                if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
518                        }
519                        for(var i=0; i < _this.rulest.length; i++){
520                                if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
521                        }
522                }
523       
524                if(_this.rulest.length > 0){
525                        var cont = parseInt(1);
526                        for(var i=0; i < _this.rulest.length ; i++){
527                                var n_rulest = _this.rulest[i].split("&&");
528                                n_rulest[1] = cont;
529                                cont = cont + parseInt(2);
530                                var aux = "";
531                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
532                                aux = aux.substr(0,(aux.length - 2));
533                                _this.rulest[i] = aux;
534                        }
535                }
536                // out office
537                if(Element("out_0") != null){
538                        if(Element("out_0").checked){
539                                _this.out_officeR ='';
540                                _this.out_officeF = false;
541                                //Save outoffice in prefs:
542                                connector.loadScript("preferences");
543                                        prefe.save("outoffice", _this.out_officeF);
544                        }
545                }
546               
547                // Voip
548                if(Element("voip_rule_0") != null){
549                        for(var i=0; i < _this.rulesVoip.length; i++){
550                                if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
551                        }
552                        for(var i=0; i < _this.rulesVoip.length; i++){
553                                if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
554                        }
555                }
556       
557                if(_this.rulesVoip.length > 0){
558                        var cont = parseInt(1);
559                        for(var i=0; i < _this.rulesVoip.length ; i++){
560                                var n_rulest = _this.rulesVoip[i].split("&&");
561                                n_rulest[1] = cont;
562                                cont = cont + parseInt(2);
563                                var aux = "";
564                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
565                                aux = aux.substr(0,(aux.length - 2));
566                                _this.rulesVoip[i] = aux;
567                        }
568                }
569               
570                _this.reload_rules();
571        }
572       
573        cfilter.prototype.reload_rules = function()
574        {
575                this.saved_all();
576                Element('form_body').innerHTML = "";
577                this.load_rules();
578
579                if(this.out_officeF)
580                {
581                        write_msg(get_lang("Attention, you are in out of office mode."), true);
582                }else{
583                        clean_msg();
584                        this.out_officeF = false;
585                }
586                filters.mount_list();
587        }
588
589        cfilter.prototype.forwardAddressValidation = function(addr) {
590            if (addr == "")
591            {
592                return true;
593            }
594            domains = sieve_forward_domains.replace(/\s/g, "").replace(/\./g, "\\.").replace(/,/g, "|");
595            domainRegexp = new RegExp("(" + domains +")$");
596            return domainRegexp.test(addr);
597        }
598
599        cfilter.prototype.saved_rules = function(){
600
601                var mount_rule = "";
602                var form = this.ac_form.split("_");
603                var n_rule = "";
604
605                if(form[1] == "rule")
606                {
607                        mount_rule = "#rule&&";
608                        if(form[0] == "new")
609                        {
610                                n_rule = "1&&";
611                                if(this.rulest.length > 0)
612                                {
613                                        aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
614                                        n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
615                                }
616                                mount_rule += n_rule + "ENABLED&&";
617                        }
618                        else
619                        {
620                                n_rule = this.rulest[this.ind].split("&&");
621                                mount_rule += n_rule[1] + "&&";
622                                mount_rule += n_rule[2] + "&&";
623                        }
624
625                        if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && LTrim(Element("field4").value).length == 0)
626                        {
627                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
628                                return false;
629                        }
630                        if((LTrim(Element("field1").value).length <= 3) && LTrim(Element("field1").value) != ""){
631                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
632                                return false;
633                        }if((LTrim(Element("field2").value).length <= 3) && LTrim(Element("field2").value) != ""){
634                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
635                                return false;
636                        }if((LTrim(Element("field3").value).length <= 3) && LTrim(Element("field3").value) != ""){
637                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
638                                return false;
639                        }
640                       
641                        if (LTrim(Element("field4").value).length > 0){
642                                var isNumero = /^\d+$/.test(Element("field4").value);
643                                if(!isNumero){
644                                        alert(get_lang("Enter a numerical value to the message size!"));
645                                        return false;                           
646                                }
647                        }
648                        for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";}
649                        var v_checked = false;
650                        if(Element("radio1").checked){
651                                if( /[^\x00-\x80]/.test( Element("select_mailboxes").value ) ) {
652                                        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.' ) );
653                                        return false;
654                                }
655                               
656                                mount_rule += "folder&&";
657                                var sel_nameBox = Element("select_mailboxes");
658                                for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
659                                v_checked = true;
660                        }
661                        if(Element("radio2").checked){
662                            if (this.forwardAddressValidation(Element("field5").value)){
663                                mount_rule += "address&&";
664                                if(Element("field5").value == ""){
665                                        alert(get_lang("Inform a forwarding e-mail!"));
666                                        return false;
667                                }else{
668                                    if(validateEmail(Element("field5").value)){
669                                                mount_rule += Element("field5").value + "&&";
670                                        }else{
671                                                alert(get_lang("Inform a valid e-mail!"));
672                                                return false;
673                                        }
674                                }
675                                v_checked = true;
676                            }
677                            else
678                                {
679                                    alert(get_lang("You can't forward e-mails to this domain: %1", Element("field5").value.split("@")[1]));
680                                    return false;
681                                }
682                        }
683                        if(Element("radio3").checked){
684                                mount_rule += "reject&&";
685                                if(Element("field6").value == ""){
686                                        alert(get_lang("Inform a text for rejection!"));
687                                        return false;
688                                }else{
689                                        mount_rule += Element("field6").value + "&&";
690                                }
691                                v_checked = true;
692                        }                               
693                        if(Element("radio4").checked){
694                                mount_rule += "discard&&&&";
695                                v_checked = true;
696                        }
697                        if(Element("radio5").checked){
698                                mount_rule += "flagged&&&&";
699                                v_checked = true;
700                        }
701                        if(!v_checked){
702                                alert(get_lang("No option marked!"));
703                                return false;
704                        }
705                        var opts = "";
706                        if(Element("checkBox1").checked == true){
707                            opts += ",checkBox1";
708                        }
709                        if(Element("checkBox2").checked == true){
710                            opts += ",checkBox2";
711                        }
712                        if(Element("select_size").options[1].selected == true){
713                            opts += ",select_size=1";
714                        }
715                        if(Element("select_rules").options[1].selected == true){
716                            opts += ",select_rules=1";
717                        }
718                        for(var i=0; i < this.values.length; i++)
719                        {
720                            if(this.values[i] == opts)
721                            {
722                                mount_rule += i + "&&";
723                            }
724                        }
725                        mount_rule += "&&&&";
726                        if(LTrim(Element("field4").value) != "" && LTrim(Element("field4").value) >= 0){
727                                mount_rule += LTrim(Element("field4").value);
728                        }
729                        if(form[0] == "new")
730                        {
731                                this.rulest[this.rulest.length] = mount_rule;
732                        }
733                        else
734                                this.rulest[this.ind] = mount_rule;
735                }
736                else if(form[1] == "out")
737                {
738                        mount_rule = "";
739                        var fld_emails = this.email_ld; // Get first email of list!
740                        var fld_men        = Element("field8");
741                        mount_rule = "#vacation&&";
742                        mount_rule += "1&&";
743                        mount_rule += "\"" + fld_emails + "\", ";                       
744                        mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
745                        mount_rule += "&&";
746                        mount_rule += fld_men.value + "&&on";
747                        if(LTrim(fld_men.value) == ""){
748                                alert(get_lang("Message required"));
749                                return false;
750                        }
751                        else if(fld_men.value.length > 10000){
752                                alert(get_lang("Your message have %1 characters, the message needs to have less then 10000 characters",fld_men.value.length));
753                                return false;
754                        }
755                        this.out_officeR = mount_rule;
756                }
757                else if(form[1] == "voip")
758                {
759                        if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
760                        {
761                                mount_rule = "#rule&&";
762                                if(form[0] == "new")
763                                {
764                                        n_rule = "1&&";
765                                        if( this.rulesVoip.length > 0 )
766                                        {
767                                                aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
768                                                n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
769                                        }
770                                        mount_rule += n_rule + "ENABLED&&";
771                                }
772                                else
773                                {
774                                        n_rule = this.rulesVoip[this.ind].split("&&");
775                                        mount_rule += n_rule[1] + "&&";
776                                        mount_rule += n_rule[2] + "&&";
777                                }
778
779                                if ( Element("field9").value.indexOf("#") >= 0 )
780                                {
781                                        alert(get_lang('Caracter "#" is not allowed!'));
782                                        return false;
783                                }
784                               
785                                mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
786
787                                if( form[0] == "new" )
788                                {
789                                        this.rulesVoip[this.rulesVoip.length] = mount_rule;
790                                }
791                                else
792                                {
793                                        this.rulesVoip[this.ind] = mount_rule;
794                                }
795                        }
796                        else
797                        {
798                                alert( 'CAMPOS EM BRANCO !!' );
799                                return false;
800                        }
801                }
802               
803                Element('form_buttons').style.display = '';
804                Element('Edit_form_buttons').style.display = 'none';
805                this.reload_rules();
806        }
807
808        cfilter.prototype.close_frm= function()
809        {
810                filters.filter_Sh['window_ffilter_ccform'].close();
811        }
812       
813        cfilter.prototype.saved_all = function()
814        {
815                var aux_rul = "";
816                var _this = this;
817                var cont = 0;
818               
819                // Regras Gerais
820                if(_this.rulest.length > 0)
821                {
822                        for(var i=0; i < _this.rulest.length; i++)
823                        {
824                                var fieldsNormal = _this.rulest[i].split("&&");                         
825                                aux_rul += "_begin_##";
826                                for(var j=0 ; j < fieldsNormal.length; j++)
827                                {
828                                        aux_rul += url_encode(fieldsNormal[j]) + "##";
829                                        cont = parseInt(fieldsNormal[1]);                                       
830                                }       
831                                aux_rul += "_end_\n";
832                        }
833                }
834       
835                // Voip
836                if(_this.rulesVoip.length > 0)
837                {
838                        for(var i=0; i < _this.rulesVoip.length; i++)
839                        {
840                                var fieldsVoip = _this.rulesVoip[i].split("&&");
841                                aux_rul += "_begin_##";
842                                for(var j=0 ; j < fieldsVoip.length; j++)
843                                {
844                                        if(j == 1)
845                                        {
846                                                if( cont == 0 )
847                                                        cont = parseInt(1);
848                                                else
849                                                        cont = parseInt(cont) + parseInt(2);
850                                                aux_rul += cont;
851                                                aux_rul += "##";
852                                        }
853                                        else
854                                                aux_rul += url_encode(fieldsVoip[j]) + "##";
855                                }
856                                aux_rul += "_end_\n";
857                        }
858                }
859               
860                // Fora do Escritório
861                if(_this.out_officeR.length > 0)
862                {
863                                var aux = _this.out_officeR.split("&&");                               
864                                aux_rul += "_begin_##";
865                                for(var j=0 ; j < aux.length; j++)
866                                {
867                                        aux_rul += url_encode(aux[j]) + "##";                                   
868                                }       
869                                aux_rul += "_end_\n";
870                                _this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
871                                //Save outoffice in prefs:
872                                connector.loadScript("preferences");
873                                if(typeof(prefe) == 'undefined')
874                                        setTimeout("filter.saved_all();",500);
875                                else
876                                        prefe.save("outoffice", _this.out_officeF);
877                }
878               
879                var h_filter = function(data)
880                {
881                        if(data != "Ok"){alert("Erro : \n" + get_lang(data));}
882                }
883                var args   = "$this.ScriptS.rec_rules";
884                var params = "arfilter="+aux_rul;
885                if(!_this.criticalError)
886                        cExecute(args,h_filter,params);
887        }
888
889// build object
890   var filter;
891   filter = new cfilter();
Note: See TracBrowser for help on using the repository browser.