source: branches/2.2/expressoAdmin1_2/js/jscode/shared_accounts.js @ 3353

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