]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/network.js
make things simpler
[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                                                 f(req);
41                                         }
42                                 );
43                                 request.send(false);
44                                 return null;
45                         } else {
46                                 request.send(true);
47                                 var result = request.getResultObject();
48                                 this.error.sdump('D_SES_RESULT','synced result #' + obj.link_id + '\n\n' + js2JSON(result));
49                                 return result;
50                         }
51
52                 } catch(E) {
53                         if (instanceOf(E,perm_ex)) {
54                                 alert('permission exception: ' + js2JSON(E));
55                         }
56                         throw(E);
57                 }
58         }
59 }
60
61 /*
62 function sample_callback(request) {
63         var result = request.getResultObject();
64 }
65 */
66
67 dump('exiting util/network.js\n');