source: trunk/expressoAdmin1_2/js/jscode/groups.js @ 73

Revision 73, 10.6 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1// Variaveis Globais
2countFiles = 0;
3function validate_fields(type, restrictionsOnGroup)
4{
5        document.forms[0].cn.value = document.forms[0].cn.value.toLowerCase();
6        document.forms[0].old_cn.value = document.forms[0].old_cn.value.toLowerCase();
7       
8        if (document.forms[0].cn.value == ''){
9                alert('Campo NOME do grupo está vazio.');
10                return;
11        }
12               
13        if (document.forms[0].description.value == ''){
14                alert('Campo DESCRIÇÃO está vazio.');
15                return;
16        }
17       
18        if (restrictionsOnGroup == 'true')
19        {
20                cn_tmp = document.forms[0].cn.value.split("-");
21                if ( (cn_tmp.length < 3) || ((cn_tmp[0] != 'grupo') && (cn_tmp[0] != 'smb')) ){
22                        alert(
23                                'O campo NOME do grupo está incompleto.\n' +
24                                'O nome do grupo deve ser formado assim:\n' +
25                                'grupo-ORGANIZACAO-NOME_DO_GRUPO.\n' +
26                                'Ex: grupo-celepar-rh.');
27                        return;
28                }
29        }
30       
31        var reCn = /^([a-zA-Z0-9_\-])+$/;
32        var reDesc = /^([a-zA-Z0-9_\- .])+$/;
33       
34        if(!reCn.test(document.forms[0].cn.value)){
35                alert('Campo NOME DO GRUPO comtém caracteres não permitidos.');
36                document.forms[0].cn.focus();
37                return;
38        }
39
40        if(!reDesc.test(document.forms[0].description.value)){
41                alert('Campo DESCRIÇÃO comtém caracteres não permitidos.');
42                document.forms[0].description.focus();
43                return;
44        }
45       
46        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
47        if ( (document.forms[0].email.value != '') && (!reEmail.test(document.forms[0].email.value)) )
48        {
49                alert("Campo E-mail não é válido.");
50                return false;
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_group')
60                                cExecuteForm ("$this.group.create", document.forms[0], handler_create);
61                        else if (type == 'edit_group')
62                                cExecuteForm ("$this.group.save", document.forms[0], handler_save);
63                }
64        }
65
66        // Needed select all options from select
67        select_userInGroup = document.getElementById('ea_select_usersInGroup');
68        for(var i=0; i<select_userInGroup.options.length; i++)
69                select_userInGroup.options[i].selected = true;
70       
71        // O CN do grupo foi alterado ou é um novo grupo.
72        if ((document.forms[0].old_cn.value != document.forms[0].cn.value) || (type == 'create_group')){
73                cExecute ('$this.group.validate_fields&cn='+document.forms[0].cn.value, handler_validate_fields);
74        }
75        else if (type == 'edit_group')
76        {
77                cExecuteForm ("$this.group.save", document.forms[0], handler_save);
78        }
79}
80
81// HANDLER CREATE
82// É necessário 2 funcões de retorno por causa do cExecuteForm.
83function handler_create(data)
84{
85        return_handler_create(data);
86}
87function return_handler_create(data)
88{
89        if (!data.status)
90                alert(data.msg);
91        else{
92                alert('Grupo criado com êxito!');
93                location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
94        }
95        return;
96}
97
98// HANDLER SAVE
99// É necessário 2 funcões de retorno por causa do cExecuteForm.
100function handler_save(data)
101{
102        return_handler_save(data);
103}
104function return_handler_save(data)
105{
106        if (!data.status)
107                alert(data.msg);
108        else{
109                alert('Grupo salvo com êxito!!');
110                location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
111        }
112        return;
113}
114
115function sinc_combos_org(context, recursive)
116{
117        combo_org_groups = document.getElementById('ea_combo_org_groups');
118
119        for (i=0; i<combo_org_groups.length; i++)
120        {
121                if (combo_org_groups.options[i].value == context)
122                {
123                        combo_org_groups.options[i].selected = true;
124                        get_available_users(context, recursive);
125                        break;
126                }
127        }
128}
129
130function get_available_users(context, recursive)
131{
132        var handler_get_available_users = function(data)
133        {
134                select_available_users = document.getElementById('ea_select_available_users');
135               
136                //Limpa o select
137                for(var i=0; i<select_available_users.options.length; i++)
138                {
139                        select_available_users.options[i] = null;
140                        i--;
141                }
142
143                if ((data) && (data.length > 0))
144                {
145                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
146                        select_available_users.innerHTML = 'lixo' + data;
147                        select_available_users.outerHTML = select_available_users.outerHTML;
148                       
149                        select_available_users.disabled = false;
150                        select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true);
151                        document.getElementById('ea_input_searchUser').value = '';
152                }
153        }
154       
155        //Impede chamada recursiva na raiz das organizações
156        if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_groups').value))
157        {
158                alert('Nao é possível selecionar todos os usuários da organização raiz.')
159                document.getElementById('ea_check_allUsers').checked = false;
160
161                // Limpa select
162                select_available_users = document.getElementById('ea_select_available_users');
163                select_available_users.innerHTML = 'lixo';
164                select_available_users.outerHTML = select_available_users.outerHTML;
165                return;
166        }
167        cExecute ('$this.ldap_functions.get_available_users&context='+context+'&recursive='+recursive, handler_get_available_users);
168}
169
170function add_user2group()
171{
172        var select_available_users = document.getElementById('ea_select_available_users');
173        var select_usersInGroup = document.getElementById('ea_select_usersInGroup');
174
175        var count_available_users = select_available_users.length;
176        var count_usersInGroup = select_usersInGroup.options.length;
177        var new_options = '';
178       
179        for (i = 0 ; i < count_available_users ; i++)
180        {
181                if (select_available_users.options[i].selected)
182                {
183                        if(document.all)
184                        {
185                                if ( (select_usersInGroup.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
186                                {
187                                        new_options +=  '<option value='
188                                                                + select_available_users.options[i].value
189                                                                + '>'
190                                                                + select_available_users.options[i].text
191                                                                + '</option>';
192                                }
193                        }
194                        else
195                        {
196                                if ( (select_usersInGroup.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
197                                {
198                                        new_options +=  '<option value='
199                                                                + select_available_users.options[i].value
200                                                                + '>'
201                                                                + select_available_users.options[i].text
202                                                                + '</option>';
203                                }
204                        }
205                }
206        }
207
208        if (new_options != '')
209        {
210                select_usersInGroup.innerHTML = 'lixo' + new_options + select_usersInGroup.innerHTML;
211                select_usersInGroup.outerHTML = select_usersInGroup.outerHTML;
212        }
213}
214
215function remove_user2group()
216{
217        select_usersInGroup = document.getElementById('ea_select_usersInGroup');
218       
219        for(var i = 0;i < select_usersInGroup.options.length; i++)
220                if(select_usersInGroup.options[i].selected)
221                        select_usersInGroup.options[i--] = null;
222}
223
224// Variaveis Locais
225if (document.getElementById('ea_select_available_users'))
226{
227        var select_available_users  = document.getElementById('ea_select_available_users');
228        var select_available_users_clone = select_available_users.cloneNode(true);
229}
230else
231{
232        var select_available_users  = '';
233        var select_available_users_clone = '';
234}
235var finderTimeout = '';
236
237// Funcoes                                                                                     
238function optionFinderTimeout(obj)
239{
240        clearTimeout(finderTimeout);   
241        var oWait = document.getElementById("ea_span_searching");
242        oWait.innerHTML = 'Buscando...';
243        var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
244}
245function optionFinder(id) {
246        var oWait = document.getElementById("ea_span_searching");
247        var oText = document.getElementById(id);
248                       
249        //Limpa todo o select
250        var select_available_users_tmp = document.getElementById('ea_select_available_users')
251        for(var i = 0;i < select_available_users_tmp.options.length; i++)
252                select_available_users_tmp.options[i--] = null;
253
254        var RegExp_name = new RegExp("\\b"+oText.value, "i");
255
256        //Inclui usuário começando com a pesquisa
257        for(i = 0; i < select_available_users_clone.length; i++){
258                if (RegExp_name.test(select_available_users_clone[i].text))
259                {
260                        sel = select_available_users_tmp.options;
261                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);                               
262                        sel[sel.length] = option;
263                }
264        }
265       
266        oWait.innerHTML = '&nbsp;';
267}                       
268
269function delete_group(cn, gidnumber)
270{
271        if (confirm("Realmente deletar Grupo " + cn + " ??"))
272        {
273                var handler_delete_group = function(data)
274                {
275                        if (!data.status)
276                                alert(data.msg);
277                        else
278                                alert('Grupo deletado com êxito!!');
279                       
280                        location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
281                        return;
282                }
283                cExecute ('$this.group.delete&gidnumber='+gidnumber+'&cn='+cn, handler_delete_group);
284        }
285}
286
287function use_samba_attrs(value)
288{
289        document.forms[0].sambasid.disabled = !value;
290}
291
292function get_available_sambadomains(context, type)
293{
294        if ((type == 'create_group') && (document.getElementById('ea_div_display_samba_options').style.display != 'none'))
295        {
296                var handler_get_available_sambadomains = function(data)
297                {
298                        document.forms[0].use_attrs_samba.checked = data.status;
299                        use_samba_attrs(data.status);
300                       
301                        if (data.status)
302                        {
303                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
304                                for (i=0; i<data.sambaDomains.length; i++)
305                                {
306                                        for (j=0; j<combo_sambadomains.length; j++)
307                                        {
308                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
309                                                {
310                                                        combo_sambadomains.options[j].selected = true;
311                                                        break;
312                                                }
313                                        }
314                                }
315                               
316                        }
317                }
318                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
319        }
320}
321
322function groupEmailSuggestion(concatenateDomain, type)
323{
324        if (document.forms[0].email.disabled)
325                return;
326       
327        if (type != 'create_group')
328                return;
329       
330        if (concatenateDomain == 'true')
331        {
332                var ldap_context = document.forms[0].ufn_ldap_context.value.toLowerCase();
333                var organization_context = document.forms[0].context.value.toLowerCase();
334                var select_orgs = document.getElementById('ea_combo_org_info');
335               
336                for(var i=0; i<select_orgs.options.length; i++)
337                {
338                        if(select_orgs.options[i].selected == true)
339                        {
340                                var x;
341                                var context = '';
342                                select_context = select_orgs.options[i].value.toLowerCase();
343                                organization_name = organization_context.split(",");
344                       
345                                for (x in organization_name)
346                                {
347                                        tmp = organization_name[x].split("=");
348                                        context += tmp[1] + '.';
349                                }
350                        }
351                }
352                domain_name = document.forms[0].defaultDomain.value;
353       
354                x=context.indexOf(ldap_context,0);
355                org_name_par = context.substring(0,(x-1));
356                org_name = org_name_par.split('.');
357                org_name = org_name[org_name.length-1];
358               
359                if (org_name != '')
360                        document.forms[0].email.value = document.forms[0].cn.value + '@' + org_name + '.aaa' + domain_name;
361                else
362                        document.forms[0].email.value = document.forms[0].cn.value;
363        }
364        else
365        {
366                document.forms[0].email.value = document.forms[0].cn.value;
367        }
368}
369
370function search_organization(key)
371{
372        var organizations = document.getElementById('ea_combo_org_info');
373        var RegExp_org = new RegExp("\\b"+key, "i");
374       
375        for(i = 0; i < organizations.length; i++)
376        {
377                if (RegExp_org.test(organizations[i].text))
378                {
379                        organizations[i].selected = true;
380                        return;
381                }
382        }
383}
Note: See TracBrowser for help on using the repository browser.