[903] | 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 - Email Gathering Window |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | function ccEmailWinClass(params) |
---|
| 19 | { |
---|
| 20 | if (typeof(params) != 'object') |
---|
| 21 | { |
---|
| 22 | return false; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | this.Connector = new cConnector(); |
---|
| 26 | this.searching = false; |
---|
| 27 | |
---|
| 28 | var _this = this; |
---|
| 29 | var search_params = new Array(); |
---|
| 30 | search_params['holder'] = Element('cc_email_search'); |
---|
| 31 | search_params['total_width'] = '550px'; |
---|
| 32 | search_params['input_width'] = '200px'; |
---|
| 33 | search_params['progress_top'] = '0px'; |
---|
| 34 | search_params['progress_left'] = '380px'; |
---|
| 35 | search_params['progress_color'] = '#3978d6'; |
---|
| 36 | search_params['progress_width'] = '250px'; |
---|
| 37 | search_params['conn_1_msg'] = Element('cc_loading_1').value; |
---|
| 38 | search_params['conn_2_msg'] = Element('cc_loading_2').value; |
---|
| 39 | search_params['conn_3_msg'] = Element('cc_loading_3').value; |
---|
| 40 | search_params['button_text'] = Element('cc_email_search_text').value; |
---|
| 41 | search_params['Connector'] = this.Connector; |
---|
| 42 | |
---|
| 43 | var catalog_params = new Array(); |
---|
| 44 | catalog_params['name'] = 'ccEmailWin.catalogues'; |
---|
| 45 | catalog_params['id_destination'] = 'cc_email_catalogues'; |
---|
| 46 | |
---|
| 47 | this.window = params['window']; |
---|
| 48 | this.search = new ccSearchClass(search_params); |
---|
| 49 | this.catalogues = new ccCatalogTree(catalog_params); |
---|
| 50 | |
---|
| 51 | this.catalogues.afterSetCatalog = function() {_this._getAllEntries();}; |
---|
| 52 | this.catalogues.Connector = this.Connector; |
---|
| 53 | |
---|
| 54 | this.entries = Element('cc_email_win_entries'); |
---|
| 55 | this.to = Element('cc_email_win_to'); |
---|
| 56 | this.cc = Element('cc_email_win_cc'); |
---|
| 57 | this.cco = Element('cc_email_win_cco'); |
---|
| 58 | |
---|
| 59 | this.to_count = 0; |
---|
| 60 | this.cc_count = 0; |
---|
| 61 | this.cco_count = 0; |
---|
| 62 | |
---|
| 63 | this.contents = new Array(); |
---|
| 64 | |
---|
| 65 | this.onOk = null; |
---|
| 66 | |
---|
| 67 | this.entries.style.overflow = 'auto'; |
---|
| 68 | |
---|
| 69 | this._search_set(); |
---|
| 70 | |
---|
| 71 | this.window.buttons.xDIV.onclick = function() {_this.close();}; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | ccEmailWinClass.prototype.setContents = function(data) |
---|
| 75 | { |
---|
| 76 | if (typeof(data) != 'object') |
---|
| 77 | { |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | this.clearAll(); |
---|
| 82 | |
---|
| 83 | if (data['entries']) |
---|
| 84 | { |
---|
| 85 | for (var i in data['entries']) |
---|
| 86 | { |
---|
| 87 | this.entries = new Option(data['entries'][i], i); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if (data['to']) |
---|
| 92 | { |
---|
| 93 | for (var i in data['to']) |
---|
| 94 | { |
---|
| 95 | this.to = new Option(data['to'][i], i); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | if (data['cc']) |
---|
| 100 | { |
---|
| 101 | for (var i in data['cc']) |
---|
| 102 | { |
---|
| 103 | this.cc = new Option(data['cc'][i], i); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | if (data['cco']) |
---|
| 108 | { |
---|
| 109 | for (var i in data['cco']) |
---|
| 110 | { |
---|
| 111 | this.cco = new Option(data['cco'][i], i); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | ccEmailWinClass.prototype.getContents = function() |
---|
| 117 | { |
---|
| 118 | var i; |
---|
| 119 | |
---|
| 120 | this.contents = new Array(); |
---|
| 121 | this.contents['entries'] = new Array(); |
---|
| 122 | this.contents['to'] = new Array(); |
---|
| 123 | this.contents['cc'] = new Array(); |
---|
| 124 | this.contents['cco'] = new Array(); |
---|
| 125 | |
---|
| 126 | for (i = 0; i < this.entries.options.length; i++) |
---|
| 127 | { |
---|
| 128 | this.contents['entries'][this.contents['entries'].length] = this.entries.options[i].text; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | for (i = 0; i < this.to.options.length; i++) |
---|
| 132 | { |
---|
| 133 | this.contents['to'][this.contents['to'].length] = this.to.options[i].text; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | for (i = 0; i < this.cc.options.length; i++) |
---|
| 137 | { |
---|
| 138 | this.contents['cc'][this.contents['cc'].length] = this.cc.options[i].text; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | for (i = 0; i < this.cco.options.length; i++) |
---|
| 142 | { |
---|
| 143 | this.contents['cco'][this.contents['cco'].length] = this.cco.options[i].text; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | return this.contents; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | ccEmailWinClass.prototype.open = function(search) |
---|
| 150 | { |
---|
| 151 | if (!search) { |
---|
| 152 | this.search.DOMinput.value = ''; |
---|
| 153 | this.Connector.setVisible(true); |
---|
| 154 | this.window.open(); |
---|
| 155 | } else { |
---|
| 156 | this.search.DOMinput.value = search; |
---|
| 157 | this.catalogues.select("0.2", search); |
---|
| 158 | this.Connector.setVisible(true); |
---|
| 159 | this.window.open(); |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | ccEmailWinClass.prototype.ok = function() |
---|
| 164 | { |
---|
| 165 | if (this.onOk) |
---|
| 166 | { |
---|
| 167 | this.onOk(this.getContents()); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | this.clearAll(); |
---|
| 171 | this.window.close(); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | ccEmailWinClass.prototype.clearAll = function() |
---|
| 175 | { |
---|
| 176 | // this.clearEntries(); |
---|
| 177 | this.clearTo(); |
---|
| 178 | this.clearCC(); |
---|
| 179 | this.clearCCO(); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | ccEmailWinClass.prototype.clearEntries = function() |
---|
| 183 | { |
---|
| 184 | var length; |
---|
| 185 | |
---|
| 186 | if (this.entries.options.length) |
---|
| 187 | { |
---|
| 188 | length = this.entries.options.length-1; |
---|
| 189 | for (var i = length; i >= 0; i--) |
---|
| 190 | { |
---|
| 191 | this.entries.removeChild(this.entries.options[i]); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | ccEmailWinClass.prototype.clearTo = function() |
---|
| 197 | { |
---|
| 198 | var length; |
---|
| 199 | |
---|
| 200 | if (this.to.options.length) |
---|
| 201 | { |
---|
| 202 | length = this.to.options.length-1; |
---|
| 203 | for (var i = length; i >= 0; i--) |
---|
| 204 | { |
---|
| 205 | this.to.removeChild(this.to.options[i]); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | ccEmailWinClass.prototype.clearCC = function() |
---|
| 211 | { |
---|
| 212 | var length; |
---|
| 213 | |
---|
| 214 | if (this.cc.options.length) |
---|
| 215 | { |
---|
| 216 | length = this.cc.options.length-1; |
---|
| 217 | for (var i = length; i >= 0; i--) |
---|
| 218 | { |
---|
| 219 | this.cc.removeChild(this.cc.options[i]); |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | ccEmailWinClass.prototype.clearCCO = function() |
---|
| 225 | { |
---|
| 226 | var length; |
---|
| 227 | |
---|
| 228 | if (this.cco.options.length) |
---|
| 229 | { |
---|
| 230 | length = this.cco.options.length-1; |
---|
| 231 | for (var i = length; i >= 0; i--) |
---|
| 232 | { |
---|
| 233 | this.cco.removeChild(this.cco.options[i]); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | ccEmailWinClass.prototype.close = function() |
---|
| 239 | { |
---|
| 240 | this.Connector.setVisible(false); |
---|
| 241 | //this.clearAll(); |
---|
| 242 | this.window.close(); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | ccEmailWinClass.prototype.entries_to = function() |
---|
| 246 | { |
---|
| 247 | var i; |
---|
| 248 | var length = this.entries.options.length-1; |
---|
| 249 | for (i = length; i >= 0; i--) |
---|
| 250 | { |
---|
| 251 | if (this.entries.options[i].selected) |
---|
| 252 | { |
---|
| 253 | this.to.options[this.to.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value); |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | ccEmailWinClass.prototype.entries_cc = function() |
---|
| 259 | { |
---|
| 260 | var i; |
---|
| 261 | var length = this.entries.options.length-1; |
---|
| 262 | for (i = length; i >= 0; i--) |
---|
| 263 | { |
---|
| 264 | if (this.entries.options[i].selected) |
---|
| 265 | { |
---|
| 266 | this.cc.options[this.cc.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value); |
---|
| 267 | } |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | ccEmailWinClass.prototype.entries_cco = function() |
---|
| 272 | { |
---|
| 273 | var i; |
---|
| 274 | var length = this.entries.options.length-1; |
---|
| 275 | for (i = length; i >= 0; i--) |
---|
| 276 | { |
---|
| 277 | if (this.entries.options[i].selected) |
---|
| 278 | { |
---|
| 279 | this.cco.options[this.cco.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | ccEmailWinClass.prototype.to_entries = function() |
---|
| 285 | { |
---|
| 286 | var i; |
---|
| 287 | var length = this.to.options.length-1; |
---|
| 288 | for (i = length; i >= 0; i--) |
---|
| 289 | { |
---|
| 290 | if (this.to.options[i].selected) |
---|
| 291 | { |
---|
| 292 | this.to.removeChild(this.to.options[i]); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | ccEmailWinClass.prototype.cc_entries = function() |
---|
| 298 | { |
---|
| 299 | var i; |
---|
| 300 | var length = this.cc.options.length-1; |
---|
| 301 | for (i = length; i >= 0; i--) |
---|
| 302 | { |
---|
| 303 | if (this.cc.options[i].selected) |
---|
| 304 | { |
---|
| 305 | this.cc.removeChild(this.cc.options[i]); |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | ccEmailWinClass.prototype.cco_entries = function() |
---|
| 311 | { |
---|
| 312 | var i; |
---|
| 313 | var length = this.cco.options.length-1; |
---|
| 314 | for (i = length; i >= 0; i--) |
---|
| 315 | { |
---|
| 316 | if (this.cco.options[i].selected) |
---|
| 317 | { |
---|
| 318 | this.cco.removeChild(this.cco.options[i]); |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | /****************************************************************************\ |
---|
| 324 | * Private Methods * |
---|
| 325 | \****************************************************************************/ |
---|
| 326 | |
---|
| 327 | ccEmailWinClass.prototype._search_set = function() |
---|
| 328 | { |
---|
| 329 | var _this = this; |
---|
| 330 | |
---|
| 331 | this.search.onSearchFinish = function (result) |
---|
| 332 | { |
---|
| 333 | if (!result || typeof(result) != 'object') |
---|
| 334 | { |
---|
| 335 | _this.clearEntries(); |
---|
| 336 | _this.searching = false; |
---|
| 337 | return false; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | var sdata = new Array(); |
---|
| 341 | |
---|
| 342 | sdata['ids'] = result; |
---|
| 343 | sdata['fields'] = new Array() |
---|
| 344 | sdata['fields']['names_ordered'] = true; |
---|
| 345 | sdata['fields']['connections'] = true; |
---|
| 346 | |
---|
| 347 | var str_data = 'data='+serialize(sdata); |
---|
| 348 | |
---|
| 349 | _this.Connector.newRequest('email_search', CC_url+'get_multiple_entries', 'POST', _this._getEntriesHandler(), str_data); |
---|
| 350 | }; |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | ccEmailWinClass.prototype._getAllEntries = function(offset) |
---|
| 354 | { |
---|
| 355 | if (this.searching && !offset) |
---|
| 356 | { |
---|
| 357 | return false; |
---|
| 358 | } |
---|
| 359 | /* |
---|
| 360 | this.searching = true; |
---|
| 361 | this.clearEntries(); |
---|
| 362 | this._search_set(); |
---|
| 363 | this.search.DOMinput.value = '*'; |
---|
| 364 | this.search.go(); |
---|
| 365 | this.search.DOMinput.value = ''; |
---|
| 366 | */ |
---|
| 367 | this.searching = true; |
---|
| 368 | |
---|
| 369 | var _this = this; |
---|
| 370 | var str_data; |
---|
| 371 | var sdata; |
---|
| 372 | |
---|
| 373 | sdata = new Array(); |
---|
| 374 | sdata['fields'] = new Array(); |
---|
| 375 | sdata['fields']['names_ordered'] = true; |
---|
| 376 | sdata['fields']['connections'] = true; |
---|
| 377 | sdata['maxlength'] = -1; |
---|
| 378 | |
---|
| 379 | if (offset) |
---|
| 380 | { |
---|
| 381 | sdata['offset'] = offset; |
---|
| 382 | } |
---|
| 383 | else |
---|
| 384 | { |
---|
| 385 | this.clearEntries(); |
---|
| 386 | sdata['new'] = true; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | str_data = 'data='+serialize(sdata); |
---|
| 390 | |
---|
| 391 | var handler = function(responseText) |
---|
| 392 | { |
---|
| 393 | Element('cc_debug').innerHTML = responseText; |
---|
| 394 | var data = unserialize(responseText); |
---|
| 395 | Element('cc_type_contact').value = data['typeContact']; |
---|
| 396 | |
---|
| 397 | if (!data || typeof(data) != 'object') |
---|
| 398 | { |
---|
| 399 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 400 | _this.searching = false; |
---|
| 401 | return false; |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | if (data['status'] != 'ok') |
---|
| 405 | { |
---|
| 406 | _this.search.DOMresult.innerHTML = data['msg']; |
---|
| 407 | setTimeout(function(){_this.search.DOMresult.innerHTML = '';}, 1000); |
---|
| 408 | _this.searching = false; |
---|
| 409 | return false; |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | //_this._updateEntries(data['data']); |
---|
| 413 | eval(data['data']); |
---|
| 414 | |
---|
| 415 | if (!data['final']) |
---|
| 416 | { |
---|
| 417 | _this._getAllEntries(data['offset']); |
---|
| 418 | } |
---|
| 419 | else |
---|
| 420 | { |
---|
| 421 | _this.searching = false; |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | setTimeout(function(){_this.Connector.newRequest('email_search', CC_url+'get_all_entries', 'POST', handler, str_data);}, 50); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | ccEmailWinClass.prototype._getEntriesHandler = function() |
---|
| 429 | { |
---|
| 430 | var _this = this; |
---|
| 431 | |
---|
| 432 | var f = function (responseText) |
---|
| 433 | { |
---|
| 434 | Element('cc_debug').innerHTML = responseText; |
---|
| 435 | var data = unserialize(responseText); |
---|
| 436 | |
---|
| 437 | if (!data) |
---|
| 438 | { |
---|
| 439 | //showMessage(Element('cc_msg_err_invalid_catalog').value); |
---|
| 440 | //showMessage('Error getting user Info'); |
---|
| 441 | _this.searching = false; |
---|
| 442 | return false; |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | _this.clearEntries(); |
---|
| 446 | |
---|
| 447 | if (data['status'] == 'empty') |
---|
| 448 | { |
---|
| 449 | //showMessage(data['msg']); |
---|
| 450 | _this.searching = false; |
---|
| 451 | return false; |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | if (data['status'] != 'ok') |
---|
| 455 | { |
---|
| 456 | //showMessage(data['msg']); |
---|
| 457 | _this.searching = false; |
---|
| 458 | return false; |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | //showMessage(data['msg']); |
---|
| 462 | |
---|
| 463 | _this._updateEntries(data['data']); |
---|
| 464 | |
---|
| 465 | _this.searching = false; |
---|
| 466 | }; |
---|
| 467 | |
---|
| 468 | return f; |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | ccEmailWinClass.prototype._updateEntries = function (data) |
---|
| 472 | { |
---|
| 473 | var name = ''; |
---|
| 474 | var emails = new Array(); |
---|
| 475 | for (var i in data) |
---|
| 476 | { |
---|
| 477 | emails_count = 0; |
---|
| 478 | for (var j in data[i]) |
---|
| 479 | { |
---|
| 480 | if (j == 'names_ordered') |
---|
| 481 | { |
---|
| 482 | name = '"'+data[i][j]+'"'; |
---|
| 483 | } |
---|
| 484 | else if (j == 'connections') |
---|
| 485 | { |
---|
| 486 | for (var k in data[i][j]) |
---|
| 487 | { |
---|
| 488 | if (data[i][j][k]['id_type'] == Element('cc_email_id_type').value) |
---|
| 489 | { |
---|
| 490 | emails[emails.length] = ' <'+data[i][j][k]['connection_value']+'>'; |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | else if (j == 'title') |
---|
| 495 | { |
---|
| 496 | name = '"'+data[i][j]+'"'; |
---|
| 497 | } |
---|
| 498 | else if (j == 'short_name') |
---|
| 499 | { |
---|
| 500 | emails[emails.length] = ' ('+data[i][j]+')'; |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | if (name != '' && emails.length) |
---|
| 505 | { |
---|
| 506 | for (var j in emails) |
---|
| 507 | { |
---|
| 508 | var scroll = this.entries.scrollTop; |
---|
| 509 | this.entries.options[this.entries.options.length] = new Option(name+emails[j], i+'_'+j); |
---|
| 510 | this.entries.scrollTop = scroll; |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | name = ''; |
---|
| 515 | emails = new Array(); |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | /****************************************************************************\ |
---|
| 520 | * Auxiliar Functions * |
---|
| 521 | \****************************************************************************/ |
---|