From 4defd8729314aad6ccc805b02d6e6fed1087d3bb Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 17 Aug 2010 19:55:02 +0000 Subject: [PATCH] backport of 17216, org hiding depth in opac git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6_1@17232 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/opac_utils.js | 33 ++++++++++++--- Open-ILS/web/opac/common/js/org_utils.js | 23 ++++++++--- Open-ILS/web/opac/locale/en-US/lang.dtd | 2 + .../web/opac/skin/default/js/depth_selector.js | 11 ++++- Open-ILS/web/opac/skin/default/js/myopac.js | 6 +++ Open-ILS/web/opac/skin/default/js/rdetail.js | 12 ++++++ Open-ILS/web/opac/skin/default/js/result_common.js | 48 ++++++++++++++-------- .../opac/skin/default/xml/myopac/myopac_prefs.xml | 4 +- .../server/admin/org_unit_settings.xhtml | 5 +++ 9 files changed, 112 insertions(+), 32 deletions(-) diff --git a/Open-ILS/web/opac/common/js/opac_utils.js b/Open-ILS/web/opac/common/js/opac_utils.js index 7d739f9cf2..b62ad4bb9f 100644 --- a/Open-ILS/web/opac/common/js/opac_utils.js +++ b/Open-ILS/web/opac/common/js/opac_utils.js @@ -797,20 +797,43 @@ function drawOrgTree() { setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 ); } +function checkOrgHiding() { + var context_org = getOrigLocation() || globalOrgTree.id(); + var depth = fetchOrgSettingDefault( context_org, 'opac.org_unit_hiding.depth'); + if (isXUL()) { + return false; // disable org hiding for staff client + } + if ( findOrgDepth( context_org ) < depth ) { + return false; // disable org hiding if Original Location doesn't make sense with setting depth (avoids disjointed org selectors) + } + return { 'org' : findOrgUnit(context_org), 'depth' : depth }; +} + var orgTreeSelector; function buildOrgSelector(node) { var tree = new SlimTree(node,'orgTreeSelector'); orgTreeSelector = tree; + var orgHiding = checkOrgHiding(); for( var i in orgArraySearcher ) { var node = orgArraySearcher[i]; if( node == null ) continue; - if(!isXUL() && !isTrue(node.opac_visible())) continue; - if(node.parent_ou() == null) + if(!isXUL() && !isTrue(node.opac_visible())) continue; + if (orgHiding) { + if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) { + continue; + } + } + if(node.parent_ou() == null) { tree.addNode(node.id(), -1, node.name(), "javascript:orgSelect(" + node.id() + ");", node.name()); - else { - tree.addNode(node.id(), node.parent_ou(), node.name(), - "javascript:orgSelect(" + node.id() + ");", node.name()); + } else { + if (orgHiding && orgHiding.depth == findOrgDepth(node)) { + tree.addNode(node.id(), -1, node.name(), + "javascript:orgSelect(" + node.id() + ");", node.name()); + } else { + tree.addNode(node.id(), node.parent_ou(), node.name(), + "javascript:orgSelect(" + node.id() + ");", node.name()); + } } } hideMe($('org_loading_div')); diff --git a/Open-ILS/web/opac/common/js/org_utils.js b/Open-ILS/web/opac/common/js/org_utils.js index 9fe33f47d9..98786595f7 100644 --- a/Open-ILS/web/opac/common/js/org_utils.js +++ b/Open-ILS/web/opac/common/js/org_utils.js @@ -92,13 +92,26 @@ function orgNodeTrail(node) { function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); } -/* true if 'org' is 'me' or a child of mine */ -function orgIsMine(me, org) { - if(!me || !org) return false; - if(me.id() == org.id()) return true; +/* true if 'org' is 'me' or a child of mine, or optionally, a child of an ancestor org within the specified depth */ +function orgIsMine(me, org, depth) { + if(!me || !org) { + return false; + } + if(me.id() == org.id()) { + return true; + } + if (depth) { + while (depth < findOrgDepth(me)) { + me = findOrgUnit( me.parent_ou() ); + } + if(me.id() == org.id()) { + return true; + } + } for( var i in me.children() ) { - if(orgIsMine(me.children()[i], org)) + if(orgIsMine(me.children()[i], org, false)) { return true; + } } return false; } diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 1c519bab6a..6719f0b339 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -1687,6 +1687,8 @@ + + diff --git a/Open-ILS/web/opac/skin/default/js/depth_selector.js b/Open-ILS/web/opac/skin/default/js/depth_selector.js index 1bd983ee48..6bd4b0ef7d 100644 --- a/Open-ILS/web/opac/skin/default/js/depth_selector.js +++ b/Open-ILS/web/opac/skin/default/js/depth_selector.js @@ -78,6 +78,7 @@ function buildLocationSelector(newLoc) { var type; if (location) type = findOrgType(location.ou_type()); + var orgHiding = checkOrgHiding(); while( type && location ) { var n = node.cloneNode(true); n.setAttribute("value", type.depth()); @@ -85,8 +86,14 @@ function buildLocationSelector(newLoc) { n.appendChild(text(type.opac_label())); selector.appendChild(n); location = findOrgUnit(location.parent_ou()); - if(location) type = findOrgType(location.ou_type()); - else type = null; + if(location) { + type = findOrgType(location.ou_type()); + if (orgHiding && orgHiding.depth > type.depth()) { + type = null; + } + } else { + type = null; + } } selector.appendChild(node); diff --git a/Open-ILS/web/opac/skin/default/js/myopac.js b/Open-ILS/web/opac/skin/default/js/myopac.js index 414655e028..7f2b648b22 100644 --- a/Open-ILS/web/opac/skin/default/js/myopac.js +++ b/Open-ILS/web/opac/skin/default/js/myopac.js @@ -21,6 +21,12 @@ function clearNodes( node, keepArray ) { function myOPACInit() { + var orgHiding = checkOrgHiding(); + if (orgHiding) { + hideMe($('prefs_def_location_row')); + hideMe($('prefs_def_range_row')); + } + if(!(G.user && G.user.session)) { initLogin(); diff --git a/Open-ILS/web/opac/skin/default/js/rdetail.js b/Open-ILS/web/opac/skin/default/js/rdetail.js index 1602733c4f..8c9478019a 100644 --- a/Open-ILS/web/opac/skin/default/js/rdetail.js +++ b/Open-ILS/web/opac/skin/default/js/rdetail.js @@ -42,6 +42,8 @@ var rdetailNext = null; var rdetailStart = null; var rdetailEnd = null; +var orgHiding = false; + /* serials are currently the only use of Dojo strings in the OPAC */ if (rdetailDisplaySerialHoldings) { dojo.require("dijit.Menu"); @@ -736,6 +738,14 @@ function _rdetailRows(node) { if(!isXUL() && !isTrue(node.opac_visible())) return; + if (orgHiding) { + if (isTrue( findOrgType(node.ou_type()).can_have_vols() )) { + if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) { + return; + } + } + } + var row = copyRow.cloneNode(true); row.id = "cp_info_" + node.id(); @@ -785,6 +795,8 @@ function _rdetailBuildInfoRows(r) { removeChildren(copyRowParent); + orgHiding = checkOrgHiding(); + _rdetailRows(); var summary = r.getResultObject(); diff --git a/Open-ILS/web/opac/skin/default/js/result_common.js b/Open-ILS/web/opac/skin/default/js/result_common.js index 549fd0a64d..f93d7f64ed 100644 --- a/Open-ILS/web/opac/skin/default/js/result_common.js +++ b/Open-ILS/web/opac/skin/default/js/result_common.js @@ -631,7 +631,17 @@ function resultAddCopyCounts(rec, pagePosition) { var ccell = $n(countsrow, config.names.result.count_cell); var nodes = orgNodeTrail(findOrgUnit(getLocation())); - var node = nodes[0]; + var start_here = 0; + var orgHiding = checkOrgHiding(); + if (orgHiding) { + for (var i = 0; i < nodes.length; i++) { + if (orgHiding.depth == findOrgDepth(nodes[i])) { + start_here = i; + } + } + } + + var node = nodes[start_here]; var type = findOrgType(node.ou_type()); ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition; ccell.title = type.opac_label(); @@ -652,10 +662,10 @@ function resultAddCopyCounts(rec, pagePosition) { resultCCHeaderApplied = true; } - if(nodes[1]) { + if(nodes[start_here+1]) { - var x = 1; - var d = findOrgDepth(nodes[1]); + var x = start_here+1; + var d = findOrgDepth(nodes[start_here+1]); var d2 = findOrgDepth(nodes[nodes.length -1]); for( var i = d; i <= d2 ; i++ ) { @@ -732,20 +742,22 @@ function resultDisplayCopyCounts(rec, pagePosition, copy_counts) { var i = 0; while(copy_counts[i] != null) { var cell = $("copy_count_cell_" + i +"_" + pagePosition); - var cts = copy_counts[i]; - cell.appendChild(text(cts.available + " / " + cts.count)); - - if(isXUL()) { - /* here we style opac-invisible records for xul */ - - if( cts.depth == 0 ) { - if(cts.transcendant == null && cts.unshadow == 0) { - _debug("found an opac-shadowed record: " + rec.doc_id()); - var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; - if( cts.count == 0 ) - addCSSClass( row, 'no_copies' ); - else - addCSSClass( row, 'shadowed' ); + if (cell) { + var cts = copy_counts[i]; + cell.appendChild(text(cts.available + " / " + cts.count)); + + if(isXUL()) { + /* here we style opac-invisible records for xul */ + + if( cts.depth == 0 ) { + if(cts.transcendant == null && cts.unshadow == 0) { + _debug("found an opac-shadowed record: " + rec.doc_id()); + var row = cell.parentNode.parentNode.parentNode.parentNode.parentNode; + if( cts.count == 0 ) + addCSSClass( row, 'no_copies' ); + else + addCSSClass( row, 'shadowed' ); + } } } } diff --git a/Open-ILS/web/opac/skin/default/xml/myopac/myopac_prefs.xml b/Open-ILS/web/opac/skin/default/xml/myopac/myopac_prefs.xml index 99ffb88e7c..0687aa6294 100644 --- a/Open-ILS/web/opac/skin/default/xml/myopac/myopac_prefs.xml +++ b/Open-ILS/web/opac/skin/default/xml/myopac/myopac_prefs.xml @@ -56,7 +56,7 @@ - + &myopac.prefs.search.location;
@@ -71,7 +71,7 @@ - + &myopac.prefs.search.range;