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

Revision 2712, 12.7 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Adaptando todo o expressoAdmin1_2 para não realizar reload.

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