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

Revision 5133, 10.5 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoAdmin.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1countFiles = 0;
2
3function Element(id){
4   return document.getElementById( id );
5}
6
7function validate_fields(type)
8{
9        document.forms[0].uid.value = document.forms[0].uid.value.toLowerCase();
10        document.forms[0].old_uid.value = document.forms[0].old_uid.value.toLowerCase();
11
12        if (document.forms[0].uid.value == ''){
13                alert(get_lang('login field is empty') + '.');
14                return;
15        }
16
17        if (document.forms[0].cn.value == ''){
18                alert(get_lang('name field is empty') + '.');
19                return;
20        }
21       
22        if (document.forms[0].restrictionsOnEmailLists.value == 'true')
23        {
24                uid_tmp = document.forms[0].uid.value.split("-");
25                if ((uid_tmp.length < 3) || (uid_tmp[0] != 'lista')){
26                        alert(
27                                get_lang('login field is incomplete') + '.\n' +
28                                get_lang('the login field must be formed like') + ':\n' +
29                                get_lang('list') + '-' + get_lang('organization') + '-' + get_lang('listname') + '.\n' +
30                                get_lang('eg') + ': ' + 'lista-celepar-rh.');
31                        return;
32                }
33        }
34               
35        if (document.forms[0].uid.value.split(" ").length > 1){
36                alert(get_lang('LOGIN field contains characters not allowed') + '.');
37                document.forms[0].uid.focus();
38                return;
39        }
40       
41        if (document.forms[0].mail.value == ''){
42                alert(get_lang('EMAIL field is empty') + '.');
43                document.forms[0].mail.focus();
44                return;
45        }
46        var reEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
47        if(!reEmail.test(document.forms[0].mail.value)){
48                alert(get_lang('Email field is not valid') + '.');
49                return false;
50        }
51       
52        select_userInMaillist = document.getElementById('ea_select_usersInMaillist');
53        if (select_userInMaillist.options.length == 0){
54                alert(get_lang('Any user is in the list') + '.');
55                return;
56        }
57       
58        var handler_validate_fields = function(data)
59        {
60                if (!data.status)
61                        alert(data.msg);
62                else
63                {
64                        if (type == 'create_maillist')
65                                cExecuteForm ("$this.maillist.create", document.forms[0], handler_create);
66                        else if (type == 'edit_maillist')
67                                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
68                }
69        }
70
71        // Needed select all options from select
72        for(var i=0; i<select_userInMaillist.options.length; i++)
73        {
74                // No IE, não seleciona o separador do select
75                if (select_userInMaillist.options[i].value != -1)
76                        select_userInMaillist.options[i].selected = true;
77                else
78                        select_userInMaillist.options[i].selected = false;
79        }
80
81        // O UID da lista foi alterado ou é uma nova lista.
82        if ((document.forms[0].old_uid.value != document.forms[0].uid.value) || (type == 'create_maillist')){
83                cExecute ('$this.maillist.validate_fields&uid='+document.forms[0].uid.value+'&mail='+document.forms[0].mail.value, handler_validate_fields);
84        }
85        else if (type == 'edit_maillist')
86        {
87                cExecuteForm ("$this.maillist.save", document.forms[0], handler_save);
88        }
89}
90
91// HANDLER CREATE
92// É necessário 2 funcões de retorno por causa do cExecuteForm.
93function handler_create(data)
94{
95        return_handler_create(data);
96}
97function return_handler_create(data)
98{
99        if (!data.status)
100                alert(data.msg);
101        else{
102                alert(get_lang('Email list successful created') + '.');
103                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
104        }
105        return;
106}
107
108// HANDLER SAVE
109// É necessário 2 funcões de retorno por causa do cExecuteForm.
110function handler_save(data)
111{
112        return_handler_save(data);
113}
114function return_handler_save(data)
115{
116        if (!data.status)
117                alert(data.msg);
118        else{
119                alert(get_lang('Email list successful saved') + '.');
120                location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
121        }
122        return;
123}
124
125function save_scl()
126{
127        select_users_SCL_Maillist = document.getElementById('ea_select_users_SCL_Maillist');
128        // Needed select all options from select
129        for(var i=0; i<select_users_SCL_Maillist.options.length; i++)
130                select_users_SCL_Maillist.options[i].selected = true;
131
132        cExecuteForm ("$this.maillist.save_scl", document.forms[0], handler_save_scl);
133}
134function handler_save_scl(data)
135{
136        return_handler_save_scl(data);
137}
138
139function return_handler_save_scl(data)
140{
141        if (!data.status)
142                alert(data.msg);
143        else
144                alert(get_lang('SCL successful saved') + '.');
145        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
146        return;
147}
148
149function sinc_combos_org(context, recursive)
150{
151        combo_org_maillists = document.getElementById('ea_combo_org_maillists');
152
153        for (i=0; i<combo_org_maillists.length; i++)
154        {
155                if (combo_org_maillists.options[i].value == context)
156                {
157                        combo_org_maillists.options[i].selected = true;
158                        get_available_users(context, recursive);
159                        break;
160                }
161        }
162}
163
164function get_available_users(context, recursive)
165{
166//      var sentence = Element('ea_input_searchUser').value;
167//
168//      var url = '$this.ldap_functions.get_available_users_and_maillist&context='
169//                  + Element('ea_combo_org_maillists').value
170//                  + '&sentence=' + sentence
171//                  + '&denied_uidnumber=' + document.forms[0].uidnumber.value;
172//
173//      var fillHandler = function( fill ){
174//
175//      Element('ea_select_available_users').innerHTML = fill;
176//
177//      return( fill !== "" );
178//     }
179//
180//      userFinder( sentence, fillHandler, url, 'ea_span_searching' );
181                       
182        var url = '$this.ldap_functions.get_available_users_and_maillist&denied_uidnumber=' + document.forms[0].uidnumber.value;
183       
184        optionFind( 'ea_input_searchUser', 'ea_select_available_users', url,
185                    'ea_combo_org_maillists', 'ea_span_searching' );
186}
187
188function add_user2maillist()
189{
190        select_available_users = document.getElementById('ea_select_available_users');
191        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
192
193        var count_available_users = select_available_users.length;
194        var count_usersInMailList = select_usersInMaillist.options.length;
195        var new_options = '';
196
197        for (i = 0 ; i < count_available_users ; i++)
198        {
199                if (select_available_users.options[i].selected)
200                {
201                        if(document.all)
202                        {
203                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
204                                {
205                                        new_options +=  "<option value="
206                                                                + select_available_users.options[i].value
207                                                                + ">"
208                                                                + select_available_users.options[i].text
209                                                                + "</options>";
210                                }
211                        }
212                        else
213                        {               
214                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
215                                {
216                                        new_options +=  "<option value="
217                                                                + select_available_users.options[i].value
218                                                                + ">"
219                                                                + select_available_users.options[i].text
220                                                                + "</options>";
221                                }
222                        }
223                }
224        }
225
226        if (new_options != '')
227        {
228                select_usersInMaillist.innerHTML = '&nbsp;' + new_options + select_usersInMaillist.innerHTML;
229                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
230                document.getElementById('ea_input_searchUser').value = "";
231        }
232}
233
234function remove_user2maillist()
235{
236        select_usersInMaillist = document.getElementById('ea_select_usersInMaillist');
237       
238        for(var i = 0;i < select_usersInMaillist.options.length; i++)
239                if(select_usersInMaillist.options[i].selected)
240                        select_usersInMaillist.options[i--] = null;
241}
242
243function add_user2scl_maillist()
244{
245        select_available_users = document.getElementById('ea_select_available_users');
246        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
247
248        var count_available_users = select_available_users.length;
249        var count_usersInMailList = select_usersInMaillist.options.length;
250        var new_options = '';
251
252        for (i = 0 ; i < count_available_users ; i++)
253        {
254                if (select_available_users.options[i].selected)
255                {
256                        if(document.all)
257                        {
258                                if ( (select_usersInMaillist.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
259                                {
260                                        new_options +=  "<option value="
261                                                                + select_available_users.options[i].value
262                                                                + ">"
263                                                                + select_available_users.options[i].text
264                                                                + "</options>";
265                                }
266                        }
267                        else
268                        {               
269                                if ( (select_usersInMaillist.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
270                                {
271                                        new_options +=  "<option value="
272                                                                + select_available_users.options[i].value
273                                                                + ">"
274                                                                + select_available_users.options[i].text
275                                                                + "</options>";
276                                }
277                        }
278                }
279        }
280
281        if (new_options != '')
282        {
283                select_usersInMaillist.innerHTML = '#' + new_options + select_usersInMaillist.innerHTML;
284                select_usersInMaillist.outerHTML = select_usersInMaillist.outerHTML;
285        }
286}
287
288function remove_user2scl_maillist()
289{
290        select_usersInMaillist = document.getElementById('ea_select_users_SCL_Maillist');
291       
292        for(var i = 0;i < select_usersInMaillist.options.length; i++)
293                if(select_usersInMaillist.options[i].selected)
294                        select_usersInMaillist.options[i--] = null;
295}
296
297
298// Variaveis Locais
299if (document.getElementById('ea_select_available_users'))
300{
301        var select_available_users  = document.getElementById('ea_select_available_users');
302        var select_available_users_clone = select_available_users.cloneNode(true);
303}
304else
305{
306        var select_available_users  = '';
307        var select_available_users_clone = '';
308}
309var finderTimeout = '';
310
311// Funcoes
312function optionFinderTimeout(obj, event)
313{
314    if( event && event.keyCode !== 13 )
315        return;
316       
317        optionFinder( obj.id );
318}
319function optionFinder(id) {
320        get_available_users();
321}                       
322
323function delete_maillist(uid, uidnumber)
324{
325        if (confirm(get_lang('Do you really want delete the email list') + ' ' + uid + " ??"))
326       
327        {
328                var handler_delete_maillist = function(data)
329                {
330                        if (!data.status)
331                                alert(data.msg);
332                        else
333                                alert(get_lang('Email list successful deleted') + '.');
334                       
335                        location.href="./index.php?menuaction=expressoAdmin1_2.uimaillists.list_maillists";
336                        return;
337                }
338                cExecute ('$this.maillist.delete&uidnumber='+uidnumber, handler_delete_maillist);
339        }
340}
341
342function search_organization(key, element)
343{
344        var organizations = document.getElementById(element);
345        var RegExp_org = new RegExp("\\b"+key, "i");
346       
347        for(i = 0; i < organizations.length; i++)
348        {
349                if (RegExp_org.test(organizations[i].text))
350                {
351                        organizations[i].selected = true;
352                        return;
353                }
354        }
355}
356
357function emailSuggestion_maillist()
358{
359        var defaultDomain = document.forms[0].defaultDomain.value;
360        var base_dn = "." + dn2ufn(document.forms[0].ldap_context.value);
361        var selected_context = dn2ufn(document.forms[0].context.value.toLowerCase());
362
363        var uid = document.getElementById("ea_maillist_uid");
364        var mail= document.getElementById("ea_maillist_mail");
365       
366        var raw_selected_context = selected_context.replace(base_dn, "");
367       
368        var array_org_name = raw_selected_context.split('.');
369        var org_name = array_org_name[array_org_name.length-1];
370       
371        if (mail.value == "")
372                mail.value = uid.value + "@" + org_name + "." + defaultDomain;
373}
374
375function dn2ufn(dn)
376{
377        var ufn = '';
378        var array_dn = dn.split(",");
379        for (x in array_dn)
380        {
381                var tmp = array_dn[x].split("=");
382                ufn += tmp[1] + '.';
383        }
384        return ufn.substring(0,(ufn.length-1));
385}
Note: See TracBrowser for help on using the repository browser.