source: trunk/expressoAdmin1_2/js/jscode/maillists.js @ 8251

Revision 8251, 14.6 KB checked in by angelo, 10 years ago (diff)

Ticket #3498 - Nao esta salvando usuarios na lista de scl e apaga os que existem

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 0;
2
3function Element(id){
4   return document.getElementById( id );
5}
6
7function validate_fields(type)
8{
9        document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
10        document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase();
11
12        if (document.forms[0].uid.value == ''){
13                alert(get_lang('login field is empty') + '.');
14                return;
15        }
16
17        if (document.forms[0].cn.value == ''){
18                alert(get_lang('name field is empty') + '.');
19                return;
20        }
21       
22        if (document.forms[0].restrictionsOnEmailLists.value == 'true')
23        {
24                uid_tmp = document.forms[0].uid.value.split("-");
25                if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){
26                        alert(
27                                get_lang('login field is incomplete') + '.\n' +
28                                get_lang('the login field must be formed like') + ':\n' +
29                                get_lang('list') + '-' + get_lang('organization') + '-' + get_lang('listname') + '.\n' +
30                                get_lang('eg') + ': ' + 'lista-celepar-rh.');
31                        return;
32                }
33        }
34               
35        if (document.forms[0].uid.value.split(" ").length > 1){
36                alert(get_lang('LOGIN field contains characters not allowed') + '.');
37                document.forms[0].uid.focus();
38                return;
39        }
40       
41        if (document.forms[0].mail.value == ''){
42                alert(get_lang('EMAIL field is empty') + '.');
43                document.forms[0].mail.focus();
44                return;
45        }
46        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
47        if(!reEmail.test(document.forms[0].mail.value)){
48                alert(get_lang('Email field is not valid') + '.');
49                return false;
50        }
51       
52        select_userInMaillist = document.getElementById('ea_select_usersInMaillist');
53        if (select_userInMaillist.options.length == 0){
54                alert(get_lang('Any user is in the list') + '.');
55                return;
56        }
57       
58        var handler_validate_fields = function(data)
59        {
60                if (!data.status)
61                        alert(data.msg);
62                else
63                {
64                        if (type == 'create_maillist')
65                                cExecuteForm ("$this.maillist.create", document.forms[0], handler_create);
66                        else if (type == 'edit_maillist')
67                                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
68                }
69        }
70
71        // Needed select all options from select
72        for(var i=0; i<select_userInMaillist.options.length; i++)
73        {
74                // No IE, não seleciona o separador do select
75                if (select_userInMaillist.options[i].value != -1)
76                        select_userInMaillist.options[i].selected = true;
77                else
78                        select_userInMaillist.options[i].selected = false;
79        }
80
81        // O UID da lista foi alterado ou é uma nova lista.
82        if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){
83                cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value+'&mail='+document.forms[0].mail.value, handler_validate_fields);
84        }
85        else if (type == 'edit_maillist')
86        {
87                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
88        }
89}
90
91// HANDLER CREATE
92// É necessário 2 funcões de retorno por causa do cExecuteForm.
93function handler_create(data)
94{
95        return_handler_create(data);
96}
97function return_handler_create(data)
98{
99        if (!data.status)
100                alert(data.msg);
101        else{
102                alert(get_lang('Email list successful created') + '.');
103                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
104        }
105        return;
106}
107
108// HANDLER SAVE
109// É necessário 2 funcões de retorno por causa do cExecuteForm.
110function handler_save(data)
111{
112        return_handler_save(data);
113}
114function return_handler_save(data)
115{
116        if (!data.status)
117                alert(data.msg);
118        else{
119                alert(get_lang('Email list successful saved') + '.');
120                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
121        }
122        return;
123}
124
125function save_scl()
126{
127        select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist');
128        // Needed select all options from select
129        for(var i=0; i<select_users_SCL_Maillist.options.length; i++)
130                select_users_SCL_Maillist.options[i].selected = true;
131
132        cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl);
133}
134function handler_save_scl(data)
135{
136        return_handler_save_scl(data);
137}
138
139function return_handler_save_scl(data)
140{
141        console.log('pre alert');
142        if (!data.status)
143                alert(data.msg);
144        else
145                alert(get_lang('SCL successful saved') + '.');
146        console.log('pos alert');
147        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
148        return;
149}
150
151function sinc_combos_org(context, recursive)
152{
153        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
154
155        for (i=0; i<combo_org_maillists.length; i++)
156        {
157                if (combo_org_maillists.options[i].value == context)
158                {
159                        combo_org_maillists.options[i].selected = true;
160                        get_available_users(context, recursive);
161                        break;
162                }
163        }
164}
165
166function get_available_users(context, recursive)
167{
168//      var sentence = Element('ea_input_searchUser').value;
169//
170//      var url = '$this.ldap_functions.get_available_users_and_maillist&context='
171//                  + Element('ea_combo_org_maillists').value
172//                  + '&sentence=' + sentence
173//                  + '&denied_uidnumber=' + document.forms[0].uidnumber.value;
174//
175//      var fillHandler = function( fill ){
176//
177//      Element('ea_select_available_users').innerHTML = fill;
178//
179//      return( fill !== "" );
180//     }
181//
182//      userFinder( sentence, fillHandler, url, 'ea_span_searching' );
183                       
184        var url = '$this.ldap_functions.get_available_users_and_maillist&denied_uidnumber=' + document.forms[0].uidnumber.value;
185       
186        optionFind( 'ea_input_searchUser', 'ea_select_available_users', url,
187                    'ea_combo_org_maillists', 'ea_span_searching' );
188}
189
190function add_user2maillist()
191{
192        select_available_users = document.getElementById('ea_select_available_users');
193        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
194
195        var count_available_users = select_available_users.length;
196        var count_usersInMailList = select_usersInMaillist.options.length;
197        var new_options = '';
198
199        for (i = 0 ; i < count_available_users ; i++)
200        {
201                if (select_available_users.options[i].selected)
202                {
203                        if(document.all)
204                        {
205                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
206                                {
207                                        new_options +=  "<option value="
208                                                                + select_available_users.options[i].value
209                                                                + ">"
210                                                                + select_available_users.options[i].text
211                                                                + "</options>";
212                                }
213                        }
214                        else
215                        {               
216                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
217                                {
218                                        new_options +=  "<option value="
219                                                                + select_available_users.options[i].value
220                                                                + ">"
221                                                                + select_available_users.options[i].text
222                                                                + "</options>";
223                                }
224                        }
225                }
226        }
227
228        if (new_options != '')
229        {
230                select_usersInMaillist.innerHTML = '&nbsp;' + new_options + select_usersInMaillist.innerHTML;
231                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
232                document.getElementById('ea_input_searchUser').value = "";
233        }
234}
235
236function remove_user2maillist()
237{
238        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
239       
240        for(var i = 0;i < select_usersInMaillist.options.length; i++)
241                if(select_usersInMaillist.options[i].selected)
242                        select_usersInMaillist.options[i--] = null;
243}
244
245function add_user2scl_maillist()
246{
247        select_available_users = document.getElementById('ea_select_available_users');
248        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
249
250        var count_available_users = select_available_users.length;
251        var count_usersInMailList = select_usersInMaillist.options.length;
252        var new_options = '';
253
254        for (i = 0 ; i < count_available_users ; i++)
255        {
256                if (select_available_users.options[i].selected)
257                {
258                        if(document.all)
259                        {
260                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
261                                {
262                                        new_options +=  "<option value="
263                                                                + select_available_users.options[i].value
264                                                                + ">"
265                                                                + select_available_users.options[i].text
266                                                                + "</options>";
267                                }
268                        }
269                        else
270                        {               
271                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
272                                {
273                                        new_options +=  "<option value="
274                                                                + select_available_users.options[i].value
275                                                                + ">"
276                                                                + select_available_users.options[i].text
277                                                                + "</options>";
278                                }
279                        }
280                }
281        }
282        if (new_options != '')
283        {
284                usersOptionsHtml = select_usersInMaillist.innerHTML;
285                usersOptionsHtml = (($.browser.msie && $.browser.version < 9) ? '#' : '&nbsp;') + new_options + usersOptionsHtml;
286                $(select_usersInMaillist).html(usersOptionsHtml);
287        }
288}
289
290function remove_user2scl_maillist()
291{
292        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
293       
294        for(var i = 0;i < select_usersInMaillist.options.length; i++)
295                if(select_usersInMaillist.options[i].selected)
296                        select_usersInMaillist.options[i--] = null;
297}
298
299
300// Variaveis Locais
301if (document.getElementById('ea_select_available_users'))
302{
303        var select_available_users  = document.getElementById('ea_select_available_users');
304        var select_available_users_clone = select_available_users.cloneNode(true);
305}
306else
307{
308        var select_available_users  = '';
309        var select_available_users_clone = '';
310}
311var finderTimeout = '';
312
313// Funcoes
314function optionFinderTimeout(obj, event)
315{
316    if( event && event.keyCode !== 13 )
317        return;
318       
319        optionFinder( obj.id );
320}
321function optionFinder(id) {
322        get_available_users();
323}                       
324
325function delete_maillist(uid, uidnumber)
326{
327        if (confirm(get_lang('Do you really want delete the email list') + ' ' + uid + " ??"))
328       
329        {
330                var handler_delete_maillist = function(data)
331                {
332                        if (!data.status)
333                                alert(data.msg);
334                        else
335                                alert(get_lang('Email list successful deleted') + '.');
336                       
337                        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
338                        return;
339                }
340                cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist);
341        }
342}
343
344function search_organization(key, element)
345{
346        var organizations = document.getElementById(element);
347        var RegExp_org = new RegExp("\\b"+key, "i");
348       
349        for(i = 0; i < organizations.length; i++)
350        {
351                if (RegExp_org.test(organizations[i].text))
352                {
353                        organizations[i].selected = true;
354                        return;
355                }
356        }
357}
358
359function emailSuggestion_maillist()
360{
361        var defaultDomain = document.forms[0].defaultDomain.value;
362        var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value);
363        var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase());
364
365        var uid = document.getElementById("ea_maillist_uid");
366        var mail= document.getElementById("ea_maillist_mail");
367       
368        var raw_selected_context = selected_context.replace(base_dn, "");
369       
370        var array_org_name = raw_selected_context.split('.');
371        var org_name = array_org_name[array_org_name.length-1];
372       
373        if (mail.value == "")
374                mail.value = uid.value + "@" + org_name + "." + defaultDomain;
375}
376
377function dn2ufn(dn)
378{
379        var ufn = '';
380        var array_dn = dn.split(",");
381        for (x in array_dn)
382        {
383                var tmp = array_dn[x].split("=");
384                ufn += tmp[1] + '.';
385        }
386        return ufn.substring(0,(ufn.length-1));
387}
388
389function LTrim(value)
390{
391     var w_space = String.fromCharCode(32);
392     var strTemp = "";
393     var iTemp = 0;
394
395     var v_length = value ? value.length : 0;
396     if(v_length < 1)
397             return "";
398
399     while(iTemp < v_length){
400             if(value && value.charAt(iTemp) != w_space){
401                     strTemp = value.substring(iTemp,v_length);
402                     break;
403             }
404             iTemp++;
405     }
406     return strTemp;
407}
408
409function validateEmail()
410{
411
412     externalEmail = document.getElementById('ea_input_externalUser');
413
414     if( externalEmail.value )
415     {
416             //var element = arguments[0];
417             var validate = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
418
419             if(this.LTrim(externalEmail.value) != "" && externalEmail.value != "")
420             {
421                     if(!validate.test(externalEmail.value))
422                     {
423                             alert(get_lang('Email address is not valid') + '.');
424                             externalEmail.focus();
425                             return false;
426                     }else {
427                             this.add_externalUser2maillist(externalEmail.value);
428                     }
429             }
430
431     }
432}
433
434function add_externalUser2maillist(mailAddress)
435{
436     input_externalUsers = mailAddress.toLowerCase(); //document.getElementById('ea_input_externalUser').value;
437     select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
438
439     var count_externalUsers = input_externalUsers.length;
440     var count_usersInMaillist = select_usersInMaillist.options.length;
441     var new_options = '';
442
443     var teste = ''; //Variavel que ira receber mensagem de alerta ao usuario;
444     var alerta = new Boolean(0); //Variavel que sera usada para verificar se o alerta ao usuario sera exibido ou nao;
445
446     //Laco abaixo compara se o valor escolhido em select_available_users ja existe em select_usersInMaillist
447     //se existir, adiciona o valor em teste e muda a variavel alerta para true; teste sera exibido em tela
448     //apenas de alerta  true; ver if no fim da funcao;
449     for(j = 0; j < count_usersInMaillist; j++)
450     {
451             var tmp = select_usersInMaillist.options[j].text
452
453             if(tmp.match(input_externalUsers))
454             {
455                     teste = get_lang("User already belongs to the list") + "\n" + input_externalUsers + "\n";
456                     alerta = new Boolean(1);
457             }
458     }
459
460     if(alerta != true)
461     {
462             if(document.all)
463             {
464                     if ( (select_usersInMaillist.innerHTML.indexOf('value='+input_externalUsers)) == '-1' )
465                     {
466                             new_options +=  "<option value="
467                                                     + input_externalUsers
468                                                     + ">"
469                                                     + input_externalUsers
470                                                     + "</option>";
471                     }
472             }
473             else
474             {
475                     if ( (select_usersInMaillist.innerHTML.indexOf('value="'+input_externalUsers+'"')) == '-1' )
476                     {
477                             new_options +=  "<option value="
478                                                     + input_externalUsers
479                                                     + ">"
480                                                     + input_externalUsers
481                                                     + "</option>";
482                     }
483             }
484     }
485
486     if(alerta == true)
487     {
488             alert(teste);
489     }
490
491
492     if (new_options != '')
493     {
494             select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML;
495             select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
496     }
497
498     document.getElementById('ea_input_externalUser').value = '';
499}
Note: See TracBrowser for help on using the repository browser.