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 | this.mount_handler = function (responseText) |
---|
26 | { |
---|
27 | var data = new Array(); |
---|
28 | data = unserialize(responseText); |
---|
29 | |
---|
30 | if( !data ) |
---|
31 | return false; |
---|
32 | |
---|
33 | if( data[0] == 0 ) |
---|
34 | { |
---|
35 | if (_this.onSearchFinish) |
---|
36 | _this.onSearchFinish(null); |
---|
37 | return false; |
---|
38 | } |
---|
39 | |
---|
40 | if (data[3].length > 300) |
---|
41 | { |
---|
42 | alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca."); |
---|
43 | |
---|
44 | if (_this.onSearchFinish) |
---|
45 | _this.onSearchFinish(null); |
---|
46 | |
---|
47 | return false; |
---|
48 | } |
---|
49 | |
---|
50 | ccSearchUpdate(); |
---|
51 | |
---|
52 | letter = 'search'; |
---|
53 | |
---|
54 | if ( letter != CC_actual_letter ) |
---|
55 | { |
---|
56 | CC_actual_page = '1'; |
---|
57 | } |
---|
58 | else |
---|
59 | { |
---|
60 | CC_actual_page = parseInt(data[1]); |
---|
61 | } |
---|
62 | |
---|
63 | CC_actual_letter = letter; |
---|
64 | |
---|
65 | if (CC_max_cards[0] == 0) |
---|
66 | { |
---|
67 | if(CC_visual == 'cards') |
---|
68 | drawCards(0); |
---|
69 | else if(CC_visual == 'table') |
---|
70 | drawTable(0); |
---|
71 | |
---|
72 | setPages(0,0); |
---|
73 | return; |
---|
74 | } |
---|
75 | |
---|
76 | if (data[0] == '0') |
---|
77 | { |
---|
78 | Element('cc_type_contact').value = data[1]; |
---|
79 | CC_npages = 0; |
---|
80 | CC_actual_page = 1; |
---|
81 | if(CC_visual == 'cards') |
---|
82 | drawCards(0); |
---|
83 | else if(CC_visual == 'table') |
---|
84 | drawTable(0); |
---|
85 | setPages(0,0); |
---|
86 | return; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | Element('cc_type_contact').value = data[10]; |
---|
91 | } |
---|
92 | |
---|
93 | if (typeof(data) != 'object') |
---|
94 | { |
---|
95 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | if (typeof(data[3]) == 'object') |
---|
100 | { |
---|
101 | CC_npages = parseInt(data[0]); |
---|
102 | CC_actual_page = parseInt(data[1]); |
---|
103 | if(CC_visual == 'cards') |
---|
104 | drawCards(data[3].length, data[10]); |
---|
105 | else if(CC_visual == 'table') |
---|
106 | drawTable(data[3].length, data[10]); |
---|
107 | resizeWindow(); |
---|
108 | populateCards(data, data[10]); |
---|
109 | setPages(data[0], data[1]); |
---|
110 | } |
---|
111 | else if (data['error']) |
---|
112 | { |
---|
113 | showMessage(data['error']); |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
118 | return; |
---|
119 | } |
---|
120 | }; |
---|
121 | |
---|
122 | |
---|
123 | /* Attributes */ |
---|
124 | this.onSearchFinish = null; |
---|
125 | this.onClose = null; |
---|
126 | this.onOpen = null; |
---|
127 | this.DOMholder = params['holder']; |
---|
128 | this.DOMdiv = document.createElement('div'); |
---|
129 | this.DOMfields = document.createElement('select'); |
---|
130 | this.DOMinput = document.createElement('input'); |
---|
131 | this.DOMbtn = document.createElement('input'); |
---|
132 | this.DOMbtn2 = document.createElement('input'); |
---|
133 | this.DOMbtn3 = document.createElement('input'); |
---|
134 | this.DOMinputx = document.createElement('input'); |
---|
135 | this.DOMprogHold = document.createElement('div'); |
---|
136 | this.DOMresult = document.createElement('div'); |
---|
137 | |
---|
138 | this.Connector = params['Connector']; |
---|
139 | this.Connector.setProgressContent(1, params['conn_1_msg']); |
---|
140 | this.Connector.setProgressContent(2, params['conn_2_msg']); |
---|
141 | this.Connector.setProgressContent(3, params['conn_3_msg']); |
---|
142 | this.Connector.setProgressHolder(this.DOMprogHold); |
---|
143 | |
---|
144 | /* Initialization */ |
---|
145 | var _this = this; |
---|
146 | var spacer = document.createTextNode(' '); |
---|
147 | |
---|
148 | this.DOMdiv.style.position = 'relative'; |
---|
149 | this.DOMdiv.style.display = 'inline'; |
---|
150 | this.DOMdiv.style.width = '500px';//params['total_width'] ? params['total_width'] : params['input_width'] ? parseInt(params['input_width'])+210 + 'px' : '300px'; |
---|
151 | //this.DOMdiv.style.height = '25px'; |
---|
152 | |
---|
153 | this.DOMfields.style.width = '50px'; |
---|
154 | this.DOMfields.style.display = 'none'; |
---|
155 | this.DOMfields.style.position = 'absolute'; |
---|
156 | this.DOMfields.style.visibility = 'hidden'; |
---|
157 | //this.DOMfields.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
158 | |
---|
159 | this.DOMinput.type = 'text'; |
---|
160 | this.DOMinput.value = params['value'] ? params['value'] : ''; |
---|
161 | this.DOMinput.id = 'DOMinput'; |
---|
162 | this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px'; |
---|
163 | this.DOMinput.onkeypress = function (e) { |
---|
164 | if (is_ie) |
---|
165 | { |
---|
166 | if (window.event.keyCode == 13) _this.go(); |
---|
167 | } |
---|
168 | else |
---|
169 | { |
---|
170 | if (e.which == 13) _this.go(); |
---|
171 | } |
---|
172 | }; |
---|
173 | |
---|
174 | this.DOMinputx.type = 'text'; |
---|
175 | this.DOMinputx.value = params['value'] ? params['value'] : ''; |
---|
176 | this.DOMinputx.id = 'DOMinputx'; |
---|
177 | this.DOMinputx.style.width = '100px'; |
---|
178 | this.DOMinputx.onkeypress = function (e) { |
---|
179 | if (is_ie) |
---|
180 | { |
---|
181 | if (window.event.keyCode == 13) _this.go(); |
---|
182 | } |
---|
183 | else |
---|
184 | { |
---|
185 | if (e.which == 13) _this.go(); |
---|
186 | } |
---|
187 | }; |
---|
188 | |
---|
189 | //this.DOMinput.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
190 | |
---|
191 | this.DOMbtn.type = 'button'; |
---|
192 | //this.DOMbtn.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
193 | this.DOMbtn.style.width = '60px'; |
---|
194 | this.DOMbtn.value = params['button_text']; |
---|
195 | this.DOMbtn.onclick = function () {_this.go();}; |
---|
196 | |
---|
197 | this.DOMbtn2.type = 'text'; |
---|
198 | //this.DOMbtn2.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
199 | this.DOMbtn2.style.width = '60px'; |
---|
200 | this.DOMbtn2.disabled = 'disabled'; |
---|
201 | this.DOMbtn2.value = 'Nome:'; |
---|
202 | |
---|
203 | this.DOMbtn3.type = 'text'; |
---|
204 | //this.DOMbtn3.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
205 | this.DOMbtn3.style.width = '60px'; |
---|
206 | this.DOMbtn3.disabled = 'disabled'; |
---|
207 | this.DOMbtn3.value = v_label + ':'; |
---|
208 | |
---|
209 | this.DOMprogHold.style.position = 'absolute'; |
---|
210 | this.DOMprogHold.style.top = params['progress_top'] ? params['progress_top'] : '0px'; |
---|
211 | this.DOMprogHold.style.left = params['progress_left'] ? params['progress_left'] : '0px'; |
---|
212 | this.DOMprogHold.style.fontWeight = 'bold'; |
---|
213 | this.DOMprogHold.style.width = params['progress_width'] ? params['progress_width'] : '200px'; |
---|
214 | |
---|
215 | if (params['progress_color']) |
---|
216 | this.DOMprogHold.style.color = params['progress_color']; |
---|
217 | |
---|
218 | this.DOMresult.style.position = 'absolute'; |
---|
219 | this.DOMresult.style.top = params['progress_top'] ? params['progress_top'] : '0px'; |
---|
220 | this.DOMresult.style.left = params['progress_left'] ? params['progress_left'] : '0px'; |
---|
221 | this.DOMresult.style.fontWeight = 'bold'; |
---|
222 | this.DOMresult.style.width = params['progress_width'] ? params['progress_width'] : '200px'; |
---|
223 | |
---|
224 | if (params['progress_color']) |
---|
225 | this.DOMresult.style.color = params['progress_color']; |
---|
226 | |
---|
227 | this.DOMholder.appendChild(this.DOMdiv); |
---|
228 | this.DOMdiv.appendChild(this.DOMfields); |
---|
229 | this.DOMdiv.appendChild(this.DOMbtn2); |
---|
230 | this.DOMdiv.appendChild(this.DOMinput); |
---|
231 | if(v_label != false & v_atrib != false) |
---|
232 | { |
---|
233 | this.DOMdiv.appendChild(this.DOMbtn3) |
---|
234 | this.DOMdiv.appendChild(this.DOMinputx); |
---|
235 | } |
---|
236 | this.DOMdiv.appendChild(spacer); |
---|
237 | this.DOMdiv.appendChild(this.DOMbtn); |
---|
238 | this.DOMdiv.appendChild(this.DOMprogHold); |
---|
239 | this.DOMdiv.appendChild(this.DOMresult); |
---|
240 | } |
---|
241 | |
---|
242 | ccSearchClass.prototype.go = function() |
---|
243 | { |
---|
244 | if ( (this.DOMinput.value == '') && (this.DOMinputx.value == '') ) { |
---|
245 | if ((ccTree.actualCatalog != 'bo_group_manager') && |
---|
246 | (ccTree.actualCatalog != 'bo_shared_group_manager') && |
---|
247 | (!ccTree.actualCatalogIsExternal)) { //Busca avançada para pessoal e catálogo geral |
---|
248 | ccFullSearchVar.showForm(); |
---|
249 | return; |
---|
250 | } |
---|
251 | } |
---|
252 | var data = new Array(); |
---|
253 | |
---|
254 | this.DOMresult.innerHTML = ''; |
---|
255 | |
---|
256 | //TODO: Make Generic! |
---|
257 | var type = Element('cc_type_contact').value; |
---|
258 | |
---|
259 | data['fields'] = new Array(); |
---|
260 | |
---|
261 | if (type == 'groups') { |
---|
262 | data['fields']['id'] = 'group.id_group'; |
---|
263 | data['fields']['search'] = 'group.title'; |
---|
264 | } |
---|
265 | else { |
---|
266 | data['fields']['id'] = 'contact.id_contact'; |
---|
267 | data['fields']['search'] = 'contact.names_ordered'; |
---|
268 | } |
---|
269 | |
---|
270 | data['search_for'] = this.DOMinput.value; |
---|
271 | data['search_for_area'] = this.DOMinputx.value; |
---|
272 | |
---|
273 | var invalidChars = /[\%\?]/; |
---|
274 | if(invalidChars.test(data['search_for']) || invalidChars.test(data['search_for_area'])){ |
---|
275 | showMessage(Element('cc_msg_err_invalid_serch').value); |
---|
276 | return; |
---|
277 | } |
---|
278 | |
---|
279 | var search_for = data['search_for'].split(' '); |
---|
280 | var greaterThan4 = false; |
---|
281 | var use_length = v_min; |
---|
282 | |
---|
283 | if (search_for.length == 1) |
---|
284 | { |
---|
285 | if(search_for[0].length == 0) |
---|
286 | { |
---|
287 | search_for[0] = "*"; |
---|
288 | data['search_for'] = "*"; |
---|
289 | use_length = 1; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | for (i = 0; i < search_for.length; i++) |
---|
294 | { |
---|
295 | if (search_for[i].length >= use_length) |
---|
296 | { |
---|
297 | greaterThan4 = true; |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | if (!greaterThan4){ |
---|
302 | alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!"); |
---|
303 | return; |
---|
304 | } |
---|
305 | |
---|
306 | var _this = this; |
---|
307 | |
---|
308 | var handler = this.mount_handler; |
---|
309 | this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
310 | } |
---|