source: trunk/expressoMail1_2/js/QuickCatalogSearch.js @ 4787

Revision 4787, 26.2 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1820 - Tratada as interações da janela de pesquisa por F9, em IE e FF.r4635

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1        function emQuickCatalogSearch ()
2        {
3                this.arrayWin = new Array();
4                this.el;
5                this.cc_contacts = new Array();
6                this.cc_groups  = new Array();
7        }
8
9        emQuickCatalogSearch.prototype.showList = function(data, begin, end){
10                connector.loadScript("ccQuickAdd");
11               
12                id = '1';
13                _this = this;
14                var el_A = document.createElement("DIV");
15                el_A.style.visibility = "hidden";
16                el_A.style.position = "absolute";
17                el_A.style.left = "0px";
18                el_A.style.top = "0px";
19                el_A.style.width = "0px";
20                el_A.style.height = "0px";
21                el_A.id = 'window_QuickCatalogSearch_A';
22                document.body.appendChild(el_A);
23                el_A.innerHTML = "";
24
25                var el = document.createElement("DIV");
26                el.style.visibility = "hidden";
27                el.style.position = "absolute";
28                el.style.left = "0px";
29                el.style.top = "40px";
30                el.style.width = "695px";
31                el.style.height = "186px";
32                el.style.overflow = "auto";
33                el.id = 'window_QuickCatalogSearch';
34                el_A.appendChild(el);
35                el.innerHTML = "";
36               
37               
38                func_add_contact = function () {
39                        var select_QuickCatalogSearch = document.getElementById("select_QuickCatalogSearch");
40                        var contact_selected = select_QuickCatalogSearch.options[select_QuickCatalogSearch.selectedIndex].text;
41                       
42                        contact_selected = contact_selected.split('(');
43                       
44                        var first_and_last_name = contact_selected[0].split(" ");
45                       
46                        var data = [];
47                        data[0] = first_and_last_name[0];
48                        data[1] = first_and_last_name[0];
49                        data[2] = "";
50                       
51                        for (i=1; i < first_and_last_name.length; i++)
52                                data[2] += first_and_last_name[i] + " ";
53                       
54                        data[2] = data[2].replace(/\s*$/g,'');
55                        data[3] = contact_selected[1].substring(0, contact_selected[1].indexOf(")") );
56                       
57                        ccQuickAddOne.showList( data );                 
58                };             
59               
60                        var title_innerHTML = get_lang('Select a name') + ':';
61                        if (data.quickSearch_only_in_userSector)
62                                title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
63
64                        var title = document.createElement("SPAM");
65                        title.id = 'window_QuickCatalogSearch_title';
66                        title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
67                        el_A.appendChild(title);
68                        var butt = document.createElement('BUTTON');
69                        var buttext = document.createTextNode('OK');
70                        butt.id = "QuickCatalogSearch_button_ok";
71                        butt.appendChild(buttext);
72                        butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
73                        el_A.appendChild(butt);
74
75                        var space = document.createElement('SPAN');
76                        space.innerHTML = "&nbsp;&nbsp;";
77                        el_A.appendChild(space);
78
79                        var butt = document.createElement('BUTTON');
80                        butt.id = "QuickCatalogSearch_button_close";
81                        var buttext = document.createTextNode(get_lang('Close'));
82                        butt.appendChild(buttext);
83                        butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
84                        el_A.appendChild(butt);
85
86                        var space = document.createElement('SPAN');
87                        space.innerHTML = "&nbsp;&nbsp;";
88                        el_A.appendChild(space);
89
90                        var butt = document.createElement('BUTTON');
91                        butt.id = "QuickCatalogSearch_button_add_contact";
92                        var buttext = document.createTextNode(get_lang("Add Contact"));
93                        butt.appendChild(buttext);
94                        butt.onclick = func_add_contact;
95                        el_A.appendChild(butt);
96
97                if (document.getElementById('select_QuickCatalogSearch') == null){
98                       
99                        var cmb = document.createElement("SELECT");
100                        cmb.id = "select_QuickCatalogSearch";
101                        cmb.style.width = "2400px";
102                        //cmb.size = "12";
103                        cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
104                        cmb.onkeypress = function (e)
105                        {
106                                if (is_ie)
107                                {
108                                        if ((window.event.keyCode) == 13)
109                                        {
110                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
111                                        }
112                                        else if ((window.event.keyCode) == 27)
113                                        {
114                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
115                                        }
116                                }
117                                else
118                                {
119                                        if ((e.keyCode) == 13)
120                                        {
121                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
122                                        }
123                                        else if ((e.keyCode) == 27)
124                                        {
125                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
126                                        }
127                                }
128                        };
129                        el.appendChild(cmb);
130
131                }
132                else{
133                        var title_innerHTML = get_lang('Select a name') + ':';
134                        if (data.quickSearch_only_in_userSector)
135                                title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
136
137                        var title = Element('window_QuickCatalogSearch_title');
138                        title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
139                       
140                        var cmb = document.getElementById('select_QuickCatalogSearch');
141                        cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
142                        cmb.onkeypress = function (e)
143                        {
144                                if (is_ie)
145                                {
146                                        if ((window.event.keyCode) == 13)
147                                        {
148                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
149                                        }
150                                        else if ((window.event.keyCode) == 27)
151                                        {
152                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
153                                        }
154                                }
155                                else
156                                {
157                                        if ((e.keyCode) == 13)
158                                        {
159                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
160                                        }
161                                        else if ((e.keyCode) == 27)
162                                        {
163                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
164                                        }
165                                }
166                        };
167
168                        for (i=0; i<cmb.length; i++)
169                                cmb.options[i--] = null;
170                       
171                        var butt_ok = document.getElementById("QuickCatalogSearch_button_ok");
172                        var butt_close = document.getElementById("QuickCatalogSearch_button_close");
173                        var butt_add_contact = document.getElementById("QuickCatalogSearch_button_add_contact");
174                        butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
175                        butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
176                        butt_add_contact.onclick = func_add_contact;
177                }
178
179                for (i=0; i<data.length; i++){
180                        var Op = document.createElement("OPTION");
181                        Op.text = data[i].cn + ' (' + data[i].mail + ')';
182                        if (data[i].phone != '')
183                                Op.text += ' - ' + data[i].phone;
184                        if (data[i].ou != '')
185                                Op.text += ' - ' + data[i].ou; // adicionado "data[i].ou" para exibir setor (F9)
186                        Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
187                        cmb.options.add(Op);
188                }
189                cmb.options[0].selected = true;
190                cmb.size = data.length+1;
191                _this.showWindow(el_A);
192        }
193       
194        emQuickCatalogSearch.prototype.showWindow = function (div)
195        {
196                if(! div) {
197                        alert(get_lang('The list has no participant.'));
198                        return;
199                }
200                                                       
201                if(! this.arrayWin[div.id]) {
202                        div.style.width = "700px";
203                        div.style.height = "230px";
204                        var title = get_lang('The results were found in the Global Catalog')+':';
205                        var wHeight = div.offsetHeight + "px";
206                        var wWidth =  div.offsetWidth   + "px";
207                        div.style.width = div.offsetWidth - 5;
208
209                        win = new dJSWin({                     
210                                id: 'QuickCatalogSearch_'+div.id,
211                                content_id: div.id,
212                                width: wWidth,
213                                height: wHeight,
214                                title_color: '#3978d6',
215                                bg_color: '#eee',
216                                title: title,                                           
217                                title_text_color: 'white',
218                                button_x_img: '../phpgwapi/images/winclose.gif',
219                                border: true,
220                                onclose: 'QuickCatalogSearch.restoreShortcuts("'+ div.id +'")' });
221
222                        this.arrayWin[div.id] = win;
223                        win.draw();
224                }
225                else {
226                        win = this.arrayWin[div.id];
227                }
228                document.getElementById("window_QuickCatalogSearch").style.visibility = "visible";
229                win.open();
230                document.getElementById('select_QuickCatalogSearch').focus();
231
232                if(is_ie && (preferences.use_shortcuts == '1')){
233                    shortcut.remove('down');
234                    shortcut.remove('up');
235                    shortcut.remove('return');
236                }
237        }
238       
239        emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){
240                cm = document.getElementById('select_QuickCatalogSearch');
241                option_selected = cm.options[cm.selectedIndex].value + ", ";
242                emailList = document.getElementById(field + "_" + ID).value;
243               
244                new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length);
245                document.getElementById(field + "_" + ID).value = new_emailList;
246                document.getElementById(field + "_" + ID).focus();
247               
248                this.arrayWin['window_QuickCatalogSearch_A'].close();
249                document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";
250        }
251
252        emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){
253                //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
254                document.getElementById(field + "_" + ID).focus();
255                this.arrayWin['window_QuickCatalogSearch_A'].close();
256                document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";
257                if(typeof shortcut.all_shortcuts['down'] == 'undefined'){
258                    if(is_ie  && (preferences.use_shortcuts == '1'))
259                    {
260                        shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false});
261                        shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false});
262                        shortcut.add("return",function(){
263                            if ( Element('border_id_0').className==='menu-sel' )
264                            {
265                                    all_messages = Element('tbody_box').childNodes;
266                                    for (var i=0; i < all_messages.length; i++)
267                                    {
268                                            if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
269                                            {
270                                                    Element("td_who_" + all_messages[i].id).onclick();
271                                                    return;
272                                            }
273                                    }
274                            }
275                        },{'disable_in_input':true});
276                    }
277                }
278        }
279
280        emQuickCatalogSearch.prototype.restoreShortcuts = function(id) {
281
282            var search_win = document.getElementById(id);
283            if(typeof shortcut.all_shortcuts['down'] == 'undefined'){
284                if (search_win.style.visibility == 'visible')
285                {
286                    shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false});
287                    shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false});
288                    shortcut.add("return",function(){
289                        if ( Element('border_id_0').className==='menu-sel' )
290                        {
291                                all_messages = Element('tbody_box').childNodes;
292                                for (var i=0; i < all_messages.length; i++)
293                                {
294                                        if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
295                                        {
296                                                Element("td_who_" + all_messages[i].id).onclick();
297                                                return;
298                                        }
299                                }
300                        }
301                    },{'disable_in_input':true});
302                }
303            }
304            search_win.style.visibility = 'hidden';
305
306        }
307
308        emQuickCatalogSearch.prototype.close_window = function(id) {
309                this.arrayWin[id].close();
310                var group_values = Element('list_values');
311                var user_values = Element('user_values');
312        }
313        emQuickCatalogSearch.prototype.showCatalogList = function (border_id){
314                var el = Element('catalog_list');
315
316                if(el) {
317                        Element('border_id').value = border_id;
318                        win = this.arrayWin[el.id];
319                        win.open();
320                        return;         
321                }
322                var border_input   = document.createElement("INPUT");
323                border_input.type  = 'hidden';
324                border_input.id    = 'border_id';
325                border_input.value = border_id;
326                document.body.appendChild(border_input);
327                el = document.createElement("DIV");             
328                el.id = 'catalog_list';
329                document.body.appendChild(el);                 
330                el.style.visibility = "hidden";
331                el.style.position = "absolute";
332                el.style.width = "700px";
333                el.style.height = is_ie ? "360px" : "375px";           
334                el.style.left = "0px";
335                el.style.top = "0px";                   
336                el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+
337                                           "<tr><td id='td1' style='cursor:pointer' align='center' onclick='QuickCatalogSearch.select_div(\"tab1\")'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab1\");'>"+get_lang('Global Catalog')+"</a></td>"+
338                                           "<td id='td2' style='background:#cecece;cursor:pointer' onclick='QuickCatalogSearch.select_div(\"tab2\")' align='center'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab2\");'>"+get_lang('Personal Catalog')+"</a></td></tr>"+
339                                           '</table>'+
340                                           '<div id="tab1" align="center"><br>'+
341                                           '<table border="0" cellpading="0" cellspacing="0">'+
342                                           '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+'&nbsp;:</td></tr>'+
343                                        '<tr><td><select style="display:none;width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select>&nbsp'+
344                                        '<select id="select_organization" style="width:150px" name="select_organization"></select>&nbsp;'+   
345                                        '<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="30"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:visible" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
346                                           '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type_l" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" id="type_u" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
347                                           '<span style="visibility:hidden;background:#cc4444" id=msg_search>&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font>&nbsp;</span></td></tr>'+
348                                           '<tr><td>'+
349                                           '<span id="list_span"><select multiple style="display:none;width:580px" size="14" id="list_values"></select></span>'+
350                                           '<span id="user_span"><select multiple style="width:580px" size="14" id="user_values"></select></span>'+
351                                           '</td></tr>'+
352                                           '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to\')">&nbsp;'+
353                                           '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')">&nbsp;'+
354                                           '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">'+
355                                           '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
356                                           '</table>'+
357                                           '</div>'+
358                                           '<div style="display:none" id="tab2" align="center">'+
359                                           '<br><br><br>'+
360                                           '<table border="0" cellpading="0" cellspacing="0">'+
361                                           '<tr><td>'+get_lang("Select the type of contact that you want to view")+'&nbsp;:</td></tr>'+
362                                           '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" type="radio" name="type" value="p"/>' + get_lang('People') + '&nbsp;&nbsp;<input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>' + get_lang('Groups') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
363                                           '<tr><td>'+
364                                           '<span id="personal_span"><select multiple style="width:580px" size="14" id="list_personal"></select></span>'+
365                                           '<span id="groups_span"><select multiple style="display:none;width:580px" size="14" id="list_groups"></select></span>'+
366                                           '</td></tr>'+
367                                           '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to1\')">&nbsp;'+
368                                           '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')">&nbsp;'+
369                                           '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">'+
370                                           '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
371                                           '</table>'+
372                                           '</div>';
373
374                var title = get_lang('Search in the Global Catalog');
375                var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px";
376                var wWidth =  el.offsetWidth   + "px";
377                el.style.width = el.offsetWidth;
378               
379                Element('search_for').onkeypress = function (e) {
380                        if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) {
381                                QuickCatalogSearch.searchCatalogList(true);
382                        }
383                };
384
385                win = new dJSWin({                     
386                        id: 'win_'+el.id,
387                        content_id: el.id,
388                        width: wWidth,
389                        height: wHeight,
390                        title_color: '#3978d6',
391                        bg_color: '#eee',
392                        title: title,                                           
393                        title_text_color: 'white',
394                        button_x_img: '../phpgwapi/images/winclose.gif',
395                        border: true });
396                       
397                this.arrayWin[el.id] = win;             
398                win.draw();
399                win.open();
400
401                var handler_catalogs = function(data){
402                        var user_catalog = get_lang("Global Catalog");
403                        if(data.length > 1) {
404                                Element('select_catalog').style.display = '';
405                                for(i = 0; i < data.length; i++) {             
406                                        Element('select_catalog').options[i] = new Option(data[i],i);
407                                        if(user_catalog.toUpperCase() == data[i].toUpperCase())
408                                                Element('select_catalog').options[i].selected = true;
409                                }
410                        }
411                }
412                cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs);               
413               
414                this.update_organizations();
415                var handler_cc_contacts= function(data){
416                        if(data && data.length > 0){
417                                var aux = data.split(",");
418                                for(var i=0; i< aux.length; i++){
419                                        QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i];                         
420                                }
421                        }
422                }
423                cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts);
424
425                var handler_cc_groups = function(data){
426                        if(data && data.length > 0){
427                                var aux = data.split(",");
428                                for(var i=0; i < data.length; i++){
429                                        QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i];                                                             
430                                }       
431                        }
432                }
433                cExecute("$this.db_functions.get_cc_groups",handler_cc_groups);
434       
435        }
436       
437        emQuickCatalogSearch.prototype.select_div = function(element){
438                if(element == 'tab1'){
439                   Element('tab1').style.display = '';
440                   Element('tab2').style.display = 'none';
441                   Element('td1').style.background = '#eee';   
442                   Element('td2').style.background = '#cecece';
443                }
444                if(element == 'tab2'){
445                   Element('tab1').style.display = 'none';
446                   Element('tab2').style.display = '';
447                   Element('td1').style.background = '#cecece';
448                   Element('td2').style.background = '#eee';               
449
450                }
451        }
452       
453        emQuickCatalogSearch.prototype.load_catalog = function(){
454       
455                var _this = this;
456                var content = new Array;
457                var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal');
458               
459                if(Element('list_personal').style.display == 'none'){
460                        content = _this.cc_groups;
461                }else{
462                        content = _this.cc_contacts;
463                }
464                if(select.options.length > 0){
465                        for(var i=0; i < select.options.length; i++){
466                                select.options[i] = null;
467                                i--;
468                        }
469                }
470                for(var i=0; i < content.length; i++){
471                        if(content[i] != undefined){
472                                var aux = content[i].split(";");
473                                var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false);
474                                select[select.length] = opt;
475                        }
476                }
477                content.splice(0,(content.lenght));
478        }
479
480        emQuickCatalogSearch.prototype.update_organizations = function(){
481                while(Element('select_organization').options.length > 0) {
482                        Element('select_organization').remove(0);
483                }
484                var handler_org = function(data){
485                        Element('select_organization').options[0] = new Option(get_lang('all'),'all');
486                        if (data != null){
487                                var user_organization = Element('user_organization').value;
488                                for(x = 0; x < data.length; x++) {
489                                        Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]);
490                                        if(user_organization.toUpperCase() == data[x].toUpperCase())
491                                                Element('select_organization').options[x+1].selected = true;
492                                }
493                        }
494                }               
495                cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org);               
496        }
497
498        emQuickCatalogSearch.prototype.changeOptions = function(type){ 
499
500                switch(type){
501                        case 'u':
502                                Element('list_values').style.display = 'none';
503                                Element('user_values').style.display = '';
504                                break;
505                       
506                        case 'l':               
507                                Element('user_values').style.display = 'none';
508                                Element('list_values').style.display = '';             
509                                break;
510
511                        case 'p':
512                                Element('list_personal').style.display = '';
513                                Element('list_groups').style.display = 'none'
514                                QuickCatalogSearch.load_catalog();                             
515                                break;
516                       
517                        case 'g':
518                                Element('list_personal').style.display = 'none';
519                                Element('list_groups').style.display = ''
520                                QuickCatalogSearch.load_catalog();
521                                break;
522                }
523
524        }
525
526        emQuickCatalogSearch.prototype.addContacts = function(field) {
527               
528                var border_id   = Element('border_id').value;
529                var select              = Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values');
530                if(field == "to1" || field == "cc1" || field == "cco1"){
531                        field = field.substr(0,field.length - 1);
532                        var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal');
533                }
534                var fieldOpener = Element(field+"_"+border_id);
535                var not_selected = true;
536               
537                for (i = 0 ; i < select.length ; i++) {
538                        if (select.options[i].selected && select.options[i].value != '-1') {
539                                if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length - 1))){
540                                        fieldOpener.value += ",";
541                                }
542                                fieldOpener.value += select.options[i].value + ",";
543                                not_selected = false;
544                                select.options[i].selected = false;
545                        }
546                }
547               
548                if(not_selected)
549                        return false;
550                       
551                if(field != 'to'){
552                        a_link = Element("a_"+field+"_link_"+border_id);
553                        if(a_link)
554                                a_link.onclick();
555                }
556        }
557       
558        emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){
559
560                if(itemSearch && Element('search_for').value.length < preferences.search_characters_number){
561                        alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
562                        Element('search_for').focus();
563                        return false;
564                }
565                var organization = Element('select_organization').value;               
566                var search               = itemSearch ? Element('search_for').value : '';
567                var catalog              = Element('select_catalog').value;
568
569                var handler_searchResults = function(data){
570                        Element('msg_search').style.visibility = 'hidden';
571                        if(data.error){
572                                alert(get_lang('More than %1 results. Please, try to refine your search.',data.maxResult));
573                                return false;
574                        }else if(data.users.length == 0 && data.groups.length == 0){
575                                alert(get_lang('None result was found.'));
576                        }
577
578                       
579                        var group = Element('list_span');
580                        var user  = Element('user_span');       
581                        if(is_ie){
582                                group.innerHTML = '';
583                                user.innerHTML = '';
584                        }
585                        else {
586                                group = Element('list_values');
587                                user  = Element('user_values');
588                                for(var i = 0;i < group.options.length; i++)                           
589                                        group.options[i--] = null;
590                                for(var i = 0;i < user.options.length; i++)                             
591                                        user.options[i--] = null;
592                        }
593
594                        var arr         = new Array(data.maxResult);
595
596                        for(i = 0; data.groups && i < data.groups.length; i++) {
597                                // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
598                                if(is_ie)
599                                        arr[i] = '<option value="'+'&quot;'+data.groups[i].name+'&quot; &lt;'+data.groups[i].email+'&gt;">'+data.groups[i].name+' ('+data.groups[i].email+')'+'</option>';
600                                else
601                                        group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>');
602                        }
603       
604                       
605                        if(is_ie)
606                                group.innerHTML = '<select multiple style="display:none;width:580px" size="14" id="list_values">'+ arr.join() +'</select>';
607
608                        arr = new Array(data.maxResult);
609                       
610                        for(i = 0; data.users && i < data.users.length; i++) {
611                        /*******************************************************************************************/
612                        /* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela,
613                        ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o
614                        resultado apresentado em tela sera exibido de maneira mais apresentavel;
615                        */
616                                //verifica se departamento eh null ou nao;
617                                var department = data.users[i].department ? " - " + data.users[i].department : "";
618                                //verifica se email eh null ou nao;
619                                var email = data.users[i].email ? data.users[i].email : "";
620
621                                // Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
622                                if(is_ie)
623                                        arr[i] = '<option value="'+'&quot;'+data.users[i].name+'&quot; &lt;'+email+'&gt;">'+data.users[i].name+' ('+email+')'+department+'</option>';
624                                else {
625                                        user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email;
626                                }
627                        }
628       
629                        if(is_ie)
630                                user.innerHTML = '<select multiple style="width:580px" size="14" id="user_values">'+ arr.join() +'</select>';
631
632                        // Display entries found.
633                        var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u';
634                        Element("type_"+type).checked = true;
635                        QuickCatalogSearch.changeOptions(type);
636                }
637
638                Element('msg_search').style.visibility = 'visible';
639                cExecute ("$this.ldap_functions.catalogsearch&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults);
640        }
641
642       
643/* Build the Object */
644        //QuickCatalogSearch;
645        QuickCatalogSearch = new emQuickCatalogSearch();
Note: See TracBrowser for help on using the repository browser.