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

Revision 3356, 17.1 KB checked in by valmir.sena, 13 years ago (diff)

Ticket #1375 - Criar ACL para permirtir gerenciar pastas na conta compartilhada

  • 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_saveAcl').checked = false;
199                Element('em_input_folderAcl').checked = false;
200        Element('em_input_sendAcl').disabled = true;
201        select_owners = Element('ea_select_owners');
202        select_owners.options[0].selected = true;
203        }
204}
205
206function remove_user()
207{
208        select_owners = Element('ea_select_owners');
209        for(var i = 0;i < select_owners.options.length; i++)
210                if(select_owners.options[i].selected){
211                        var user = select_owners.options[i].value;
212                        delete sharemailbox.ownersAcl[user];
213                        select_owners.options[i--] = null;
214                }
215                //Nova chamada a "Element" é Necessária devido a um bug do ie com select
216           select_owners = Element('ea_select_owners');
217       if(select_owners.options.length > 0 ){
218            select_owners.options[0].selected = true;
219            var user = select_owners.options[0].value;
220            sharemailbox.getaclfromuser(user);
221       }
222}
223
224function get_shared_accounts_timeOut(input)
225{
226        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>';
227       
228        if (input.length > 4)
229        {
230                clearTimeout(finderTimeout);
231                finderTimeout = setTimeout("get_shared_accounts('"+input+"')",500);
232        }
233        else
234        {
235                Element('shared_accounts_content').innerHTML = head_table;
236        }
237}
238
239function get_shared_accounts(input)
240{
241        var handler_get_shared_accounts = function(data)
242        {
243                if (data.status == 'true')
244                {
245                        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>';
246                        Element('shared_accounts_content').innerHTML = table;
247                }
248                else
249                        write_msg(data.msg, 'error');
250        }
251        cExecute ('$this.ldap_functions.get_shared_accounts&input='+input, handler_get_shared_accounts);
252}
253
254function edit_shared_account(uid)
255{
256        var handle_edit_shared_account = function(data)
257        {
258                if (data.status == 'true')
259                {
260                        modal('shared_accounts_modal','save');
261                       
262                        var combo_org = Element('ea_combo_org');
263                        for (i=0; i<combo_org.length; i++)
264                        {
265                                if (combo_org.options[i].value == data.user_context)
266                                {
267                                        combo_org.options[i].selected = true;
268                                        break;
269                                }
270                        }
271                       
272                        // anchor
273                        Element('anchor').value = "uid=" + uid + ',' + data.user_context;                       
274                       
275                        if (data.accountStatus != 'active')
276                                Element('accountStatus').checked = false;
277                               
278                        if (data.phpgwAccountVisible == '-1')
279                                Element('phpgwAccountVisible').checked = true;
280                       
281                        Element('cn').value = data.cn;
282                        Element('mail').value = data.mail;
283            Element('mailquota').value = data.mailquota;
284            Element('mailquota_used').value = data.mailquota_used;
285            Element('quota_used_field').style.display = 'inline';
286            Element('desc').value = data.description;
287            //Necessario, pois o IE6 tem um bug que não exibe as novas opções se o innerHTML estava vazio
288            Element('ea_select_owners').innerHTML = '&nbsp;' + data.owners_options;
289            Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
290
291            Element('display_empty_inbox').style.display = data.display_empty_inbox;
292            if( data.allow_edit_shared_account_acl == "0"){
293                Element('bt_add_user').disabled = true;
294                Element('bt_remove_user').disabled = true;
295                Element('em_input_readAcl').disabled = true;
296                Element('em_input_deleteAcl').disabled = true;
297                Element('em_input_writeAcl').disabled = true;
298                Element('em_input_sendAcl').disabled = true;
299                Element('em_input_saveAcl').disabled = true;
300                Element('em_input_folderAcl').disabled = true;
301            }
302
303                        sinc_combos_org(data.user_context);
304                        sharemailbox.ownersAcl = new Array();
305            if( data.owners != "undefined" && data.owners_acl != "undefined" ){
306                                for (i=0; i<data.owners.length; i++){
307                                                sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i]; 
308                                }
309            }
310                }
311                else
312                        write_msg(data.msg, 'error');
313        }
314        cExecute ('$this.shared_accounts.get_data&uid='+uid, handle_edit_shared_account);
315}
316
317function save_shared_accounts()
318{
319        if (is_ie){
320                var i = 0;
321                while (document.forms(i).name != "shared_accounts_form"){i++}
322                form = document.forms(i);
323        }
324        else   form = document.forms["shared_accounts_form"];
325       
326        hidden_owners_acl = Element('owners_acls');
327        select_owners = Element('ea_select_owners');
328        for(var i = 0;i < select_owners.options.length; i++){           
329                var user = select_owners.options[i].value;               
330                select_owners.options[i].value = user;
331                }
332        hidden_owners_acl.value =  admin_connector.serialize(sharemailbox.ownersAcl);
333        cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts);
334        hidden_owners_acl.value = "";
335}
336
337function handler_save_shared_accounts(data_return)
338{
339        handler_save_shared_accounts2(data_return);
340        return;
341}
342function handler_save_shared_accounts2(data_return)
343{
344        if (!data_return.status)
345        {
346                write_msg(data_return.msg, 'error');
347        }
348        else
349        {
350                get_shared_accounts(Element('ea_shared_account_search').value);
351                close_lightbox();
352                write_msg(get_lang('Shared account successful saved') + '.', 'normal');
353        }
354        return;
355}
356
357function delete_shared_accounts(uid)
358{
359        if (!confirm(get_lang('Are you sure that you want to delete this shared account') + "?"))
360                return;
361       
362        var handle_delete_shared_account = function(data_return)
363        {
364                if (!data_return.status)
365                {
366                        write_msg(data_return.msg, 'error');
367                }
368                else
369                {
370                        write_msg(get_lang('Shared account successful deleted') + '.', 'normal');
371                        get_shared_accounts(Element('ea_shared_account_search').value);
372                }
373                return;
374        }
375        cExecute ('$this.shared_accounts.delete&uid='+uid, handle_delete_shared_account);
376}       function cShareMailbox()
377        {
378                this.arrayWin = new Array();
379                this.el;
380                this.alert = false;
381                this.ownersAcl = new Array();
382        }
383
384        cShareMailbox.prototype.get_available_users = function(context)
385        {
386                var handler_get_available_users = function(data)
387                {
388                        select_available_users = document.getElementById('em_select_available_users');
389               
390                        //Limpa o select
391                        for(var i=0; i<select_available_users.options.length; i++)
392                        {
393                                select_available_users.options[i] = null;
394                                i--;
395                        }
396
397                        if ((data) && (data.length > 0))
398                        {
399                                // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
400                                select_available_users.innerHTML = '#' + data;
401                                select_available_users.outerHTML = select_available_users.outerHTML;
402                       
403                                select_available_users.disabled = false;
404                                select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
405                                document.getElementById('em_input_searchUser').value = '';
406                        }
407                }
408                cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users);
409        }
410
411        cShareMailbox.prototype.getaclfromuser = function(user)
412        {
413       
414                Element('em_input_readAcl').checked = false;
415                Element('em_input_deleteAcl').checked = false;
416                Element('em_input_writeAcl').checked = false;
417                Element('em_input_sendAcl').checked = false;
418                Element('em_input_saveAcl').checked = false;
419                Element('em_input_saveAcl').disabled = true;
420                Element('em_input_folderAcl').checked = false;
421               
422                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('lrs',0) >= 0)
423                {
424                        Element('em_input_sendAcl').disabled = false;
425                        Element('em_input_readAcl').checked = true;
426                }
427                else
428                        Element('em_input_sendAcl').disabled = true;
429                       
430                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('d',0) >= 0)
431                {
432                        Element('em_input_deleteAcl').checked = true;
433                }
434                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('wi',0) >= 0)
435                {
436                        Element('em_input_writeAcl').checked = true;
437                }               
438                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('a',0) >= 0)
439                {
440                        Element('em_input_sendAcl').disabled = false;
441                        Element('em_input_sendAcl').checked = true;
442                }
443                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('p',0) >= 0)
444                {
445                        Element('em_input_saveAcl').disabled = false;
446                        Element('em_input_saveAcl').checked = true;
447                }
448                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('c',0) >= 0)
449                {
450                        Element('em_input_folderAcl').checked = true;
451                }
452                if( this.ownersAcl[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
453                        Element('em_input_saveAcl').disabled = false;
454                } else Element('em_input_saveAcl').disabled = true;
455        }
456       
457        cShareMailbox.prototype.setaclfromuser = function()
458        {
459                var acl         = '';
460                var select      = Element('ea_select_owners');
461
462                if(select.selectedIndex == "-1"){
463                        alert("Selecione antes um usuario!");
464                        return false;
465                }
466                var user = select.options[select.selectedIndex].value;
467               
468                if (Element('em_input_readAcl').checked) {
469                        Element('em_input_sendAcl').disabled = false;
470                        acl = 'lrs';
471                }
472                else{
473                        Element('em_input_sendAcl').disabled = true;
474                        Element('em_input_sendAcl').checked = false;
475                }
476                               
477                if (Element('em_input_deleteAcl').checked)
478                        acl += 'd';
479
480                if (Element('em_input_writeAcl').checked)
481                        acl += 'wi';
482
483                if (Element('em_input_sendAcl').checked)
484                        acl += 'a';
485               
486                if (Element('em_input_folderAcl').checked)
487                        acl += 'c';
488                               
489                if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
490                        Element('em_input_saveAcl').disabled = false;                           
491                } else {
492                        Element('em_input_saveAcl').disabled = true;
493                        Element('em_input_saveAcl').checked = false;
494                }
495                if (Element('em_input_saveAcl').checked)
496                        acl += 'p';
497                this.ownersAcl[user] = acl;             
498        }
499               
500        cShareMailbox.prototype.add_user = function()
501        {
502                var select_available_users = document.getElementById('em_select_available_users');
503                var select_users = document.getElementById('ea_select_owners');
504
505                var count_available_users = select_available_users.length;
506                var count_users = select_users.options.length;
507                var new_options = '';
508       
509                for (i = 0 ; i < count_available_users ; i++)
510                {
511                        if (select_available_users.options[i].selected)
512                        {
513                                if(document.all)
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                                else
525                                {
526                                        if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
527                                        {
528                                                new_options +=  '<option value='
529                                                                        + select_available_users.options[i].value
530                                                                        + '>'
531                                                                        + select_available_users.options[i].text
532                                                                        + '</option>';
533                                        }
534                                }
535                        }
536                }
537
538                if (new_options != '')
539                {
540                        select_users.innerHTML = '#' + new_options + select_users.innerHTML;
541                        select_users.outerHTML = select_users.outerHTML;
542                       
543                }
544        }
545
546        cShareMailbox.prototype.remove_user = function()
547        {
548                select_users = document.getElementById('ea_select_owners');
549       
550                for(var i = 0;i < select_users.options.length; i++)
551                        if(select_users.options[i].selected)
552                                select_users.options[i--] = null;
553                               
554                Element('em_input_readAcl').checked = false;           
555                Element('em_input_deleteAcl').checked = false;
556                Element('em_input_writeAcl').checked = false;
557                Element('em_input_sendAcl').checked = false;
558                Element('em_input_saveAcl').checked = false;
559                Element('em_input_folderAcl').checked = false;
560        }
561       
562       
563/* Build the Object */
564        var sharemailbox;
565        sharemailbox = new cShareMailbox();
Note: See TracBrowser for help on using the repository browser.