[2] | 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'); |
---|
[1598] | 34 | this.DOMbtn2 = document.createElement('input'); |
---|
| 35 | this.DOMbtn3 = document.createElement('input'); |
---|
| 36 | this.DOMinputx = document.createElement('input'); |
---|
[2] | 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'] : ''; |
---|
[1598] | 63 | this.DOMinput.id = 'DOMinput'; |
---|
[2] | 64 | this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px'; |
---|
[285] | 65 | this.DOMinput.onkeypress = function (e) { |
---|
[2] | 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 | }; |
---|
[1598] | 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 | |
---|
[2] | 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 | |
---|
[1598] | 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; |
---|
[2] | 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']; |
---|
[285] | 116 | |
---|
[2] | 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 | |
---|
[285] | 126 | this.DOMholder.appendChild(this.DOMdiv); |
---|
[2] | 127 | this.DOMdiv.appendChild(this.DOMfields); |
---|
[1598] | 128 | this.DOMdiv.appendChild(this.DOMbtn2); |
---|
[2] | 129 | this.DOMdiv.appendChild(this.DOMinput); |
---|
[1598] | 130 | if(v_label != false & v_atrib != false) |
---|
| 131 | { |
---|
| 132 | this.DOMdiv.appendChild(this.DOMbtn3) |
---|
| 133 | this.DOMdiv.appendChild(this.DOMinputx); |
---|
| 134 | } |
---|
[2] | 135 | this.DOMdiv.appendChild(spacer); |
---|
| 136 | this.DOMdiv.appendChild(this.DOMbtn); |
---|
| 137 | this.DOMdiv.appendChild(this.DOMprogHold); |
---|
| 138 | this.DOMdiv.appendChild(this.DOMresult); |
---|
| 139 | } |
---|
[285] | 140 | |
---|
[2] | 141 | ccSearchClass.prototype.go = function() |
---|
| 142 | { |
---|
| 143 | var data = new Array(); |
---|
[285] | 144 | |
---|
[2] | 145 | this.DOMresult.innerHTML = ''; |
---|
| 146 | |
---|
| 147 | //TODO: Make Generic! |
---|
| 148 | var type = Element('cc_type_contact').value; |
---|
[285] | 149 | |
---|
[2] | 150 | data['fields'] = new Array(); |
---|
[285] | 151 | |
---|
[2] | 152 | if (type == 'groups') { |
---|
[285] | 153 | data['fields']['id'] = 'group.id_group'; |
---|
[2] | 154 | data['fields']['search'] = 'group.title'; |
---|
[285] | 155 | } |
---|
| 156 | else { |
---|
| 157 | data['fields']['id'] = 'contact.id_contact'; |
---|
| 158 | data['fields']['search'] = 'contact.names_ordered'; |
---|
[2] | 159 | } |
---|
[285] | 160 | |
---|
[2] | 161 | data['search_for'] = this.DOMinput.value; |
---|
[1598] | 162 | data['search_for_area'] = this.DOMinputx.value; |
---|
[1690] | 163 | |
---|
| 164 | var invalidChars = /[\%\?]/; |
---|
| 165 | if(invalidChars.test(data['search_for'])){ |
---|
| 166 | showMessage(Element('cc_msg_err_invalid_serch').value); |
---|
| 167 | return; |
---|
| 168 | } |
---|
| 169 | |
---|
[284] | 170 | var search_for = data['search_for'].split(' '); |
---|
| 171 | var greaterThan4 = false; |
---|
[1598] | 172 | var use_length = v_min; |
---|
[284] | 173 | |
---|
[1598] | 174 | if (search_for.length == 1) |
---|
| 175 | { |
---|
| 176 | if(search_for[0].length == 0) |
---|
| 177 | { |
---|
| 178 | search_for[0] = "*"; |
---|
| 179 | data['search_for'] = "*"; |
---|
| 180 | use_length = 1; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
[284] | 184 | for (i = 0; i < search_for.length; i++) |
---|
| 185 | { |
---|
[1598] | 186 | if (search_for[i].length >= use_length) |
---|
[284] | 187 | { |
---|
| 188 | greaterThan4 = true; |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | if (!greaterThan4){ |
---|
[1598] | 193 | alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!"); |
---|
[284] | 194 | return; |
---|
| 195 | } |
---|
| 196 | |
---|
[2] | 197 | var _this = this; |
---|
[285] | 198 | |
---|
[2] | 199 | var handler = function (responseText) |
---|
| 200 | { |
---|
[285] | 201 | var data = new Array(); |
---|
| 202 | data = unserialize(responseText); |
---|
| 203 | |
---|
| 204 | if( !data ) |
---|
| 205 | return false; |
---|
[284] | 206 | |
---|
[285] | 207 | if( data[0] == 0 ) |
---|
[2] | 208 | { |
---|
[285] | 209 | if (_this.onSearchFinish) |
---|
| 210 | _this.onSearchFinish(null); |
---|
[2] | 211 | return false; |
---|
| 212 | } |
---|
[285] | 213 | |
---|
| 214 | if (data[3].length > 300) |
---|
[2] | 215 | { |
---|
[285] | 216 | alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca."); |
---|
[284] | 217 | |
---|
[2] | 218 | if (_this.onSearchFinish) |
---|
| 219 | _this.onSearchFinish(null); |
---|
[285] | 220 | |
---|
[2] | 221 | return false; |
---|
| 222 | } |
---|
[285] | 223 | |
---|
| 224 | ccSearchUpdate(); |
---|
| 225 | |
---|
| 226 | letter = 'search'; |
---|
[2] | 227 | |
---|
[285] | 228 | if ( letter != CC_actual_letter ) |
---|
[2] | 229 | { |
---|
[285] | 230 | CC_actual_page = '1'; |
---|
[2] | 231 | } |
---|
[285] | 232 | else |
---|
[284] | 233 | { |
---|
[285] | 234 | CC_actual_page = parseInt(data[1]); |
---|
[284] | 235 | } |
---|
[285] | 236 | |
---|
| 237 | CC_actual_letter = letter; |
---|
| 238 | |
---|
| 239 | if (CC_max_cards[0] == 0) |
---|
[2] | 240 | { |
---|
[285] | 241 | if(CC_visual == 'cards') |
---|
| 242 | drawCards(0); |
---|
| 243 | else if(CC_visual == 'table') |
---|
| 244 | drawTable(0); |
---|
| 245 | |
---|
| 246 | setPages(0,0); |
---|
| 247 | return; |
---|
[2] | 248 | } |
---|
[285] | 249 | |
---|
| 250 | if (data[0] == '0') |
---|
| 251 | { |
---|
| 252 | Element('cc_type_contact').value = data[1]; |
---|
| 253 | CC_npages = 0; |
---|
| 254 | CC_actual_page = 1; |
---|
| 255 | if(CC_visual == 'cards') |
---|
| 256 | drawCards(0); |
---|
| 257 | else if(CC_visual == 'table') |
---|
| 258 | drawTable(0); |
---|
| 259 | setPages(0,0); |
---|
| 260 | return; |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | Element('cc_type_contact').value = data[10]; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | if (typeof(data) != 'object') |
---|
| 268 | { |
---|
| 269 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 270 | return; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | if (typeof(data[3]) == 'object') |
---|
| 274 | { |
---|
| 275 | CC_npages = parseInt(data[0]); |
---|
| 276 | CC_actual_page = parseInt(data[1]); |
---|
| 277 | if(CC_visual == 'cards') |
---|
| 278 | drawCards(data[3].length, data[10]); |
---|
| 279 | else if(CC_visual == 'table') |
---|
| 280 | drawTable(data[3].length, data[10]); |
---|
| 281 | resizeWindow(); |
---|
| 282 | populateCards(data, data[10]); |
---|
| 283 | setPages(data[0], data[1]); |
---|
| 284 | } |
---|
| 285 | else if (data['error']) |
---|
| 286 | { |
---|
| 287 | showMessage(data['error']); |
---|
| 288 | } |
---|
| 289 | else |
---|
| 290 | { |
---|
| 291 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 292 | return; |
---|
| 293 | } |
---|
[2] | 294 | }; |
---|
[1598] | 295 | |
---|
| 296 | this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
[2] | 297 | } |
---|