]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js
161db0a732f6182190fb46eca79673be93625ed5
[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         JSAN.use('util.file');
11         JSAN.use('util.functional');
12         JSAN.use('util.fm_utils');
13
14         function gen_fm_retrieval_func(classname,data) {
15                 var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
16                 return function () {
17                         try {
18                                 obj.list[classname] = obj.G.network.request( app, method, params);
19                                 try {
20                                         if (obj.list[classname].constructor.name == 'Array') {
21                                                 obj.hash[classname] = 
22                                                         util.functional.convert_object_list_to_hash(
23                                                                 obj.list[classname]
24                                                         );
25                                         }
26                                 } catch(E) {
27
28                                         obj.G.error.sdump('D_ERROR',E + '\n');
29                                 }
30                                 // if cacheable, store an offline copy
31                                 if (cacheable) {
32                                         var file = new util.file( obj.mw, obj.G, classname );
33                                         file.set_object( obj.list[classname] );
34                                 }
35
36                         } catch(E) {
37                                 // if cacheable, try offline
38                                 if (cacheable) {
39                                 }
40                                 throw(E); // for now
41                         }
42                 }
43         }
44
45         this.chain = [];
46
47         this.chain.push(
48                 gen_fm_retrieval_func(
49                         'au',
50                         [
51                                 'open-ils.search',
52                                 'open-ils.search.actor.user.session',
53                                 [ obj.G.auth.session.key ],
54                                 false
55                         ]
56                 )
57         );
58
59         obj.G.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
60
61         for (var i in this._fm_objects) {
62                 this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
63         }
64
65         // The previous org_tree call returned a tree, not a list or hash.
66         this.chain.push(
67                 function () {
68                         obj.org_tree = obj.list.aou;
69                         obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
70                         obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
71                 }
72         );
73
74         this.chain.push(
75                 gen_fm_retrieval_func('my_aou', 
76                         [ 
77                                 'open-ils.actor', 
78                                 'open-ils.actor.org_unit.full_path.retrieve', 
79                                 [ obj.G.auth.session.key ],
80                                 true
81                         ]
82                 )
83         );
84
85         // Do this after we get the user object
86         this.chain.push(
87
88                 function () {
89
90                         gen_fm_retrieval_func( 'my_actsc', 
91                                 [ 
92                                         'open-ils.circ', 
93                                         'open-ils.circ.stat_cat.actor.retrieve.all', 
94                                         [ obj.G.auth.session.key, obj.list.au.home_ou() ],
95                                         true
96                                 ]
97                         )();
98                 }
99         );
100
101         return this;
102 };
103
104 OpenILS.data.prototype = {
105
106         'list' : {},
107         'hash' : {},
108
109         'init' : function () {
110
111                 if (typeof this.on_complete == 'function') {
112
113                         this.chain.push( this.on_complete );
114                 }
115
116                 JSAN.use('util.exec');
117                 util.exec.chain( this.chain );
118         },
119
120         '_fm_objects' : {
121
122                 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [], true ],
123                 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [], true ],
124                 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [], true ],
125                 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [], true ],
126                 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ],
127                 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ],
128                 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ]    
129         }
130
131 }
132
133 dump('exiting OpenILS/data.js\n');