[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 - Add Group |
---|
| 16 | * |
---|
| 17 | * USAGE INSTRUCTIONS |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | function cAddGroup () |
---|
| 21 | { |
---|
| 22 | // Private |
---|
| 23 | this._card; |
---|
| 24 | this._button = new Array(); |
---|
| 25 | |
---|
| 26 | // Public |
---|
| 27 | this.window; |
---|
| 28 | this.afterSave; |
---|
| 29 | this.load; |
---|
| 30 | |
---|
| 31 | // Constructor |
---|
| 32 | var wHeight = 0; |
---|
| 33 | |
---|
| 34 | // Elements |
---|
| 35 | this.title = Element('title'); |
---|
| 36 | this.contact_in_list = Element('contact_in_list'); |
---|
| 37 | this.group_id = Element('group_id'); |
---|
| 38 | |
---|
[4502] | 39 | this.old_contacts_in_list = new Array(); |
---|
| 40 | |
---|
[2] | 41 | ccAGWinHeight = 'ccAGWinHeightMO'; |
---|
| 42 | |
---|
| 43 | if (is_ie) |
---|
| 44 | ccAGWinHeight = 'ccAGWinHeightIE'; |
---|
| 45 | |
---|
| 46 | wHeight = Element(ccAGWinHeight).value; |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | this.window = new dJSWin({ |
---|
| 50 | id: 'ccAddGroup DOM', |
---|
| 51 | content_id: 'ccAddGroupContent', |
---|
| 52 | width: '700px', |
---|
| 53 | height: wHeight+'px', |
---|
| 54 | title_color: '#3978d6', |
---|
| 55 | bg_color: '#eee', |
---|
| 56 | title: Element('ccAGTitle').value, |
---|
| 57 | title_text_color: 'white', |
---|
| 58 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
| 59 | border: true }); |
---|
| 60 | |
---|
| 61 | this.window.draw(); |
---|
| 62 | |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /*! |
---|
| 66 | @method associateAsButton |
---|
| 67 | @abstract Associates the button functions with the spacified DOM Element |
---|
| 68 | @author Raphael Derosso Pereira |
---|
| 69 | |
---|
| 70 | @param div DOMElement The HTML DOM element that will "host" the |
---|
| 71 | plugin button. |
---|
| 72 | |
---|
| 73 | @param func function The function that returns the data to be used |
---|
| 74 | to pre-populate the quickAdd fields. The return format MUST be |
---|
| 75 | an Array like: |
---|
| 76 | |
---|
| 77 | var return_data = new Array(); |
---|
| 78 | return_data[0] = <value>; // Value for the first field |
---|
| 79 | return_data[1] = <value>; // Value for the second field |
---|
| 80 | ... |
---|
| 81 | |
---|
| 82 | */ |
---|
| 83 | cAddGroup.prototype.associateAsButton = function (div) |
---|
| 84 | { |
---|
| 85 | var _this = this; |
---|
| 86 | div.onclick = function() { |
---|
| 87 | |
---|
| 88 | if (_this.load) { |
---|
| 89 | switch (typeof(_this.load)) { |
---|
| 90 | |
---|
| 91 | case 'function': |
---|
| 92 | _this.load(); |
---|
| 93 | break; |
---|
| 94 | |
---|
| 95 | case 'string': |
---|
| 96 | eval(_this.load); |
---|
| 97 | break; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | }; |
---|
| 101 | |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /*! |
---|
| 105 | |
---|
| 106 | @method send |
---|
| 107 | @abstract Sends data to server |
---|
| 108 | @author Raphael Derosso Pereira |
---|
| 109 | |
---|
| 110 | */ |
---|
| 111 | cAddGroup.prototype.send = function () |
---|
| 112 | { |
---|
| 113 | var _this = this; |
---|
| 114 | |
---|
| 115 | var handler = function (responseText) |
---|
| 116 | { |
---|
| 117 | Element('cc_debug').innerHTML = responseText; |
---|
| 118 | var data = unserialize(responseText); |
---|
| 119 | |
---|
| 120 | if (!data || typeof(data) != 'object') |
---|
| 121 | { |
---|
| 122 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 123 | return; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | //showMessage(data['msg']); |
---|
| 127 | |
---|
[4477] | 128 | if (data['status'] != 'ok' && data['status'] != 'warning') |
---|
[2] | 129 | { |
---|
| 130 | return; |
---|
| 131 | } |
---|
[4766] | 132 | |
---|
[4477] | 133 | if(data['status'] == 'warning') |
---|
| 134 | showMessage(data['msg']); |
---|
[2] | 135 | |
---|
| 136 | _this.clear(); |
---|
| 137 | _this.window.close(); |
---|
| 138 | |
---|
| 139 | if (_this.afterSave) |
---|
| 140 | { |
---|
| 141 | switch (typeof(_this.afterSave)) |
---|
| 142 | { |
---|
| 143 | case 'function': |
---|
| 144 | _this.afterSave(); |
---|
| 145 | break; |
---|
| 146 | |
---|
| 147 | case 'string': |
---|
| 148 | eval(_this.afterSave); |
---|
| 149 | break; |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | var sdata = new Array(); |
---|
| 155 | var empty = true; |
---|
| 156 | |
---|
| 157 | sdata[0] = this.title.value; |
---|
[4766] | 158 | var contacts = new Array(); |
---|
[4502] | 159 | var old_contacts = new Array(); |
---|
[2] | 160 | |
---|
| 161 | for (j =0; j < this.contact_in_list.length; j++) |
---|
[4766] | 162 | contacts[j] = this.contact_in_list.options[j].value; |
---|
[4502] | 163 | for (i = 0; i < this.old_contacts_in_list.length; i++) |
---|
| 164 | old_contacts[i] = this.old_contacts_in_list[i]; |
---|
[2] | 165 | |
---|
| 166 | if(!this.title.value) { |
---|
[285] | 167 | alert(Element('cc_msg_fill_field_name').value); |
---|
[2] | 168 | this.title.focus(); |
---|
| 169 | return false; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | if(! contacts.length) { |
---|
[285] | 173 | alert(Element('cc_msg_add_contact_to_group').value); |
---|
[2] | 174 | return false; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | sdata[1] = contacts; |
---|
[4766] | 178 | sdata[2] = this.group_id.value == 'undefined' ? sdata[2] = 0 : sdata[2] = this.group_id.value; |
---|
[4502] | 179 | sdata[3] = old_contacts; |
---|
[2] | 180 | var sdata = 'add='+escape(serialize(sdata)); |
---|
| 181 | Connector.newRequest('cAddGroup.Send', CC_url+'add_group', 'POST', handler, sdata); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /*! |
---|
| 185 | |
---|
| 186 | @method clear |
---|
| 187 | @abstract Clear all Plugin Fields |
---|
| 188 | @author Raphael Derosso Pereira |
---|
| 189 | |
---|
| 190 | */ |
---|
| 191 | cAddGroup.prototype.clear = function (reload) |
---|
| 192 | { |
---|
| 193 | for (j =0; j < this.contact_in_list.options.length; j++) { |
---|
| 194 | this.contact_in_list.options[j].selected = false; |
---|
| 195 | this.contact_in_list.options[j--] = null; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | if(reload) { |
---|
[294] | 199 | if(Element("contact_list")) |
---|
| 200 | for (j =0; j < Element("contact_list").options.length; j++) { |
---|
| 201 | Element("contact_list").options[j].selected = false; |
---|
| 202 | Element("contact_list").options[j--] = null; |
---|
[2] | 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | this.title.value = ''; |
---|
| 207 | } |
---|
| 208 | |
---|
[4502] | 209 | cAddGroup.prototype.openEditWindow = function() |
---|
| 210 | { |
---|
| 211 | var list_old_contacts = Element('contact_in_list'); |
---|
| 212 | for (var i = 0; i < list_old_contacts.length; i++) |
---|
| 213 | { |
---|
| 214 | this.old_contacts_in_list[i] = list_old_contacts.options[i].value; |
---|
| 215 | } |
---|
| 216 | this.window.open(); |
---|
| 217 | }; |
---|
| 218 | |
---|
[2] | 219 | /* Função para remover contato da lista */ |
---|
| 220 | |
---|
| 221 | cAddGroup.prototype.remUser = function(){ |
---|
[294] | 222 | |
---|
[2] | 223 | select_in = this.contact_in_list; |
---|
| 224 | |
---|
| 225 | for(var i = 0;i < select_in.options.length; i++) |
---|
| 226 | if(select_in.options[i].selected) |
---|
| 227 | select_in.options[i--] = null; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | /* Função para adicionar contato na lista */ |
---|
| 231 | cAddGroup.prototype.addUser = function(){ |
---|
| 232 | |
---|
[3970] | 233 | var select = Element("contact_list"); |
---|
| 234 | var select_in = this.contact_in_list; |
---|
[2] | 235 | |
---|
| 236 | for (i = 0 ; i < select.length ; i++) { |
---|
| 237 | |
---|
| 238 | if (select.options[i].selected) { |
---|
| 239 | isSelected = false; |
---|
| 240 | |
---|
| 241 | for(var j = 0;j < select_in.options.length; j++) { |
---|
| 242 | if(select_in.options[j].value == select.options[i].value){ |
---|
| 243 | isSelected = true; |
---|
| 244 | break; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if(!isSelected){ |
---|
| 249 | |
---|
| 250 | option = document.createElement('option'); |
---|
| 251 | option.value =select.options[i].value; |
---|
| 252 | option.text = select.options[i].text; |
---|
| 253 | option.selected = true; |
---|
| 254 | select_in.options[select_in.options.length] = option; |
---|
| 255 | |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | for (j =0; j < select.options.length; j++) |
---|
| 262 | select .options[j].selected = false; |
---|
| 263 | } |
---|
| 264 | |
---|
[3970] | 265 | cAddGroup.prototype.setSelectedSourceLevel = function(sourceLevel) |
---|
| 266 | { |
---|
| 267 | var ccAGSourceSelect = Element('ccAGSourceSelect'); |
---|
| 268 | var selectedLevel = ''; |
---|
| 269 | for (i = 0; i < ccAGSourceSelect.length; i++) |
---|
| 270 | { |
---|
| 271 | if (ccAGSourceSelect[i].selected == true) |
---|
| 272 | { |
---|
| 273 | selectedLevel = ccAGSourceSelect[i].value; |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | if (selectedLevel != sourceLevel) |
---|
| 278 | { |
---|
| 279 | for (i = 0; i < ccAGSourceSelect.length; i++) |
---|
| 280 | { |
---|
| 281 | if (ccAGSourceSelect[i].value == sourceLevel) |
---|
| 282 | { |
---|
| 283 | ccAGSourceSelect[i].selected = true; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | this.setCatalog(); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | cAddGroup.prototype.loadPersonalContacts = function(){ |
---|
| 291 | handler = function(data) |
---|
| 292 | { |
---|
| 293 | if (data) |
---|
| 294 | { |
---|
| 295 | data = unserialize(data); |
---|
| 296 | if (data.result == 'ok') |
---|
| 297 | { |
---|
| 298 | var options_contact_list = Element('span_contact_list'); |
---|
| 299 | var select_contact_list = '<select id="contact_list" multiple name="contact_list[]" style="width:280px" size="10">'; |
---|
| 300 | select_contact_list += data['contact_list'] + "</select>"; |
---|
| 301 | options_contact_list.innerHTML = select_contact_list; |
---|
| 302 | } |
---|
| 303 | return; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | alert(get_lang('Erro ao carregar contatos pessoais.')); |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | Connector.newRequest('cAddGroup.loadPersonalContacts', CC_url+'get_group', 'GET', handler); |
---|
| 312 | |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | cAddGroup.prototype.clearSourceList = function(){ |
---|
| 316 | var contact_list = Element("contact_list"); |
---|
| 317 | var options = contact_list.options; |
---|
| 318 | for (j =0; j < options.length; j++) { |
---|
| 319 | contact_list.options[j].selected = false; |
---|
| 320 | contact_list.options[j--] = null; |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | // usar ui_data.get_cards_data('all', 1); |
---|
| 325 | cAddGroup.prototype.search = function(){ |
---|
| 326 | |
---|
| 327 | var type = Element('cc_type_contact').value; |
---|
| 328 | |
---|
| 329 | var data = new Array(); |
---|
| 330 | data['fields'] = new Array(); |
---|
| 331 | |
---|
| 332 | // never search groups |
---|
| 333 | data['fields']['id'] = 'contact.id_contact'; |
---|
| 334 | data['fields']['search'] = 'contact.names_ordered'; |
---|
| 335 | |
---|
| 336 | var ccAGSearchTerm = Element('ccAGSearchTerm'); |
---|
| 337 | |
---|
| 338 | data['search_for'] = ccAGSearchTerm.value; |
---|
| 339 | data['ccAddGroup'] = true; |
---|
| 340 | |
---|
| 341 | var invalidChars = /[\%\?]/; |
---|
| 342 | if(invalidChars.test(data['search_for']) || invalidChars.test(data['search_for_area'])){ |
---|
| 343 | showMessage(Element('cc_msg_err_invalid_serch').value); |
---|
| 344 | return; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | var search_for = data['search_for'].split(' '); |
---|
| 348 | var greaterThan4 = false; |
---|
| 349 | var use_length = v_min; |
---|
| 350 | |
---|
| 351 | for (i = 0; i < search_for.length; i++) |
---|
| 352 | { |
---|
| 353 | if (search_for[i].length >= use_length) |
---|
| 354 | { |
---|
| 355 | greaterThan4 = true; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | if (!greaterThan4){ |
---|
| 360 | alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!"); |
---|
| 361 | return; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | var handler = function(data) |
---|
| 365 | { |
---|
| 366 | data = unserialize(data); |
---|
| 367 | |
---|
[4769] | 368 | if( !data || data[0] == 0){ |
---|
| 369 | |
---|
| 370 | var contact_list = Element('contact_list'); |
---|
| 371 | for (var i = contact_list.options.length - 1; i >= 0; i--){ |
---|
| 372 | contact_list.options[i] = null; |
---|
| 373 | } |
---|
| 374 | contact_list.selectedIndex = -1; |
---|
| 375 | return false; |
---|
| 376 | } |
---|
| 377 | |
---|
[3970] | 378 | ccAddGroup.clearSourceList(); |
---|
| 379 | ccAGSearchTerm.value = ''; |
---|
| 380 | if (typeof(data) != 'object') |
---|
| 381 | { |
---|
| 382 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 383 | return false; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | if (data[3].length > 300) |
---|
| 387 | { |
---|
| 388 | alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca."); |
---|
| 389 | |
---|
| 390 | return false; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | var contact_list = Element('contact_list'); |
---|
| 394 | for (var i=0; i < data[3].length; i++) |
---|
| 395 | { |
---|
| 396 | |
---|
[4766] | 397 | var item = data[3][i]; |
---|
| 398 | if (data[8] == 'bo_shared_people_manager' || data[8] == 'bo_people_catalog'){ |
---|
[4767] | 399 | var id = data[3][i][13]; |
---|
[4766] | 400 | } |
---|
| 401 | else |
---|
| 402 | { |
---|
| 403 | var id = 'ldap:'+data[11]+':'+item[6]; |
---|
| 404 | } |
---|
| 405 | var option = document.createElement('OPTION'); |
---|
| 406 | option.value = id; |
---|
| 407 | option.text = item[1]+' ('+item[4]+')'; |
---|
| 408 | contact_list.options[contact_list.options.length] = option; |
---|
[3970] | 409 | } |
---|
| 410 | |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | Connector.newRequest('ccAGSearch', CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
| 414 | |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | cAddGroup.prototype.setCatalog = function(){ |
---|
| 418 | var select = Element('ccAGSourceSelect'); |
---|
| 419 | var catalogLevel = '0.0'; |
---|
| 420 | for (i = 0 ; i < select.length ; i++) { |
---|
| 421 | if (select.options[i].selected) |
---|
| 422 | { |
---|
| 423 | catalogLevel = select.options[i].value; |
---|
| 424 | break; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | } |
---|
| 428 | ccTree.select(catalogLevel); |
---|
| 429 | |
---|
| 430 | if (catalogLevel == '0.0') |
---|
| 431 | { |
---|
| 432 | ccAddGroup.loadPersonalContacts(); |
---|
| 433 | } |
---|
| 434 | else |
---|
| 435 | { |
---|
| 436 | ccAddGroup.clearSourceList(); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | //eval(refresh); |
---|
| 440 | |
---|
| 441 | } |
---|
| 442 | |
---|
[2] | 443 | /* Build the Object */ |
---|
| 444 | var ccAddGroup ; |
---|
| 445 | var cAddGroup_pre_load = document.body.onload; |
---|
| 446 | /* Se for IE, modifica a largura da coluna dos botoes.*/ |
---|
| 447 | if(document.all) |
---|
| 448 | document.getElementById('buttons').width = 140; |
---|
| 449 | |
---|
| 450 | if (is_ie) |
---|
| 451 | { |
---|
| 452 | document.body.onload = function (e) |
---|
| 453 | { |
---|
| 454 | cAddGroup_pre_load(); |
---|
| 455 | ccAddGroup = new cAddGroup(); |
---|
| 456 | |
---|
| 457 | }; |
---|
| 458 | } |
---|
| 459 | else |
---|
| 460 | { |
---|
| 461 | ccAddGroup = new cAddGroup(); |
---|
| 462 | } |
---|