source: branches/2.3/contactcenter/js/connector.js @ 3176

Revision 3176, 7.9 KB checked in by niltonneto, 14 years ago (diff)

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