source: branches/2.2/expressoAdmin1_2/js/jscode/groups.js @ 640

Revision 640, 11.5 KB checked in by niltonneto, 15 years ago (diff)

Resolve #416

  • 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(get_lang('NAME field is empty') + '.');
10                return;
11        }
12               
13        if (document.forms[0].description.value == ''){
14                alert(get_lang('DESCRIPTION field is empty') + '.');
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                                get_lang('NAME field is incomplete') + '.\n' +
24                                get_lang('the name field must be formed like') + ':\n' +
25                                get_lang('group') + '-' + get_lang('organization') + '-' + get_lang('group name') + '.\n' +
26                                get_lang('eg') + ': ' + '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(get_lang('NAME field contains characters not allowed') + '.');
36                document.forms[0].cn.focus();
37                return;
38        }
39
40        if(!reDesc.test(document.forms[0].description.value)){
41                alert(get_lang('DESCRIPTION field contains characters not allowed') + '.');
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(get_lang('EMAIL field is empty') + '.');
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(get_lang('Group successful created') + '.');
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(get_lang('Group successful saved') + '.');
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 = '&nbsp;' + 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(get_lang('It is not allow select all users from the root organization') + '.');
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 = '&nbsp;';
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 = '&nbsp;' + new_options + select_usersInGroup.innerHTML;
211                select_usersInGroup.outerHTML = select_usersInGroup.outerHTML;
212                document.getElementById('ea_input_searchUser').value = "";
213        }
214}
215
216function remove_user2group()
217{
218        select_usersInGroup = document.getElementById('ea_select_usersInGroup');
219       
220        for(var i = 0;i < select_usersInGroup.options.length; i++)
221                if(select_usersInGroup.options[i].selected)
222                        select_usersInGroup.options[i--] = null;
223}
224
225// Variaveis Locais
226if (document.getElementById('ea_select_available_users'))
227{
228        var select_available_users  = document.getElementById('ea_select_available_users');
229        var select_available_users_clone = select_available_users.cloneNode(true);
230}
231else
232{
233        var select_available_users  = '';
234        var select_available_users_clone = '';
235}
236var finderTimeout = '';
237
238// Funcoes                                                                                     
239function optionFinderTimeout(obj)
240{
241        clearTimeout(finderTimeout);   
242        var oWait = document.getElementById("ea_span_searching");
243        oWait.innerHTML = get_lang('Searching') + '...';
244        var finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
245}
246function optionFinder(id) {
247        var oWait = document.getElementById("ea_span_searching");
248        var oText = document.getElementById(id);
249                       
250        //Limpa todo o select
251        var select_available_users_tmp = document.getElementById('ea_select_available_users')
252        for(var i = 0;i < select_available_users_tmp.options.length; i++)
253                select_available_users_tmp.options[i--] = null;
254
255        var RegExp_name = new RegExp("\\b"+oText.value, "i");
256
257        //Inclui usuário começando com a pesquisa
258        for(i = 0; i < select_available_users_clone.length; i++){
259                if (RegExp_name.test(select_available_users_clone[i].text))
260                {
261                        sel = select_available_users_tmp.options;
262                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);                               
263                        sel[sel.length] = option;
264                }
265        }
266       
267        oWait.innerHTML = '&nbsp;';
268}                       
269
270function delete_group(cn, gidnumber)
271{
272        if (confirm(get_lang('Do you really want delete the group') + ' ' + cn + " ??"))
273        {
274                var handler_delete_group = function(data)
275                {
276                        if (!data.status)
277                                alert(data.msg);
278                        else
279                                alert(get_lang('Group success deleted') + '.');
280                       
281                        location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
282                        return;
283                }
284                cExecute ('$this.group.delete&gidnumber='+gidnumber+'&cn='+cn, handler_delete_group);
285        }
286}
287
288function use_samba_attrs(value)
289{
290        document.forms[0].sambasid.disabled = !value;
291}
292
293function get_available_sambadomains(context, type)
294{
295        if ((type == 'create_group') && (document.getElementById('ea_div_display_samba_options').style.display != 'none'))
296        {
297                var handler_get_available_sambadomains = function(data)
298                {
299                        document.forms[0].use_attrs_samba.checked = data.status;
300                        use_samba_attrs(data.status);
301                       
302                        if (data.status)
303                        {
304                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
305                                for (i=0; i<data.sambaDomains.length; i++)
306                                {
307                                        for (j=0; j<combo_sambadomains.length; j++)
308                                        {
309                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
310                                                {
311                                                        combo_sambadomains.options[j].selected = true;
312                                                        break;
313                                                }
314                                        }
315                                }
316                               
317                        }
318                }
319                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
320        }
321}
322
323function groupEmailSuggestion(concatenateDomain, type)
324{
325        if (document.forms[0].email.disabled)
326                return;
327       
328        if (type != 'create_group')
329                return;
330       
331        if (concatenateDomain == 'true')
332        {
333                var ldap_context = document.forms[0].ufn_ldap_context.value.toLowerCase();
334                var organization_context = document.forms[0].context.value.toLowerCase();
335                var select_orgs = document.getElementById('ea_combo_org_info');
336               
337                for(var i=0; i<select_orgs.options.length; i++)
338                {
339                        if(select_orgs.options[i].selected == true)
340                        {
341                                var x;
342                                var context = '';
343                                select_context = select_orgs.options[i].value.toLowerCase();
344                                organization_name = organization_context.split(",");
345                       
346                                for (x in organization_name)
347                                {
348                                        tmp = organization_name[x].split("=");
349                                        context += tmp[1] + '.';
350                                }
351                        }
352                }
353                domain_name = document.forms[0].defaultDomain.value;
354       
355                x=context.indexOf(ldap_context,0);
356                org_name_par = context.substring(0,(x-1));
357                org_name = org_name_par.split('.');
358                org_name = org_name[org_name.length-1];
359               
360                if (org_name != '')
361                        document.forms[0].email.value = document.forms[0].cn.value + '@' + org_name + '.aaa' + domain_name;
362                else
363                        document.forms[0].email.value = document.forms[0].cn.value;
364        }
365        else
366        {
367                document.forms[0].email.value = document.forms[0].cn.value;
368        }
369}
370
371function search_organization(key, element)
372{
373        var organizations = document.getElementById(element);
374        var RegExp_org = new RegExp("\\b"+key, "i");
375       
376        for(i = 0; i < organizations.length; i++)
377        {
378                if (RegExp_org.test(organizations[i].text))
379                {
380                        organizations[i].selected = true;
381                        return;
382                }
383        }
384}
385
386function popup_group_info()
387{
388        var select_usersInGroup = document.getElementById('ea_select_usersInGroup');
389        var count_usersInGroup = select_usersInGroup.options.length;
390        var html = '';
391       
392        for (i = 0 ; i < count_usersInGroup ; i++)
393        {
394                if(parseInt(select_usersInGroup.options[i].value) > 0)
395                        html += select_usersInGroup.options[i].text + '<br>';
396        }
397
398        var window_group = window.open('','','width=300,height=400,resizable=yes,scrollbars=yes,left=100,top=100');
399        window_group.document.body.innerHTML = '<html><head></head><body><H1>'+ document.forms[0].cn.value + '</H1>'+html+'</body></html>';
400        window_group.document.close();
401        return true;
402}
Note: See TracBrowser for help on using the repository browser.