From ed5dbb784af5206e15ae0e16c9ee8c48a154e2a3 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 17 Sep 2013 17:23:21 -0400 Subject: [PATCH] patron search js Signed-off-by: Bill Erickson --- circ.js | 2 +- env.js | 30 +++++++++++++ idl.js | 3 +- main.js | 23 ++++++++++ org.js | 59 +++++++++++++++++++++++++ patron.html | 17 +++++--- patron.js | 15 +++++++ patron_search.js | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 270 insertions(+), 10 deletions(-) create mode 100644 env.js create mode 100644 main.js create mode 100644 org.js create mode 100644 patron.js create mode 100644 patron_search.js diff --git a/circ.js b/circ.js index b53112cc5..18c034fb1 100644 --- a/circ.js +++ b/circ.js @@ -81,7 +81,7 @@ function loadOrgTree() { dojo.addOnLoad(function() { - loadIDL(); + load_IDL(); authtoken = dojo.cookie('ses'); diff --git a/env.js b/env.js new file mode 100644 index 000000000..2edd84b59 --- /dev/null +++ b/env.js @@ -0,0 +1,30 @@ +// load various bits of data we need via asnc call chain + +function load_what_i_need(onload) { + var ses = new OpenSRF.ClientSession('open-ils.pcrud'); + + function load_pgt(onl) { + ses.request({ + async : true, + method : 'open-ils.pcrud.search.pgt.atomic', + params : [ + cache.authtoken, + {id : {'!=' : null}}, // flat list + ], + oncomplete : function(r) { + var grps = r.recv().content(); + cache.pgt = {map : {}}; + dojo.forEach(grps, function(grp) { + cache.pgt.map[grp.id()] = grp; + }); + if (onl) onl(); + } + }).send(); + } + + + load_org_tree( + function() { load_pgt(onload) } + ); +} + diff --git a/idl.js b/idl.js index 943a04d4d..66606f09a 100644 --- a/idl.js +++ b/idl.js @@ -4,7 +4,7 @@ var fieldmapper = {}; // this is just enough code to get fieldmapper objects working // it does not contain everything fieldmapper.IDL does -function loadIDL() { +function load_IDL() { function mkclass(cls, fields) { @@ -32,4 +32,3 @@ function loadIDL() { window._preload_fieldmapper_IDL = null; } - diff --git a/main.js b/main.js new file mode 100644 index 000000000..32c6a78c0 --- /dev/null +++ b/main.js @@ -0,0 +1,23 @@ +dojo.require('dojo.cookie'); +dojo.require('dojo.keys'); +dojo.require('dojo.date'); +dojo.require('dojo.date.stamp'); +dojo.require('dojo.date.locale'); + +// meh. nice to have all locally cached blobs in +// one var to reduce the number of global vars. +// works fine in the xul client. similar in ways +// to TPAC 'ctx' var. +var cache = {}; + +function init(onload) { + cache.authtoken = dojo.cookie('ses'); + + if (!cache.authtoken) { + dojo.removeClass('login', 'hidden'); + return; + } + + load_IDL(); + load_what_i_need(onload); +} diff --git a/org.js b/org.js new file mode 100644 index 000000000..9f3822a1f --- /dev/null +++ b/org.js @@ -0,0 +1,59 @@ +// fetches the org unit tree. +// creates cache.aou.tree and cache.aou.map +function load_org_tree(onload) { + cache.aou = {}; + var ses = new OpenSRF.ClientSession('open-ils.pcrud'); + ses.request({ + async : true, + method : 'open-ils.pcrud.search.aou', + params : [ + cache.authtoken, + {parent_ou : null}, + { flesh : -1, + flesh_fields : {aou : ['children', 'ou_type']} + } + ], + + oncomplete : function(r) { + cache.aou.tree = r.recv().content(); + cache.aou.map = {}; + // map the tree into the map + function d(node) { + cache.aou.map[node.id()] = node; + dojo.forEach(node.children(), function(c) { d(c) }); + } + d(cache.aou.tree); + if (onload) + onload(); + } + }).send(); +} + +function get_org_unit(node_or_id) { + return + (typeof node_or_id == 'object') ? + node_or_id : + cache.aou.map[node_or_id]; +} + +function org_unit_ancestors(node_or_id) { + var node = get_org_unit(node_or_id); + if (!node) return []; + var nodes = [node]; + while( (node = get_org_unit(node.parent_ou())) ) { + push(nodes, node); + } + return nodes; +} + +function org_unit_descendants(node_or_id) { + var node = get_org_unit(node_or_id); + if (!node) return []; + var nodes = []; + function descend(n) { + nodes.push(n); + dojo.forEach(n.children(), descend); + } + descend(node); + return nodes; +} diff --git a/patron.html b/patron.html index 807d597c6..6d7e9a892 100644 --- a/patron.html +++ b/patron.html @@ -5,6 +5,8 @@ @@ -38,7 +40,7 @@
-
+