From 3906afb1156a473efc9a2de4b44cb052cbf4b1aa Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 3 Oct 2005 07:40:32 +0000 Subject: [PATCH] start of staff client 3 git-svn-id: svn://svn.open-ils.org/ILS/trunk@1886 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/xul/staff_client/LICENSE | 0 Open-ILS/xul/staff_client/Makefile | 98 ++++++ Open-ILS/xul/staff_client/README | 0 Open-ILS/xul/staff_client/application.ini | 39 +++ .../xul/staff_client/chrome/chrome.manifest | 3 + .../chrome/content/evergreen/OpenILS/data.js | 92 ++++++ .../content/evergreen/auth/controller.js | 141 +++++++++ .../chrome/content/evergreen/auth/session.js | 84 +++++ .../chrome/content/evergreen/main/JSAN.js | 290 ++++++++++++++++++ .../chrome/content/evergreen/main/main.js | 59 ++++ .../chrome/content/evergreen/main/main.xul | 90 ++++++ .../chrome/content/evergreen/main/network.js | 56 ++++ .../chrome/content/evergreen/main/window.js | 31 ++ .../chrome/content/evergreen/test/test.js | 13 + .../chrome/content/evergreen/util/error.js | 189 ++++++++++++ .../chrome/content/evergreen/util/exec.js | 39 +++ .../chrome/locale/en-US/evergreen/auth.dtd | 12 + .../chrome/skin/evergreen/auth.css | 3 + .../chrome/skin/evergreen/evergreen.css | 23 ++ .../defaults/preferences/evergreen.js | 15 + Open-ILS/xul/staff_client/install.rdf | 39 +++ 21 files changed, 1316 insertions(+) create mode 100644 Open-ILS/xul/staff_client/LICENSE create mode 100644 Open-ILS/xul/staff_client/Makefile create mode 100644 Open-ILS/xul/staff_client/README create mode 100644 Open-ILS/xul/staff_client/application.ini create mode 100644 Open-ILS/xul/staff_client/chrome/chrome.manifest create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/auth/controller.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/main/JSAN.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.xul create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/main/network.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/main/window.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/test/test.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/util/error.js create mode 100644 Open-ILS/xul/staff_client/chrome/content/evergreen/util/exec.js create mode 100644 Open-ILS/xul/staff_client/chrome/locale/en-US/evergreen/auth.dtd create mode 100644 Open-ILS/xul/staff_client/chrome/skin/evergreen/auth.css create mode 100644 Open-ILS/xul/staff_client/chrome/skin/evergreen/evergreen.css create mode 100644 Open-ILS/xul/staff_client/defaults/preferences/evergreen.js create mode 100755 Open-ILS/xul/staff_client/install.rdf diff --git a/Open-ILS/xul/staff_client/LICENSE b/Open-ILS/xul/staff_client/LICENSE new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Open-ILS/xul/staff_client/Makefile b/Open-ILS/xul/staff_client/Makefile new file mode 100644 index 0000000000..87df089d52 --- /dev/null +++ b/Open-ILS/xul/staff_client/Makefile @@ -0,0 +1,98 @@ +VERSION=0.1.0 +PACKAGE=Evergreen +DESCRIPTION=Evergreen Staff Client +BUILD=2005072719 + +RETRIEVE_FIELDMAPPER=wget -N http://gapines.org/opac/common/js/util/fieldmapper.js +RETRIEVE_FM_ALL=wget -N http://gapines.org/opac/common/js/fmall.js +RETRIEVE_ORG_TREE=wget -N http://gapines.org/opac/common/js/OrgTree.js +RETRIEVE_CLIENT_CONFIG=cp ../../../../../../../OpenSRF/examples/math_xul_client/math/content/conf/client_config.xml . + +all: build package + @echo + @echo How do makefiles work again? + @echo BUILD = ${BUILD} + touch application.ini + +#build: generated open-ils patron circ +build: generated open-ils custom + @echo + @echo Everything before packaging + +package: evergreen.xpi + @echo + @echo Packaging + +stamp: + sed -i s/^Version=.\*/Version=${VERSION}/ application.ini + sed -i s/^BuildID=.\*/BuildID=${BUILD}/ application.ini + sed -i s/^Name=.\*/Name=${PACKAGE}/ application.ini + sed -i 's/.*<\/em:version>/${VERSION}<\/em:version>/' install.rdf + sed -i 's/.*<\/em:name>/${PACKAGE}<\/em:name>/' install.rdf + sed -i 's/.*<\/em:description>/${DESCRIPTION}<\/em:description>/' install.rdf + sed -i "s/extVersion: '.\*'/extVersion: '${VERSION}'/" install.js + sed -i "s/extFullName: '.\*'/extFullName: '${DESCRIPTION}'/" install.js + sed -i 's/auth\.title ".*"/auth\.title "${DESCRIPTION}"/' chrome/locale/en-US/evergreen/auth.dtd + sed -i 's/auth\.version ".*"/auth\.version "${PACKAGE} ${VERSION} ${BUILD}"/' chrome/locale/en-US/evergreen/auth.dtd + +generated: + @echo + @echo These things are installation specific. The staff client is the last thing you should try to build. + #(cd chrome/content/evergreen/util ; ${RETRIEVE_FIELDMAPPER} ); + #(cd chrome/content/evergreen/util ; ${RETRIEVE_ORG_TREE} ); + (cd chrome/content/evergreen/conf ; ${RETRIEVE_CLIENT_CONFIG} ); + (cd chrome/content/evergreen/OpenILS/util/ ; ${RETRIEVE_FM_ALL} ); + +open-ils: + cp ../../../OpenSRF/src/javascript/*.js chrome/content/evergreen/OpenSRF/ + cp ../../../Open-ILS/web/opac/common/js/*.js chrome/content/evergreen/OpenILS/util/ + #cp ../../../Open-ILS/src/javascript/widgets/*.js chrome/content/evergreen/OpenILS/widgets/ + #cp ../../../Open-ILS/src/javascript/widgets/menu/*.js chrome/content/evergreen/OpenILS/widgets/menu/ + +patron: + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/patron_items/g | sed s/PagedTree/PatronItems/g > chrome/content/evergreen/patron/patron_items_overlay.xul ) + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/patron_search_results/g | sed s/PagedTree/PatronSearchResults/g > chrome/content/evergreen/patron/patron_search_results_overlay.xul ) + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/patron_checkout_items/g | sed s/PagedTree/PatronCheckoutItems/g > chrome/content/evergreen/patron/patron_checkout_items_overlay.xul ) + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/patron_holds/g | sed s/PagedTree/PatronHolds/g > chrome/content/evergreen/patron/patron_holds_overlay.xul ) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/patron_items.dtd) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/patron_search_results.dtd) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/patron_checkout_items.dtd) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/patron_holds.dtd) + +circ: + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/checkin_items/g | sed s/PagedTree/CheckinItems/g > chrome/content/evergreen/circ/checkin_items_overlay.xul ) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/checkin_items.dtd) + (cat chrome/content/evergreen/main/paged_tree_overlay.xul | sed s/paged_tree/hold_capture_items/g | sed s/PagedTree/HoldCaptureItems/g > chrome/content/evergreen/circ/hold_capture_items_overlay.xul ) + (cp chrome/locale/en-US/evergreen/paged_tree.dtd chrome/locale/en-US/evergreen/hold_capture_items.dtd) + +custom: + #(cd chrome/content/evergreen/OpenILS/util; cp RemoteRequest.js~ RemoteRequest.js) + +evergreen.xpi: evergreen.jar + @echo + @echo make the xpi file + zip -r evergreen.xpi chrome/ defaults/ install.js install.rdf application.ini Makefile LICENSE README -x \*CVS\* > /dev/null + +evergreen.jar: build + @echo + @echo make the jar file + (cd chrome; zip -r evergreen.jar content/ locale/ skin/ -x \*CVS\* > /dev/null ) + +clean: + @echo + @echo delete derived files + rm -f evergreen.xpi + rm -f chrome/evergreen.jar + rm -f chrome/content/evergreen/patron/patron_items_overlay.xul chrome/locale/en-US/evergreen/patron_items.dtd + rm -f chrome/content/evergreen/patron/patron_search_results_overlay.xul chrome/locale/en-US/evergreen/patron_search_results.dtd + rm -f chrome/content/evergreen/patron/patron_checkout_items_overlay.xul chrome/locale/en-US/evergreen/patron_checkout_items.dtd + rm -f chrome/content/evergreen/patron/patron_holds_overlay.xul chrome/locale/en-US/evergreen/patron_holds.dtd + rm -f chrome/content/evergreen/circ/checkin_items_overlay.xul chrome/locale/en-US/evergreen/checkin_items.dtd + rm -f chrome/content/evergreen/circ/hold_capture_items_overlay.xul chrome/locale/en-US/evergreen/hold_capture_items.dtd + rm -f chrome/content/evergreen/conf/client_config.xml + rm -f chrome/content/evergreen/util/fieldmapper.js + rm -f chrome/content/evergreen/util/OrgTree.js + rm -f chrome/content/evergreen/OpenSRF/*js + rm -f chrome/content/evergreen/OpenILS/util/*js + rm -f chrome/content/evergreen/OpenILS/widgets/*js + rm -f chrome/content/evergreen/OpenILS/widgets/menu/*js diff --git a/Open-ILS/xul/staff_client/README b/Open-ILS/xul/staff_client/README new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Open-ILS/xul/staff_client/application.ini b/Open-ILS/xul/staff_client/application.ini new file mode 100644 index 0000000000..e9b8e12d36 --- /dev/null +++ b/Open-ILS/xul/staff_client/application.ini @@ -0,0 +1,39 @@ +[App] +; Modified by Jason for Evergreen +; This file is used by XUL Runner like so: xulrunner ./application.ini +; +; This field specifies your organization's name. This field is recommended, +; but optional. +Vendor=PINES +; +; This field specifies your application's name. This field is required. +Name=Evergreen +; +; This field specifies your application's version. This field is optional. +Version=0.1.0 +; +; This field specifies your application's build ID (timestamp). This field is +; required. +BuildID=2005072719 +; +; This field specifies a compact copyright notice for your application. This +; field is optional. +Copyright=Copyright (c) 2005 GPLS/PINES +; +; This ID is just an example. Every XUL app ought to have it's own unique ID. +; You can use the microsoft "guidgen" or "uuidgen" tools, or go on +; irc.mozilla.org and /msg botbot uuid. This field is optional. +ID={c3dd711b-c9b4-4785-b8f8-6157149c8905} + +[Gecko] +; +; This field is required. It specifies the minimum Gecko version that this +; application requires. Specifying 1.8 matches all releases with a version +; prefixed by 1.8 (e.g., 1.8a4, 1.8b, 1.8.2). +MinVersion=1.8 +; +; This field is optional. It specifies the maximum Gecko version that this +; application requires. It should be specified if your application uses +; unfrozen interfaces. Specifying 1.8 matches all releases with a version +; prefixed by 1.8 (e.g., 1.8a4, 1.8b, 1.8.2). +MaxVersion=1.8 diff --git a/Open-ILS/xul/staff_client/chrome/chrome.manifest b/Open-ILS/xul/staff_client/chrome/chrome.manifest new file mode 100644 index 0000000000..4179af3129 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/chrome.manifest @@ -0,0 +1,3 @@ +content evergreen jar:evergreen.jar!/content/evergreen/ +locale evergreen en-US jar:evergreen.jar!/locale/en-US/evergreen/ +skin evergreen evergreen jar:evergreen.jar!/skin/evergreen/ diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js new file mode 100644 index 0000000000..f39e28b078 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/OpenILS/data.js @@ -0,0 +1,92 @@ +dump('entering OpenILS/data.js\n'); + +if (typeof OpenILS == 'undefined') OpenILS = {}; +OpenILS.data = function (mw,G) { + + this.mw = mw; this.G = G; + + var obj = this; + + this.chain = []; + + this.chain.push( + function() { + try { + obj.au = obj.G.network.request( + 'open-ils.search', + 'open-ils.search.actor.user.session', + [ obj.G.auth.session.key ] + ); + } catch(E) { + // what should we do? + } + } + ); + + function a_get(obj,i) { return [i, obj[i]]; } // funkiness with loops and closures + + for (var i in this._cacheable_fm_objects) { + var classname = a_get(this._cacheable_fm_objects,i)[0]; + var data = a_get(this._cacheable_fm_objects,i)[1]; + var app = data[0]; var method = data[1]; var params = data[2]; + this.chain.push( + function() { + try { + obj.list[classname] = obj.G.network.request( app, method, params); + // store an offline copy + } catch(E) { + // try offline + } + //obj.hash[classname] = convert_object_list_to_hash( obj.list[classname] ); + } + ); + } + + /* + var other_fm_objects = { + 'my_aou' : [ + 'open-ils.actor', + 'open-ils.actor.org_unit.full_path.retrieve', + [ obj.G.auth.session.key ] + ], + 'my_actsc' : [ + 'open-ils.circ', + 'open-ils.circ.stat_cat.actor.retrieve.all', + [ obj.G.auth.session.key, obj.au.home_ou.id() ] + ] + } + */ + + return this; +}; + +OpenILS.data.prototype = { + + 'list' : {}, + 'hash' : {}, + + 'init' : function () { + + if (typeof this.on_complete == 'function') { + + this.chain.push( this.on_complete ); + } + + JSAN.use('util.exec'); + util.exec.chain( this.chain ); + }, + + '_cacheable_fm_objects' : { + + 'pgt' : [ 'open-ils.actor', 'open-ils.actor.groups.retrieve', [] ], + 'cit' : [ 'open-ils.actor', 'open-ils.actor.user.ident_types.retrieve', [] ], + 'cst' : [ 'open-ils.actor', 'open-ils.actor.standings.retrieve', [] ], + 'acpl' : [ 'open-ils.search', 'open-ils.search.config.copy_location.retrieve.all', [] ], + 'ccs' : [ 'open-ils.search', 'open-ils.search.config.copy_status.retrieve.all', [] ], + 'aou' : [ 'open-ils.actor', 'open-ils.actor.org_tree.retrieve', [] ], + 'aout' : [ 'open-ils.actor', 'open-ils.actor.org_types.retrieve', [] ] + } + +} + +dump('exiting OpenILS/data.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/controller.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/controller.js new file mode 100644 index 0000000000..fedac660d7 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/controller.js @@ -0,0 +1,141 @@ +dump('entering auth/controller.js\n'); + +if (typeof auth == 'undefined') auth = {}; +auth.controller = function (mw,G) { + + this.mw = mw; this.G = G; + + return this; +}; + +auth.controller.prototype = { + + 'init' : function () { + + var obj = this; // so the 'this' in event handlers don't confuse us + var mw = obj.mw; + var G = obj.G; + + // This talks to our ILS + JSAN.use('auth.session'); + obj.session = new auth.session(obj,mw,G); + + // Attach this object to the XUL through event listeners + + var cmd_login = mw.document.getElementById('cmd_login'); + if (cmd_login) + cmd_login.addEventListener('command',function () { obj.login(); },false); + + var cmd_logoff = mw.document.getElementById('cmd_logoff'); + if (cmd_logoff) + cmd_logoff.addEventListener('command',function () { obj.logoff(); },false); + + var cmd_close_window = mw.document.getElementById('cmd_close_window'); + if (cmd_close_window) + cmd_close_window.addEventListener('command',function () { obj.close(); },false); + + obj.view.name_prompt = mw.document.getElementById('name_prompt'); + if (obj.view.name_prompt) { + obj.view.name_prompt.addEventListener('keypress',handle_keypress,false); + obj.view.name_prompt.focus(); + } + + obj.view.password_prompt = mw.document.getElementById('password_prompt'); + if (obj.view.password_prompt) + obj.view.password_prompt.addEventListener('keypress',handle_keypress,false); + + obj.view.submit_button = mw.document.getElementById('submit_button'); + + obj.view.progress_bar = mw.document.getElementById('auth_meter'); + + function handle_keypress(ev) { + if (ev.keyCode && ev.keyCode == 13) { + switch(this) { + case obj.name_prompt: + ev.preventDefault(); + obj.view.password_prompt.focus(); obj.view.password_prompt.select(); + break; + case obj.view.password_prompt: + ev.preventDefault(); + obj.view.submit_button.focus(); + obj.login(); + break; + default: break; + } + } + } + + if (typeof this.on_init == 'function') { + this.G.error.sdump('D_AUTH','auth.controller.on_init()\n'); + this.on_init(); + } + }, + + 'view' : {}, + + 'login' : function() { + + this.G.error.sdump('D_AUTH','login with ' + this.view.name_prompt.value + ' and ' + this.view.password_prompt.value + '\n'); + this.view.name_prompt.disabled = true; + this.view.password_prompt.disabled = true; + this.view.submit_button.disabled = true; + + try { + + if (typeof this.on_login == 'function') { + this.G.error.sdump('D_AUTH','auth.controller.session.on_init = ' + + 'auth.controller.on_login\n'); + this.session.on_init = this.on_login; + } + + this.session.init(); + + } catch(E) { + var error = '!! ' + E + '\n'; + this.G.error.sdump('D_ERROR',error); + alert(error); + this.logoff(); + + if (typeof this.on_login_error == 'function') { + this.G.error.sdump('D_AUTH','auth.controller.on_login_error()\n'); + this.on_login_error(E); + } + } + + }, + 'logoff' : function() { + + this.G.error.sdump('D_AUTH','logoff' + this.mw + '\n'); + this.view.progress_bar.value = 0; this.view.progress_bar.setAttribute('real','0.0'); + this.view.submit_button.disabled = false; + this.view.password_prompt.disabled = false; + this.view.password_prompt.value = ''; + this.view.name_prompt.disabled = false; + this.view.name_prompt.focus(); this.view.name_prompt.select(); + + this.session.close(); + + if (typeof this.on_logoff == 'function') { + this.G.error.sdump('D_AUTH','auth.controller.on_logoff()\n'); + this.on_logoff(); + } + + }, + 'close' : function() { + + this.G.error.sdump('D_AUTH','close' + this.mw + '\n'); + this.logoff(); + for (var w in this.G.window.appshell_list) { + this.G.window.appshell_list[w].close(); + } + this.mw.close(); /* Probably won't go any further */ + + if (typeof this.on_close == 'function') { + this.G.error.sdump('D_AUTH','auth.controller.on_close()\n'); + this.on_close(); + } + + } +} + +dump('exiting auth/controller.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js new file mode 100644 index 0000000000..5dfdebb450 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js @@ -0,0 +1,84 @@ +dump('entering auth/session.js\n'); + +if (typeof auth == 'undefined') auth = {}; +auth.session = function (controller,mw,G) { + + this.mw = mw; this.G = G; this.controller = controller; + + return this; +}; + +auth.session.prototype = { + + 'init' : function () { + + try { + var init = this.G.network.request( + 'open-ils.auth', + 'open-ils.auth.authenticate.init', + [ this.controller.view.name_prompt.value ] + ); + + if (init) { + + this.key = this.G.network.request( + 'open-ils.auth', + 'open-ils.auth.authenticate.complete', + [ + this.controller.view.name_prompt.value, + hex_md5( + init + + hex_md5( + this.controller.view.password_prompt.value + ) + ) + ] + ); + + this.G.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n'); + + if (Number(this.key) == 0) { + throw('Invalid name/password combination.'); + } else if (instanceOf(this.key,ex)) { + throw(this.key.err_msg()); + } + + if (typeof this.on_init == 'function') { + this.G.error.sdump('D_AUTH','auth.session.on_init()\n'); + this.on_init(); + } + + } else { + + var error = 'open-ils.auth.authenticate.init returned false\n'; + this.G.error.sdump('D_ERROR',error); + this.controller.logoff(); + throw(error); + } + + } catch(E) { + var error = 'Error on auth.session.init(): ' + E + '\n'; + this.G.error.sdump('D_ERROR',error); + + if (typeof this.on_init_error == 'function') { + this.G.error.sdump('D_AUTH','auth.session.on_init_error()\n'); + this.on_init_error(E); + } + + throw(E); + } + + }, + + 'close' : function () { + this.G.error.sdump('D_AUTH','auth.session.close()\n'); + this.key = null; + if (typeof this.G.on_close == 'function') { + this.G.error.sdump('D_AUTH','auth.session.on_close()\n'); + this.G.on_close(); + } + } + +} + +dump('exiting auth/session.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/main/JSAN.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/JSAN.js new file mode 100644 index 0000000000..809367caa3 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/JSAN.js @@ -0,0 +1,290 @@ +/* + +*/ + +var JSAN = function () { JSAN.addRepository(arguments) } + +JSAN.VERSION = 0.10; + +/* + +*/ + +JSAN.globalScope = self; +JSAN.includePath = ['.', 'lib']; +JSAN.errorLevel = "die"; +JSAN.errorMessage = ""; +JSAN.loaded = {}; + +/* + +*/ + +JSAN.use = function () { + var classdef = JSAN.require(arguments[0]); + if (!classdef) return null; + + var importList = JSAN._parseUseArgs.apply(JSAN, arguments).importList; + JSAN.exporter(classdef, importList); + + return classdef; +} + +/* + +*/ + +JSAN.require = function (pkg) { + var path = JSAN._convertPackageToPath(pkg); + if (JSAN.loaded[path]) { + return JSAN.loaded[path]; + } + + try { + var classdef = eval(pkg); + if (typeof classdef != 'undefined') return classdef; + } catch (e) { /* nice try, eh? */ } + + + for (var i = 0; i < JSAN.includePath.length; i++) { + var js; + try{ + var url = JSAN._convertPathToUrl(path, JSAN.includePath[i]); + js = JSAN._loadJSFromUrl(url); + } catch (e) { + if (i == JSAN.includePath.length - 1) throw e; + } + if (js != null) { + var classdef = JSAN._createScript(js, pkg); + JSAN.loaded[path] = classdef; + return classdef; + } + } + return false; + +} + +/* + +*/ + +JSAN.exporter = function () { + JSAN._exportItems.apply(JSAN, arguments); +} + +/* + +*/ + +JSAN.addRepository = function () { + var temp = JSAN._flatten( arguments ); + // Need to go in reverse to do something as simple as unshift( @foo, @_ ); + for ( var i = temp.length - 1; i >= 0; i-- ) + JSAN.includePath.unshift(temp[i]); + return JSAN; +} + +JSAN._flatten = function( list1 ) { + var list2 = new Array(); + for ( var i = 0; i < list1.length; i++ ) { + if ( typeof list1[i] == 'object' ) { + list2 = JSAN._flatten( list1[i], list2 ); + } + else { + list2.push( list1[i] ); + } + } + return list2; +}; + +JSAN._findMyPath = function () { + if (document) { + var scripts = document.getElementsByTagName('script'); + for ( var i = 0; i < scripts.length; i++ ) { + var src = scripts[i].getAttribute('src'); + if (src) { + var inc = src.match(/^(.*?)\/?JSAN.js/); + if (inc && inc[1]) { + var repo = inc[1]; + for (var j = 0; j < JSAN.includePath.length; j++) { + if (JSAN.includePath[j] == repo) { + return; + } + } + JSAN.addRepository(repo); + } + } + } + } +} +JSAN._findMyPath(); + +JSAN._convertPathToUrl = function (path, repository) { + return repository.concat('/' + path); +}; + + +JSAN._convertPackageToPath = function (pkg) { + var path = pkg.replace(/\./g, '/'); + path = path.concat('.js'); + return path; +} + +JSAN._parseUseArgs = function () { + var pkg = arguments[0]; + var importList = []; + + for (var i = 1; i < arguments.length; i++) + importList.push(arguments[i]); + + return { + pkg: pkg, + importList: importList + } +} + +JSAN._loadJSFromUrl = function (url) { + return new JSAN.Request().getText(url); +} + +JSAN._findExportInList = function (list, request) { + if (list == null) return false; + for (var i = 0; i < list.length; i++) + if (list[i] == request) + return true; + return false; +} + +JSAN._findExportInTag = function (tags, request) { + if (tags == null) return []; + for (var i in tags) + if (i == request) + return tags[i]; + return []; +} + +JSAN._exportItems = function (classdef, importList) { + var exportList = new Array(); + var EXPORT = classdef.EXPORT; + var EXPORT_OK = classdef.EXPORT_OK; + var EXPORT_TAGS = classdef.EXPORT_TAGS; + + if (importList.length > 0) { + importList = JSAN._flatten( importList ); + + for (var i = 0; i < importList.length; i++) { + var request = importList[i]; + if ( JSAN._findExportInList(EXPORT, request) + || JSAN._findExportInList(EXPORT_OK, request)) { + exportList.push(request); + continue; + } + var list = JSAN._findExportInTag(EXPORT_TAGS, request); + for (var i = 0; i < list.length; i++) { + exportList.push(list[i]); + } + } + } else { + exportList = EXPORT; + } + JSAN._exportList(classdef, exportList); +} + +JSAN._exportList = function (classdef, exportList) { + if (typeof(exportList) != 'object') return null; + for (var i = 0; i < exportList.length; i++) { + var name = exportList[i]; + + if (JSAN.globalScope[name] == null) + JSAN.globalScope[name] = classdef[name]; + } +} + +JSAN._makeNamespace = function(js, pkg) { + var spaces = pkg.split('.'); + var parent = JSAN.globalScope; + eval(js); + var classdef = eval(pkg); + for (var i = 0; i < spaces.length; i++) { + var name = spaces[i]; + if (i == spaces.length - 1) { + if (typeof parent[name] == 'undefined') { + parent[name] = classdef; + if ( typeof classdef['prototype'] != 'undefined' ) { + parent[name].prototype = classdef.prototype; + } + } + } else { + if (parent[name] == undefined) { + parent[name] = {}; + } + } + + parent = parent[name]; + } + return classdef; +} + +JSAN._handleError = function (msg, level) { + if (!level) level = JSAN.errorLevel; + JSAN.errorMessage = msg; + + switch (level) { + case "none": + break; + case "warn": + alert(msg); + break; + case "die": + default: + throw new Error(msg); + break; + } +} + +JSAN._createScript = function (js, pkg) { + try { + return JSAN._makeNamespace(js, pkg); + } catch (e) { + JSAN._handleError("Could not create namespace[" + pkg + "]: " + e); + } + return null; +} + + +JSAN.prototype = { + use: function () { JSAN.use.apply(JSAN, arguments) } +}; + + +// Low-Level HTTP Request +JSAN.Request = function (jsan) { + if (JSAN.globalScope.XMLHttpRequest) { + this._req = new XMLHttpRequest(); + } else { + this._req = new ActiveXObject("Microsoft.XMLHTTP"); + } +} + +JSAN.Request.prototype = { + _req: null, + + getText: function (url) { + this._req.open("GET", url, false); + try { + this._req.send(null); + if (this._req.status == 200 || this._req.status == 0) + return this._req.responseText; + } catch (e) { + JSAN._handleError("File not found: " + url); + return null; + }; + + JSAN._handleError("File not found: " + url); + return null; + } +}; + +/* + +*/ diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.js b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.js new file mode 100644 index 0000000000..4ebb91be95 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.js @@ -0,0 +1,59 @@ +dump('entering main/main.js\n'); + +function main_init() { + dump('entering main_init()\n'); + try { + if (typeof JSAN == 'undefined') { + throw( + "The JSAN library object is missing." + ); + } + ///////////////////////////////////////////////////////////////////////////// + + JSAN.errorLevel = "die"; // none, warn, or die + JSAN.addRepository('..'); + + //JSAN.use('test.test'); test.test.hello_world(); + + var mw = self; + var G = {}; + G.OpenILS = {}; + G.OpenSRF = {}; + + JSAN.use('util.error'); + G.error = new util.error( mw, G ); + + JSAN.use('main.window'); + G.window = new main.window( mw, G ); + + JSAN.use('main.network'); + G.network = new main.network( mw, G ); + + JSAN.use('auth.controller'); + G.auth = new auth.controller( mw, G ); + + G.auth.on_login = function() { + + JSAN.use('OpenILS.data'); + G.OpenILS.data = new OpenILS.data( mw, G ); + G.OpenILS.data.on_complete = function () { + + alert('spawn app_shell'); + } + G.OpenILS.data.init(); + } + + G.auth.init(); + + ///////////////////////////////////////////////////////////////////////////// + + } catch(E) { + var error = "!! This software has encountered an error. Please tell your friendly " + + "system administrator or software developer the following:\n" + E + '\n'; + try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); } + alert(error); + } + dump('exiting main_init()\n'); +} + +dump('exiting main/main.js\n'); diff --git a/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.xul b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.xul new file mode 100644 index 0000000000..6cce151851 --- /dev/null +++ b/Open-ILS/xul/staff_client/chrome/content/evergreen/main/main.xul @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +