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

Revision 1983, 16.6 KB checked in by valmir.sena, 14 years ago (diff)

Ticket #882 - Falha ao tentar criar uma conta compartilhada no IE

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