source: sandbox/2.5.1-evolucao/expressoAdmin1_2/js/jscode/maillists.js @ 8265

Revision 8265, 14.5 KB checked in by angelo, 10 years ago (diff)

Ticket #0000 - sincronizacao das alteracoes do trunk com este sandbox

  • 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        if (!data.status)
142                alert(data.msg);
143        else
144                alert(get_lang('SCL successful saved') + '.');
145        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
146        return;
147}
148
149function sinc_combos_org(context, recursive)
150{
151        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
152
153        for (i=0; i<combo_org_maillists.length; i++)
154        {
155                if (combo_org_maillists.options[i].value == context)
156                {
157                        combo_org_maillists.options[i].selected = true;
158                        get_available_users(context, recursive);
159                        break;
160                }
161        }
162}
163
164function get_available_users(context, recursive)
165{
166//      var sentence = Element('ea_input_searchUser').value;
167//
168//      var url = '$this.ldap_functions.get_available_users_and_maillist&context='
169//                  + Element('ea_combo_org_maillists').value
170//                  + '&sentence=' + sentence
171//                  + '&denied_uidnumber=' + document.forms[0].uidnumber.value;
172//
173//      var fillHandler = function( fill ){
174//
175//      Element('ea_select_available_users').innerHTML = fill;
176//
177//      return( fill !== "" );
178//     }
179//
180//      userFinder( sentence, fillHandler, url, 'ea_span_searching' );
181                       
182        var url = '$this.ldap_functions.get_available_users_and_maillist&denied_uidnumber=' + document.forms[0].uidnumber.value;
183       
184        optionFind( 'ea_input_searchUser', 'ea_select_available_users', url,
185                    'ea_combo_org_maillists', 'ea_span_searching' );
186}
187
188function add_user2maillist()
189{
190        select_available_users = document.getElementById('ea_select_available_users');
191        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
192
193        var count_available_users = select_available_users.length;
194        var count_usersInMailList = select_usersInMaillist.options.length;
195        var new_options = '';
196
197        for (i = 0 ; i < count_available_users ; i++)
198        {
199                if (select_available_users.options[i].selected)
200                {
201                        if(document.all)
202                        {
203                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
204                                {
205                                        new_options +=  "<option value="
206                                                                + select_available_users.options[i].value
207                                                                + ">"
208                                                                + select_available_users.options[i].text
209                                                                + "</options>";
210                                }
211                        }
212                        else
213                        {               
214                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
215                                {
216                                        new_options +=  "<option value="
217                                                                + select_available_users.options[i].value
218                                                                + ">"
219                                                                + select_available_users.options[i].text
220                                                                + "</options>";
221                                }
222                        }
223                }
224        }
225
226        if (new_options != '')
227        {
228                select_usersInMaillist.innerHTML = '&nbsp;' + new_options + select_usersInMaillist.innerHTML;
229                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
230                document.getElementById('ea_input_searchUser').value = "";
231        }
232}
233
234function remove_user2maillist()
235{
236        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
237       
238        for(var i = 0;i < select_usersInMaillist.options.length; i++)
239                if(select_usersInMaillist.options[i].selected)
240                        select_usersInMaillist.options[i--] = null;
241}
242
243function add_user2scl_maillist()
244{
245        select_available_users = document.getElementById('ea_select_available_users');
246        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
247
248        var count_available_users = select_available_users.length;
249        var count_usersInMailList = select_usersInMaillist.options.length;
250        var new_options = '';
251
252        for (i = 0 ; i < count_available_users ; i++)
253        {
254                if (select_available_users.options[i].selected)
255                {
256                        if(document.all)
257                        {
258                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
259                                {
260                                        new_options +=  "<option value="
261                                                                + select_available_users.options[i].value
262                                                                + ">"
263                                                                + select_available_users.options[i].text
264                                                                + "</options>";
265                                }
266                        }
267                        else
268                        {               
269                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
270                                {
271                                        new_options +=  "<option value="
272                                                                + select_available_users.options[i].value
273                                                                + ">"
274                                                                + select_available_users.options[i].text
275                                                                + "</options>";
276                                }
277                        }
278                }
279        }
280
281        if (new_options != '')
282        {
283                usersOptionsHtml = select_usersInMaillist.innerHTML;
284                usersOptionsHtml = (($.browser.msie && $.browser.version < 9) ? '#' : '&nbsp;') + new_options + usersOptionsHtml;
285                $(select_usersInMaillist).html(usersOptionsHtml);
286        }
287}
288
289function remove_user2scl_maillist()
290{
291        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
292       
293        for(var i = 0;i < select_usersInMaillist.options.length; i++)
294                if(select_usersInMaillist.options[i].selected)
295                        select_usersInMaillist.options[i--] = null;
296}
297
298
299// Variaveis Locais
300if (document.getElementById('ea_select_available_users'))
301{
302        var select_available_users  = document.getElementById('ea_select_available_users');
303        var select_available_users_clone = select_available_users.cloneNode(true);
304}
305else
306{
307        var select_available_users  = '';
308        var select_available_users_clone = '';
309}
310var finderTimeout = '';
311
312// Funcoes
313function optionFinderTimeout(obj, event)
314{
315    if( event && event.keyCode !== 13 )
316        return;
317       
318        optionFinder( obj.id );
319}
320function optionFinder(id) {
321        get_available_users();
322}                       
323
324function delete_maillist(uid, uidnumber)
325{
326        if (confirm(get_lang('Do you really want delete the email list') + ' ' + uid + " ??"))
327       
328        {
329                var handler_delete_maillist = function(data)
330                {
331                        if (!data.status)
332                                alert(data.msg);
333                        else
334                                alert(get_lang('Email list successful deleted') + '.');
335                       
336                        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
337                        return;
338                }
339                cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist);
340        }
341}
342
343function search_organization(key, element)
344{
345        var organizations = document.getElementById(element);
346        var RegExp_org = new RegExp("\\b"+key, "i");
347       
348        for(i = 0; i < organizations.length; i++)
349        {
350                if (RegExp_org.test(organizations[i].text))
351                {
352                        organizations[i].selected = true;
353                        return;
354                }
355        }
356}
357
358function emailSuggestion_maillist()
359{
360        var defaultDomain = document.forms[0].defaultDomain.value;
361        var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value);
362        var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase());
363
364        var uid = document.getElementById("ea_maillist_uid");
365        var mail= document.getElementById("ea_maillist_mail");
366       
367        var raw_selected_context = selected_context.replace(base_dn, "");
368       
369        var array_org_name = raw_selected_context.split('.');
370        var org_name = array_org_name[array_org_name.length-1];
371       
372        if (mail.value == "")
373                mail.value = uid.value + "@" + org_name + "." + defaultDomain;
374}
375
376function dn2ufn(dn)
377{
378        var ufn = '';
379        var array_dn = dn.split(",");
380        for (x in array_dn)
381        {
382                var tmp = array_dn[x].split("=");
383                ufn += tmp[1] + '.';
384        }
385        return ufn.substring(0,(ufn.length-1));
386}
387
388function LTrim(value)
389{
390     var w_space = String.fromCharCode(32);
391     var strTemp = "";
392     var iTemp = 0;
393
394     var v_length = value ? value.length : 0;
395     if(v_length < 1)
396             return "";
397
398     while(iTemp < v_length){
399             if(value && value.charAt(iTemp) != w_space){
400                     strTemp = value.substring(iTemp,v_length);
401                     break;
402             }
403             iTemp++;
404     }
405     return strTemp;
406}
407
408function validateEmail()
409{
410
411     externalEmail = document.getElementById('ea_input_externalUser');
412
413     if( externalEmail.value )
414     {
415             //var element = arguments[0];
416             var validate = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
417
418             if(this.LTrim(externalEmail.value) != "" && externalEmail.value != "")
419             {
420                     if(!validate.test(externalEmail.value))
421                     {
422                             alert(get_lang('Email address is not valid') + '.');
423                             externalEmail.focus();
424                             return false;
425                     }else {
426                             this.add_externalUser2maillist(externalEmail.value);
427                     }
428             }
429
430     }
431}
432
433function add_externalUser2maillist(mailAddress)
434{
435     input_externalUsers = mailAddress.toLowerCase(); //document.getElementById('ea_input_externalUser').value;
436     select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
437
438     var count_externalUsers = input_externalUsers.length;
439     var count_usersInMaillist = select_usersInMaillist.options.length;
440     var new_options = '';
441
442     var teste = ''; //Variavel que ira receber mensagem de alerta ao usuario;
443     var alerta = new Boolean(0); //Variavel que sera usada para verificar se o alerta ao usuario sera exibido ou nao;
444
445     //Laco abaixo compara se o valor escolhido em select_available_users ja existe em select_usersInMaillist
446     //se existir, adiciona o valor em teste e muda a variavel alerta para true; teste sera exibido em tela
447     //apenas de alerta  true; ver if no fim da funcao;
448     for(j = 0; j < count_usersInMaillist; j++)
449     {
450             var tmp = select_usersInMaillist.options[j].text
451
452             if(tmp.match(input_externalUsers))
453             {
454                     teste = get_lang("User already belongs to the list") + "\n" + input_externalUsers + "\n";
455                     alerta = new Boolean(1);
456             }
457     }
458
459     if(alerta != true)
460     {
461             if(document.all)
462             {
463                     if ( (select_usersInMaillist.innerHTML.indexOf('value='+input_externalUsers)) == '-1' )
464                     {
465                             new_options +=  "<option value="
466                                                     + input_externalUsers
467                                                     + ">"
468                                                     + input_externalUsers
469                                                     + "</option>";
470                     }
471             }
472             else
473             {
474                     if ( (select_usersInMaillist.innerHTML.indexOf('value="'+input_externalUsers+'"')) == '-1' )
475                     {
476                             new_options +=  "<option value="
477                                                     + input_externalUsers
478                                                     + ">"
479                                                     + input_externalUsers
480                                                     + "</option>";
481                     }
482             }
483     }
484
485     if(alerta == true)
486     {
487             alert(teste);
488     }
489
490
491     if (new_options != '')
492     {
493             select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML;
494             select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
495     }
496
497     document.getElementById('ea_input_externalUser').value = '';
498}
Note: See TracBrowser for help on using the repository browser.