source: sandbox/2.3-MailArchiver/expressoMail1_2/js/QuickCatalogSearch.js @ 6779

Revision 6779, 29.0 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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