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

Revision 482, 12.1 KB checked in by niltonneto, 16 years ago (diff)

Corrigido tradução.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 0;
2function validate_fields(type)
3{
4        document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
5        document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase();
6
7        if (document.forms[0].uid.value == ''){
8                alert(get_lang('login field is empty') + '.');
9                return;
10        }
11
12        if (document.forms[0].cn.value == ''){
13                alert(get_lang('name field is empty') + '.');
14                return;
15        }
16       
17        if (document.forms[0].restrictionsOnEmailLists.value == 'true')
18        {
19                uid_tmp = document.forms[0].uid.value.split("-");
20                if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){
21                        alert(
22                                get_lang('login field is incomplete') + '.\n' +
23                                get_lang('the login field must be formed like') + ':\n' +
24                                get_lang('list') + '-' + get_lang('organization') + '-' + get_lang('listname') + '.\n' +
25                                get_lang('eg') + ': ' + 'lista-celepar-rh.');
26                        return;
27                }
28        }
29               
30        if (document.forms[0].uid.value.split(" ").length > 1){
31                alert(get_lang('LOGIN field contains characters not allowed') + '.');
32                document.forms[0].uid.focus();
33                return;
34        }
35       
36        if (document.forms[0].mail.value == ''){
37                alert(get_lang('EMAIL field is empty') + '.');
38                document.forms[0].mail.focus();
39                return;
40        }
41        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
42        if(!reEmail.test(document.forms[0].mail.value)){
43                alert(get_lang('Email field is not valid') + '.');
44                return false;
45        }
46       
47        select_userInMaillist = document.getElementById('ea_select_usersInMaillist');
48        if (select_userInMaillist.options.length == 0){
49                alert(get_lang('Any user is in the list') + '.');
50                return;
51        }
52       
53        var handler_validate_fields = function(data)
54        {
55                if (!data.status)
56                        alert(data.msg);
57                else
58                {
59                        if (type == 'create_maillist')
60                                cExecuteForm ("$this.maillist.create", document.forms[0], handler_create);
61                        else if (type == 'edit_maillist')
62                                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
63                }
64        }
65
66        // Needed select all options from select
67        for(var i=0; i<select_userInMaillist.options.length; i++)
68        {
69                // No IE, não seleciona o separador do select
70                if (select_userInMaillist.options[i].value != -1)
71                        select_userInMaillist.options[i].selected = true;
72                else
73                        select_userInMaillist.options[i].selected = false;
74        }
75
76        // O UID da lista foi alterado ou é uma nova lista.
77        if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){
78                cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value+'&mail='+document.forms[0].mail.value, handler_validate_fields);
79        }
80        else if (type == 'edit_maillist')
81        {
82                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
83        }
84}
85
86// HANDLER CREATE
87// É necessário 2 funcões de retorno por causa do cExecuteForm.
88function handler_create(data)
89{
90        return_handler_create(data);
91}
92function return_handler_create(data)
93{
94        if (!data.status)
95                alert(data.msg);
96        else{
97                alert(get_lang('Email list successful created') + '.');
98                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
99        }
100        return;
101}
102
103// HANDLER SAVE
104// É necessário 2 funcões de retorno por causa do cExecuteForm.
105function handler_save(data)
106{
107        return_handler_save(data);
108}
109function return_handler_save(data)
110{
111        if (!data.status)
112                alert(data.msg);
113        else{
114                alert(get_lang('Email list successful saved') + '.');
115                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
116        }
117        return;
118}
119
120function save_scl()
121{
122        select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist');
123        // Needed select all options from select
124        for(var i=0; i<select_users_SCL_Maillist.options.length; i++)
125                select_users_SCL_Maillist.options[i].selected = true;
126
127        cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl);
128}
129function handler_save_scl(data)
130{
131        return_handler_save_scl(data);
132}
133
134function return_handler_save_scl(data)
135{
136        if (!data.status)
137                alert(data.msg);
138        else
139                alert(get_lang('SCL successful saved') + '.');
140        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
141        return;
142}
143
144function sinc_combos_org(context, recursive)
145{
146        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
147
148        for (i=0; i<combo_org_maillists.length; i++)
149        {
150                if (combo_org_maillists.options[i].value == context)
151                {
152                        combo_org_maillists.options[i].selected = true;
153                        get_available_users(context, recursive);
154                        break;
155                }
156        }
157}
158
159function get_available_users(context, recursive)
160{
161        var handler_get_available_users = function(data)
162        {
163                select_available_users = document.getElementById('ea_select_available_users');
164               
165                //Limpa o select
166                for(var i=0; i<select_available_users.options.length; i++)
167                {
168                        select_available_users.options[i] = null;
169                        i--;
170                }
171
172                if ((data) && (data.length > 0))
173                {
174                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
175                        select_available_users.innerHTML = '&nbsp;' + data;
176                        select_available_users.outerHTML = select_available_users.outerHTML;
177                       
178                        select_available_users.disabled = false;
179                        select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true);
180                        document.getElementById('ea_input_searchUser').value = '';
181                }
182        }
183       
184        //Impede chamada recursiva na raiz das organizações
185        if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_maillists').value))
186        {
187                alert(get_lang('It is not allow select all users from the root organization') + '.');
188                document.getElementById('ea_check_allUsers').checked = false;
189               
190                // Limpa select
191                select_available_users = document.getElementById('ea_select_available_users');
192                select_available_users.innerHTML = '&nbsp;';
193                select_available_users.outerHTML = select_available_users.outerHTML;
194                return;
195        }
196        cExecute ('$this.ldap_functions.get_available_users_and_maillist&context='+context+'&recursive='+recursive+'&denied_uidnumber='+document.forms[0].uidnumber.value, handler_get_available_users);
197}
198
199function add_user2maillist()
200{
201        select_available_users = document.getElementById('ea_select_available_users');
202        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
203
204        var count_available_users = select_available_users.length;
205        var count_usersInMailList = select_usersInMaillist.options.length;
206        var new_options = '';
207
208        for (i = 0 ; i < count_available_users ; i++)
209        {
210                if (select_available_users.options[i].selected)
211                {
212                        if(document.all)
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                        else
224                        {               
225                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
226                                {
227                                        new_options +=  "<option value="
228                                                                + select_available_users.options[i].value
229                                                                + ">"
230                                                                + select_available_users.options[i].text
231                                                                + "</options>";
232                                }
233                        }
234                }
235        }
236
237        if (new_options != '')
238        {
239                select_usersInMaillist.innerHTML = '&nbsp;' + new_options + select_usersInMaillist.innerHTML;
240                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
241                document.getElementById('ea_input_searchUser').value = "";
242        }
243}
244
245function remove_user2maillist()
246{
247        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
248       
249        for(var i = 0;i < select_usersInMaillist.options.length; i++)
250                if(select_usersInMaillist.options[i].selected)
251                        select_usersInMaillist.options[i--] = null;
252}
253
254function add_user2scl_maillist()
255{
256        select_available_users = document.getElementById('ea_select_available_users');
257        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
258
259        var count_available_users = select_available_users.length;
260        var count_usersInMailList = select_usersInMaillist.options.length;
261        var new_options = '';
262
263        for (i = 0 ; i < count_available_users ; i++)
264        {
265                if (select_available_users.options[i].selected)
266                {
267                        if(document.all)
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                        else
279                        {               
280                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
281                                {
282                                        new_options +=  "<option value="
283                                                                + select_available_users.options[i].value
284                                                                + ">"
285                                                                + select_available_users.options[i].text
286                                                                + "</options>";
287                                }
288                        }
289                }
290        }
291
292        if (new_options != '')
293        {
294                select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML;
295                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
296        }
297}
298
299function remove_user2scl_maillist()
300{
301        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
302       
303        for(var i = 0;i < select_usersInMaillist.options.length; i++)
304                if(select_usersInMaillist.options[i].selected)
305                        select_usersInMaillist.options[i--] = null;
306}
307
308
309// Variaveis Locais
310if (document.getElementById('ea_select_available_users'))
311{
312        var select_available_users  = document.getElementById('ea_select_available_users');
313        var select_available_users_clone = select_available_users.cloneNode(true);
314}
315else
316{
317        var select_available_users  = '';
318        var select_available_users_clone = '';
319}
320var finderTimeout = '';
321
322// Funcoes
323function optionFinderTimeout(obj)
324{
325        clearTimeout(finderTimeout);   
326        var oWait = document.getElementById("ea_span_searching");
327        oWait.innerHTML = get_lang('Searching') + '...';
328        finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
329}
330function optionFinder(id) {
331        var oWait = document.getElementById("ea_span_searching");
332        var oText = document.getElementById(id);
333               
334        //Limpa todo o select
335        var select_available_users_tmp = document.getElementById('ea_select_available_users')
336
337        for(var i = 0;i < select_available_users_tmp.options.length; i++)
338                select_available_users_tmp.options[i--] = null;
339
340        var RegExp_name = new RegExp("\\b"+oText.value, "i");
341       
342        //Inclui usuário começando com a pesquisa
343        for(i = 0; i < select_available_users_clone.length; i++){
344                if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) )
345                {
346                        sel = select_available_users_tmp.options;
347                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
348
349                        if (select_available_users_clone[i].value == -1)
350                                option.disabled = true;
351
352                        sel[sel.length] = option;
353                }
354        }
355        oWait.innerHTML = '&nbsp;';
356}                       
357
358function delete_maillist(uid, uidnumber)
359{
360        if (confirm(get_lang('Do you really want delete the email list') + ' ' + uid + " ??"))
361       
362        {
363                var handler_delete_maillist = function(data)
364                {
365                        if (!data.status)
366                                alert(data.msg);
367                        else
368                                alert(get_lang('Email list successful deleted') + '.');
369                       
370                        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
371                        return;
372                }
373                cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist);
374        }
375}
376
377function search_organization(key, element)
378{
379        var organizations = document.getElementById(element);
380        var RegExp_org = new RegExp("\\b"+key, "i");
381       
382        for(i = 0; i < organizations.length; i++)
383        {
384                if (RegExp_org.test(organizations[i].text))
385                {
386                        organizations[i].selected = true;
387                        return;
388                }
389        }
390}
391
392function emailSuggestion_maillist()
393{
394        var defaultDomain = document.forms[0].defaultDomain.value;
395        var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value);
396        var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase());
397
398        var uid = document.getElementById("ea_maillist_uid");
399        var mail= document.getElementById("ea_maillist_mail");
400       
401        var raw_selected_context = selected_context.replace(base_dn, "");
402       
403        var array_org_name = raw_selected_context.split('.');
404        var org_name = array_org_name[array_org_name.length-1];
405       
406        if (mail.value == "")
407                mail.value = uid.value + "@" + org_name + "." + defaultDomain;
408}
409
410function dn2ufn(dn)
411{
412        var ufn = '';
413        var array_dn = dn.split(",");
414        for (x in array_dn)
415        {
416                var tmp = array_dn[x].split("=");
417                ufn += tmp[1] + '.';
418        }
419        return ufn.substring(0,(ufn.length-1));
420}
Note: See TracBrowser for help on using the repository browser.