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

Revision 1915, 16.2 KB checked in by valmir.sena, 14 years ago (diff)

Ticket #849 - Criacao de caixas compartilhadas pelo administrador, commit final

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