source: trunk/contactcenter/js/cc_search.js @ 1598

Revision 1598, 8.7 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #704 - Incluido outro campo para busca utilizando atributo do LDAP

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1  /***************************************************************************\
2  * eGroupWare - Contacts Center                                              *
3  * http://www.egroupware.org                                                 *
4  * Written by:                                                               *
5  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
6  *  sponsored by Thyamad - http://www.thyamad.com                            *
7  * ------------------------------------------------------------------------- *
8  *  This program is free software; you can redistribute it and/or modify it  *
9  *  under the terms of the GNU General Public License as published by the    *
10  *  Free Software Foundation; either version 2 of the License, or (at your   *
11  *  option) any later version.                                               *
12  \***************************************************************************/
13
14        /*
15         * ContactCenter API - Search for Entries Window
16         */
17
18        function ccSearchClass(params)
19        {
20                if (!params || typeof(params) != 'object')
21                {
22                        return false;
23                }
24
25                /* Attributes */
26                this.onSearchFinish = null;
27                this.onClose = null;
28                this.onOpen = null;
29                this.DOMholder = params['holder'];
30                this.DOMdiv = document.createElement('div');
31                this.DOMfields = document.createElement('select');
32                this.DOMinput = document.createElement('input');
33                this.DOMbtn = document.createElement('input');
34                this.DOMbtn2 = document.createElement('input');
35                this.DOMbtn3 = document.createElement('input');
36                this.DOMinputx = document.createElement('input');
37                this.DOMprogHold = document.createElement('div');
38                this.DOMresult = document.createElement('div');
39
40                this.Connector = params['Connector'];
41                this.Connector.setProgressContent(1, params['conn_1_msg']);
42                this.Connector.setProgressContent(2, params['conn_2_msg']);
43                this.Connector.setProgressContent(3, params['conn_3_msg']);
44                this.Connector.setProgressHolder(this.DOMprogHold);
45
46                /* Initialization */
47                var _this = this;
48                var spacer = document.createTextNode(' ');
49
50                this.DOMdiv.style.position = 'relative';
51                this.DOMdiv.style.display = 'inline';
52                this.DOMdiv.style.width    = params['total_width'] ? params['total_width'] : params['input_width'] ? parseInt(params['input_width'])+210 + 'px' : '300px';
53                //this.DOMdiv.style.height   = '25px';
54
55                this.DOMfields.style.width = '50px';
56                this.DOMfields.style.display = 'none';
57                this.DOMfields.style.position = 'absolute';
58                this.DOMfields.style.visibility = 'hidden';
59                //this.DOMfields.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
60
61                this.DOMinput.type = 'text';
62                this.DOMinput.value = params['value'] ? params['value'] : '';
63                this.DOMinput.id = 'DOMinput';
64                this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px';
65                this.DOMinput.onkeypress = function (e) {
66                                if (is_ie)
67                                {
68                                        if (window.event.keyCode == 13) _this.go();
69                                }
70                                else
71                                {
72                                        if (e.which == 13) _this.go();
73                                }
74                        };
75
76                this.DOMinputx.type = 'text';
77                this.DOMinputx.value = params['value'] ? params['value'] : '';
78                this.DOMinputx.id = 'DOMinputx';
79                this.DOMinputx.style.width = '100px';
80                this.DOMinputx.onkeypress = function (e) {
81                                if (is_ie)
82                                {
83                                        if (window.event.keyCode == 13) _this.go();
84                                }
85                                else
86                                {
87                                        if (e.which == 13) _this.go();
88                                }
89                        };
90
91                //this.DOMinput.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
92
93                this.DOMbtn.type = 'button';
94                //this.DOMbtn.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
95                this.DOMbtn.style.width = '60px';
96                this.DOMbtn.value = params['button_text'];
97                this.DOMbtn.onclick = function () {_this.go();};
98
99                this.DOMbtn2.type = 'button';
100                //this.DOMbtn2.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
101                this.DOMbtn2.style.width = '60px';
102                this.DOMbtn2.value = 'Nome:';
103
104                this.DOMbtn3.type = 'button';
105                //this.DOMbtn3.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
106                this.DOMbtn3.style.width = '60px';
107                this.DOMbtn3.value =  v_label;
108                this.DOMprogHold.style.position = 'absolute';
109                this.DOMprogHold.style.top = params['progress_top'] ? params['progress_top'] : '0px';
110                this.DOMprogHold.style.left = params['progress_left'] ? params['progress_left'] : '0px';
111                this.DOMprogHold.style.fontWeight = 'bold';
112                this.DOMprogHold.style.width = params['progress_width'] ? params['progress_width'] : '200px';
113
114                if (params['progress_color'])
115                        this.DOMprogHold.style.color = params['progress_color'];
116               
117                this.DOMresult.style.position = 'absolute';
118                this.DOMresult.style.top = params['progress_top'] ? params['progress_top'] : '0px';
119                this.DOMresult.style.left = params['progress_left'] ? params['progress_left'] : '0px';
120                this.DOMresult.style.fontWeight = 'bold';
121                this.DOMresult.style.width = params['progress_width'] ? params['progress_width'] : '200px';
122
123                if (params['progress_color'])
124                        this.DOMresult.style.color = params['progress_color'];
125
126                this.DOMholder.appendChild(this.DOMdiv);       
127                this.DOMdiv.appendChild(this.DOMfields);
128                this.DOMdiv.appendChild(this.DOMbtn2);
129                this.DOMdiv.appendChild(this.DOMinput);
130                if(v_label != false &  v_atrib != false)
131                    {
132                        this.DOMdiv.appendChild(this.DOMbtn3)
133                        this.DOMdiv.appendChild(this.DOMinputx);
134                    }
135                this.DOMdiv.appendChild(spacer);
136                this.DOMdiv.appendChild(this.DOMbtn);
137                this.DOMdiv.appendChild(this.DOMprogHold);
138                this.DOMdiv.appendChild(this.DOMresult);
139        }
140       
141        ccSearchClass.prototype.go = function()
142        {
143                var data = new Array();
144               
145                this.DOMresult.innerHTML = '';
146
147                //TODO: Make Generic!
148                var type = Element('cc_type_contact').value;
149               
150                data['fields']           = new Array();
151               
152                if (type == 'groups') {
153                        data['fields']['id']     = 'group.id_group';                   
154                        data['fields']['search'] = 'group.title';
155                }               
156                else {                 
157                        data['fields']['id']     = 'contact.id_contact';               
158                        data['fields']['search'] = 'contact.names_ordered';                                     
159                }
160               
161                data['search_for']       = this.DOMinput.value;
162                data['search_for_area']       = this.DOMinputx.value;
163
164                var search_for = data['search_for'].split(' ');
165                var greaterThan4 = false;
166                var use_length = v_min;
167
168                if (search_for.length == 1)
169                    {
170                        if(search_for[0].length == 0)
171                            {
172                                search_for[0] = "*";
173                                data['search_for'] = "*";
174                                use_length = 1;
175                            }
176                    }
177
178                for (i = 0; i < search_for.length; i++)
179                {
180                        if (search_for[i].length >= use_length)
181                        {
182                                greaterThan4 = true;
183                        }
184                }
185
186                if (!greaterThan4){
187                        alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!");
188                        return;
189                }
190
191                var _this = this;
192               
193                var handler = function (responseText)
194                {
195                        var data = new Array();
196                        data = unserialize(responseText);
197                       
198                        if( !data )
199                                return false;
200
201                        if( data[0] == 0 )
202                        {
203                                if (_this.onSearchFinish)
204                                        _this.onSearchFinish(null);
205                                return false;
206                        }
207                       
208                        if (data[3].length > 300)
209                        {
210                                alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca.");
211
212                                if (_this.onSearchFinish)
213                                        _this.onSearchFinish(null);
214
215                                return false;
216                        }
217                       
218                        ccSearchUpdate();
219       
220                        letter = 'search';
221
222                        if ( letter != CC_actual_letter )
223                        {
224                                CC_actual_page = '1';
225                        }
226                        else
227                        {
228                                CC_actual_page = parseInt(data[1]);
229                        }
230       
231                        CC_actual_letter = letter;
232       
233                        if (CC_max_cards[0] == 0)
234                        {
235                                if(CC_visual == 'cards')
236                                        drawCards(0);
237                                else if(CC_visual == 'table')
238                                        drawTable(0);
239       
240                                setPages(0,0);
241                                return;
242                        }
243       
244                        if (data[0] == '0')
245                        {
246                                Element('cc_type_contact').value = data[1];
247                                CC_npages = 0;
248                                CC_actual_page = 1;
249                                if(CC_visual == 'cards')
250                                        drawCards(0);
251                                else if(CC_visual == 'table')
252                                        drawTable(0);
253                                setPages(0,0);
254                                return;
255                        }
256                        else
257                        {
258                                Element('cc_type_contact').value = data[10];
259                        }
260       
261                        if (typeof(data) != 'object')
262                        {
263                                showMessage(Element('cc_msg_err_contacting_server').value);
264                                return;
265                        }
266       
267                        if (typeof(data[3]) == 'object')
268                        {
269                                CC_npages = parseInt(data[0]);
270                                CC_actual_page = parseInt(data[1]);
271                                if(CC_visual == 'cards')
272                                        drawCards(data[3].length, data[10]);
273                                else if(CC_visual == 'table')
274                                        drawTable(data[3].length, data[10]);
275                                resizeWindow();
276                                populateCards(data, data[10]);
277                                setPages(data[0], data[1]);
278                        }
279                        else if (data['error'])
280                        {
281                                showMessage(data['error']);
282                        }
283                        else
284                        {
285                                showMessage(Element('cc_msg_err_contacting_server').value);
286                                return;
287                        }
288                };
289
290                this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
291        }
Note: See TracBrowser for help on using the repository browser.