source: trunk/contactcenter/js/connector.js @ 2474

Revision 2474, 7.8 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Correção de problemas no ExpressoContacts? ao exibir contatos.

  • 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        function cConnector()
15        {
16                /* Public Attributes */
17                this.requests = new Array();
18                this.progressContents = new Array();
19                this.visible = false;
20
21                var _this = this;
22
23                /* Private Attributes */
24                this._progressBox = null;
25                this._progressHolder = document.createElement('span');
26                this._progressBlank   = null;
27
28                this._progressHolder.style.visibility = 'hidden';
29//              this._progressHolder.style.backgroundColor = '#db7e22';
30        }
31
32        cConnector.prototype.newRequest = function (id, target, method, handler, data)
33        {
34                var _this = this;
35               
36                if (this.requests[id] && this.requests[id] != null)
37                {
38                       
39                        //this.requests[id].abort();
40                        //delete this.requests[id];
41                        //this.requests[id] = null;
42                       
43                        //setTimeout(function() { _this.newRequest(id, target, method, handler, data); }, 100);
44
45                        return;
46                }
47
48                var oxmlhttp = null;
49               
50                try
51                {
52                        oxmlhttp = new XMLHttpRequest();
53                        oxmlhttp.overrideMimeType('text/plain');
54                }
55                catch (e)
56                {
57                        try
58                        {
59                                oxmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
60                        }
61                        catch (e1)
62                        {
63                                try
64                                {
65                                        oxmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
66                                }
67                                catch (e2)
68                                {
69                                        oxmlhttp = null;
70                                }
71                        }
72                }
73               
74                if (!oxmlhttp)
75                {
76                        return false;
77                }
78               
79                this.requests[id] = oxmlhttp;
80
81                var _this = this;
82               
83                var sub_handler = function ()
84                {
85                        try
86                        {
87                                _this._setProgressState(oxmlhttp.readyState);
88                               
89                                if (oxmlhttp.readyState == 4 )//&& oxmlhttp.channel.status == 0)
90                                {
91                                        switch (oxmlhttp.status)
92                                        {
93                                                case 200:
94                                                        if (typeof(handler) == 'function')
95                                                        {
96                                                                handler(oxmlhttp.responseText);
97                                                        }
98                                                        delete _this.requests[id];
99                                                        _this.requests[id] = null;
100                                                        break;
101
102                                                case 404:
103                                                        alert('Page Not Found!');
104                                                        break;
105
106                                                default:
107                                                        //alert('Some problem while accessing the server. The status is '+oxmlhttp.status);
108                                        }
109                                }
110                        }
111                        catch (e)
112                        {
113                                delete _this.requests[id];
114                                //showMessage(e);
115                        }
116                }
117
118                try
119                {
120                        if ( method != 'POST')
121                                method = 'GET';
122                        oxmlhttp.open( method, target, true);
123                        oxmlhttp.setRequestHeader( 'BackgroundRequest', Date.parse( new Date ) );
124                        if ( method == 'GET')
125                        {
126                                if (typeof(handler) == 'function')
127                                {
128                                        oxmlhttp.onreadystatechange = sub_handler;
129                                }
130                                oxmlhttp.send(null);
131                        }
132                        else if (method == 'POST')
133                        {
134                                if (typeof(handler) == 'function')
135                                {
136                                        oxmlhttp.onreadystatechange = sub_handler;
137                                }
138                                oxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
139                                oxmlhttp.send(data);
140                                //oxmlhttp.setRequestHeader('Content-Type','multipart/form-data; boundary=-----------------------------1156053686807595044986274307');
141                                //oxmlhttp.setRequestHeader('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5');
142                        }
143                }
144                catch(e)
145                {
146                        //showMessage(e);
147                }
148               
149                return true;
150        }
151
152        cConnector.prototype.cancelRequest = function (id)
153        {
154                if (!this.requests[id])
155                {
156                        return false;
157                }
158
159                this.requests[id].abort();
160        }
161
162        cConnector.prototype.setProgressContent = function (state, content)
163        {
164                switch (state)
165                {
166                        case 0:
167                        case 'UNINITIALIZED':
168                                this.progressContents[0] = content;
169                                break;
170
171                        case 1:
172                        case 'LOADING':
173                                this.progressContents[1] = content;
174                                break;
175
176                        case 2:
177                        case 'LOADED':
178                                this.progressContents[2] = content;
179                                break;
180
181                        case 3:
182                        case 'INTERACTIVE':
183                                this.progressContents[3] = content;
184                                break;
185
186                        case 4:
187                        case 'COMPLETED':
188                                this.progressContents[4] = content;
189                                break;
190
191                        default:
192                                throw('INVALID STATE!');
193                }
194        }
195
196        cConnector.prototype.setProgressHolder = function (holder)
197        {
198                var objHolder;
199               
200                if (typeof(holder) == 'string')
201                {
202                        objHolder = Element(holder);
203                }
204                else if (typeof(holder) == 'object')
205                {
206                        objHolder = holder;
207                }
208                else
209                {
210                        return false;
211                }
212
213                objHolder.appendChild(this._progressHolder);
214        }
215
216        cConnector.prototype.setProgressBox = function (box, auto)
217        {
218                var objBox;
219
220                if (typeof(box) == 'string')
221                {
222                        objBox = Element(box);
223                }
224                else if (typeof(box) == 'object')
225                {
226                        objBox = box;
227                }
228                else
229                {
230                        return false;
231                }
232
233                this._progressBox = objBox;
234                this._progressBoxAuto = auto ? true : false;
235        }
236
237        cConnector.prototype.setVisible = function (visible)
238        {
239                this.visible = visible;
240                if (!visible)
241                {
242                        this._progressHolder.style.visibility = 'hidden';
243                }
244        }
245
246        /****************************************************************************\
247         *                          Private Methods                                 *
248        \****************************************************************************/
249       
250        cConnector.prototype._setProgressState = function (state)
251        {
252                switch (state)
253                {
254                        case 0:
255                        case 4:
256                                if (this._progressBox != null)
257                                {
258                                        this._progressBox.style.visibility = 'hidden';
259                                        this._progressBox.style.zIndex = '-1';
260                               
261                                        if (is_ie && this._progressBlank)
262                                                this._progressBlank.style.visibility = 'hidden';
263                                }
264                               
265                                this._progressHolder.style.visibility = 'hidden';
266                                this._progressHolder.style.zIndex = '-1';
267                               
268                                if (is_ie && this._progressBlank)
269                                        this._progressBlank.style.visibility = 'hidden';
270                               
271                                break;
272
273                        default:
274                                if (this.visible && Element('cc_connector_visible').value == 'true')
275                                {
276                                        if (this._progressBox != null)
277                                        {
278                                                if (this._progressBoxAuto)
279                                                {
280                                                        if (is_ie)
281                                                        {
282                                                                this._progressBox.style.top = parseInt(document.body.offsetHeight)/2 + 'px';
283                                                                this._progressBox.style.left = parseInt(document.body.offsetWidth)/2 + 'px';
284                                                                this._progressBlank = document.getElementById('divBlank');                                                             
285                                                                if(! this._progressBlank ) {
286                                                                        document.body.insertAdjacentHTML("beforeEnd", '<iframe id="divBlank" src="about:blank" style="position:absolute" scrolling="no" frameborder="0"></iframe>');
287                                                                        this._progressBlank = document.getElementById('divBlank');
288                                                                        this._progressBlank.style.top = parseInt(document.body.offsetHeight)/2 + 'px';
289                                                                        this._progressBlank.style.left = parseInt(document.body.offsetWidth)/2 + 'px';
290                                                                        this._progressBlank.style.height = "36px";
291                                                                        this._progressBlank.style.width = "130px";
292                                                                }
293                                                        }
294                                                        else
295                                                        {
296                                                                this._progressBox.style.top = parseInt(window.innerHeight)/2 + parseInt(window.pageYOffset) - this._progressBox.style.height/2 + 'px';
297                                                                this._progressBox.style.left = parseInt(window.innerWidth)/2 + parseInt(window.pageXOffset) - this._progressBox.style.width/2 + 'px';
298                                                        }
299                                                }
300                                                this._progressBox.style.visibility = 'visible';
301                                                this._progressBox.style.zIndex = '1000';
302                                        }
303                                       
304                                        this._progressHolder.style.visibility = 'visible';
305                                        this._progressHolder.style.zIndex = '1000';
306                                       
307                                        this._progressHolder.innerHTML = this.progressContents[state] ? this.progressContents[state] : '';
308
309                                        if(is_ie) {
310                                                this._progressBlank.style.visibility = 'visible';
311                                                this._progressBlank .style.zIndex = '999';
312                                        }                                       
313                                       
314                                }
315                }
316        }
Note: See TracBrowser for help on using the repository browser.