From 8b06b79a61beb4771c312ad1be507e9f3c49f3db Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 15 Dec 2005 23:11:41 +0000 Subject: [PATCH] break out the org depth selector to share git-svn-id: svn://svn.open-ils.org/ILS/trunk@2415 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../opac/skin/default/js/depth_selector.js | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Open-ILS/web/opac/skin/default/js/depth_selector.js diff --git a/Open-ILS/web/opac/skin/default/js/depth_selector.js b/Open-ILS/web/opac/skin/default/js/depth_selector.js new file mode 100644 index 0000000000..895c862052 --- /dev/null +++ b/Open-ILS/web/opac/skin/default/js/depth_selector.js @@ -0,0 +1,112 @@ + +attachEvt( "common", "locationChanged", updateLoc ); + +var _ds; +var _libselspan; +var _libselslink; +var _dselspan; +var _newlocation; + +function depthSelInit() { + _ds = $('depth_selector'); + _ds.onchange = depthSelectorChanged; + _libselspan = $('lib_selector_span'); + _libsellink = $('lib_selector_link'); + _dselspan = $('depth_selector_span'); + + if( getLocation() == globalOrgTree.id() ) { + unHideMe( _libselspan ); + _libsellink.onclick = _opacHandleLocationTagClick; + } else { + unHideMe( _dselspan ); + buildLocationSelector(); + } + + setSelector(_ds, getDepth()); + _newlocation = getLocation(); +} + + +var orgTreeIsBuilt = false; +function _opacHandleLocationTagClick() { + + swapCanvas(G.ui.common.org_container); + + if(!orgTreeIsBuilt) { + drawOrgTree(); + orgTreeIsBuilt = true; + } + +} + +function depthSelGetDepth() { + return parseInt(_ds.options[_ds.selectedIndex].value); +} + +function depthSelectorChanged() { + var i = _ds.selectedIndex; + if( i == _ds.options.length - 1 ) { + setSelector( _ds, getDepth() ); + _opacHandleLocationTagClick(); + } else { runEvt('common', 'depthChanged'); } +} + +var chooseAnotherNode; +function buildLocationSelector(newLoc) { + + var loc; + if(newLoc != null) loc = newLoc; + else loc = getLocation(); + + if( loc == globalOrgTree.id() ) return; + + var selector = _ds; + if(!chooseAnotherNode) + chooseAnotherNode = selector.removeChild( + selector.getElementsByTagName("option")[0]); + var node = chooseAnotherNode; + removeChildren(selector); + + var location = findOrgUnit(loc); + var type = findOrgType(location.ou_type()); + + while( type && location ) { + var n = node.cloneNode(true); + n.setAttribute("value", type.depth()); + removeChildren(n); + n.appendChild(text(type.opac_label())); + selector.appendChild(n); + location = findOrgUnit(location.parent_ou()); + if(location) type = findOrgType(location.ou_type()); + else type = null; + } + + selector.appendChild(node); +} + +function depthSelGetNewLoc() { return _newlocation; } + +function updateLoc(location, depth) { + if( depth != null ) { + if(depth != 0 ){ + _libsellink.onclick = _opacHandleLocationTagClick; + if( location == globalOrgTree.id() ) { + hideMe( _dselspan ); + unHideMe( _libselspan ); + } else { + buildLocationSelector(location); + hideMe( _libselspan ); + unHideMe( _dselspan ); + } + } + + setSelector(_ds, depth); + newSearchDepth = depth; + } + + _newlocation = location; + runEvt('common','locationUpdated', location); +} + + + -- 2.43.2