]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js
store/retrieve objects in files
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / OpenILS / data.js
1 dump('entering OpenILS/data.js\n');
2
3 if (typeof OpenILS == 'undefined') OpenILS = {};
4 OpenILS.data = function (mw,G) {
5
6         this.mw = mw; this.G = G;
7
8         var obj = this;
9
10         this.chain = [];
11
12         this.chain.push(
13                 function() {
14                         try {
15                                 obj.au = obj.G.network.request(
16                                         'open-ils.search',
17                                         'open-ils.search.actor.user.session',
18                                         [ obj.G.auth.session.key ]
19                                 );
20                         } catch(E) {
21                                 // what should we do?
22                         }
23                 }
24         );
25
26         function a_get(obj,i) { return [i, obj[i]]; }  // funkiness with loops and closures
27
28         JSAN.use('util.file');
29
30         function gen_fm_retrieval_func(classname,data) {
31                 var app = data[0]; var method = data[1]; var params = data[2];
32                 return function () {
33                         try {
34                                 obj.list[classname] = obj.G.network.request( app, method, params);
35                                 // store an offline copy
36                                 var file = new util.file( obj.mw, obj.G, classname );
37                                 file.set_object( obj.list[classname] );
38
39                         } catch(E) {
40                                 // try offline
41                         }
42                         //obj.hash[classname] = convert_object_list_to_hash( obj.list[classname] );
43                 }
44         }
45
46         obj.G.error.sdump('D_DEBUG','_cacheable_fm_objects = ' + js2JSON(this._cacheable_fm_objects) + '\n');
47
48         for (var i in this._cacheable_fm_objects) {
49                 this.chain.push( gen_fm_retrieval_func(i,this._cacheable_fm_objects[i]) );
50         }
51
52         /*
53         var other_fm_objects = {
54                 'my_aou' : [ 
55                         'open-ils.actor', 
56                         'open-ils.actor.org_unit.full_path.retrieve', 
57                         [ obj.G.auth.session.key ] 
58                 ],
59                 'my_actsc' : [ 
60                         'open-ils.circ', 
61                         'open-ils.circ.stat_cat.actor.retrieve.all', 
62                         [ obj.G.auth.session.key, obj.au.home_ou.id() ] 
63                 ]
64         }
65         */
66
67         return this;
68 };
69
70 OpenILS.data.prototype = {
71
72         'list' : {},
73         'hash' : {},
74
75         'init' : function () {
76
77                 if (typeof this.on_complete == 'function') {
78
79                         this.chain.push( this.on_complete );
80                 }
81
82                 JSAN.use('util.exec');
83                 util.exec.chain( this.chain );
84         },
85
86         '_cacheable_fm_objects' : {
87
88                 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [] ],
89                 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [] ],
90                 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [] ],
91                 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [] ],
92                 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [] ],
93                 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [] ],
94                 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [] ]  
95         }
96
97 }
98
99 dump('exiting OpenILS/data.js\n');