source: sandbox/expresso2.2/contactcenter/js/cc_search.js @ 1662

Revision 1662, 8.5 KB checked in by amuller, 15 years ago (diff)

Ticket #490 - Criação dos códigos de unificação ajax

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