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