source: branches/2.3/expressoMail1_2/js/QuickCatalogSearch.js @ 5102

Revision 5102, 26.3 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #2275 - Resultado mal formatado na Busca de endereços com F9.

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