source: branches/2.2/contactcenter/js/cc_search.js @ 3282

Revision 3282, 9.2 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1251 - Commit principal com adição da melhoria no módulo

  • Property svn:eol-style set to native
  • Property svn:executable set to *
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                this.mount_handler = function (responseText)
26                {
27                        var data = new Array();
28                        data = unserialize(responseText);
29                       
30                        if( !data )
31                                return false;
32
33                        if( data[0] == 0 )
34                        {
35                                if (_this.onSearchFinish)
36                                        _this.onSearchFinish(null);
37                                return false;
38                        }
39                       
40                        if (data[3].length > 300)
41                        {
42                                alert("Mais de 300 resultados foram retornados! \n Favor refinar sua busca.");
43
44                                if (_this.onSearchFinish)
45                                        _this.onSearchFinish(null);
46
47                                return false;
48                        }
49                       
50                        ccSearchUpdate();
51       
52                        letter = 'search';
53
54                        if ( letter != CC_actual_letter )
55                        {
56                                CC_actual_page = '1';
57                        }
58                        else
59                        {
60                                CC_actual_page = parseInt(data[1]);
61                        }
62       
63                        CC_actual_letter = letter;
64       
65                        if (CC_max_cards[0] == 0)
66                        {
67                                if(CC_visual == 'cards')
68                                        drawCards(0);
69                                else if(CC_visual == 'table')
70                                        drawTable(0);
71       
72                                setPages(0,0);
73                                return;
74                        }
75       
76                        if (data[0] == '0')
77                        {
78                                Element('cc_type_contact').value = data[1];
79                                CC_npages = 0;
80                                CC_actual_page = 1;
81                                if(CC_visual == 'cards')
82                                        drawCards(0);
83                                else if(CC_visual == 'table')
84                                        drawTable(0);
85                                setPages(0,0);
86                                return;
87                        }
88                        else
89                        {
90                                Element('cc_type_contact').value = data[10];
91                        }
92       
93                        if (typeof(data) != 'object')
94                        {
95                                showMessage(Element('cc_msg_err_contacting_server').value);
96                                return;
97                        }
98       
99                        if (typeof(data[3]) == 'object')
100                        {
101                                CC_npages = parseInt(data[0]);
102                                CC_actual_page = parseInt(data[1]);
103                                if(CC_visual == 'cards')
104                                        drawCards(data[3].length, data[10]);
105                                else if(CC_visual == 'table')
106                                        drawTable(data[3].length, data[10]);
107                                resizeWindow();
108                                populateCards(data, data[10]);
109                                setPages(data[0], data[1]);
110                        }
111                        else if (data['error'])
112                        {
113                                showMessage(data['error']);
114                        }
115                        else
116                        {
117                                showMessage(Element('cc_msg_err_contacting_server').value);
118                                return;
119                        }
120                };
121
122
123                /* Attributes */
124                this.onSearchFinish = null;
125                this.onClose = null;
126                this.onOpen = null;
127                this.DOMholder = params['holder'];
128                this.DOMdiv = document.createElement('div');
129                this.DOMfields = document.createElement('select');
130                this.DOMinput = document.createElement('input');
131                this.DOMbtn = document.createElement('input');
132                this.DOMbtn2 = document.createElement('input');
133                this.DOMbtn3 = document.createElement('input');
134                this.DOMinputx = document.createElement('input');
135                this.DOMprogHold = document.createElement('div');
136                this.DOMresult = document.createElement('div');
137
138                this.Connector = params['Connector'];
139                this.Connector.setProgressContent(1, params['conn_1_msg']);
140                this.Connector.setProgressContent(2, params['conn_2_msg']);
141                this.Connector.setProgressContent(3, params['conn_3_msg']);
142                this.Connector.setProgressHolder(this.DOMprogHold);
143
144                /* Initialization */
145                var _this = this;
146                var spacer = document.createTextNode(' ');
147
148                this.DOMdiv.style.position = 'relative';
149                this.DOMdiv.style.display = 'inline';
150                this.DOMdiv.style.width    = params['total_width'] ? params['total_width'] : params['input_width'] ? parseInt(params['input_width'])+210 + 'px' : '300px';
151                //this.DOMdiv.style.height   = '25px';
152
153                this.DOMfields.style.width = '50px';
154                this.DOMfields.style.display = 'none';
155                this.DOMfields.style.position = 'absolute';
156                this.DOMfields.style.visibility = 'hidden';
157                //this.DOMfields.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
158
159                this.DOMinput.type = 'text';
160                this.DOMinput.value = params['value'] ? params['value'] : '';
161                this.DOMinput.id = 'DOMinput';
162                this.DOMinput.style.width = params['input_width'] ? params['input_width'] : '200px';
163                this.DOMinput.onkeypress = function (e) {
164                                if (is_ie)
165                                {
166                                        if (window.event.keyCode == 13) _this.go();
167                                }
168                                else
169                                {
170                                        if (e.which == 13) _this.go();
171                                }
172                        };
173
174                this.DOMinputx.type = 'text';
175                this.DOMinputx.value = params['value'] ? params['value'] : '';
176                this.DOMinputx.id = 'DOMinputx';
177                this.DOMinputx.style.width = '100px';
178                this.DOMinputx.onkeypress = function (e) {
179                                if (is_ie)
180                                {
181                                        if (window.event.keyCode == 13) _this.go();
182                                }
183                                else
184                                {
185                                        if (e.which == 13) _this.go();
186                                }
187                        };
188
189                //this.DOMinput.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
190
191                this.DOMbtn.type = 'button';
192                //this.DOMbtn.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
193                this.DOMbtn.style.width = '60px';
194                this.DOMbtn.value = params['button_text'];
195                this.DOMbtn.onclick = function () {_this.go();};
196
197                this.DOMbtn2.type = 'button';
198                //this.DOMbtn2.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
199                this.DOMbtn2.style.width = '60px';
200                this.DOMbtn2.value = 'Nome:';
201
202                this.DOMbtn3.type = 'button';
203                //this.DOMbtn3.style.height = parseInt(this.DOMdiv.style.height)/2 + 'px';
204                this.DOMbtn3.style.width = '60px';
205                this.DOMbtn3.value =  v_label;
206                this.DOMprogHold.style.position = 'absolute';
207                this.DOMprogHold.style.top = params['progress_top'] ? params['progress_top'] : '0px';
208                this.DOMprogHold.style.left = params['progress_left'] ? params['progress_left'] : '0px';
209                this.DOMprogHold.style.fontWeight = 'bold';
210                this.DOMprogHold.style.width = params['progress_width'] ? params['progress_width'] : '200px';
211
212                if (params['progress_color'])
213                        this.DOMprogHold.style.color = params['progress_color'];
214               
215                this.DOMresult.style.position = 'absolute';
216                this.DOMresult.style.top = params['progress_top'] ? params['progress_top'] : '0px';
217                this.DOMresult.style.left = params['progress_left'] ? params['progress_left'] : '0px';
218                this.DOMresult.style.fontWeight = 'bold';
219                this.DOMresult.style.width = params['progress_width'] ? params['progress_width'] : '200px';
220
221                if (params['progress_color'])
222                        this.DOMresult.style.color = params['progress_color'];
223
224                this.DOMholder.appendChild(this.DOMdiv);       
225                this.DOMdiv.appendChild(this.DOMfields);
226                this.DOMdiv.appendChild(this.DOMbtn2);
227                this.DOMdiv.appendChild(this.DOMinput);
228                if(v_label != false &  v_atrib != false)
229                    {
230                        this.DOMdiv.appendChild(this.DOMbtn3)
231                        this.DOMdiv.appendChild(this.DOMinputx);
232                    }
233                this.DOMdiv.appendChild(spacer);
234                this.DOMdiv.appendChild(this.DOMbtn);
235                this.DOMdiv.appendChild(this.DOMprogHold);
236                this.DOMdiv.appendChild(this.DOMresult);
237        }
238       
239        ccSearchClass.prototype.go = function()
240        {
241                if (this.DOMinput.value == '') {
242                        if ((ccTree.actualCatalog != 'bo_group_manager') &&
243                                        (ccTree.actualCatalog != 'bo_shared_group_manager') &&
244                                        (!ccTree.actualCatalogIsExternal)) { //Busca avançada para pessoal e catálogo geral
245                                ccFullSearchVar.showForm();
246                                return;
247                        }
248                }
249                var data = new Array();
250               
251                this.DOMresult.innerHTML = '';
252
253                //TODO: Make Generic!
254                var type = Element('cc_type_contact').value;
255               
256                data['fields']           = new Array();
257               
258                if (type == 'groups') {
259                        data['fields']['id']     = 'group.id_group';                   
260                        data['fields']['search'] = 'group.title';
261                }               
262                else {                 
263                        data['fields']['id']     = 'contact.id_contact';               
264                        data['fields']['search'] = 'contact.names_ordered';                                     
265                }
266               
267                data['search_for']       = this.DOMinput.value;
268                data['search_for_area']       = this.DOMinputx.value;
269               
270                var invalidChars = /[\%\?]/;
271                if(invalidChars.test(data['search_for'])){
272                        showMessage(Element('cc_msg_err_invalid_serch').value);
273                        return;
274                }
275               
276                var search_for = data['search_for'].split(' ');
277                var greaterThan4 = false;
278                var use_length = v_min;
279
280                if (search_for.length == 1)
281                    {
282                        if(search_for[0].length == 0)
283                            {
284                                search_for[0] = "*";
285                                data['search_for'] = "*";
286                                use_length = 1;
287                            }
288                    }
289
290                for (i = 0; i < search_for.length; i++)
291                {
292                        if (search_for[i].length >= use_length)
293                        {
294                                greaterThan4 = true;
295                        }
296                }
297
298                if (!greaterThan4){
299                        alert("Favor fazer a consulta com pelo menos " + v_min + " caracteres!");
300                        return;
301                }
302
303                var _this = this;
304               
305                var handler = this.mount_handler;
306        this.Connector.newRequest('search', CC_url+'search&data='+serialize(data), 'GET', handler);
307        }
Note: See TracBrowser for help on using the repository browser.