source: companies/serpro/expressoAdminSerpro/js/jscode/institutional_accounts.js @ 903

Revision 903, 8.4 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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