source: trunk/expressoAdmin1_2/js/jscode/maillists.js @ 86

Revision 86, 10.9 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 0;
2function validate_fields(type)
3{
4        document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
5        document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase();
6       
7        if (document.forms[0].uid.value == ''){
8                alert('Campo LOGIN da lista está vazio.');
9                return;
10        }
11
12        if (document.forms[0].cn.value == ''){
13                alert('Campo NOME da lista está vazio.');
14                return;
15        }
16       
17        if (document.forms[0].restrictionsOnEmailLists.value == 'true')
18        {
19                uid_tmp = document.forms[0].uid.value.split("-");
20                if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){
21                        alert(
22                                'O campo LOGIN da lista está incompleto.\n' +
23                                'O nome da lista deve ser formado assim:\n' +
24                                'lista-ORGANIZACAO-NOME_DA_LISTA.\n' +
25                                'Ex: lista-celepar-rh.');
26                        return;
27                }
28        }
29               
30        if (document.forms[0].uid.value.split(" ").length > 1){
31                alert('Campo LOGIN comtém espaços.');
32                document.forms[0].uid.focus();
33                return;
34        }
35       
36        if (document.forms[0].mail.value == ''){
37                alert('Campo E-MAIL da lista está vazio.');
38                document.forms[0].mail.focus();
39                return;
40        }
41        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
42        if(!reEmail.test(document.forms[0].mail.value)){
43                alert("Campo E-mail não é válido.");
44                return false;
45        }
46       
47        select_userInMaillist = document.getElementById('ea_select_usersInMaillist');
48        if (select_userInMaillist.options.length == 0){
49                alert('Nenhum usuário faz parte da lista.');
50                return;
51        }
52       
53        var handler_validate_fields = function(data)
54        {
55                if (!data.status)
56                        alert(data.msg);
57                else
58                {
59                        if (type == 'create_maillist')
60                                cExecuteForm ("$this.maillist.create", document.forms[0], handler_create);
61                        else if (type == 'edit_maillist')
62                                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
63                }
64        }
65
66        // Needed select all options from select
67        for(var i=0; i<select_userInMaillist.options.length; i++)
68                select_userInMaillist.options[i].selected = true;
69       
70        // O UID da lista foi alterado ou é uma nova lista.
71        if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){
72                cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value, handler_validate_fields);
73        }
74        else if (type == 'edit_maillist')
75        {
76                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
77        }
78}
79
80// HANDLER CREATE
81// É necessário 2 funcões de retorno por causa do cExecuteForm.
82function handler_create(data)
83{
84        return_handler_create(data);
85}
86function return_handler_create(data)
87{
88        if (!data.status)
89                alert(data.msg);
90        else{
91                alert('Lista de emails criada com êxito!');
92                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
93        }
94        return;
95}
96
97// HANDLER SAVE
98// É necessário 2 funcões de retorno por causa do cExecuteForm.
99function handler_save(data)
100{
101        return_handler_save(data);
102}
103function return_handler_save(data)
104{
105        if (!data.status)
106                alert(data.msg);
107        else{
108                alert('Lista de emails salva com êxito!!');
109                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
110        }
111        return;
112}
113
114function save_scl()
115{
116        select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist');
117        // Needed select all options from select
118        for(var i=0; i<select_users_SCL_Maillist.options.length; i++)
119                select_users_SCL_Maillist.options[i].selected = true;
120
121        cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl);
122}
123function handler_save_scl(data)
124{
125        return_handler_save_scl(data);
126}
127
128function return_handler_save_scl(data)
129{
130        if (!data.status)
131                alert(data.msg);
132        else
133                alert('Sending Control List salva com êxito!!');
134        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
135        return;
136}
137
138function sinc_combos_org(context, recursive)
139{
140        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
141
142        for (i=0; i<combo_org_maillists.length; i++)
143        {
144                if (combo_org_maillists.options[i].value == context)
145                {
146                        combo_org_maillists.options[i].selected = true;
147                        get_available_users(context, recursive);
148                        break;
149                }
150        }
151}
152
153function get_available_users(context, recursive)
154{
155        var handler_get_available_users = function(data)
156        {
157                select_available_users = document.getElementById('ea_select_available_users');
158               
159                //Limpa o select
160                for(var i=0; i<select_available_users.options.length; i++)
161                {
162                        select_available_users.options[i] = null;
163                        i--;
164                }
165
166                if ((data) && (data.length > 0))
167                {
168                        // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
169                        select_available_users.innerHTML = '&nbsp;' + data;
170                        select_available_users.outerHTML = select_available_users.outerHTML;
171                       
172                        select_available_users.disabled = false;
173                        select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true);
174                        document.getElementById('ea_input_searchUser').value = '';
175                }
176        }
177       
178        //Impede chamada recursiva na raiz das organizações
179        if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_maillists').value))
180        {
181                alert('Nao é possível selecionar todos os usuários da organização raiz.')
182                document.getElementById('ea_check_allUsers').checked = false;
183               
184                // Limpa select
185                select_available_users = document.getElementById('ea_select_available_users');
186                select_available_users.innerHTML = '&nbsp;';
187                select_available_users.outerHTML = select_available_users.outerHTML;
188                return;
189        }
190        cExecute ('$this.ldap_functions.get_available_users_and_maillist&context='+context+'&recursive='+recursive+'&denied_uidnumber='+document.forms[0].uidnumber.value, handler_get_available_users);
191}
192
193function add_user2maillist()
194{
195        select_available_users = document.getElementById('ea_select_available_users');
196        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
197
198        var count_available_users = select_available_users.length;
199        var count_usersInMailList = select_usersInMaillist.options.length;
200        var new_options = '';
201
202        for (i = 0 ; i < count_available_users ; i++)
203        {
204                if (select_available_users.options[i].selected)
205                {
206                        if(document.all)
207                        {
208                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
209                                {
210                                        new_options +=  "<option value="
211                                                                + select_available_users.options[i].value
212                                                                + ">"
213                                                                + select_available_users.options[i].text
214                                                                + "</options>";
215                                }
216                        }
217                        else
218                        {               
219                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
220                                {
221                                        new_options +=  "<option value="
222                                                                + select_available_users.options[i].value
223                                                                + ">"
224                                                                + select_available_users.options[i].text
225                                                                + "</options>";
226                                }
227                        }
228                }
229        }
230
231        if (new_options != '')
232        {
233                select_usersInMaillist.innerHTML = '&nbsp;' + new_options + select_usersInMaillist.innerHTML;
234                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
235                document.getElementById('ea_input_searchUser').value = "";
236        }
237}
238
239function remove_user2maillist()
240{
241        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
242       
243        for(var i = 0;i < select_usersInMaillist.options.length; i++)
244                if(select_usersInMaillist.options[i].selected)
245                        select_usersInMaillist.options[i--] = null;
246}
247
248function add_user2scl_maillist()
249{
250        select_available_users = document.getElementById('ea_select_available_users');
251        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
252
253        var count_available_users = select_available_users.length;
254        var count_usersInMailList = select_usersInMaillist.options.length;
255        var new_options = '';
256
257        for (i = 0 ; i < count_available_users ; i++)
258        {
259                if (select_available_users.options[i].selected)
260                {
261                        if(document.all)
262                        {
263                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
264                                {
265                                        new_options +=  "<option value="
266                                                                + select_available_users.options[i].value
267                                                                + ">"
268                                                                + select_available_users.options[i].text
269                                                                + "</options>";
270                                }
271                        }
272                        else
273                        {               
274                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
275                                {
276                                        new_options +=  "<option value="
277                                                                + select_available_users.options[i].value
278                                                                + ">"
279                                                                + select_available_users.options[i].text
280                                                                + "</options>";
281                                }
282                        }
283                }
284        }
285
286        if (new_options != '')
287        {
288                select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML;
289                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
290        }
291}
292
293function remove_user2scl_maillist()
294{
295        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
296       
297        for(var i = 0;i < select_usersInMaillist.options.length; i++)
298                if(select_usersInMaillist.options[i].selected)
299                        select_usersInMaillist.options[i--] = null;
300}
301
302
303// Variaveis Locais
304if (document.getElementById('ea_select_available_users'))
305{
306        var select_available_users  = document.getElementById('ea_select_available_users');
307        var select_available_users_clone = select_available_users.cloneNode(true);
308}
309else
310{
311        var select_available_users  = '';
312        var select_available_users_clone = '';
313}
314var finderTimeout = '';
315
316// Funcoes                                                                                     
317function optionFinderTimeout(obj)
318{
319        clearTimeout(finderTimeout);   
320        var oWait = document.getElementById("ea_span_searching");
321        oWait.innerHTML = 'Buscando...';
322        finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
323}
324function optionFinder(id) {
325        var oWait = document.getElementById("ea_span_searching");
326        var oText = document.getElementById(id);
327               
328        //Limpa todo o select
329        var select_available_users_tmp = document.getElementById('ea_select_available_users')
330
331        for(var i = 0;i < select_available_users_tmp.options.length; i++)
332                select_available_users_tmp.options[i--] = null;
333
334        var RegExp_name = new RegExp("\\b"+oText.value, "i");
335       
336        //Inclui usuário começando com a pesquisa
337        for(i = 0; i < select_available_users_clone.length; i++){
338                if ( RegExp_name.test(select_available_users_clone[i].text) || (select_available_users_clone[i].value == -1) )
339                {
340                        sel = select_available_users_tmp.options;
341                        option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
342
343                        if (select_available_users_clone[i].value == -1)
344                                option.disabled = true;
345
346                        sel[sel.length] = option;
347                }
348        }
349        oWait.innerHTML = '&nbsp;';
350}                       
351
352function delete_maillist(uid, uidnumber)
353{
354        if (confirm("Realmente deletar Lista " + uid + " ??"))
355        {
356                var handler_delete_maillist = function(data)
357                {
358                        if (!data.status)
359                                alert(data.msg);
360                        else
361                                alert('Lista de email deletada com êxito!!');
362                       
363                        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
364                        return;
365                }
366                cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist);
367        }
368}
369
370function search_organization(key)
371{
372        var organizations = document.getElementById('ea_combo_org_info');
373        var RegExp_org = new RegExp("\\b"+key, "i");
374       
375        for(i = 0; i < organizations.length; i++)
376        {
377                if (RegExp_org.test(organizations[i].text))
378                {
379                        organizations[i].selected = true;
380                        return;
381                }
382        }
383}
Note: See TracBrowser for help on using the repository browser.