From 3cefb0af938927b419e3085ea37d4d74d20c54ad Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 22 Sep 2005 21:17:53 +0000 Subject: [PATCH] some offline stuff git-svn-id: svn://svn.open-ils.org/ILS/trunk@1858 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/evergreen/auth/auth.js | 141 ++++++++++++------ .../chrome/content/evergreen/util/file.js | 33 ++++ 2 files changed, 127 insertions(+), 47 deletions(-) diff --git a/Evergreen/staff_client/chrome/content/evergreen/auth/auth.js b/Evergreen/staff_client/chrome/content/evergreen/auth/auth.js index ea9fdcef13..6c4779e2ab 100644 --- a/Evergreen/staff_client/chrome/content/evergreen/auth/auth.js +++ b/Evergreen/staff_client/chrome/content/evergreen/auth/auth.js @@ -36,7 +36,52 @@ var G = { 'auth_ses' : [], // Org Unit for the login user - 'user_ou' : '' + 'user_ou' : '', + + // The related org units for the login user + 'my_orgs' : [], 'my_orgs_hash' : {}, + +///////////////////////////////////////////////////////////////////////////////////// + + // The Org Unit tree + 'org_tree' : '', 'org_tree_hash' : {}, + +///////////////////////////////////////////////////////////////////////////////////// + + // Historically, was the list of actor::profile's, but now it's user groups. + 'ap_list' : [], 'ap_hash' : {}, + + // config::identification_type + 'cit_list' : [], 'cit_hash' : {}, + + // config::standing + 'cst_list' : [], 'cst_hash' : {}, + + // assett::copy_location, and for my_orgs + 'acpl_list' : [], 'acpl_hash' : {}, + 'acpl_my_orgs' : [], 'acpl_my_orgs_hash' : {}, + + // actor::org_unit_type + 'aout_list' : [], 'aout_hash' : {}, + + // config::copy_status + 'ccs_list' : [], 'ccs_hash' : {}, + + // asset::stat_cat. WHERE IS THIS POPULATED AGAIN? + 'asc_list' : [], + + // actor::stat_cat + 'actsc_list' : [], 'actsc_hash' : {}, + +///////////////////////////////////////////////////////////////////////////////////// + + 'itemsout_header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:
    ', + 'itemsout_line_item' : '
  1. %TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n', + 'itemsout_footer' : '

%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%', + + 'checkout_header' : 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:
    ', + 'checkout_line_item' : '
  1. %TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n', + 'checkout_footer' : '

%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%' ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// @@ -44,49 +89,23 @@ var G = { var debug_ignore_auth_failures = false; -G['org_tree'] = ''; -G['my_orgs'] = []; -G['my_orgs_hash'] = {}; - -G['ap_list'] = []; // actor::profile -G['ap_hash'] = {}; -G['cit_list'] = []; // config::identification_type -G['cit_hash'] = {}; -G['cst_list'] = []; // config::standing -G['cst_hash'] = {}; -G['acpl_list'] = []; // asset::copy_location -G['acpl_hash'] = {}; G['acpl_my_orgs'] = []; G['acpl_my_orgs_hash'] = {}; -G['aout_list'] = []; // actor::org_unit_type -G['aout_hash'] = {}; -G['ccs_list'] = []; // config::copy_status -G['ccs_hash'] = {}; -G['asc_list'] = []; // asset::stat_cat -G['actsc_list'] = []; // actor::stat_cat -G['actsc_hash']; // actor::stat_cat - -G['itemsout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou have the following items:
    '; -G['itemsout_line_item'] = '
  1. %TITLE: 50%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n'; -G['itemsout_footer'] = '

%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%'; - -G['checkout_header'] = 'Welcome %PATRON_FIRSTNAME%, to %LIBRARY%!\r\nYou checked out the following items:
    '; -G['checkout_line_item'] = '
  1. %TITLE%\r\nBarcode: %COPY_BARCODE% Due: %DUE_D%\r\n'; -G['checkout_footer'] = '

