source: companies/celepar/contactcenter/js/cc_search.js @ 763

Revision 763, 7.0 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
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                var search_for = data['search_for'].split(' ');
129                var greaterThan4 = false;
130
131                for (i = 0; i < search_for.length; i++)
132                {
133                        if (search_for[i].length >= 4)
134                        {
135                                greaterThan4 = true;
136                        }
137                }
138
139                if (!greaterThan4){
140                        alert("Favor fazer a consulta com pelo menos 4 caracteres!");
141                        return;
142                }
143
144                var _this = this;
145               
146                var handler = function (responseText)
147                {
148                        var data = new Array();
149                        data = unserialize(responseText);
150                       
151                        if( !data )
152                                return false;
153
154                        if( data[0] == 0 )
155                        {
156                                if (_this.onSearchFinish)
157                                        _this.onSearchFinish(null);
158                                return false;
159                        }
160                       
161                        if (data[3].length > 300)
162                        {
163                                alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca.");
164
165                                if (_this.onSearchFinish)
166                                        _this.onSearchFinish(null);
167
168                                return false;
169                        }
170                       
171                        ccSearchUpdate();
172       
173                        letter = 'search';
174
175                        if ( letter != CC_actual_letter )
176                        {
177                                CC_actual_page = '1';
178                        }
179                        else
180                        {
181                                CC_actual_page = parseInt(data[1]);
182                        }
183       
184                        CC_actual_letter = letter;
185       
186                        if (CC_max_cards[0] == 0)
187                        {
188                                if(CC_visual == 'cards')
189                                        drawCards(0);
190                                else if(CC_visual == 'table')
191                                        drawTable(0);
192       
193                                setPages(0,0);
194                                return;
195                        }
196       
197                        if (data[0] == '0')
198                        {
199                                Element('cc_type_contact').value = data[1];
200                                CC_npages = 0;
201                                CC_actual_page = 1;
202                                if(CC_visual == 'cards')
203                                        drawCards(0);
204                                else if(CC_visual == 'table')
205                                        drawTable(0);
206                                setPages(0,0);
207                                return;
208                        }
209                        else
210                        {
211                                Element('cc_type_contact').value = data[10];
212                        }
213       
214                        if (typeof(data) != 'object')
215                        {
216                                showMessage(Element('cc_msg_err_contacting_server').value);
217                                return;
218                        }
219       
220                        if (typeof(data[3]) == 'object')
221                        {
222                                CC_npages = parseInt(data[0]);
223                                CC_actual_page = parseInt(data[1]);
224                                if(CC_visual == 'cards')
225                                        drawCards(data[3].length, data[10]);
226                                else if(CC_visual == 'table')
227                                        drawTable(data[3].length, data[10]);
228                                resizeWindow();
229                                populateCards(data, data[10]);
230                                setPages(data[0], data[1]);
231                        }
232                        else if (data['error'])
233                        {
234                                showMessage(data['error']);
235                        }
236                        else
237                        {
238                                showMessage(Element('cc_msg_err_contacting_server').value);
239                                return;
240                        }
241                };
242               
243                this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
244        }
Note: See TracBrowser for help on using the repository browser.