source: trunk/expressoAdmin1_2/js/jscode/institutional_accounts.js @ 2707

Revision 2707, 8.9 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1058 - Corrigindo problemas no expressoAdmin1_2.

Line 
1countFiles = 1;
2
3function create_institutional_accounts()
4{
5        select_owners = Element('ea_select_owners');
6        for(var i = 0;i < select_owners.options.length; i++)
7                select_owners.options[i].selected = true;       
8        cExecuteForm ("$this.ldap_functions.create_institutional_accounts", document.forms['institutional_accounts_form'], handler_create_institutional_accounts);
9}
10
11function handler_create_institutional_accounts(data_return)
12{
13        handler_create_institutional_accounts2(data_return);
14        return;
15}
16
17function handler_create_institutional_accounts2(data_return)
18{
19        if (!data_return.status)
20        {
21                write_msg(data_return.msg, 'error');
22        }
23        else
24        {
25                close_lightbox();
26                write_msg(get_lang('Institutional account successful created') + '.', 'normal');
27        }
28        return;
29}
30
31function set_onload()
32{
33        sinc_combos_org(Element('ea_combo_org').value);
34        get_available_users(Element('ea_combo_org').value);
35        get_associated_domain(Element('ea_combo_org').value);
36}
37
38function get_available_users(context)
39{
40        var     handler_get_users = function(data)
41        {
42                select_available_users = Element('ea_select_available_users');
43               
44                //Clean select
45                for(var i=0; i<select_available_users.options.length; i++)
46                {
47                        select_available_users.options[i] = null;
48                        i--;
49                }
50
51                if ((data) && (data.length > 0))
52                {
53                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
54                        select_available_users.innerHTML = '&nbsp;' + data;
55                        select_available_users.outerHTML = select_available_users.outerHTML;
56                       
57                        select_available_users.disabled = false;
58                        select_available_users_clone = Element('ea_select_available_users').cloneNode(true);
59                        //document.getElementById('ea_input_searchUser').value = '';
60                }
61        }
62        ExpressoLivre.go( {
63                "access" : 'expressoAdmin1_2.ldap_functions.get_available_users&context=' + escape(context),
64                "handler" : handler_get_users
65        } );
66}
67
68function search_organization(key, element)
69{
70        var organizations = Element(element);
71        var RegExp_org = new RegExp("\\b"+key, "i");
72       
73        for(i = 0; i < organizations.length; i++)
74        {
75                if (RegExp_org.test(organizations[i].text))
76                {
77                        organizations[i].selected = true;
78                        return;
79                }
80        }
81}
82
83function sinc_combos_org(context)
84{
85        combo_org_available_users = Element('ea_combo_org_available_users');
86
87        for (i=0; i<combo_org_available_users.length; i++)
88        {
89                if (combo_org_available_users.options[i].value == context)
90                {
91                        combo_org_available_users.options[i].selected = true;
92                        get_available_users(context);
93                        break;
94                }
95        }
96}
97
98var finderTimeout = '';
99function optionFinderTimeout(obj)
100{
101        clearTimeout(finderTimeout);
102        var oWait = Element("ea_span_searching");
103        oWait.innerHTML = get_lang('searching') + '...';
104        finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
105}
106function optionFinder(id) {
107        var oWait = Element("ea_span_searching");
108        var oText = Element(id);
109               
110        //Limpa todo o select
111        var select_available_users_tmp = Element('ea_select_available_users')
112
113        for(var i = 0;i < select_available_users_tmp.options.length; i++)
114                select_available_users_tmp.options[i--] = null;
115
116        var RegExp_name = new RegExp("\\b"+oText.value, "i");
117       
118        //Inclui usuario comecando com a pesquisa
119        //for(i = 0; i < select_available_users_clone.length; i++){
120        //      if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) )
121        //      {
122        //              sel = select_available_users_tmp.options;
123        //              option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
124//
125//                      if (select_available_users_clone[i].value == -1)
126//                              option.disabled = true;
127//
128//                      sel[sel.length] = option;
129//              }
130//      }
131        oWait.innerHTML = '&nbsp;';
132}                       
133
134function add_user()
135{
136        select_available_users = Element('ea_select_available_users');
137        select_owners = Element('ea_select_owners');
138
139        var count_available_users = select_available_users.length;
140//      var count_owners = select_owners.options.length;
141        var new_options = '';
142
143        for (i = 0 ; i < count_available_users ; i++)
144        {
145                if (select_available_users.options[i].selected)
146                {
147                        if(document.all)
148                        {
149                                if ( (select_owners.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
150                                {
151                                        new_options +=  "<option value="
152                                                                + select_available_users.options[i].value
153                                                                + ">"
154                                                                + select_available_users.options[i].text
155                                                                + "</options>";
156                                }
157                        }
158                        else
159                        {
160                                if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
161                                {
162                                        new_options +=  "<option value="
163                                                                + select_available_users.options[i].value
164                                                                + ">"
165                                                                + select_available_users.options[i].text
166                                                                + "</options>";
167                                }
168                        }
169                }
170        }
171
172        if (new_options != '')
173        {
174                select_owners.innerHTML = '&nbsp;' + new_options + select_owners.innerHTML;
175                select_owners.outerHTML = select_owners.outerHTML;
176                document.getElementById('ea_input_searchUser').value = "";
177        }
178}
179
180function remove_user()
181{
182        select_owners = Element('ea_select_owners');
183        for(var i = 0;i < select_owners.options.length; i++)
184                if(select_owners.options[i].selected)
185                        select_owners.options[i--] = null;
186}
187
188function get_institutional_accounts_timeOut(input)
189{
190        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>';
191       
192        if (input.length > 4)
193        {
194                clearTimeout(finderTimeout);
195                finderTimeout = setTimeout("get_institutional_accounts('"+input+"')",500);
196        }
197        else
198        {
199                Element('institutional_accounts_content').innerHTML = head_table;
200        }
201}
202
203function get_institutional_accounts(input)
204{
205        var handler_get_institutional_accounts = function(data)
206        {
207                data = data.JSON( );
208                if (data.status == 'true')
209                {
210                        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>';
211                        Element('institutional_accounts_content').innerHTML = table;
212                }
213                else
214                        write_msg(data.msg, 'error');
215        }
216        ExpressoLivre.go( {
217                "access" : 'expressoAdmin1_2.ldap_functions.get_institutional_accounts&input='+input,
218                "handler" : handler_get_institutional_accounts
219        } );
220}
221
222function edit_institutional_account(uid)
223{
224        var handle_edit_institutional_account = function(data)
225        {
226                if (data.status == 'true')
227                {
228                        modal('institutional_accounts_modal','save');
229                       
230                        var combo_org = Element('ea_combo_org');
231                        for (i=0; i<combo_org.length; i++)
232                        {
233                                if (combo_org.options[i].value == data.user_context)
234                                {
235                                        combo_org.options[i].selected = true;
236                                        break;
237                                }
238                        }
239                       
240                        // anchor
241                        Element('anchor').value = "uid=" + uid + ',' + data.user_context;
242                       
243                        if (data.accountStatus != 'active')
244                                Element('accountStatus').checked = false;
245                               
246                        if (data.phpgwAccountVisible == '-1')
247                                Element('phpgwAccountVisible').checked = true;
248                       
249                        Element('cn').value = data.cn;
250                        Element('mail').value = data.mail;
251                        Element('desc').value = data.description;
252                        //Necessario, pois o IE6 tem um bug que nao exibe as novas opcoes se o innerHTML estava vazio
253                        Element('ea_select_owners').innerHTML = '&nbsp;' + data.owners;
254                        Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML;
255
256                        sinc_combos_org(data.user_context);
257                }
258                else
259                        write_msg(data.msg, 'error');
260        }
261        cExecute ('$this.ldap_functions.get_institutional_account_data&uid='+uid, handle_edit_institutional_account);
262}
263
264function save_institutional_accounts()
265{
266        if (is_ie){
267                var i = 0;
268                while (document.forms(i).name != "institutional_accounts_form"){i++}
269                form = document.forms(i);
270        }
271        else
272                form = document.forms["institutional_accounts_form"];
273       
274        select_owners = Element('ea_select_owners');
275        for(var i = 0;i < select_owners.options.length; i++)
276                select_owners.options[i].selected = true;       
277        cExecuteForm ("$this.ldap_functions.save_institutional_accounts", form, handler_save_institutional_accounts);
278}
279
280function handler_save_institutional_accounts(data_return)
281{
282        handler_save_institutional_accounts2(data_return);
283        return;
284}
285function handler_save_institutional_accounts2(data_return)
286{
287        if (!data_return.status)
288        {
289                write_msg(data_return.msg, 'error');
290        }
291        else
292        {
293                get_institutional_accounts(Element('ea_institutional_account_search').value);
294                close_lightbox();
295                write_msg(get_lang('Institutional account successful saved') + '.', 'normal');
296        }
297        return;
298}
299
300function delete_institutional_accounts(uid)
301{
302        if (!confirm(get_lang('Are you sure that you want to delete this institutional account') + "?"))
303                return;
304       
305        var handle_delete_institutional_account = function(data_return)
306        {
307                if (!data_return.status)
308                {
309                        write_msg(data_return.msg, 'error');
310                }
311                else
312                {
313                        write_msg(get_lang('Institutional account successful deleted') + '.', 'normal');
314                        get_institutional_accounts(Element('ea_institutional_account_search').value);
315                }
316                return;
317        }
318        cExecute ('$this.ldap_functions.delete_institutional_account_data&uid='+uid, handle_delete_institutional_account);
319}
Note: See TracBrowser for help on using the repository browser.