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

Revision 2, 18.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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                id = '1';
11                _this = this;
12
13                var title = 'Escolha um nome:';
14                var el = document.createElement("DIV");
15                el.style.visibility = "hidden";
16                el.style.position = "absolute";
17                el.style.left = "0px";
18                el.style.top = "0px";
19                el.style.width = "0px";
20                el.style.height = "0px";
21                el.id = 'window_QuickCatalogSearch';
22                document.body.appendChild(el);
23                el.innerHTML = "";
24               
25                el.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title+"</font></b>"+
26                "&nbsp;&nbsp;<br><u></u>&nbsp;&nbsp;";
27               
28                if (document.getElementById('select_QuickCatalogSearch') == null){
29                        var cmb = document.createElement("SELECT");
30                        cmb.id = "select_QuickCatalogSearch";
31                        cmb.style.width = "585px";
32                        cmb.size = "12";
33                        cmb.onkeypress = function (e)
34                        {
35                                if (is_ie)
36                                {
37                                        if ((window.event.keyCode) == 13)
38                                        {
39                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
40                                        }
41                                        else if ((window.event.keyCode) == 27)
42                                        {
43                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
44                                        }
45                                }
46                                else
47                                {
48                                        if ((e.keyCode) == 13)
49                                        {
50                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
51                                        }
52                                        else if ((e.keyCode) == 27)
53                                        {
54                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
55                                        }
56                                }
57                        };
58                        el.appendChild(cmb);
59
60                        var space = document.createElement('SPAN');
61                        space.innerHTML = "<BR>&nbsp;&nbsp;";
62                        el.appendChild(space);
63
64                        var butt = document.createElement('BUTTON');
65                        var buttext = document.createTextNode('OK');
66                        butt.id = "QuickCatalogSearch_button_ok";
67                        butt.appendChild(buttext);
68                        butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
69                        el.appendChild(butt);
70
71                        var space = document.createElement('SPAN');
72                        space.innerHTML = "&nbsp;&nbsp;";
73                        el.appendChild(space);
74
75                        var butt = document.createElement('BUTTON');
76                        butt.id = "QuickCatalogSearch_button_close";
77                        var buttext = document.createTextNode('Fechar');
78                        butt.appendChild(buttext);
79                        butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
80                        el.appendChild(butt);
81                }
82                else{
83                        var cmb = document.getElementById('select_QuickCatalogSearch');
84                        cmb.onkeypress = function (e)
85                        {
86                                if (is_ie)
87                                {
88                                        if ((window.event.keyCode) == 13)
89                                        {
90                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
91                                        }
92                                        else if ((window.event.keyCode) == 27)
93                                        {
94                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
95                                        }
96                                }
97                                else
98                                {
99                                        if ((e.keyCode) == 13)
100                                        {
101                                                QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
102                                        }
103                                        else if ((e.keyCode) == 27)
104                                        {
105                                                QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
106                                        }
107                                }
108                        };
109                       
110                       
111                        for (i=0; i<cmb.length; i++)
112                                cmb.options[i--] = null;
113                       
114                        var butt_ok = document.getElementById("QuickCatalogSearch_button_ok");
115                        var butt_close = document.getElementById("QuickCatalogSearch_button_close");
116                        butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
117                        butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
118                }
119
120                for (i=0; i<data.length; i++){
121                        var Op = document.createElement("OPTION");
122                        Op.text = data[i].cn + ' (' + data[i].mail + ')';
123                        if (data[i].phone != '')
124                                Op.text += ' (tel: ' + data[i].phone + ')';
125                        Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
126                        cmb.options.add(Op);
127                }
128                cmb.options[0].selected = true;
129                _this.showWindow(el);
130        }
131       
132        emQuickCatalogSearch.prototype.showWindow = function (div)
133        {
134                if(! div) {
135                        alert(get_lang('The list has no participant.'));
136                        return;
137                }
138                                                       
139                if(! this.arrayWin[div.id]) {
140                        div.style.width = "600px";
141                        div.style.height = "250px";
142                        var title = get_lang('The results were found in the Global Catalog')+':';
143                        var wHeight = div.offsetHeight + "px";
144                        var wWidth =  div.offsetWidth   + "px";
145                        div.style.width = div.offsetWidth - 5;
146
147                        win = new dJSWin({                     
148                                id: 'QuickCatalogSearch_'+div.id,
149                                content_id: div.id,
150                                width: wWidth,
151                                height: wHeight,
152                                title_color: '#3978d6',
153                                bg_color: '#eee',
154                                title: title,                                           
155                                title_text_color: 'white',
156                                button_x_img: '../phpgwapi/images/winclose.gif',
157                                border: true });
158                       
159                        this.arrayWin[div.id] = win;
160                        win.draw();
161                }
162                else {
163                        win = this.arrayWin[div.id];
164                }
165                //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "";
166                win.open();
167                document.getElementById('select_QuickCatalogSearch').focus();
168        }
169       
170        emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){
171                cm = document.getElementById('select_QuickCatalogSearch');
172                option_selected = cm.options[cm.selectedIndex].value + ", ";
173                emailList = document.getElementById(field + "_" + ID).value;
174               
175                new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length);
176                document.getElementById(field + "_" + ID).value = new_emailList;
177                document.getElementById(field + "_" + ID).focus();
178               
179                //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
180                this.arrayWin['window_QuickCatalogSearch'].close();
181        }
182       
183        emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){
184                //document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
185                document.getElementById(field + "_" + ID).focus();
186                this.arrayWin['window_QuickCatalogSearch'].close();
187        }
188
189        emQuickCatalogSearch.prototype.close_window = function(id) {
190                this.arrayWin[id].close();
191                var group_values = Element('list_values');
192                var user_values = Element('user_values');       
193        }
194        emQuickCatalogSearch.prototype.showCatalogList = function (border_id){
195                var el = Element('catalog_list');
196
197                if(el) {
198                        Element('border_id').value = border_id;
199                        win = this.arrayWin[el.id];
200                        win.open();
201                        return;         
202                }
203                var border_input   = document.createElement("INPUT");
204                border_input.type  = 'hidden';
205                border_input.id    = 'border_id';
206                border_input.value = border_id;
207                document.body.appendChild(border_input);
208                el = document.createElement("DIV");             
209                el.id = 'catalog_list';
210                document.body.appendChild(el);                 
211                el.style.visibility = "hidden";
212                el.style.position = "absolute";
213                el.style.width = "495px";
214                el.style.height = is_ie ? "360px" : "375px";           
215                el.style.left = "0px";
216                el.style.top = "0px";                   
217                el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+
218                                           "<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>"+
219                                           "<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>"+
220                                           '</table>'+
221                                           '<div id="tab1" align="center"><br>'+
222                                           '<table border="0" cellpading="0" cellspacing="0">'+
223                                           '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+'&nbsp;:</td></tr>'+
224                                           '<tr><td><select id="select_organization" name="select_organization"></select>&nbsp;'+
225                                           '<input type="text" id="search_for" name="search_for" value="" size="17" maxlength="20"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
226                                           '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
227                                           '<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>'+
228                                           '<tr><td>'+
229                                           '<span id="list_span"><select multiple style="display:none;width:400px" size="14" id="list_values"></select></span>'+
230                                           '<span id="user_span"><select multiple style="width:400px" size="14" id="user_values"></select></span>'+
231                                           '</td></tr>'+
232                                           '<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;'+
233                                           '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')">&nbsp;'+
234                                           '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">'+
235                                           '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
236                                           '</table>'+
237                                           '</div>'+
238                                           '<div style="display:none" id="tab2" align="center">'+
239                                           '<br><br><br>'+
240                                           '<table border="0" cellpading="0" cellspacing="0">'+
241                                           '<tr><td>'+get_lang("Select the type of contact that it desires to visualize")+'&nbsp;:</td></tr>'+
242                                           '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type" type="radio" name="type" value="p"/>Pessoas&nbsp;&nbsp;<input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>Grupos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
243                                           '<tr><td>'+
244                                           '<span id="personal_span"><select multiple style="width:400px" size="14" id="list_personal"></select></span>'+
245                                           '<span id="groups_span"><select multiple style="display:none;width:400px" size="14" id="list_groups"></select></span>'+
246                                           '</td></tr>'+
247                                           '<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;'+
248                                           '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')">&nbsp;'+
249                                           '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">'+
250                                           '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
251                                           '</table>'+
252                                           '</div>';
253
254                var title = get_lang('Search in the Global Catalog');
255                var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px";
256                var wWidth =  el.offsetWidth   + "px";
257                el.style.width = el.offsetWidth;
258               
259                Element('search_for').onkeypress = function (e) {
260                        if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) {
261                                QuickCatalogSearch.searchCatalogList(true);
262                        }
263                };
264
265                win = new dJSWin({                     
266                        id: 'win_'+el.id,
267                        content_id: el.id,
268                        width: wWidth,
269                        height: wHeight,
270                        title_color: '#3978d6',
271                        bg_color: '#eee',
272                        title: title,                                           
273                        title_text_color: 'white',
274                        button_x_img: '../phpgwapi/images/winclose.gif',
275                        border: true });
276                       
277                this.arrayWin[el.id] = win;             
278                win.draw();
279                win.open();
280
281                var handler_organizations = function(data){
282                        var user_organization = Element('user_organization').value;
283
284                        for(i = 0; i < data.length; i++) {
285                                Element('select_organization').options[i] = new Option(data[i],data[i]);
286                                if(user_organization.toUpperCase() == data[i].toUpperCase())
287                                        Element('select_organization').options[i].selected = true;
288                        }
289                }
290                cExecute ("$this.ldap_functions.get_organizations&referral=true", handler_organizations);
291               
292                var handler_cc_contacts= function(data){
293                        if(data.length > 0){
294                                var aux = data.split(",");
295                                for(var i=0; i< aux.length; i++){
296                                        QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i];                         
297                                }
298                        }
299                }
300                cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts);
301
302                var handler_cc_groups = function(data){
303                        if(data.length > 0){
304                                var aux = data.split(",");
305                                for(var i=0; i < data.length; i++){
306                                        QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i];                                                             
307                                }       
308                        }
309                }
310                cExecute("$this.db_functions.get_cc_groups",handler_cc_groups);
311       
312        }
313       
314        emQuickCatalogSearch.prototype.select_div = function(element){
315                if(element == 'tab1'){
316                   Element('tab1').style.display = '';
317                   Element('tab2').style.display = 'none';
318                   Element('td1').style.background = '#eee';   
319                   Element('td2').style.background = '#cecece';
320                }
321                if(element == 'tab2'){
322                   Element('tab1').style.display = 'none';
323                   Element('tab2').style.display = '';
324                   Element('td1').style.background = '#cecece';
325                   Element('td2').style.background = '#eee';               
326
327                }
328        }
329       
330        emQuickCatalogSearch.prototype.load_catalog = function(){
331       
332                var _this = this;
333                var content = new Array;
334                var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal');
335               
336                if(Element('list_personal').style.display == 'none'){
337                        content = _this.cc_groups;
338                }else{
339                        content = _this.cc_contacts;
340                }
341                if(select.options.length > 0){
342                        for(var i=0; i < select.options.length; i++){
343                                select.options[i] = null;
344                                i--;
345                        }
346                }
347                for(var i=0; i < content.length; i++){
348                        if(content[i] != undefined){
349                                var aux = content[i].split(";");
350                                var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false);
351                                select[select.length] = opt;
352                        }
353                }
354                content.splice(0,(content.lenght));
355        }
356
357        emQuickCatalogSearch.prototype.changeOptions = function(type){ 
358
359                switch(type){
360                        case 'u':
361                                Element('list_values').style.display = 'none';
362                                Element('user_values').style.display = '';
363                                break;
364                       
365                        case 'l':               
366                                Element('user_values').style.display = 'none';
367                                Element('list_values').style.display = '';             
368                                break;
369
370                        case 'p':
371                                Element('list_personal').style.display = '';
372                                Element('list_groups').style.display = 'none'
373                                QuickCatalogSearch.load_catalog();                             
374                                break;
375                       
376                        case 'g':
377                                Element('list_personal').style.display = 'none';
378                                Element('list_groups').style.display = ''
379                                QuickCatalogSearch.load_catalog();
380                                break;
381                }
382
383        }
384
385        emQuickCatalogSearch.prototype.addContacts = function(field) {
386               
387                var border_id   = Element('border_id').value;
388                var select              = Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values');
389                if(field == "to1" || field == "cc1" || field == "cco1"){
390                        field = field.substr(0,field.length - 1);
391                        var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal');
392                }
393                var fieldOpener = Element(field+"_"+border_id);
394                var not_selected = true;               
395                for (i = 0 ; i < select.length ; i++) {                 
396                        if (select.options[i].selected && select.options[i].value != '-1') {
397                                if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length -1))){
398                                        fieldOpener.value += ",";
399                                }
400                                fieldOpener.value += select.options[i].value + ",";
401                                not_selected = false;
402                                select.options[i].selected = false;
403                        }
404                }
405               
406                if(not_selected)
407                        return false;
408                       
409                if(field != 'to'){
410                        a_link = Element("a_"+field+"_link_"+border_id);
411                        if(a_link)
412                                a_link.onclick();                       
413                }                               
414        }
415       
416        emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){
417
418                if(itemSearch && Element('search_for').value.length == 0){
419                        alert(get_lang('No data to search'));
420                        Element('search_for').focus();
421                        return false;
422                }
423                var organization = Element('select_organization').value;               
424                var search               = itemSearch ? Element('search_for').value : '';
425                var max_result   = 2000;
426
427                var handler_searchResults = function(data){
428
429                        Element('msg_search').style.visibility = 'hidden';
430                        if(data.error){
431                                alert(get_lang('More than %1 results. Please, try to refine your search.',max_result));
432                                return false;
433                        }
434                       
435                        var group = Element('list_span');
436                        var user  = Element('user_span');       
437                        if(is_ie){
438                                group.innerHTML = '';
439                                user.innerHTML = '';
440                        }
441                        else {
442                                group = Element('list_values');
443                                user  = Element('user_values');
444                                for(var i = 0;i < group.options.length; i++)                           
445                                        group.options[i--] = null;
446                                for(var i = 0;i < user.options.length; i++)                             
447                                        user.options[i--] = null;
448                        }
449
450                        var arr         = new Array(max_result);
451                        var display     = Element('type').value == 'l'? 'display:none;' : '';
452
453                        for(i = 0; data.groups && i < data.groups.length; i++) {                       
454                                if(is_ie)
455                                        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>';
456                                else
457                                        group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>');
458                        }
459       
460                        if(is_ie)
461                                group.innerHTML = '<select multiple style="'+display+'width:400px" size="14" id="list_values">'+ arr.join() +'</select>';
462
463                        arr = new Array(max_result);
464                        display = display ? "" : "display:none;";
465                       
466                        for(i = 0; data.users && i < data.users.length; i++) {                 
467                                if(is_ie)
468                                        arr[i] = '<option value="'+'&quot;'+data.users[i].name+'&quot; &lt;'+data.users[i].email+'&gt;">'+data.users[i].name+' ('+data.users[i].email+')'+'</option>';
469                                else
470                                        user.options[i] = new Option(data.users[i].name+' ('+data.users[i].email+')','"'+data.users[i].name+'" <'+data.users[i].email+'>');
471                        }
472       
473                        if(is_ie)
474                                user.innerHTML = '<select multiple style="'+display+'width:400px" size="14" id="user_values">'+ arr.join() +'</select>';
475                }
476
477                Element('msg_search').style.visibility = 'visible';
478                cExecute ("$this.ldap_functions.catalogsearch&max_result="+max_result+"&organization="+organization+"&search_for="+search, handler_searchResults);
479        }
480
481       
482/* Build the Object */
483        var QuickCatalogSearch;
484        QuickCatalogSearch = new emQuickCatalogSearch();
Note: See TracBrowser for help on using the repository browser.