[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 | |
---|
| 30 | this.DOMholder = params['holder']; |
---|
| 31 | this.DOMdiv = document.createElement('div'); |
---|
| 32 | this.DOMfields = document.createElement('select'); |
---|
| 33 | this.DOMinput = document.createElement('input'); |
---|
| 34 | this.DOMbtn = document.createElement('input'); |
---|
| 35 | this.DOMprogHold = document.createElement('div'); |
---|
| 36 | this.DOMresult = document.createElement('div'); |
---|
| 37 | |
---|
| 38 | this.Connector = params['Connector']; |
---|
| 39 | this.Connector.setProgressContent(1, params['conn_1_msg']); |
---|
| 40 | this.Connector.setProgressContent(2, params['conn_2_msg']); |
---|
| 41 | this.Connector.setProgressContent(3, params['conn_3_msg']); |
---|
| 42 | this.Connector.setProgressHolder(this.DOMprogHold); |
---|
| 43 | |
---|
| 44 | /* Initialization */ |
---|
| 45 | var _this = this; |
---|
| 46 | var spacer = document.createTextNode(' '); |
---|
| 47 | |
---|
| 48 | this.DOMdiv.style.position = 'relative'; |
---|
| 49 | this.DOMdiv.style.display = 'inline'; |
---|
| 50 | this.DOMdiv.style.width = params['total_width'] ? params['total_width'] : params['input_width'] ? parseInt(params['input_width'])+210 + 'px' : '300px'; |
---|
| 51 | //this.DOMdiv.style.height = '25px'; |
---|
| 52 | |
---|
| 53 | this.DOMfields.style.width = '50px'; |
---|
| 54 | this.DOMfields.style.display = 'none'; |
---|
| 55 | this.DOMfields.style.position = 'absolute'; |
---|
| 56 | this.DOMfields.style.visibility = 'hidden'; |
---|
| 57 | //this.DOMfields.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
| 58 | |
---|
| 59 | this.DOMinput.type = 'text'; |
---|
| 60 | this.DOMinput.value = params['value'] ? params['value'] : ''; |
---|
| 61 | this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px'; |
---|
| 62 | this.DOMinput.onkeypress = function (e) { |
---|
| 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 | }; |
---|
| 72 | //this.DOMinput.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
| 73 | |
---|
| 74 | this.DOMbtn.type = 'button'; |
---|
| 75 | //this.DOMbtn.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px'; |
---|
| 76 | this.DOMbtn.style.width = '60px'; |
---|
| 77 | this.DOMbtn.value = params['button_text']; |
---|
| 78 | this.DOMbtn.onclick = function () {_this.go();}; |
---|
| 79 | |
---|
| 80 | this.DOMprogHold.style.position = 'absolute'; |
---|
| 81 | this.DOMprogHold.style.top = params['progress_top'] ? params['progress_top'] : '0px'; |
---|
| 82 | this.DOMprogHold.style.left = params['progress_left'] ? params['progress_left'] : '0px'; |
---|
| 83 | this.DOMprogHold.style.fontWeight = 'bold'; |
---|
| 84 | this.DOMprogHold.style.width = params['progress_width'] ? params['progress_width'] : '200px'; |
---|
| 85 | |
---|
| 86 | if (params['progress_color']) |
---|
| 87 | this.DOMprogHold.style.color = params['progress_color']; |
---|
| 88 | |
---|
| 89 | this.DOMresult.style.position = 'absolute'; |
---|
| 90 | this.DOMresult.style.top = params['progress_top'] ? params['progress_top'] : '0px'; |
---|
| 91 | this.DOMresult.style.left = params['progress_left'] ? params['progress_left'] : '0px'; |
---|
| 92 | this.DOMresult.style.fontWeight = 'bold'; |
---|
| 93 | this.DOMresult.style.width = params['progress_width'] ? params['progress_width'] : '200px'; |
---|
| 94 | |
---|
| 95 | if (params['progress_color']) |
---|
| 96 | this.DOMresult.style.color = params['progress_color']; |
---|
| 97 | |
---|
| 98 | this.DOMholder.appendChild(this.DOMdiv); |
---|
| 99 | this.DOMdiv.appendChild(this.DOMfields); |
---|
| 100 | this.DOMdiv.appendChild(this.DOMinput); |
---|
| 101 | this.DOMdiv.appendChild(spacer); |
---|
| 102 | this.DOMdiv.appendChild(this.DOMbtn); |
---|
| 103 | this.DOMdiv.appendChild(this.DOMprogHold); |
---|
| 104 | this.DOMdiv.appendChild(this.DOMresult); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | ccSearchClass.prototype.go = function() |
---|
| 108 | { |
---|
| 109 | var data = new Array(); |
---|
| 110 | |
---|
| 111 | this.DOMresult.innerHTML = ''; |
---|
| 112 | |
---|
| 113 | //TODO: Make Generic! |
---|
| 114 | var type = Element('cc_type_contact').value; |
---|
| 115 | |
---|
| 116 | data['fields'] = new Array(); |
---|
| 117 | |
---|
| 118 | if (type == 'groups') { |
---|
| 119 | data['fields']['id'] = 'group.id_group'; |
---|
| 120 | data['fields']['search'] = 'group.title'; |
---|
| 121 | } |
---|
| 122 | else { |
---|
| 123 | data['fields']['id'] = 'contact.id_contact'; |
---|
| 124 | data['fields']['search'] = 'contact.names_ordered'; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | data['search_for'] = this.DOMinput.value; |
---|
| 128 | //data['recursive'] = this.recursive.checked ? true : false; |
---|
| 129 | |
---|
| 130 | var _this = this; |
---|
| 131 | |
---|
| 132 | var handler = function (responseText) |
---|
| 133 | { |
---|
| 134 | Element('cc_debug').innerHTML = responseText; |
---|
| 135 | |
---|
| 136 | var data = unserialize(responseText); |
---|
| 137 | |
---|
| 138 | if (!data || !data['status']) |
---|
| 139 | { |
---|
| 140 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 141 | return false; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if (data['status'] == 'empty') |
---|
| 145 | { |
---|
| 146 | //showMessage(data['msg']); |
---|
| 147 | _this.DOMresult.innerHTML = data['msg']; |
---|
| 148 | setTimeout(function(){_this.DOMresult.innerHTML = '';}, 1000); |
---|
| 149 | |
---|
| 150 | if (_this.onSearchFinish) |
---|
| 151 | { |
---|
| 152 | _this.onSearchFinish(null); |
---|
| 153 | } |
---|
| 154 | return false; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | if (data['status'] != 'ok') |
---|
| 158 | { |
---|
| 159 | //showMessage(data['msg']); |
---|
| 160 | _this.DOMresult.innerHTML = data['msg']; |
---|
| 161 | setTimeout(function(){_this.DOMresult.innerHTML = '';}, 1000); |
---|
| 162 | return false; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | //showMessage(data['msg']); |
---|
| 166 | |
---|
| 167 | if (_this.onSearchFinish) |
---|
| 168 | { |
---|
| 169 | _this.onSearchFinish(data['data']); |
---|
| 170 | } |
---|
| 171 | }; |
---|
| 172 | |
---|
| 173 | this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
| 174 | } |
---|