Better call number prefix/support in opac. The copy count status/location summary...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 22 Apr 2011 00:20:08 +0000 (00:20 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 22 Apr 2011 00:20:08 +0000 (00:20 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@20273 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/biblio.pm
Open-ILS/web/opac/skin/default/js/copy_details.js
Open-ILS/web/opac/skin/default/js/rdetail.js

index 5cd7087..4be3a41 100644 (file)
@@ -2012,7 +2012,7 @@ __PACKAGE__->register_method(
     method   => "copy_count_summary",
     api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
     notes    => "returns an array of these: "
-              . "[ org_id, callnumber_label, <status1_count>, <status2_count>,...] "
+              . "[ org_id, callnumber_prefix, callnumber_label, callnumber_suffix, <status1_count>, <status2_count>,...] "
               . "where statusx is a copy status name.  The statuses are sorted by ID.",
 );
                
@@ -2024,14 +2024,18 @@ sub copy_count_summary {
     my $data = $U->storagereq(
                'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
 
-    return [ sort { $a->[1] cmp $b->[1] } @$data ];
+    return [ sort {
+        (($a->[1] ? $a->[1] . ' ' : '') . $a->[2] . ($a->[3] ? ' ' . $a->[3] : ''))
+        cmp
+        (($b->[1] ? $b->[1] . ' ' : '') . $b->[2] . ($b->[3] ? ' ' . $b->[3] : ''))
+    } @$data ];
 }
 
 __PACKAGE__->register_method(
     method   => "copy_location_count_summary",
     api_name => "open-ils.search.biblio.copy_location_counts.summary.retrieve",
     notes    => "returns an array of these: "
-              . "[ org_id, callnumber_label, copy_location, <status1_count>, <status2_count>,...] "
+              . "[ org_id, callnumber_prefix, callnumber_label, callnumber_suffix, copy_location, <status1_count>, <status2_count>,...] "
               . "where statusx is a copy status name.  The statuses are sorted by ID.",
 );
 
@@ -2042,14 +2046,20 @@ sub copy_location_count_summary {
     my $data = $U->storagereq(
                'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
 
-    return [ sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] } @$data ];
+    return [ sort {
+        (($a->[1] ? $a->[1] . ' ' : '') . $a->[2] . ($a->[3] ? ' ' . $a->[3] : ''))
+        cmp
+        (($b->[1] ? $b->[1] . ' ' : '') . $b->[2] . ($b->[3] ? ' ' . $b->[3] : ''))
+
+        || $a->[4] cmp $b->[4]
+    } @$data ];
 }
 
 __PACKAGE__->register_method(
     method   => "copy_count_location_summary",
     api_name => "open-ils.search.biblio.copy_counts.location.summary.retrieve",
     notes    => "returns an array of these: "
-              . "[ org_id, callnumber_label, <status1_count>, <status2_count>,...] "
+              . "[ org_id, callnumber_prefix, callnumber_label, callnumber_suffix, <status1_count>, <status2_count>,...] "
               . "where statusx is a copy status name.  The statuses are sorted by ID."
 );
 
@@ -2059,7 +2069,11 @@ sub copy_count_location_summary {
     $depth ||= 0;
     my $data = $U->storagereq(
         'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
-    return [ sort { $a->[1] cmp $b->[1] } @$data ];
+    return [ sort {
+        (($a->[1] ? $a->[1] . ' ' : '') . $a->[2] . ($a->[3] ? ' ' . $a->[3] : ''))
+        cmp
+        (($b->[1] ? $b->[1] . ' ' : '') . $b->[2] . ($b->[3] ? ' ' . $b->[3] : ''))
+    } @$data ];
 }
 
 
@@ -2620,9 +2634,11 @@ __PACKAGE__->register_method(
 );
 
 sub copies_by_cn_label {
-       my( $self, $conn, $record, $label, $circ_lib ) = @_;
+       my( $self, $conn, $record, $cn_parts, $circ_lib ) = @_;
        my $e = new_editor();
-       my $cns = $e->search_asset_call_number({record => $record, label => $label, deleted => 'f'}, {idlist=>1});
+    my $cnp_id = $cn_parts->[0] eq '' ? -1 : $e->search_asset_call_number_prefix({label => $cn_parts->[0]}, {idlist=>1})->[0];
+    my $cns_id = $cn_parts->[2] eq '' ? -1 : $e->search_asset_call_number_suffix({label => $cn_parts->[2]}, {idlist=>1})->[0];
+       my $cns = $e->search_asset_call_number({record => $record, prefix => $cnp_id, label => $cn_parts->[1], suffix => $cns_id, deleted => 'f'}, {idlist=>1});
        return [] unless @$cns;
 
        # show all non-deleted copies in the staff client ...
index 7c7c830..b6dd586 100644 (file)
@@ -381,7 +381,7 @@ sub record_copy_status_count {
 
        my $cn_table = asset::call_number->table;
        my $cnp_table = asset::call_number_prefix->table;
-       my $cns_table = asset::call_number_prefix->table;
+       my $cns_table = asset::call_number_suffix->table;
        my $cp_table = asset::copy->table;
        my $cl_table = asset::copy_location->table;
        my $cs_table = config::copy_status->table;
@@ -389,7 +389,9 @@ sub record_copy_status_count {
        my $sql = <<"   SQL";
 
                SELECT  cp.circ_lib,
-                               CASE WHEN cnp.id > -1 THEN cnp.label || ' ' ELSE '' END || cn.label || CASE WHEN cns.id > -1 THEN ' ' || cns.label ELSE '' END,
+                               CASE WHEN cnp.id > -1 THEN cnp.label ELSE '' END,
+                cn.label,
+                CASE WHEN cns.id > -1 THEN cns.label ELSE '' END,
                                cp.status,
                                count(cp.id)
                  FROM  $cp_table cp,
@@ -410,7 +412,7 @@ sub record_copy_status_count {
                        AND cp.opac_visible IS TRUE
                        AND cp.deleted IS FALSE
                        AND cs.opac_visible IS TRUE
-                 GROUP BY 1,2,3;
+                 GROUP BY 1,2,3,4,5;
        SQL
 
        my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
@@ -418,13 +420,17 @@ sub record_copy_status_count {
 
        my %data = ();
        for my $row (@{$sth->fetchall_arrayref}) {
-               $data{$$row[0]}{$$row[1]}{$$row[2]} += $$row[3];
+               $data{$$row[0]}{$$row[1]}{$$row[2]}{$$row[3]}{$$row[4]} += $$row[5];
        }
        
        for my $ou (keys %data) {
-               for my $cn (keys %{$data{$ou}}) {
-                       $client->respond( [$ou, $cn, $data{$ou}{$cn}] );
-               }
+               for my $cn_prefix (keys %{$data{$ou}}) {
+                   for my $cn (keys %{$data{$ou}{$cn_prefix}}) {
+                       for my $cn_suffix (keys %{$data{$ou}{$cn_prefix}{$cn}}) {
+                               $client->respond( [$ou, $cn_prefix, $cn, $cn_suffix, $data{$ou}{$cn}{$cn_prefix}{$cn}{$cn_suffix}] );
+                       }
+            }
+        }
        }
        return undef;
 }
@@ -450,7 +456,7 @@ sub record_copy_status_location_count {
 
        my $cn_table = asset::call_number->table;
        my $cnp_table = asset::call_number_prefix->table;
-       my $cns_table = asset::call_number_prefix->table;
+       my $cns_table = asset::call_number_suffix->table;
        my $cp_table = asset::copy->table;
        my $cl_table = asset::copy_location->table;
        my $cs_table = config::copy_status->table;
@@ -461,7 +467,9 @@ sub record_copy_status_location_count {
        my $sql = <<"   SQL";
 
                SELECT  cp.circ_lib,
-                               CASE WHEN cnp.id > -1 THEN cnp.label || ' ' ELSE '' END || cn.label || CASE WHEN cns.id > -1 THEN ' ' || cns.label ELSE '' END,
+                               CASE WHEN cnp.id > -1 THEN cnp.label ELSE '' END,
+                cn.label,
+                CASE WHEN cns.id > -1 THEN cns.label ELSE '' END,
                                oils_i18n_xlate('asset.copy_location', 'acpl', 'name', 'id', cl.id::TEXT, ?),
                                cp.status,
                                count(cp.id)
@@ -483,7 +491,7 @@ sub record_copy_status_location_count {
                        AND cp.opac_visible IS TRUE
                        AND cp.deleted IS FALSE
                        AND cs.opac_visible IS TRUE
-                 GROUP BY 1,2,3,4;
+                 GROUP BY 1,2,3,4,5,6;
        SQL
 
        my $sth = biblio::record_entry->db_Main->prepare_cached($sql);
@@ -492,14 +500,18 @@ sub record_copy_status_location_count {
 
        my %data = ();
        for my $row (@{$sth->fetchall_arrayref}) {
-               $data{$$row[0]}{$$row[1]}{$$row[2]}{$$row[3]} += $$row[4];
+               $data{$$row[0]}{$$row[1]}{$$row[2]}{$$row[3]}{$$row[4]}{$$row[5]} += $$row[6];
        }
        
        for my $ou (keys %data) {
-               for my $cn (keys %{$data{$ou}}) {
-                   for my $cl (keys %{$data{$ou}{$cn}}) {
-                       $client->respond( [$ou, $cn, $cl, $data{$ou}{$cn}{$cl}] );
-            }
+               for my $cn_prefix (keys %{$data{$ou}}) {
+                   for my $cn (keys %{$data{$ou}{$cn_prefix}}) {
+                       for my $cn_suffix (keys %{$data{$ou}{$cn_prefix}{$cn}}) {
+                    for my $cl (keys %{$data{$ou}{$cn_prefix}{$cn}{$cn_suffix}}) {
+                        $client->respond( [$ou, $cn_prefix, $cn, $cn_suffix, $cl, $data{$ou}{$cn_prefix}{$cn}{$cn_suffix}{$cl}] );
+                    }
+                       }
+                   }
                }
        }
        return undef;
index 50361b6..992c9a0 100644 (file)
@@ -43,7 +43,7 @@ function cpdBuild( contextTbody, contextRow, record, callnumber, orgid, depth, c
        var print = $n(templateRow,'print');
        print.onclick = function() { cpdBuildPrintPane(
                contextRow, record, callnumber, orgid, depth) };
-    if (typeof callnumber == 'object') {
+    if (callnumber == null) {
         addCSSClass(print,'hide_me');
     }
 
@@ -123,11 +123,12 @@ function cpdStylePopupWindow(div) {
 
 
 /* builds a friendly print window for this CNs data */
-function cpdBuildPrintPane(contextRow, record, callnumber, orgid, depth) {
+function cpdBuildPrintPane(contextRow, record, cn, orgid, depth) {
 
        var div = cpdBuildPrintWindow( record, orgid);
 
-       $n(div, 'cn').appendChild(text(callnumber));
+    var whole_cn_text = (cn[0] ? cn[0] + ' ' : '') + cn[1] + (cn[2] ? ' ' + cn[2] : '');
+       $n(div, 'cn').appendChild(text(whole_cn_text));
 
        unHideMe($n(div, 'copy_header'));
 
index 4b2984d..9ba7567 100644 (file)
@@ -810,7 +810,7 @@ function rdetailShowExtra(type, args) {
 function rdetailVolumeDetails(args) {
        var row = $(args.rowid);
        var tbody = row.parentNode;
-       cpdBuild( tbody, row, record, args.cn, args.org, args.depth, args.copy_location );
+       cpdBuild( tbody, row, record, [args.cn_prefix, args.cn, args.cn_suffix], args.org, args.depth, args.copy_location );
        return;
 }
 
@@ -819,7 +819,7 @@ function rdetailBuildCNList() {
        var select = $('cn_browse_selector');
        var index = 0;
        var arr = [];
-       for( var cn in callnumberCache ) arr.push( cn );
+       for( var cn_json in callnumberCache ) arr.push( cn_json );
        arr.sort();
 
        if( arr.length == 0 ) {
@@ -828,8 +828,10 @@ function rdetailBuildCNList() {
        }
 
        for( var i = 0; i < arr.length; i++ ) {
-               var cn = arr[i];
-               var opt = new Option(cn);
+               var cn_json = arr[i];
+        var cn = JSON2js(cn_json);
+        var whole_cn_text = (cn[0] ? cn[0] + ' ' : '') + cn[1] + (cn[2] ? ' ' + cn[2] : '');
+               var opt = new Option(whole_cn_text,cn_json);
                select.options[index++] = opt;
        }
        select.onchange = rdetailGatherCN;
@@ -837,7 +839,7 @@ function rdetailBuildCNList() {
 
 function rdetailGatherCN() {
        var cn = getSelectorVal($('cn_browse_selector'));
-       rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
+       rdetailShowCNBrowse( JSON2js(cn), getLocation(), getDepth(), true );
        setSelector( $('cn_browse_selector'), cn );
 }
 
@@ -852,7 +854,7 @@ function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
 
        unHideMe($('rdetail_cn_browse_select_div'));
        rdetailBuildCNList();
-       setSelector( $('cn_browse_selector'), cn );
+       setSelector( $('cn_browse_selector'), js2JSON(cn) );
        hideMe($('rdetail_copy_info_div'));
        hideMe($('rdetail_reviews_div'));
        hideMe($('rdetail_summary_div'));
@@ -926,7 +928,6 @@ function rdetailBuildInfoRows() {
        var method = FETCH_COPY_COUNTS_SUMMARY;
        if (rdetailShowCopyLocation)
                method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
-
        if( rdetailShowLocal ) 
                req = new Request(method, record.doc_id(), getLocation(), getDepth())
        else
@@ -1036,7 +1037,7 @@ function _rdetailBuildInfoRows(r) {
        for( var i = 0; i < summary.length; i++ ) {
 
                var arr = summary[i];
-               globalCNCache[arr[1]] = 1;
+               globalCNCache[js2JSON([arr[1],arr[2],arr[3]])] = 1; // prefix, label, suffix.  FIXME - Am I used anywhere?
                var thisOrg = findOrgUnit(arr[0]);
                var rowNode = $("cp_info_" + thisOrg.id());
                if(!rowNode) continue;
@@ -1070,11 +1071,11 @@ function _rdetailBuildInfoRows(r) {
                var cpc_temp = rowNode.removeChild(
                                findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
 
-               var statuses = arr[2];
+               var statuses = arr[4];
                var cl = '';
                if (rdetailShowCopyLocation) {
-                       cl = arr[2];
-                       statuses = arr[3];
+                       cl = arr[4];
+                       statuses = arr[5];
                }
 
 
@@ -1086,7 +1087,7 @@ function _rdetailBuildInfoRows(r) {
                        isLocal = true; 
                        if(!localCNFound) {
                                localCNFound = true;
-                               defaultCN = arr[1];
+                               defaultCN = [arr[1],arr[2],arr[3]]; // prefix, label, suffix
                        }
                }
 
@@ -1094,9 +1095,9 @@ function _rdetailBuildInfoRows(r) {
                unHideMe(rowNode);
 
                rdetailSetPath( thisOrg, isLocal );
-               rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
+               rdetailBuildBrowseInfo( rowNode, [arr[1],arr[2],arr[3]], isLocal, thisOrg, cl );
 
-               if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
+               if( i == summary.length - 1 && !defaultCN) defaultCN = [arr[1],arr[2],arr[3]]; // prefix, label, suffix
        }
 
        if(!found) unHideMe(G.ui.rdetail.cp_info_none);
@@ -1104,16 +1105,19 @@ function _rdetailBuildInfoRows(r) {
 
 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
 
+    var whole_cn_json = js2JSON(cn);
+    var whole_cn_text = (cn[0] ? cn[0] + ' ' : '') + cn[1] + (cn[2] ? ' ' + cn[2] : '');
+
        if(local) {
-               var cache = callnumberCache[cn];
+               var cache = callnumberCache[whole_cn_json];
                if( cache ) cache.count++;
-               else callnumberCache[cn] = { count : 1 };
+               else callnumberCache[whole_cn_json] = { count : 1 };
        }
 
        var depth = getDepth();
        if( !local ) depth = findOrgDepth(globalOrgTree);
 
-       $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
+       $n(row, 'rdetail_callnumber_cell').appendChild(text(whole_cn_text));
 
        if (rdetailShowCopyLocation) {
                var cl_cell = $n(row, 'rdetail_copylocation_cell');
@@ -1121,12 +1125,12 @@ function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
                unHideMe(cl_cell);
        }
 
-       _debug('setting action clicks for cn ' + cn);
+       _debug('setting action clicks for cn ' + whole_cn_text);
 
        var dHref = 'javascript:rdetailVolumeDetails('+
-                       '{copy_location : "'+cl.replace(/\"/g, '\\"')+'", rowid : "'+row.id+'", cn :"'+cn.replace(/\"/g, '\\"')+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
+                       '{copy_location : "'+cl.replace(/\"/g, '\\"')+'", rowid : "'+row.id+'", cn_prefix :"'+cn[0].replace(/\"/g, '\\"')+'",cn :"'+cn[1].replace(/\"/g, '\\"')+'",cn_suffix :"'+cn[2].replace(/\"/g, '\\"')+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
 
-       var bHref = 'javascript:rdetailShowCNBrowse("' + cn.replace(/\"/g, '\\"') + '", '+orgNode.id()+', "'+depth+'");'; 
+       var bHref = 'javascript:rdetailShowCNBrowse(["' + cn[0].replace(/\"/g, '\\"') + '","'+cn[1].replace(/\"/g, '\\"') + '","'+cn[2].replace(/\"/g, '\\"') + '"], '+orgNode.id()+', "'+depth+'");'; 
 
        unHideMe( $n(row, 'details') )
                $n(row, 'details').setAttribute('href', dHref);