changed OpenILS.data. cleaner init, on_error
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Dec 2005 21:57:28 +0000 (21:57 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Dec 2005 21:57:28 +0000 (21:57 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2273 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js
Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.js
Open-ILS/xul/staff_client/chrome/content/evergreen/util/error.js
Open-ILS/xul/staff_client/server/circ/checkout.js
Open-ILS/xul/staff_client/server/patron/display.js

index f61b618..066079c 100644 (file)
@@ -6,161 +6,29 @@ OpenILS.data = function () {
        JSAN.use('util.error'); this.error = new util.error();
        JSAN.use('main.network'); this.network = new main.network();
 
-       var obj = this;
-
-       JSAN.use('util.file');
-       JSAN.use('util.functional');
-       JSAN.use('util.fm_utils');
-
-       function gen_fm_retrieval_func(classname,data) {
-               var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
-               return function () {
-
-                       function convert() {
-                               try {
-                                       if (obj.list[classname].constructor.name == 'Array') {
-                                               obj.hash[classname] = 
-                                                       util.functional.convert_object_list_to_hash(
-                                                               obj.list[classname]
-                                                       );
-                                       }
-                               } catch(E) {
-
-                                       obj.error.sdump('D_ERROR',E + '\n');
-                               }
-
-                       }
-
-                       try {
-                               obj.list[classname] = obj.network.request( app, method, params);
-                               convert();
-                               // if cacheable, store an offline copy
-                               if (cacheable) {
-                                       var file = new util.file( classname );
-                                       file.set_object( obj.list[classname] );
-                               }
-
-                       } catch(E) {
-                               // if cacheable, try offline
-                               if (cacheable) {
-                                       try {
-                                               var file = new util.file( classname );
-                                               obj.list[classname] = file.get_object();
-                                               convert();
-                                       } catch(E) {
-                                               throw(E);
-                                       }
-                               } else {
-                                       throw(E); // for now
-                               }
-                       }
-               }
-       }
-
-       this.chain = [];
-
-       this.chain.push(
-               function() {
-                       var f = gen_fm_retrieval_func(
-                               'au',
-                               [
-                                       'open-ils.search',
-                                       'open-ils.search.actor.user.session',
-                                       [ obj.session ],
-                                       false
-                               ]
-                       );
-                       try {
-                               f();
-                       } catch(E) {
-                               // Probably the one thing we should not cache, so what do we do?
-                               obj.list.au = new au();
-                               obj.list.au.home_lib( '1' );
-                       }
-               }
-       );
-
-       obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
-
-       for (var i in this._fm_objects) {
-               this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
-       }
-
-       // The previous org_tree call returned a tree, not a list or hash.
-       this.chain.push(
-               function () {
-                       obj.org_tree = obj.list.aou;
-                       obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
-                       obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
-               }
-       );
-
-       this.chain.push(
-               gen_fm_retrieval_func('my_aou', 
-                       [ 
-                               'open-ils.actor', 
-                               'open-ils.actor.org_unit.full_path.retrieve', 
-                               [ obj.session ],
-                               true
-                       ]
-               )
-       );
-
-       // Do this after we get the user object
-       this.chain.push(
-
-               function () {
-
-                       gen_fm_retrieval_func( 'my_actsc', 
-                               [ 
-                                       'open-ils.circ', 
-                                       'open-ils.circ.stat_cat.actor.retrieve.all', 
-                                       [ obj.session, obj.list.au.home_ou() ],
-                                       true
-                               ]
-                       )();
-               }
-       );
-
        return this;
-};
+}
 
 OpenILS.data.prototype = {
 
        'list' : {},
        'hash' : {},
 
-       'init' : function (stash) {
-
-               if (stash) {
-
-                       try {
-                               const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
-                               var data_cache=new OpenILS( );
-                               var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
-                               for (var i in dc) {
-                                       this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
-                                       this[i] = dc[i];
-                               }
-                       } catch(E) {
-                               this.error.sdump('D_ERROR','Error in OpenILS.data.init(true): ' + js2JSON(E) );
-                       }
+       'init' : function (params) {
 
-                       if (typeof this.on_complete == 'function') {
-
-                               this.on_complete();
+               try {
+                       if (params && params.via == 'stash') {  
+                               this.stash_retrieve();
+                       } else {
+                               this.network_retrieve();
                        }
+               
+               } catch(E) {
+                       this.error.sdump('D_ERROR','Error in OpenILS.data.init('
+                               +js2JSON(params)+'): ' + js2JSON(E) );
+               }
 
-               } else {
-                       if (typeof this.on_complete == 'function') {
-
-                               this.chain.push( this.on_complete );
-                       }
-                       JSAN.use('util.exec'); this.exec = new util.exec();
-                       this.exec.on_error = function(E) { alert('oops: ' + E ); }
 
-                       this.exec.chain( this.chain );
-               }
        },
 
        'stash' : function () {
@@ -197,8 +65,156 @@ OpenILS.data.prototype = {
                'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [], true ],
                'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [], true ],
                'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [], true ]    
-       }
+       },
+
+       'stash_retrieve' : function() {
+               const OpenILS=new Components.Constructor("@mozilla.org/openils_data_cache;1", "nsIOpenILS");
+               var data_cache=new OpenILS( );
+               var dc = data_cache.wrappedJSObject.OpenILS.prototype.data;
+               for (var i in dc) {
+                       this.error.sdump('D_DATA','Retrieving ' + i + ' : ' + dc[i] + '\n');
+                       this[i] = dc[i];
+               }
+               if (typeof this.on_complete == 'function') {
+
+                       this.on_complete();
+               }
+       },
+
+       'network_retrieve' : function() {
+               var obj = this;
+
+               JSAN.use('util.file');
+               JSAN.use('util.functional');
+               JSAN.use('util.fm_utils');
+
+               function gen_fm_retrieval_func(classname,data) {
+                       var app = data[0]; var method = data[1]; var params = data[2]; var cacheable = data[3];
+                       return function () {
+
+                               function convert() {
+                                       try {
+                                               if (obj.list[classname].constructor.name == 'Array') {
+                                                       obj.hash[classname] = 
+                                                               util.functional.convert_object_list_to_hash(
+                                                                       obj.list[classname]
+                                                               );
+                                               }
+                                       } catch(E) {
+
+                                               obj.error.sdump('D_ERROR',E + '\n');
+                                       }
 
+                               }
+
+                               try {
+                                       obj.list[classname] = obj.network.request( app, method, params);
+                                       convert();
+                                       // if cacheable, store an offline copy
+                                       if (cacheable) {
+                                               var file = new util.file( classname );
+                                               file.set_object( obj.list[classname] );
+                                       }
+
+                               } catch(E) {
+                                       // if cacheable, try offline
+                                       if (cacheable) {
+                                               try {
+                                                       var file = new util.file( classname );
+                                                       obj.list[classname] = file.get_object();
+                                                       convert();
+                                               } catch(E) {
+                                                       throw(E);
+                                               }
+                                       } else {
+                                               throw(E); // for now
+                                       }
+                               }
+                       }
+               }
+
+               this.chain = [];
+
+               this.chain.push(
+                       function() {
+                               var f = gen_fm_retrieval_func(
+                                       'au',
+                                       [
+                                               'open-ils.search',
+                                               'open-ils.search.actor.user.session',
+                                               [ obj.session ],
+                                               false
+                                       ]
+                               );
+                               try {
+                                       f();
+                               } catch(E) {
+                                       // Probably the one thing we should not cache, so what do we do?
+                                       obj.list.au = new au();
+                                       obj.list.au.home_lib( '1' );
+                               }
+                       }
+               );
+
+               obj.error.sdump('D_DEBUG','_fm_objects = ' + js2JSON(this._fm_objects) + '\n');
+
+               for (var i in this._fm_objects) {
+                       this.chain.push( gen_fm_retrieval_func(i,this._fm_objects[i]) );
+               }
+
+               // The previous org_tree call returned a tree, not a list or hash.
+               this.chain.push(
+                       function () {
+                               obj.org_tree = obj.list.aou;
+                               obj.list.aou = util.fm_utils.flatten_ou_branch( obj.org_tree );
+                               obj.hash.aou = util.functional.convert_object_list_to_hash( obj.list.aou );
+                       }
+               );
+
+               this.chain.push(
+                       gen_fm_retrieval_func('my_aou', 
+                               [ 
+                                       'open-ils.actor', 
+                                       'open-ils.actor.org_unit.full_path.retrieve', 
+                                       [ obj.session ],
+                                       true
+                               ]
+                       )
+               );
+
+               // Do this after we get the user object
+               this.chain.push(
+
+                       function () {
+
+                               gen_fm_retrieval_func( 'my_actsc', 
+                                       [ 
+                                               'open-ils.circ', 
+                                               'open-ils.circ.stat_cat.actor.retrieve.all', 
+                                               [ obj.session, obj.list.au.home_ou() ],
+                                               true
+                                       ]
+                               )();
+                       }
+               );
+
+               if (typeof this.on_complete == 'function') {
+
+                       this.chain.push( this.on_complete );
+               }
+               JSAN.use('util.exec'); this.exec = new util.exec();
+               this.exec.on_error = function(E) { 
+               
+                       if (typeof obj.on_error == 'function') {
+                               obj.on_error();
+                       } else {
+                               alert('oops: ' + E ); 
+                       }
+               }
+
+               this.exec.chain( this.chain );
+
+       }
 }
 
 dump('exiting OpenILS/data.js\n');
index 9583763..9f58bd2 100644 (file)
@@ -39,6 +39,7 @@ function main_init() {
 
                JSAN.use('OpenILS.data');
                G.OpenILS.data = new OpenILS.data()
+               G.OpenILS.data.on_error = G.auth.logoff;
                G.OpenILS.data.entities = entities;
                G.OpenILS.data.stash('entities');
 
index a7e17d9..c343b40 100644 (file)
@@ -197,7 +197,7 @@ util.error.prototype = {
 
        'get_ilsevent' : function(status) {
                JSAN.use('OpenILS.data'); 
-               this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init(true);
+               this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
                return this.OpenILS.data.entities['ilsevent.'+status];
        }
 }      
index fda9135..5bbe157 100644 (file)
@@ -7,7 +7,7 @@ circ.checkout = function (params) {
        JSAN.use('main.network'); this.network = new main.network();
 
        JSAN.use('OpenILS.data'); this.OpenILS = {};
-       this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init(true);
+       this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
 }
 
 circ.checkout.prototype = {
index 693609c..fba3a35 100644 (file)
@@ -19,7 +19,7 @@ patron.display.prototype = {
                obj.barcode = params['barcode'];
 
                JSAN.use('OpenILS.data'); this.OpenILS = {}; 
-               obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init(true);
+               obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
 
                JSAN.use('util.deck');  obj.deck = new util.deck('patron_deck');