forwardport of 17216, org hiding depth in opac
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 16 Aug 2010 17:41:54 +0000 (17:41 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 16 Aug 2010 17:41:54 +0000 (17:41 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17228 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0373.data.org-setting-opac.org_unit_hiding.depth.sql [new file with mode: 0644]
Open-ILS/web/opac/common/js/opac_utils.js
Open-ILS/web/opac/common/js/org_utils.js
Open-ILS/web/opac/skin/default/js/depth_selector.js
Open-ILS/web/opac/skin/default/js/myopac.js
Open-ILS/web/opac/skin/default/js/rdetail.js
Open-ILS/web/opac/skin/default/js/result_common.js
Open-ILS/web/opac/skin/default/xml/myopac/myopac_prefs.xml

index 9a21c27..3106a8e 100644 (file)
@@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0372'); -- atz
+INSERT INTO config.upgrade_log (version) VALUES ('0373'); -- phasefx
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index 6446844..0a77833 100644 (file)
@@ -6605,3 +6605,19 @@ INSERT INTO action_trigger.environment (
         ,( 34, 'circ_lib.billing_address')
 ;
 
+-- 0373.data.org-setting-opac.org_unit_hiding.depth.sql
+INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
+        'opac.org_unit_hiding.depth',
+        oils_i18n_gettext(
+            'opac.org_unit_hiding.depth',
+            'OPAC: Org Unit Hiding Depth', 
+            'coust', 
+            'label'),
+        oils_i18n_gettext(
+            'opac.org_unit_hiding.depth',
+            'This will hide certain org units in the public OPAC if the Original Location (url param "ol") for the OPAC inherits this setting.  This setting specifies an org unit depth, that together with the OPAC Original Location determines which section of the Org Hierarchy should be visible in the OPAC.  For example, a stock Evergreen installation will have a 3-tier hierarchy (Consortium/System/Branch), where System has a depth of 1 and Branch has a depth of 2.  If this setting contains a depth of 1 in such an installation, then every library in the System in which the Original Location belongs will be visible, and everything else will be hidden.  A depth of 0 will effectively make every org visible.  The embedded OPAC in the staff client ignores this setting.', 
+            'coust', 
+            'description'),
+        'integer'
+);
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/0373.data.org-setting-opac.org_unit_hiding.depth.sql b/Open-ILS/src/sql/Pg/upgrade/0373.data.org-setting-opac.org_unit_hiding.depth.sql
new file mode 100644 (file)
index 0000000..c240b79
--- /dev/null
@@ -0,0 +1,20 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0373'); -- phasefx
+
+INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
+        'opac.org_unit_hiding.depth',
+        oils_i18n_gettext(
+            'opac.org_unit_hiding.depth',
+            'OPAC: Org Unit Hiding Depth', 
+            'coust', 
+            'label'),
+        oils_i18n_gettext(
+            'opac.org_unit_hiding.depth',
+            'This will hide certain org units in the public OPAC if the Original Location (url param "ol") for the OPAC inherits this setting.  This setting specifies an org unit depth, that together with the OPAC Original Location determines which section of the Org Hierarchy should be visible in the OPAC.  For example, a stock Evergreen installation will have a 3-tier hierarchy (Consortium/System/Branch), where System has a depth of 1 and Branch has a depth of 2.  If this setting contains a depth of 1 in such an installation, then every library in the System in which the Original Location belongs will be visible, and everything else will be hidden.  A depth of 0 will effectively make every org visible.  The embedded OPAC in the staff client ignores this setting.', 
+            'coust', 
+            'description'),
+        'integer'
+);
+
+COMMIT;
index b6d89ec..038983e 100644 (file)
@@ -826,20 +826,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'));
index 4c88977..1012c81 100644 (file)
@@ -92,14 +92,28 @@ 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;
-    var kids = me.children();
+/* 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;
+               }
+       }
+       var kids = me.children();
        for( var i = 0; kids && i < kids.length; i++ ) {
-               if(orgIsMine(kids[i], org))
+               if(orgIsMine(kids[i], org, false)) {
                        return true;
+               }
+
        }
        return false;
 }
index 1bd983e..6bd4b0e 100644 (file)
@@ -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);
index f47852e..3a37b83 100644 (file)
@@ -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();
 
index adb2343..03157aa 100644 (file)
@@ -44,6 +44,7 @@ var rdetailStart = null;
 var rdetailEnd = null;
 
 var mfhdDetails = [];
+var orgHiding = false;
 
 /* serials are currently the only use of Dojo strings in the OPAC */
 if (rdetailDisplaySerialHoldings) {
@@ -835,6 +836,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();
 
@@ -887,6 +896,8 @@ function _rdetailBuildInfoRows(r) {
 
        removeChildren(copyRowParent);
 
+       orgHiding = checkOrgHiding();
+
        _rdetailRows();
 
        var summary = r.getResultObject();
index 6510750..45ccb08 100644 (file)
@@ -697,7 +697,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();
@@ -718,10 +728,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++ ) {
@@ -798,20 +808,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' );
+                                       }
                                }
                        }
                }
index 99ffb88..0687aa6 100644 (file)
@@ -56,7 +56,7 @@
                        </tr>
 
 
-                       <tr>
+                       <tr id='prefs_def_location_row'>
                                <td>&myopac.prefs.search.location;</td>
                                <td>
                                        <div style='margin-bottom: 5px;'>
@@ -71,7 +71,7 @@
                                </td>
                        </tr>
 
-                       <tr>
+                       <tr id='prefs_def_range_row'>
                                <td>&myopac.prefs.search.range;</td>
                                <td>
                                        <select id='prefs_def_range'>