]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/network.js
test for session timeout
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / network.js
1 dump('entering util/network.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.network = function () {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         // Place a test here for network connectivity
8         // this.offline = true;
9
10         return this;
11 };
12
13 util.network.prototype = {
14
15         // Flag for whether the staff client should act as if it were offline or not
16         'offline' : false,
17
18         'link_id' : 0,
19
20         'simple_request' : function(id,params,f) {
21                 return this.request(api[id].app,api[id].method,params,f);
22         },
23
24         'request' : function (app,name,params,f) {
25                 try {
26                         var obj = this;
27                         var sparams = js2JSON(params);
28                         obj.error.sdump('D_SES','request '+app+' '+name+' '+sparams.slice(1,sparams.length-1)+
29                                 '\nResult #' + (++obj.link_id) + ( f ? ' asynced' : ' synced' ) );
30                         var request = new RemoteRequest( app, name );
31                         for(var index in params) {
32                                 request.addParam(params[index]);
33                         }
34         
35                         if (f)  {
36                                 request.setCompleteCallback(
37                                         function(req) {
38                                                 obj.error.sdump('D_SES_RESULT','asynced result #' + obj.link_id + '\n\n' + 
39                                                         js2JSON(req.getResultObject()));
40                                                         obj.test_session_timeout(req);
41                                                 f(req);
42                                         }
43                                 );
44                                 request.send(false);
45                                 return null;
46                         } else {
47                                 request.send(true);
48                                 obj.test_session_timeout(request);
49                                 var result = request.getResultObject();
50                                 this.error.sdump('D_SES_RESULT','synced result #' + obj.link_id + '\n\n' + js2JSON(result));
51                                 return result;
52                         }
53
54                 } catch(E) {
55                         if (instanceOf(E,perm_ex)) {
56                                 alert('permission exception: ' + js2JSON(E));
57                         }
58                         throw(E);
59                 }
60         },
61
62         'test_session_timeout' : function(req) {
63                 try {
64                         var robj = req.getResultObject();
65                         if (robj.ilsevent && robj.ilsevent == 1001) {
66                                 alert("Your session has timed out.  In the future we may give you the ability to log back in without losing your work, but for now, the behavior at this point is undefined and this message will almost certainly be followed by error messages.  Please logout of the staff client and then back in.");
67                         }
68                 } catch(E) {
69                         this.error.sdump('D_ERROR',E);
70                 }
71         }
72 }
73
74 /*
75 function sample_callback(request) {
76         var result = request.getResultObject();
77 }
78 */
79
80 dump('exiting util/network.js\n');