source: trunk/expressoAdmin1_2/js/jscode/shared_accounts.js @ 3354

Revision 3354, 16.9 KB checked in by valmir.sena, 14 years ago (diff)

Ticket #1374 - Problemas ao criar conta compartilhada, variavel connector nao definida

  • Property svn:mime-type set to text/plain
Line 
1countFiles = 1;
2
3function create_shared_accounts()
4{
5        select_owners = Element('ea_select_owners');
6        hidden_owners_acl = Element('owners_acls');
7        for(var i = 0;i < select_owners.options.length; i++){           
8                var user = select_owners.options[i].value;
9                select_owners.options[i].value = user;               
10        }
11        hidden_owners_acl.value =  admin_connector.serialize(sharemailbox.ownersAcl);
12        cExecuteForm ("$this.shared_accounts.create", document.forms['shared_accounts_form'], handler_create_shared_accounts);
13        hidden_owners_acl.value = "";
14}
15
16function handler_create_shared_accounts(data_return)
17{
18        handler_create_shared_accounts2(data_return);
19        return;
20}
21
22function handler_create_shared_accounts2(data_return)
23{
24        if (!data_return.status)
25        {
26                write_msg(data_return.msg, 'error');
27        }
28        else
29        {
30                close_lightbox();
31                write_msg(get_lang('Shared account successful created') + '.', 'normal');
32        }
33        return;
34}
35
36function empty_inbox(uid)
37{
38var action = get_lang('Cleanned user mailbox');
39var handler_write_log = function(){}
40
41var handler_empty_inbox = function(data)
42{
43    if (!data.status)
44        alert(data.msg);
45    else{
46        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
47        alert(get_lang('Emptied') +' '+ data.inbox_size + ' ' + get_lang('MB from user inbox'));
48        document.getElementById('mailquota_used').value = data.mailquota_used;
49    }
50}
51    cExecute ('$this.shared_accounts.empty_inbox&uid='+Element('anchor').value, handler_empty_inbox);
52}
53function set_onload()
54{
55        sinc_combos_org(Element('ea_combo_org').value);
56        get_available_users(Element('ea_combo_org').value);
57        get_associated_domain(Element('ea_combo_org').value);
58}
59
60function get_available_users(context)
61{
62        var     handler_get_users = function(data)
63        {
64                data = data.JSON( );
65                select_available_users = Element('ea_select_available_users');
66               
67                //Clean select
68                for(var i=0; i<select_available_users.options.length; i++)
69                {
70                        select_available_users.options[i] = null;
71                        i--;
72                }
73
74                if ((data) && (data.length > 0))
75                {
76                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
77                        select_available_users.innerHTML = '&nbsp;' + data;
78                        select_available_users.outerHTML = select_available_users.outerHTML;
79                       
80                        select_available_users.disabled = false;
81                        select_available_users_clone = Element('ea_select_available_users').cloneNode(true);
82                        //document.getElementById('ea_input_searchUser').value = '';
83                }
84        }
85        ExpressoLivre.go( {
86                "access" : 'expressoAdmin1_2.ldap_functions.get_available_users2&context='+context,
87                "handler" : handler_get_users
88        } );
89}
90
91function search_organization(key, element)
92{
93        var organizations = Element(element);
94        var RegExp_org = new RegExp("\\b"+key, "i");
95       
96        for(i = 0; i < organizations.length; i++)
97        {
98                if (RegExp_org.test(organizations[i].text))
99                {
100                        organizations[i].selected = true;
101                        return;
102                }
103        }
104}
105
106function sinc_combos_org(context)
107{
108        combo_org_available_users = Element('ea_combo_org_available_users');
109
110        for (i=0; i<combo_org_available_users.length; i++)
111        {
112                if (combo_org_available_users.options[i].value == context)
113                {
114                        combo_org_available_users.options[i].selected = true;
115                        get_available_users(context);
116                        break;
117                }
118        }
119}
120
121var finderTimeout = '';
122function optionFinderTimeout(obj)
123{
124        clearTimeout(finderTimeout);
125        var oWait = Element("ea_span_searching");
126        oWait.innerHTML = get_lang('searching') + '...';
127        finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
128}
129function optionFinder(id) {
130        var oWait = Element("ea_span_searching");
131        var oText = Element(id);
132               
133        //Limpa todo o select
134        var select_available_users_tmp = Element('ea_select_available_users')
135
136        for(var i = 0;i < select_available_users_tmp.options.length; i++)
137                select_available_users_tmp.options[i--] = null;
138
139        var RegExp_name = new RegExp("\\b"+oText.value, "i");
140       
141        //Inclui usuario comecando com a pesquisa
142        for(i = 0; i < select_available_users_clone.length; i++){
143                if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) )
144                {
145                        sel = select_available_users_tmp.options;
146                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
147
148                        if (select_available_users_clone[i].value == -1)
149                                option.disabled = true;
150
151                        sel[sel.length] = option;
152                }
153        }
154        oWait.innerHTML = '&nbsp;';
155}                       
156
157function add_user()
158{
159        select_available_users = Element('ea_select_available_users');
160        select_owners = Element('ea_select_owners');
161
162        var count_available_users = select_available_users.length;
163        var new_options = '';
164
165        for (i = 0 ; i < count_available_users ; i++)
166        {
167                if (select_available_users.options[i].selected)
168                {
169                        if(document.all)
170                        {
171                                if ( (select_owners.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
172                                {
173                                        new_options +=  "<option value="
174                                                                + select_available_users.options[i].value
175                                                                + ">"
176                                                                + select_available_users.options[i].text
177                                                                + "</options>";
178                                }
179                        }
180                        else
181                        {
182                                if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
183                                {
184                                        new_options +=  "<option value="
185                                                                + select_available_users.options[i].value
186                                                                + ">"
187                                                                + select_available_users.options[i].text
188                                                                + "</options>";
189                                }
190                        }
191                }
192        }
193
194        if (new_options != '')
195        {
196                select_owners.innerHTML = "&nbsp;" + new_options + select_owners.innerHTML;
197                select_owners.outerHTML = select_owners.outerHTML;             
198        Element('em_input_readAcl').checked = false;
199                Element('em_input_deleteAcl').checked = false;
200                Element('em_input_writeAcl').checked = false;
201                Element('em_input_sendAcl').checked = false;
202        Element('em_input_sendAcl').disabled = true;
203        select_owners = Element('ea_select_owners');
204        select_owners.options[0].selected = true;
205        }
206}
207
208function remove_user()
209{
210        select_owners = Element('ea_select_owners');
211        for(var i = 0;i < select_owners.options.length; i++)
212                if(select_owners.options[i].selected){
213                        var user = select_owners.options[i].value;
214                        delete sharemailbox.ownersAcl[user];
215                        select_owners.options[i--] = null;
216                }
217                //Nova chamada a "Element" eh Necessaria devido a um bug do ie com select
218           select_owners = Element('ea_select_owners');
219       if(select_owners.options.length > 0 ){
220            select_owners.options[0].selected = true;
221            var user = select_owners.options[0].value;
222            sharemailbox.getaclfromuser(user);
223       }
224}
225
226function get_shared_accounts_timeOut(input)
227{
228        var head_table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("remove")+'</td></tr></table>';
229       
230        if (input.length > 4)
231        {
232                clearTimeout(finderTimeout);
233                finderTimeout = setTimeout("get_shared_accounts('"+input+"')",500);
234        }
235        else
236        {
237                Element('shared_accounts_content').innerHTML = head_table;
238        }
239}
240
241function get_shared_accounts(input)
242{
243        var handler_get_shared_accounts = function(data)
244        {
245                data = data.JSON( );
246                if (data.status == 'true')
247                {
248                        var table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("remove")+'</td></tr>'+data.trs+'</table>';
249                        Element('shared_accounts_content').innerHTML = table;
250                }
251                else
252                        write_msg(data.msg, 'error');
253        }
254        ExpressoLivre.go( {
255                "access" : 'expressoAdmin1_2.ldap_functions.get_shared_accounts&input='+input,
256                "handler" : handler_get_shared_accounts
257        } );
258}
259
260function edit_shared_account(uid)
261{
262        var handle_edit_shared_account = function(data)
263        {
264                data = data.JSON( );
265                if (data.status == 'true')
266                {
267                        modal('shared_accounts_modal','save');
268                       
269                        var combo_org = Element('ea_combo_org');
270                        for (i=0; i<combo_org.length; i++)
271                        {
272                                if (combo_org.options[i].value == data.user_context)
273                                {
274                                        combo_org.options[i].selected = true;
275                                        break;
276                                }
277                        }
278                       
279                        // anchor
280                        Element('anchor').value = "uid=" + uid + ',' + data.user_context;                       
281                       
282                        if (data.accountStatus != 'active')
283                                Element('accountStatus').checked = false;
284                               
285                        if (data.phpgwAccountVisible == '-1')
286                                Element('phpgwAccountVisible').checked = true;
287                       
288                        Element('cn').value = data.cn;
289                        Element('mail').value = data.mail;
290            Element('mailquota').value = data.mailquota;
291            Element('mailquota_used').value = data.mailquota_used;
292            Element('quota_used_field').style.display = 'inline';
293            Element('desc').value = data.description;
294            //Necessario, pois o IE6 tem um bug que nao exibe as novas opcoes se o innerHTML estava vazio
295            Element('ea_select_owners').innerHTML = '&nbsp;' + data.owners_options;
296            Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
297
298            Element('display_empty_inbox').style.display = data.display_empty_inbox;
299            if( data.allow_edit_shared_account_acl == "0"){
300                Element('bt_add_user').disabled = true;
301                Element('bt_remove_user').disabled = true;
302                Element('em_input_readAcl').disabled = true;
303                Element('em_input_deleteAcl').disabled = true;
304                Element('em_input_writeAcl').disabled = true;
305                Element('em_input_sendAcl').disabled = true;
306                Element('em_input_saveAcl').disabled = true;
307            }
308
309                        sinc_combos_org(data.user_context);
310                        sharemailbox.ownersAcl = new Array();
311            if( data.owners && data.owners != "undefined" && data.owners_acl != "undefined" ){
312                                for (i=0; i<data.owners.length; i++){
313                                                sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i]; 
314                                }
315            }
316                }
317                else
318                        write_msg(data.msg, 'error');
319        }
320        ExpressoLivre.go( {
321                "access" : 'expressoAdmin1_2.shared_accounts.get_data&uid='+uid,
322                "handler" : handle_edit_shared_account
323        } );
324}
325
326function save_shared_accounts()
327{
328        if (is_ie){
329                var i = 0;
330                while (document.forms(i).name != "shared_accounts_form"){i++}
331                form = document.forms(i);
332        }
333        else   form = document.forms["shared_accounts_form"];
334       
335        hidden_owners_acl = Element('owners_acls');
336        select_owners = Element('ea_select_owners');
337        for(var i = 0;i < select_owners.options.length; i++){           
338                var user = select_owners.options[i].value;               
339                select_owners.options[i].value = user;
340                }
341        hidden_owners_acl.value =  admin_connector.serialize(sharemailbox.ownersAcl);
342        cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts);
343        hidden_owners_acl.value = "";
344}
345
346function handler_save_shared_accounts(data_return)
347{
348        handler_save_shared_accounts2(data_return);
349        return;
350}
351function handler_save_shared_accounts2(data_return)
352{
353        if (!data_return.status)
354        {
355                write_msg(data_return.msg, 'error');
356        }
357        else
358        {
359                get_shared_accounts(Element('ea_shared_account_search').value);
360                close_lightbox();
361                write_msg(get_lang('Shared account successful saved') + '.', 'normal');
362        }
363        return;
364}
365
366function delete_shared_accounts(uid)
367{
368        if (!confirm(get_lang('Are you sure that you want to delete this shared account') + "?"))
369                return;
370       
371        var handle_delete_shared_account = function(data_return)
372        {
373                if (!data_return.status)
374                {
375                        write_msg(data_return.msg, 'error');
376                }
377                else
378                {
379                        write_msg(get_lang('Shared account successful deleted') + '.', 'normal');
380                        get_shared_accounts(Element('ea_shared_account_search').value);
381                }
382                return;
383        }
384        cExecute ('$this.shared_accounts.delete&uid='+uid, handle_delete_shared_account);
385}       function cShareMailbox()
386        {
387                this.arrayWin = new Array();
388                this.el;
389                this.alert = false;
390                this.ownersAcl = new Array();
391        }
392
393        cShareMailbox.prototype.get_available_users = function(context)
394        {
395                var handler_get_available_users = function(data)
396                {
397                        data = data.JSON( );
398
399                        select_available_users = document.getElementById('em_select_available_users');
400               
401                        //Limpa o select
402                        for(var i=0; i<select_available_users.options.length; i++)
403                        {
404                                select_available_users.options[i] = null;
405                                i--;
406                        }
407
408                        if ((data) && (data.length > 0))
409                        {
410                                // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
411                                select_available_users.innerHTML = '#' + data;
412                                select_available_users.outerHTML = select_available_users.outerHTML;
413                       
414                                select_available_users.disabled = false;
415                                select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
416                                document.getElementById('em_input_searchUser').value = '';
417                        }
418                }
419                ExpressoLivre.go( {
420                        "access" : 'expressoAdmin1_2.ldap_functions.get_available_users2&context='+context,
421                        "handler" : handler_get_available_users
422                } );
423        }
424
425        cShareMailbox.prototype.getaclfromuser = function(user)
426        {
427       
428                Element('em_input_readAcl').checked = false;
429                Element('em_input_deleteAcl').checked = false;
430                Element('em_input_writeAcl').checked = false;
431                Element('em_input_sendAcl').checked = false;
432                Element('em_input_saveAcl').checked = false;
433                Element('em_input_saveAcl').disabled = true;
434               
435                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('lrs',0) >= 0)
436                {
437                        Element('em_input_sendAcl').disabled = false;
438                        Element('em_input_readAcl').checked = true;
439                }
440                else
441                        Element('em_input_sendAcl').disabled = true;
442                       
443                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('d',0) >= 0)
444                {
445                        Element('em_input_deleteAcl').checked = true;
446                }
447                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('wi',0) >= 0)
448                {
449                        Element('em_input_writeAcl').checked = true;
450                }               
451                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('a',0) >= 0)
452                {
453                        Element('em_input_sendAcl').disabled = false;
454                        Element('em_input_sendAcl').checked = true;
455                }
456                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('p',0) >= 0)
457                {
458                        Element('em_input_saveAcl').disabled = false;
459                        Element('em_input_saveAcl').checked = true;
460                }
461                if( this.ownersAcl[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
462                        Element('em_input_saveAcl').disabled = false;
463                } else Element('em_input_saveAcl').disabled = true;
464        }
465       
466        cShareMailbox.prototype.setaclfromuser = function()
467        {
468                var acl         = '';
469                var select      = Element('ea_select_owners');
470
471                if(select.selectedIndex == "-1"){
472                        alert("Selecione antes um usuario!");
473                        return false;
474                }
475                var user = select.options[select.selectedIndex].value;
476               
477                if (Element('em_input_readAcl').checked) {
478                        Element('em_input_sendAcl').disabled = false;
479                        acl = 'lrs';
480                }
481                else{
482                        Element('em_input_sendAcl').disabled = true;
483                        Element('em_input_sendAcl').checked = false;
484                }
485                               
486                if (Element('em_input_deleteAcl').checked)
487                        acl += 'd';
488
489                if (Element('em_input_writeAcl').checked)
490                        acl += 'wi';
491
492                if (Element('em_input_sendAcl').checked)
493                        acl += 'a';
494                               
495                if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
496                        Element('em_input_saveAcl').disabled = false;                           
497                } else {
498                        Element('em_input_saveAcl').disabled = true;
499                        Element('em_input_saveAcl').checked = false;
500                }
501                if (Element('em_input_saveAcl').checked)
502                        acl += 'p';
503                this.ownersAcl[user] = acl;             
504        }
505               
506        cShareMailbox.prototype.add_user = function()
507        {
508                var select_available_users = document.getElementById('em_select_available_users');
509                var select_users = document.getElementById('ea_select_owners');
510
511                var count_available_users = select_available_users.length;
512                var count_users = select_users.options.length;
513                var new_options = '';
514       
515                for (i = 0 ; i < count_available_users ; i++)
516                {
517                        if (select_available_users.options[i].selected)
518                        {
519                                if(document.all)
520                                {
521                                        if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
522                                        {
523                                                new_options +=  '<option value='
524                                                                        + select_available_users.options[i].value
525                                                                        + '>'
526                                                                        + select_available_users.options[i].text
527                                                                        + '</option>';
528                                        }
529                                }
530                                else
531                                {
532                                        if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
533                                        {
534                                                new_options +=  '<option value='
535                                                                        + select_available_users.options[i].value
536                                                                        + '>'
537                                                                        + select_available_users.options[i].text
538                                                                        + '</option>';
539                                        }
540                                }
541                        }
542                }
543
544                if (new_options != '')
545                {
546                        select_users.innerHTML = '#' + new_options + select_users.innerHTML;
547                        select_users.outerHTML = select_users.outerHTML;
548                       
549                }
550        }
551
552        cShareMailbox.prototype.remove_user = function()
553        {
554                select_users = document.getElementById('ea_select_owners');
555       
556                for(var i = 0;i < select_users.options.length; i++)
557                        if(select_users.options[i].selected)
558                                select_users.options[i--] = null;
559                               
560                Element('em_input_readAcl').checked = false;
561                Element('em_input_deleteAcl').checked = false;
562                Element('em_input_writeAcl').checked = false;
563                Element('em_input_sendAcl').checked = false;
564                Element('em_input_saveAcl').checked = false;
565        }
566       
567       
568/* Build the Object */
569        var sharemailbox;
570        sharemailbox = new cShareMailbox();
Note: See TracBrowser for help on using the repository browser.