[2] | 1 | /***************************************************************************\ |
---|
| 2 | * eGroupWare - Contacts Center * |
---|
| 3 | * http://www.egroupware.org * |
---|
| 4 | * Written by: * |
---|
| 5 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
| 6 | * - Jonas Goes <jqhcb@users.sourceforge.net> * |
---|
| 7 | * sponsored by Thyamad - http://www.thyamad.com * |
---|
| 8 | * ------------------------------------------------------------------------- * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 10 | * under the terms of the GNU General Public License as published by the * |
---|
| 11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 12 | * option) any later version. * |
---|
| 13 | \***************************************************************************/ |
---|
| 14 | |
---|
| 15 | /* |
---|
| 16 | * ContactCenter API - Search for Entries Window |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | function ccSearchWinClass(params) |
---|
| 20 | { |
---|
| 21 | if (!params || typeof(params) != 'object') |
---|
| 22 | { |
---|
| 23 | return false; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | this.window = params['window']; |
---|
| 27 | this.catalogs_area = Element('cc_search_catalogues'); |
---|
| 28 | this.search_for = Element('cc_search_for'); |
---|
| 29 | //this.recursive = Element('cc_search_recursive'); |
---|
| 30 | |
---|
| 31 | this.onSearchFinish = null; |
---|
| 32 | this.onClose = null; |
---|
| 33 | this.onOpen = null; |
---|
| 34 | |
---|
| 35 | /* Populate Catalogues */ |
---|
| 36 | this.catalogues = new ccCatalogTree({name: 'ccSearchWin.catalogues', |
---|
| 37 | id_destination: 'cc_search_catalogues'}); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | ccSearchWinClass.prototype.open = function() |
---|
| 41 | { |
---|
| 42 | if (this.onOpen) |
---|
| 43 | { |
---|
| 44 | this.onOpen(); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | this.window.open(); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | ccSearchWinClass.prototype.close = function() |
---|
| 51 | { |
---|
| 52 | if (this.onClose) |
---|
| 53 | { |
---|
| 54 | this.onClose(); |
---|
| 55 | } |
---|
| 56 | this.window.close(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ccSearchWinClass.prototype.go = function() |
---|
| 60 | { |
---|
| 61 | var data = new Array(); |
---|
| 62 | |
---|
| 63 | //TODO: Make Generic! |
---|
| 64 | data['fields'] = new Array(); |
---|
| 65 | data['fields']['id'] = 'contact.id_contact'; |
---|
| 66 | data['fields']['search'] = 'contact.names_ordered'; |
---|
| 67 | data['search_for'] = this.search_for.value; |
---|
| 68 | //data['recursive'] = this.recursive.checked ? true : false; |
---|
| 69 | |
---|
| 70 | var obj = httpRequestObj(); |
---|
| 71 | var win = this; |
---|
| 72 | |
---|
| 73 | var handler = function () |
---|
| 74 | { |
---|
| 75 | try |
---|
| 76 | { |
---|
| 77 | setLoadingState(obj.readyState); |
---|
| 78 | if (obj.readyState == 4 && obj.status == 200) |
---|
| 79 | { |
---|
| 80 | Element('cc_debug').innerHTML = obj.responseText; |
---|
| 81 | var data = unserialize(obj.responseText); |
---|
| 82 | |
---|
| 83 | if (!data || !data['status']) |
---|
| 84 | { |
---|
| 85 | showMessage('Error Contacting Server'); |
---|
| 86 | return false; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if (data['status'] == 'empty') |
---|
| 90 | { |
---|
| 91 | showMessage(data['msg']); |
---|
| 92 | win.close(); |
---|
| 93 | |
---|
| 94 | if (win.onSearchFinish) |
---|
| 95 | { |
---|
| 96 | win.onSearchFinish(null); |
---|
| 97 | } |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | if (data['status'] != 'ok') |
---|
| 102 | { |
---|
| 103 | showMessage(data['msg']); |
---|
| 104 | return false; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | //showMessage(data['msg']); |
---|
| 108 | win.close(); |
---|
| 109 | |
---|
| 110 | if (win.onSearchFinish) |
---|
| 111 | { |
---|
| 112 | win.onSearchFinish(data['data']); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | catch (e) |
---|
| 117 | { |
---|
| 118 | //showMessage(e); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | httpRequest(obj, CC_url+'search&data='+serialize(data), 'GET', handler); |
---|
| 124 | } |
---|