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

Revision 1913, 16.1 KB checked in by valmir.sena, 14 years ago (diff)

Ticket #849 - Criacao de caixas compartilhadas pelo administrador, commit inicial com as principais mudancas

  • 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                        }
291
292                        sinc_combos_org(data.user_context);
293                        sharemailbox.ownersAcl = new Array();
294                        for (i=0; i<data.owners.length; i++){
295                                        sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i]; 
296                        }
297                }
298                else
299                        write_msg(data.msg, 'error');
300        }
301        cExecute ('$this.shared_accounts.get_data&uid='+uid, handle_edit_shared_account);
302}
303
304function save_shared_accounts()
305{
306        if (is_ie){
307                var i = 0;
308                while (document.forms(i).name != "shared_accounts_form"){i++}
309                form = document.forms(i);
310        }
311        else   form = document.forms["shared_accounts_form"];
312       
313        hidden_owners_acl = Element('owners_acls');
314        select_owners = Element('ea_select_owners');
315        for(var i = 0;i < select_owners.options.length; i++){           
316                var user = select_owners.options[i].value;               
317                select_owners.options[i].value = user;
318                }
319        hidden_owners_acl.value =  connector.serialize(sharemailbox.ownersAcl);
320        cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts);
321        hidden_owners_acl.value = "";
322}
323
324function handler_save_shared_accounts(data_return)
325{
326        handler_save_shared_accounts2(data_return);
327        return;
328}
329function handler_save_shared_accounts2(data_return)
330{
331        if (!data_return.status)
332        {
333                write_msg(data_return.msg, 'error');
334        }
335        else
336        {
337                get_shared_accounts(Element('ea_shared_account_search').value);
338                close_lightbox();
339                write_msg(get_lang('Shared account successful saved') + '.', 'normal');
340        }
341        return;
342}
343
344function delete_shared_accounts(uid)
345{
346        if (!confirm(get_lang('Are you sure that you want to delete this shared account') + "?"))
347                return;
348       
349        var handle_delete_shared_account = function(data_return)
350        {
351                if (!data_return.status)
352                {
353                        write_msg(data_return.msg, 'error');
354                }
355                else
356                {
357                        write_msg(get_lang('Shared account successful deleted') + '.', 'normal');
358                        get_shared_accounts(Element('ea_shared_account_search').value);
359                }
360                return;
361        }
362        cExecute ('$this.shared_accounts.delete&uid='+uid, handle_delete_shared_account);
363}       function cShareMailbox()
364        {
365                this.arrayWin = new Array();
366                this.el;
367                this.alert = false;
368                this.ownersAcl = new Array();
369        }
370
371        cShareMailbox.prototype.get_available_users = function(context)
372        {
373                var handler_get_available_users = function(data)
374                {
375                        select_available_users = document.getElementById('em_select_available_users');
376               
377                        //Limpa o select
378                        for(var i=0; i<select_available_users.options.length; i++)
379                        {
380                                select_available_users.options[i] = null;
381                                i--;
382                        }
383
384                        if ((data) && (data.length > 0))
385                        {
386                                // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
387                                select_available_users.innerHTML = '#' + data;
388                                select_available_users.outerHTML = select_available_users.outerHTML;
389                       
390                                select_available_users.disabled = false;
391                                select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
392                                document.getElementById('em_input_searchUser').value = '';
393                        }
394                }
395                cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users);
396        }
397
398        cShareMailbox.prototype.getaclfromuser = function(user)
399        {
400       
401                Element('em_input_readAcl').checked = false;
402                Element('em_input_deleteAcl').checked = false;
403                Element('em_input_writeAcl').checked = false;
404                Element('em_input_sendAcl').checked = false;
405                Element('em_input_saveAcl').checked = false;
406                Element('em_input_saveAcl').disabled = true;
407               
408                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('lrs',0) >= 0)
409                {
410                        Element('em_input_sendAcl').disabled = false;
411                        Element('em_input_readAcl').checked = true;
412                }
413                else
414                        Element('em_input_sendAcl').disabled = true;
415                       
416                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('d',0) >= 0)
417                {
418                        Element('em_input_deleteAcl').checked = true;
419                }
420                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('wi',0) >= 0)
421                {
422                        Element('em_input_writeAcl').checked = true;
423                }               
424                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('a',0) >= 0)
425                {
426                        Element('em_input_sendAcl').disabled = false;
427                        Element('em_input_sendAcl').checked = true;
428                }
429                if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('p',0) >= 0)
430                {
431                        Element('em_input_saveAcl').disabled = false;
432                        Element('em_input_saveAcl').checked = true;
433                }
434                if( this.ownersAcl[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
435                        Element('em_input_saveAcl').disabled = false;
436                } else Element('em_input_saveAcl').disabled = true;
437        }
438       
439        cShareMailbox.prototype.setaclfromuser = function()
440        {
441                var acl         = '';
442                var select      = Element('ea_select_owners');
443
444                if(select.selectedIndex == "-1"){
445                        alert("Selecione antes um usuario!");
446                        return false;
447                }
448                var user = select.options[select.selectedIndex].value;
449               
450                if (Element('em_input_readAcl').checked) {
451                        Element('em_input_sendAcl').disabled = false;
452                        acl = 'lrs';
453                }
454                else{
455                        Element('em_input_sendAcl').disabled = true;
456                        Element('em_input_sendAcl').checked = false;
457                }
458                               
459                if (Element('em_input_deleteAcl').checked)
460                        acl += 'd';
461
462                if (Element('em_input_writeAcl').checked)
463                        acl += 'wi';
464
465                if (Element('em_input_sendAcl').checked)
466                        acl += 'a';
467                               
468                if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
469                        Element('em_input_saveAcl').disabled = false;                           
470                } else {
471                        Element('em_input_saveAcl').disabled = true;
472                        Element('em_input_saveAcl').checked = false;
473                }
474                if (Element('em_input_saveAcl').checked)
475                        acl += 'p';
476                this.ownersAcl[user] = acl;             
477        }
478               
479        cShareMailbox.prototype.add_user = function()
480        {
481                var select_available_users = document.getElementById('em_select_available_users');
482                var select_users = document.getElementById('ea_select_owners');
483
484                var count_available_users = select_available_users.length;
485                var count_users = select_users.options.length;
486                var new_options = '';
487       
488                for (i = 0 ; i < count_available_users ; i++)
489                {
490                        if (select_available_users.options[i].selected)
491                        {
492                                if(document.all)
493                                {
494                                        if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
495                                        {
496                                                new_options +=  '<option value='
497                                                                        + select_available_users.options[i].value
498                                                                        + '>'
499                                                                        + select_available_users.options[i].text
500                                                                        + '</option>';
501                                        }
502                                }
503                                else
504                                {
505                                        if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
506                                        {
507                                                new_options +=  '<option value='
508                                                                        + select_available_users.options[i].value
509                                                                        + '>'
510                                                                        + select_available_users.options[i].text
511                                                                        + '</option>';
512                                        }
513                                }
514                        }
515                }
516
517                if (new_options != '')
518                {
519                        select_users.innerHTML = '#' + new_options + select_users.innerHTML;
520                        select_users.outerHTML = select_users.outerHTML;
521                       
522                }
523        }
524
525        cShareMailbox.prototype.remove_user = function()
526        {
527                select_users = document.getElementById('ea_select_owners');
528       
529                for(var i = 0;i < select_users.options.length; i++)
530                        if(select_users.options[i].selected)
531                                select_users.options[i--] = null;
532                               
533                Element('em_input_readAcl').checked = false;
534                Element('em_input_deleteAcl').checked = false;
535                Element('em_input_writeAcl').checked = false;
536                Element('em_input_sendAcl').checked = false;
537        }
538       
539       
540/* Build the Object */
541        var sharemailbox;
542        sharemailbox = new cShareMailbox();
Note: See TracBrowser for help on using the repository browser.