%PINES_CODE% %TODAY%\r\nYou were helped by %STAFF_FIRSTNAME% %STAFF_LASTNAME%'; - var mw = G['main_window']; var auth_meter_incr = 10; +///////////////////////////////////////////////////////////////////////////////////// + function auth_init() { sdump('D_AUTH','TESTING: auth.js: ' + mw.G['main_test_variable'] + '\n'); sdump('D_AUTH',arg_dump(arguments)); + var np = document.getElementById('name_prompt'); - np.addEventListener("keypress",handle_keypress,false); - np.focus(); + np.addEventListener("keypress",handle_keypress,false); + np.focus(); var pp = document.getElementById('password_prompt'); - pp.addEventListener("keypress",handle_keypress,false); + pp.addEventListener("keypress",handle_keypress,false); self.addEventListener("unload",nice_shutdown,false); - G['sound'] = xp_sound_init(); - //G.sound.beep(); - snd_logon(); + + G['sound'] = xp_sound_init(); snd_logon(); } function handle_keypress(ev) { @@ -120,12 +139,14 @@ function enable_login_prompts() { enable_widgets(document,'password_prompt','name_prompt','submit_button'); document.getElementById('password_prompt').value = ''; var np = document.getElementById('name_prompt'); - np.focus(); np.select(); + np.focus(); np.select(); document.getElementById('auth_meter').value = 0; document.getElementById('auth_meter').setAttribute('real', '0.0'); G.sound.beep(); } +///////////////////////////////////////////////////////////////////////////////////// + function authenticate() { sdump('D_AUTH',arg_dump(arguments)); timer_init('cat'); @@ -157,6 +178,7 @@ function auth_init_callback(request) { var pw = document.getElementById('password_prompt').value; G.name = name; G.pw = pw; + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.auth', 'open-ils.auth.authenticate.complete', @@ -185,6 +207,7 @@ function auth_ses_callback(request) { mw.G.auth_ses = [ auth_ses ]; sdump( 'D_AUTH', 'D_AUTH_SES: ' + typeof(mw.G['auth_ses'][0]) + ' : ' + mw.G['auth_ses'][0] + '\n'); + ///////////////////////////////////////////////////////////////////////////////////////////////////// //'open-ils.actor.user.profiles.retrieve', user_async_request( 'open-ils.actor', @@ -197,30 +220,26 @@ function auth_ses_callback(request) { function ap_list_callback(request) { sdump('D_AUTH',arg_dump(arguments)); + var ap_file = get_file('ap_list'); var ap_list; try { ap_list = request.getResultObject(); - if (!ap_list) { - if (!G.offline) { - throw('null result'); - } else { - var f = create_input_stream('ap_list'); - ap_list = JSON2js( f.read(-1) ); f.close(); - } + if (!ap_list && G.offline) { + ap_list = get_object_in_file('ap_list'); } + if (!ap_list) { throw('null result'); } if (ap_list.length == 0) { throw('zero length result'); } } catch(E) { - alert('Login failed on ap_list: ' + js2JSON(E)); + handle_error('Login failed on ap_list: ' + js2JSON(E)); if (!debug_ignore_auth_failures) { enable_login_prompts(); return; } } - var f = create_output_stream('ap_list'); - var ap_list_json = js2JSON( ap_list ); - f.write( ap_list_json, ap_list_json.length ); f.close(); + try { set_object_in_file('ap_list',ap_list); } catch(E) { handle_error(E); } mw.G.ap_list = ap_list; mw.G.ap_hash = convert_object_list_to_hash( ap_list ); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', @@ -235,6 +254,7 @@ function cit_list_callback(request) { var cit_list; try { cit_list = request.getResultObject(); + if (!cit_list && G.offline) { cit_list = get_object_in_file('cit_list'); } if (!cit_list) { throw('null result'); } if (cit_list.length == 0) { throw('zero length result'); } } catch(E) { @@ -243,9 +263,11 @@ function cit_list_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('cit_list',cit_list); } catch(E) { handle_error(E); } mw.G.cit_list = cit_list; mw.G.cit_hash = convert_object_list_to_hash( cit_list ); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.actor', 'open-ils.actor.standings.retrieve', @@ -261,6 +283,7 @@ function cst_list_callback(request) { var cst_list; try { cst_list = request.getResultObject(); + if (!cst_list && G.offline) { cst_list = get_object_in_file('cst_list'); } if (!cst_list) { throw('null result'); } if (cst_list.length == 0) { throw('zero length result'); } } catch(E) { @@ -269,10 +292,12 @@ function cst_list_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('cst_list',cst_list); } catch(E) { handle_error(E); } mw.G.cst_list = cst_list; mw.G.cst_hash = convert_object_list_to_hash( cst_list ); sdump('D_AUTH', 'cst_list = ' + js2JSON(cst_list) + '\n'); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', @@ -288,6 +313,7 @@ function acpl_list_callback(request) { var acpl_list; try { acpl_list = request.getResultObject(); + if (!acpl_list && G.offline) { acpl_list = get_object_in_file('acpl_list'); } if (!acpl_list) { throw('null result'); } if (acpl_list.length == 0) { throw('zero length result'); } } catch(E) { @@ -296,10 +322,12 @@ function acpl_list_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('acpl_list',acpl_list); } catch(E) { handle_error(E); } mw.G.acpl_list = acpl_list; mw.G.acpl_hash = convert_object_list_to_hash( acpl_list ); sdump('D_AUTH', 'acpl_list = ' + js2JSON(acpl_list) + '\n'); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', @@ -314,6 +342,7 @@ function ccs_list_callback(request) { var ccs_list; try { ccs_list = request.getResultObject(); + if (!ccs_list && G.offline) { ccs_list = get_object_in_file('ccs_list'); } if (!ccs_list) { throw('null result'); } if (ccs_list.length == 0) { throw('zero length result'); } } catch(E) { @@ -322,10 +351,12 @@ function ccs_list_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('ccs_list',ccs_list); } catch(E) { handle_error(E); } mw.G.ccs_list = ccs_list; mw.G.ccs_hash = convert_object_list_to_hash( ccs_list ); sdump('D_AUTH', 'ccs_list = ' + js2JSON(ccs_list) + '\n'); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.search', 'open-ils.search.actor.user.session', @@ -341,6 +372,10 @@ function user_callback(request) { var user_ou; try { user = request.getResultObject(); + if (!user && G.offline) { + user = new au(); + user.home_ou( get_object_in_file('user_ou') ); + } if (!user) { throw('null result'); } if (typeof(user) != 'object') { throw('result not an object' + user); } } catch(E) { @@ -349,10 +384,13 @@ function user_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('user_ou',user_ou); } catch(E) { handle_error(E); } mw.G.user = user; mw.G.user_ou = user.home_ou(); sdump('D_AUTH', "user: " + js2JSON(mw.G['user']) + '\n'); sdump('D_AUTH', "user_ou: " + js2JSON(mw.G['user_ou']) + '\n'); + + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', @@ -366,6 +404,7 @@ function org_tree_callback(request) { var org_tree; try { org_tree = request.getResultObject(); + if (!org_tree && G.offline) { org_tree = get_object_in_file('org_tree'); } if (!org_tree) { throw('null result'); } if (typeof(org_tree) != 'object') { throw('result not an object' + org_tree); } } catch(E) { @@ -373,10 +412,12 @@ function org_tree_callback(request) { } //mw.G.org_tree = globalOrgTree; + try { set_object_in_file('org_tree',org_tree); } catch(E) { handle_error(E); } mw.G.org_tree = org_tree; mw.G.org_tree_hash = convert_object_list_to_hash( flatten_ou_branch( mw.G.org_tree ) ); mw.G.user_ou = find_ou( mw.G.org_tree, mw.G.user_ou ); + ///////////////////////////////////////////////////////////////////////////////////////////////////// /*user_async_request( 'open-ils.actor', 'open-ils.actor.org_types.retrieve', @@ -400,6 +441,7 @@ function org_type_callback(request) { mw.G.aout_list = aout_list; mw.G.aout_hash = convert_object_list_to_hash( aout_list ); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.actor', 'open-ils.actor.org_unit.full_path.retrieve', @@ -414,6 +456,7 @@ function my_orgs_callback(request) { var my_orgs; try { my_orgs = request.getResultObject(); + if (!my_orgs && G.offline) { my_orgs = get_object_in_file('my_orgs'); } if (!my_orgs) { throw('null result'); } if (typeof(my_orgs) != 'object') { throw('result not an object' + my_orgs); } if (my_orgs.length == 0) { throw('empty my_orgs'); } @@ -424,6 +467,7 @@ function my_orgs_callback(request) { } } + try { set_object_in_file('my_orgs',my_orgs); } catch(E) { handle_error(E); } mw.G.my_orgs = my_orgs; mw.G.my_orgs_hash = convert_object_list_to_hash( my_orgs ); sdump('D_AUTH','my_orgs = ' + js2JSON(my_orgs) + '\n'); @@ -437,6 +481,7 @@ function my_orgs_callback(request) { mw.G.acpl_my_orgs_hash = convert_object_list_to_hash( mw.G.acpl_my_orgs ); //sdump('D_AUTH', 'my_orgs.length = ' + mw.G.my_orgs.length + ' other_orgs.length = ' + mw.G.other_orgs.length + '\n'); + ///////////////////////////////////////////////////////////////////////////////////////////////////// user_async_request( 'open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all', @@ -452,6 +497,7 @@ function my_actsc_list_callback(request) { var actsc_list; try { actsc_list = request.getResultObject(); + if (!actsc_list && G.offline) { actsc_list = get_object_in_file('actsc_list'); } if (!actsc_list) { throw('null result'); } //if (actsc_list.length == 0) { throw('zero length result'); } } catch(E) { @@ -460,6 +506,7 @@ function my_actsc_list_callback(request) { enable_login_prompts(); return; } } + try { set_object_in_file('actsc_list',actsc_list); } catch(E) { handle_error(E); } mw.G.actsc_list = actsc_list; mw.G.actsc_hash = convert_object_list_to_hash( actsc_list ); sdump('D_AUTH', 'actsc_list = ' + js2JSON(actsc_list) + '\n'); diff --git a/Evergreen/staff_client/chrome/content/evergreen/util/file.js b/Evergreen/staff_client/chrome/content/evergreen/util/file.js index 995fe63969..378f44db19 100644 --- a/Evergreen/staff_client/chrome/content/evergreen/util/file.js +++ b/Evergreen/staff_client/chrome/content/evergreen/util/file.js @@ -3,6 +3,39 @@ sdump('D_TRACE','Loading file.js\n'); var dirService = Components.classes["@mozilla.org/file/directory_service;1"]. getService( Components.interfaces.nsIProperties ); +////////////////////////////////////////////////////////////////////////////////////////////////////// + +function set_object_in_file(file,obj) { + try { + if (typeof(file)=='string') file = get_file( file ); + var f = create_output_stream(file); + var obj_json = js2JSON( obj ); + f.write( obj_json, obj_json.length ); f.close(); + } catch(E) { + sdump('D_FILE', 'set_object_in_file: ' + js2JSON(E) + '\n'); + throw(E); + } +} + +function get_object_in_file(file) { + try { + if (typeof(file)=='string') file = get_file( file ); + if (file.exists()) { + var f = create_input_stream(file); + var obj = JSON2js( f.read(-1) ); + f.close(); + return obj; + } else { + throw('File does not exist. '); + } + } catch(E) { + sdump('D_FILE', 'get_object_in_file: ' + js2JSON(E) + '\n'); + throw(E); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// + function create_input_stream(file) { try { if (typeof(file)=='string') file = get_file( file ); -- 2.43.2