source: branches/1.2/contactcenter/js/connector.js @ 2

Revision 2, 7.7 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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/xml');
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                                //showMessage(e);
114                        }
115                }
116
117                try
118                {
119                        if (method == '' || method == 'GET')
120                        {
121                                if (typeof(handler) == 'function')
122                                {
123                                        oxmlhttp.onreadystatechange = sub_handler;
124                                }
125                                oxmlhttp.open("GET",target,true);
126                                oxmlhttp.send(null);
127                        }
128                        else if (method == 'POST')
129                        {
130                                if (typeof(handler) == 'function')
131                                {
132                                        oxmlhttp.onreadystatechange = sub_handler;
133                                }
134                                oxmlhttp.open("POST",target, true);
135                                oxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
136                                oxmlhttp.send(data);
137                                //oxmlhttp.setRequestHeader('Content-Type','multipart/form-data; boundary=-----------------------------1156053686807595044986274307');
138                                //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');
139                        }
140                }
141                catch(e)
142                {
143                        //showMessage(e);
144                }
145               
146                return true;
147        }
148
149        cConnector.prototype.cancelRequest = function (id)
150        {
151                if (!this.requests[id])
152                {
153                        return false;
154                }
155
156                this.requests[id].abort();
157        }
158
159        cConnector.prototype.setProgressContent = function (state, content)
160        {
161                switch (state)
162                {
163                        case 0:
164                        case 'UNINITIALIZED':
165                                this.progressContents[0] = content;
166                                break;
167
168                        case 1:
169                        case 'LOADING':
170                                this.progressContents[1] = content;
171                                break;
172
173                        case 2:
174                        case 'LOADED':
175                                this.progressContents[2] = content;
176                                break;
177
178                        case 3:
179                        case 'INTERACTIVE':
180                                this.progressContents[3] = content;
181                                break;
182
183                        case 4:
184                        case 'COMPLETED':
185                                this.progressContents[4] = content;
186                                break;
187
188                        default:
189                                throw('INVALID STATE!');
190                }
191        }
192
193        cConnector.prototype.setProgressHolder = function (holder)
194        {
195                var objHolder;
196               
197                if (typeof(holder) == 'string')
198                {
199                        objHolder = Element(holder);
200                }
201                else if (typeof(holder) == 'object')
202                {
203                        objHolder = holder;
204                }
205                else
206                {
207                        return false;
208                }
209
210                objHolder.appendChild(this._progressHolder);
211        }
212
213        cConnector.prototype.setProgressBox = function (box, auto)
214        {
215                var objBox;
216
217                if (typeof(box) == 'string')
218                {
219                        objBox = Element(box);
220                }
221                else if (typeof(box) == 'object')
222                {
223                        objBox = box;
224                }
225                else
226                {
227                        return false;
228                }
229
230                this._progressBox = objBox;
231                this._progressBoxAuto = auto ? true : false;
232        }
233
234        cConnector.prototype.setVisible = function (visible)
235        {
236                this.visible = visible;
237                if (!visible)
238                {
239                        this._progressHolder.style.visibility = 'hidden';
240                }
241        }
242
243        /****************************************************************************\
244         *                          Private Methods                                 *
245        \****************************************************************************/
246       
247        cConnector.prototype._setProgressState = function (state)
248        {
249                switch (state)
250                {
251                        case 0:
252                        case 4:
253                                if (this._progressBox != null)
254                                {
255                                        this._progressBox.style.visibility = 'hidden';
256                                        this._progressBox.style.zIndex = '-1';
257                               
258                                        if (is_ie && this._progressBlank)
259                                                this._progressBlank.style.visibility = 'hidden';
260                                }
261                               
262                                this._progressHolder.style.visibility = 'hidden';
263                                this._progressHolder.style.zIndex = '-1';
264                               
265                                if (is_ie && this._progressBlank)
266                                        this._progressBlank.style.visibility = 'hidden';
267                               
268                                break;
269
270                        default:
271                                if (this.visible && Element('cc_connector_visible').value == 'true')
272                                {
273                                        if (this._progressBox != null)
274                                        {
275                                                if (this._progressBoxAuto)
276                                                {
277                                                        if (is_ie)
278                                                        {
279                                                                this._progressBox.style.top = parseInt(document.body.offsetHeight)/2 + 'px';
280                                                                this._progressBox.style.left = parseInt(document.body.offsetWidth)/2 + 'px';
281                                                                this._progressBlank = document.getElementById('divBlank');                                                             
282                                                                if(! this._progressBlank ) {
283                                                                        document.body.insertAdjacentHTML("beforeEnd", '<iframe id="divBlank" src="about:blank" style="position:absolute" scrolling="no" frameborder="0"></iframe>');
284                                                                        this._progressBlank = document.getElementById('divBlank');
285                                                                        this._progressBlank.style.top = parseInt(document.body.offsetHeight)/2 + 'px';
286                                                                        this._progressBlank.style.left = parseInt(document.body.offsetWidth)/2 + 'px';
287                                                                        this._progressBlank.style.height = "36px";
288                                                                        this._progressBlank.style.width = "130px";
289                                                                }
290                                                        }
291                                                        else
292                                                        {
293                                                                this._progressBox.style.top = parseInt(window.innerHeight)/2 + parseInt(window.pageYOffset) - this._progressBox.style.height/2 + 'px';
294                                                                this._progressBox.style.left = parseInt(window.innerWidth)/2 + parseInt(window.pageXOffset) - this._progressBox.style.width/2 + 'px';
295                                                        }
296                                                }
297                                                this._progressBox.style.visibility = 'visible';
298                                                this._progressBox.style.zIndex = '1000';
299                                        }
300                                       
301                                        this._progressHolder.style.visibility = 'visible';
302                                        this._progressHolder.style.zIndex = '1000';
303                                       
304                                        this._progressHolder.innerHTML = this.progressContents[state] ? this.progressContents[state] : '';
305
306                                        if(is_ie) {
307                                                this._progressBlank.style.visibility = 'visible';
308                                                this._progressBlank .style.zIndex = '999';
309                                        }                                       
310                                       
311                                }
312                }
313        }
Note: See TracBrowser for help on using the repository browser.