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

Revision 7326, 9.8 KB checked in by acoutinho, 12 years ago (diff)

Ticket #3134 - Inconsistencias na criacao de grupos, erros sendo apresentado no javaScript

  • 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
81function Element( id )
82{
83    return document.getElementById( id );
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('Group successful created') + '.');
98                location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
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('Group successful saved') + '.');
115                location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
116        }
117        return;
118}
119
120function sinc_combos_org(context)
121{
122        combo_org_groups = document.getElementById('ea_combo_org_groups');
123
124        for (i=0; i<combo_org_groups.length; i++)
125        {
126                if (combo_org_groups.options[i].value == context)
127                {
128                        combo_org_groups.options[i].selected = true;
129                        get_available_users();
130                        break;
131                }
132        }
133}
134
135function get_available_users()
136{
137/*      var sentence = Element('ea_input_searchUser').value;
138               
139        var url = '$this.ldap_functions.get_available_users_and_shared_acounts&context='
140                    + Element('ea_combo_org_info').value
141                    + '&sentence=' + sentence;
142
143        var fillHandler = function( fill ){
144                       
145        Element('ea_select_available_users').innerHTML = fill;
146
147        return( fill !== "" );
148        }
149       
150        userFinder( sentence, fillHandler, url, 'ea_span_searching' );*/
151
152        optionFind( 'ea_input_searchUser', 'ea_select_available_users',
153                    '$this.ldap_functions.get_available_users_and_shared_acounts',
154                    'ea_combo_org_groups', 'ea_span_searching' );
155}
156
157function add_user2group()
158{
159        var select_available_users = document.getElementById('ea_select_available_users');
160        var select_usersInGroup = document.getElementById('ea_select_usersInGroup');
161
162        var count_available_users = select_available_users.length;
163        var count_usersInGroup = select_usersInGroup.options.length;
164        var new_options = '';
165       
166        for (i = 0 ; i < count_available_users ; i++)
167        {
168                if (select_available_users.options[i].selected)
169                {
170                        if(document.all)
171                        {
172                                if ( (select_usersInGroup.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
173                                {
174                                        new_options +=  '<option value='
175                                                                + select_available_users.options[i].value
176                                                                + '>'
177                                                                + select_available_users.options[i].text
178                                                                + '</option>';
179                                }
180                        }
181                        else
182                        {
183                                if ( (select_usersInGroup.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
184                                {
185                                        new_options +=  '<option value='
186                                                                + select_available_users.options[i].value
187                                                                + '>'
188                                                                + select_available_users.options[i].text
189                                                                + '</option>';
190                                }
191                        }
192                }
193        }
194
195        if (new_options != '')
196        {
197                select_usersInGroup.innerHTML = '&nbsp;' + new_options + select_usersInGroup.innerHTML;
198                select_usersInGroup.outerHTML = select_usersInGroup.outerHTML;
199                document.getElementById('ea_input_searchUser').value = "";
200        }
201}
202
203function remove_user2group()
204{
205        select_usersInGroup = document.getElementById('ea_select_usersInGroup');
206       
207        for(var i = 0;i < select_usersInGroup.options.length; i++)
208                if(select_usersInGroup.options[i].selected)
209                        select_usersInGroup.options[i--] = null;
210}
211
212// Variaveis Locais
213if (document.getElementById('ea_select_available_users'))
214{
215        var select_available_users  = document.getElementById('ea_select_available_users');
216        var select_available_users_clone = select_available_users.cloneNode(true);
217}
218else
219{
220        var select_available_users  = '';
221        var select_available_users_clone = '';
222}
223var finderTimeout = '';
224
225// Funcoes                                                                                     
226function optionFinderTimeout(obj, event)
227{
228
229        if( event.keyCode == 13 )
230                {
231            limit = 0;
232            optionFinder(obj.id);
233                }
234}
235function optionFinder(id)
236{
237        get_available_users();
238}                       
239
240function delete_group(cn, gidnumber)
241{
242        if (confirm(get_lang('Do you really want delete the group') + ' ' + cn + " ??"))
243        {
244                var handler_delete_group = function(data)
245                {
246                        if (!data.status)
247                                alert(data.msg);
248                        else
249                                alert(get_lang('Group success deleted') + '.');
250                       
251                        location.href="./index.php?menuaction=expressoAdmin1_2.uigroups.list_groups";
252                        return;
253                }
254                cExecute ('$this.group.delete&gidnumber='+gidnumber+'&cn='+cn, handler_delete_group);
255        }
256}
257
258function use_samba_attrs(value)
259{
260        document.forms[0].sambasid.disabled = !value;
261}
262
263function get_available_sambadomains(context, type)
264{
265        if ((type == 'create_group') && (document.getElementById('ea_div_display_samba_options').style.display != 'none'))
266        {
267                var handler_get_available_sambadomains = function(data)
268                {
269                        document.forms[0].use_attrs_samba.checked = data.status;
270                        use_samba_attrs(data.status);
271                       
272                        if (data.status)
273                        {
274                                combo_sambadomains = document.getElementById('ea_combo_sambadomains');
275                                for (i=0; i<data.sambaDomains.length; i++)
276                                {
277                                        for (j=0; j<combo_sambadomains.length; j++)
278                                        {
279                                                if (combo_sambadomains.options[j].text == data.sambaDomains[i])
280                                                {
281                                                        combo_sambadomains.options[j].selected = true;
282                                                        break;
283                                                }
284                                        }
285                                }
286                               
287                        }
288                }
289                cExecute ('$this.ldap_functions.exist_sambadomains_in_context&context='+context, handler_get_available_sambadomains);
290        }
291}
292
293function groupEmailSuggestion(concatenateDomain, type)
294{
295        if (document.forms[0].email.disabled)
296                return;
297       
298        if (type != 'create_group')
299                return;
300       
301        if (concatenateDomain == 'true')
302        {
303                var ldap_context = document.forms[0].ufn_ldap_context.value.toLowerCase();
304                var organization_context = document.forms[0].context.value.toLowerCase();
305                var select_orgs = document.getElementById('ea_combo_org_info');
306               
307                for(var i=0; i<select_orgs.options.length; i++)
308                {
309                        if(select_orgs.options[i].selected == true)
310                        {
311                                var x;
312                                var context = '';
313                                select_context = select_orgs.options[i].value.toLowerCase();
314                                organization_name = organization_context.split(",");
315                       
316                                for (x in organization_name)
317                                {
318                                        tmp = organization_name[x].split("=");
319                                        context += tmp[1] + '.';
320                                }
321                        }
322                }
323                domain_name = document.forms[0].defaultDomain.value;
324       
325                x=context.indexOf(ldap_context,0);
326                org_name_par = context.substring(0,(x-1));
327                org_name = org_name_par.split('.');
328                org_name = org_name[org_name.length-1];
329               
330                if (org_name != '')
331                        document.forms[0].email.value = document.forms[0].cn.value + '@' + org_name + '.aaa' + domain_name;
332                else
333                        document.forms[0].email.value = document.forms[0].cn.value;
334        }
335        else
336        {
337                document.forms[0].email.value = document.forms[0].cn.value;
338        }
339}
340
341function search_organization(key, element)
342{
343        var organizations = document.getElementById(element);
344        var RegExp_org = new RegExp("\\b"+key, "i");
345       
346        for(i = 0; i < organizations.length; i++)
347        {
348                if (RegExp_org.test(organizations[i].text))
349                {
350                        organizations[i].selected = true;
351                        return;
352                }
353        }
354}
355
356function popup_group_info()
357{
358        var select_usersInGroup = document.getElementById('ea_select_usersInGroup');
359        var count_usersInGroup = select_usersInGroup.options.length;
360        var html = '';
361       
362        for (i = 0 ; i < count_usersInGroup ; i++)
363        {
364                if(parseInt(select_usersInGroup.options[i].value) > 0)
365                        html += select_usersInGroup.options[i].text + '<br>';
366        }
367
368        var window_group = window.open('','','width=300,height=400,resizable=yes,scrollbars=yes,left=100,top=100');
369        window_group.document.body.innerHTML = '<html><head></head><body><H1>'+ document.forms[0].cn.value + '</H1>'+html+'</body></html>';
370        window_group.document.close();
371        return true;
372}
Note: See TracBrowser for help on using the repository browser.