LP1853006 TPAC: add limit to available option to item table
authorZavier Banks <zbanks@catalyte.io>
Wed, 13 May 2020 11:08:38 +0000 (11:08 +0000)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 Mar 2021 15:41:20 +0000 (11:41 -0400)
This patch adds a new control to the item table in
the TPAC public catalog only to specify that only items
that are available should be displayed.

Signed-off-by: Zavier Banks <zbanks@catalyte.io>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/templates/opac/parts/record/copy_table.tt2

index 76ee00d..f8e2f49 100644 (file)
@@ -2088,7 +2088,8 @@ sub basic_opac_copy_query {
             ccs => [
                 {column => 'id', alias => 'status_code'},
                 {column => 'name', alias => 'copy_status'},
-                {column => 'holdable', alias => 'status_holdable'}
+                {column => 'holdable', alias => 'status_holdable'},
+                {column => 'is_available', alias => 'is_available'}
             ],
             acn => [
                 {column => 'label', alias => 'call_number_label'},
index 0fa267b..c4c14d0 100644 (file)
@@ -35,6 +35,8 @@ sub load_record {
     my $org_name = $ctx->{get_aou}->($org)->shortname;
     my $pref_ou = $self->_get_pref_lib();
     my $depth = $self->cgi->param('depth');
+    my $available = $self->cgi->param('available') || 'false';
+
     $depth = $ctx->{get_aou}->($org)->ou_type->depth 
         unless defined $depth; # can be 0
 
@@ -214,6 +216,7 @@ sub load_record {
     $self->timelog("past store copy retrieval call");
     $ctx->{copy_limit} = $copy_limit;
     $ctx->{copy_offset} = $copy_offset;
+    $ctx->{available} = $available;
 
     $ctx->{have_holdings_to_show} = 0;
     $ctx->{have_mfhd_to_show} = 0;
@@ -350,14 +353,27 @@ sub mk_copy_query {
     my $copy_offset = shift;
     my $pref_ou = shift;
     my $coords = shift;
+    my $staff = $self->ctx->{is_staff};
+    my $available = $self->cgi->param('available') || 'false';
 
     my $query = $U->basic_opac_copy_query(
-        $rec_id, undef, undef, $copy_limit, $copy_offset, $self->ctx->{is_staff}
+        $rec_id, undef, undef, $copy_limit, $copy_offset, $staff
     );
 
+    if($available eq 'true') {
+        $query->{where} = {
+            '+acp' => {
+                deleted => 'f',
+                ($staff ? () : (opac_visible => 't'))
+            },
+            '+ccs' => { is_available => 't'},
+            ($staff ? () : ( '+aou' => { opac_visible => 't' } ))
+        };
+    }
+
     my $lasso_orgs = $self->search_lasso_orgs;
 
-    if($lasso_orgs || $org != $self->ctx->{aou_tree}->()->id) { 
+    if($lasso_orgs || $org != $self->ctx->{aou_tree}->()->id) {
         # no need to add the org join filter if we're not actually filtering
 
         my $filter_orgs = $lasso_orgs || $org;
index 358b836..c70e356 100644 (file)
@@ -12,6 +12,7 @@ IF serial_holdings;
         copies = copies.merge(units);
     END;
 END;
+available=ctx.available;
 
 FOREACH copy_info IN copies;
     IF copy_info.call_number_label != '##URI##';
@@ -44,6 +45,7 @@ IF has_copies or ctx.foreign_copies;
   depth = CGI.param('copy_depth').defined ? CGI.param('copy_depth') : CGI.param('depth').defined ? CGI.param('depth') : ctx.copy_summary.last.depth;
   total_copies = ctx.copy_summary.$depth.count;
 %]
+
 [% use_courses = (ctx.get_org_setting(ctx.aou_tree.id, 'circ.course_materials_opt_in') == 1) ? 1 : 0 %]
 [% IF ctx.geo_sort %]
 <form method="GET">
@@ -69,6 +71,20 @@ IF has_copies or ctx.foreign_copies;
 </form>
 [% END %]
 [% END %]
+
+<div>
+[% IF available == 'true'; %]
+    <a href="[% mkurl('', {available => 'false' }) %]">
+        Show All Copies
+    </a>
+[% END; %]
+
+[% IF available == 'false'; %]
+    <a href="[% mkurl('', {available => 'true' }) %]">
+        Show Only Available Copies
+    </a>
+[% END; %]
+
 <table class="table_no_border_space table_no_cell_pad table_no_border" width="100%" id="rdetails_status">
     <thead>
         <tr>
@@ -105,30 +121,30 @@ IF has_copies or ctx.foreign_copies;
     </thead>
     <tbody class="copy_details_table">
 [%- FOREACH peer IN ctx.foreign_copies;
-        FOREACH bib IN peer.foreign_copy_maps; %]
-    <tr class="copy_details_row"><td>
-    [%- bib_lib_name = ctx.get_aou(bib.target_copy.circ_lib).name | html;
-        l("[_1] (foreign item)", bib_lib_name); -%]
-        <ul><li>
-            <span class="bib_peer_type">[% bib.peer_type.name | html %]</span>:
-            <a href="[% mkurl(ctx.opac_root _ '/record/' _ bib.target_copy.call_number.record) %]">
-                <span class="bib_peer_title">[% peer.title | html %]</span> / 
-                <span class="bib_peer_author">[% peer.author | html %]</span>
-            </a>
-        </li></ul>
-    </td>
-    <td>[% bib.target_copy.call_number.label | html %]</td>
-    <td>[% bib.target_copy.barcode | html %]</td>
-    <td>[% bib.target_copy.location.name | html %]</td>
-    <td>[% bib.target_copy.status.name | html %]</td>
-    <td>[% date.format(ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),DATE_FORMAT) %]</td>
-    [%- IF use_courses %]
-    <td></td>
-    [%- END %]
-    [%- IF ctx.geo_sort && ctx.has_valid_coords %]
-    <td>[% display_ou_distance(bib.target_copy.circ_lib) %]</td>
-    [%- END %]
-</tr>
+    FOREACH bib IN peer.foreign_copy_maps; %]
+        <tr class="copy_details_row"><td>
+            [%- bib_lib_name = ctx.get_aou(bib.target_copy.circ_lib).name | html;
+                l("[_1] (foreign item)", bib_lib_name); -%]
+                <ul><li>
+                    <span class="bib_peer_type">[% bib.peer_type.name | html %]</span>:
+                    <a href="[% mkurl(ctx.opac_root _ '/record/' _ bib.target_copy.call_number.record) %]">
+                        <span class="bib_peer_title">[% peer.title | html %]</span> / 
+                        <span class="bib_peer_author">[% peer.author | html %]</span>
+                    </a>
+                </li></ul>
+            </td>
+            <td>[% bib.target_copy.call_number.label | html %]</td>
+            <td>[% bib.target_copy.barcode | html %]</td>
+            <td>[% bib.target_copy.location.name | html %]</td>
+            <td>[% bib.target_copy.status.name | html %]</td>
+            <td>[% date.format(ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),DATE_FORMAT) %]</td>
+            [%- IF use_courses %]
+            <td></td>
+            [%- END %]
+            [%- IF ctx.geo_sort && ctx.has_valid_coords %]
+            <td>[% display_ou_distance(bib.target_copy.circ_lib) %]</td>
+            [%- END %]
+        </tr>
    [%- END; # FOREACH peer
 END; # FOREACH bib
 -%]
@@ -148,149 +164,150 @@ END; # FOREACH bib
             END;
         -%]
         <tr class="copy_details_offers_row" property="offers" typeof="Offer">
-            [%- IF serial_holdings %]<td class='rdetail-issue-issue'>
-                [%- copy_info.holding_label | html; -%]
-            </td>
-            [%- ELSE %]<td>
-            [%- INCLUDE "opac/parts/library_name_link.tt2"; -%]
-                <link property="businessFunction" href="http://purl.org/goodrelations/v1#LeaseOut">
-                <meta property="price" content="0.00">
-            </td>[% END %]
-            <td><span property="sku">[% callnum | html %]</span> [% IF ctx.get_org_setting(CGI.param('loc') 
-                OR ctx.aou_tree.id, 'sms.enable') == 1 %](<a href="[% mkurl(ctx.opac_root _ '/sms_cn', 
-               {copy_id => copy_info.id}) %];rec=[%- ctx.bre_id -%]" rel="nofollow" vocab="">Text</a>)[% END %]</td>
-            [%- IF has_parts == 'true' %]
-            <td>[% copy_info.part_label | html %]</td>
-            [%- END %]
-            <td property="serialNumber">
-                [% copy_info.barcode | html -%]
-                [% IF ctx.is_staff %]
-                  [%- IF ctx.is_browser_staff %]
-                    <a target="_blank" href="[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]">[% l('view') %]</a>
-                    [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
-                        OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
-                        <span> | </span>
-                        <a href="javascript:;" onclick='window.open("[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]/edit", "_blank");'>[% l('edit') %]</a>
+                [%- IF serial_holdings %]<td class='rdetail-issue-issue'>
+                    [%- copy_info.holding_label | html; -%]
+                </td>
+                [%- ELSE %]<td>
+                [%- INCLUDE "opac/parts/library_name_link.tt2"; -%]
+                    <link property="businessFunction" href="http://purl.org/goodrelations/v1#LeaseOut">
+                    <meta property="price" content="0.00">
+                </td>[% END %]
+                <td><span property="sku">[% callnum | html %]</span> [% IF ctx.get_org_setting(CGI.param('loc') 
+                    OR ctx.aou_tree.id, 'sms.enable') == 1 %](<a href="[% mkurl(ctx.opac_root _ '/sms_cn', 
+                {copy_id => copy_info.id}) %];rec=[%- ctx.bre_id -%]" rel="nofollow" vocab="">Text</a>)[% END %]</td>
+                [%- IF has_parts == 'true' %]
+                <td>[% copy_info.part_label | html %]</td>
+                [%- END %]
+                <td property="serialNumber">
+                    [% copy_info.barcode | html -%]
+                    [% IF ctx.is_staff %]
+                    [%- IF ctx.is_browser_staff %]
+                        <a target="_blank" href="[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]">[% l('view') %]</a>
+                        [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
+                            OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
+                            <span> | </span>
+                            <a href="javascript:;" onclick='window.open("[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]/edit", "_blank");'>[% l('edit') %]</a>
+                        [% END %]
+                    [% ELSE %]
+                        <a onclick="xulG.new_tab(xulG.urls.XUL_COPY_STATUS, {}, {'from_item_details_new': true, 'barcodes': ['[%- copy_info.barcode | html | replace('\'', '\\\'') -%]']})"
+                            href="javascript:;">[% l('view') %]</a>
+                        [%# if the user can edit copies, show the copy edit link %]
+                        [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
+                            OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
+                            <span> | </span>
+                            <a href="javascript:;" 
+                                onclick="xulG.volume_item_creator({copy_id : [% copy_info.id %]})">
+                                [% l(' edit') %]
+                            </a>
+                        [% END %]
                     [% END %]
-                  [% ELSE %]
-                    <a onclick="xulG.new_tab(xulG.urls.XUL_COPY_STATUS, {}, {'from_item_details_new': true, 'barcodes': ['[%- copy_info.barcode | html | replace('\'', '\\\'') -%]']})"
-                        href="javascript:;">[% l('view') %]</a>
-                    [%# if the user can edit copies, show the copy edit link %]
-                    [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
-                        OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
-                        <span> | </span>
-                        <a href="javascript:;" 
-                            onclick="xulG.volume_item_creator({copy_id : [% copy_info.id %]})">
-                            [% l(' edit') %]
-                        </a>
                     [% END %]
-                  [% END %]
-                [% END %]
-                [%- IF attrs.gtin13;
-                    '<meta property="gtin13" content="' _ attrs.gtin13 _ '" />';
-                END; -%]
-            </td>
-            <td property="availableAtOrFrom">[%- INCLUDE "opac/parts/location_name_link.tt2"; -%]</td>
 
-            [% IF copy_info.courses.size > 0 || ctx.is_staff %]
-            <td>[% copy_info.circ_modifier | html %]</td>
-            [% ELSIF use_courses %]
-            <td></td>
-            [% END %]
-            [% IF ctx.is_staff %]
-            <td>
-                [% copy_info.age_protect ?
-                    ctx.get_crahp(copy_info.age_protect).name : l('None') | html %]
-            </td>
-            <td>[% 
-                IF ctx.get_org_setting(copy_info.circ_lib, 'circ.holds.age_protect.active_date') == 1;
-                    disp_date = copy_info.active_date ? copy_info.active_date : copy_info.create_date;
-                ELSE;
-                    disp_date = copy_info.create_date;
-                END;
-           
-                IF disp_date;
-                    date.format(
-                        ctx.parse_datetime(disp_date),
-                        DATE_FORMAT
+                    [%- IF attrs.gtin13;
+                        '<meta property="gtin13" content="' _ attrs.gtin13 _ '" />';
+                    END; -%]
+                </td>
+                <td property="availableAtOrFrom">[%- INCLUDE "opac/parts/location_name_link.tt2"; -%]</td>
+
+                [% IF copy_info.courses.size > 0 || ctx.is_staff %]
+                <td>[% copy_info.circ_modifier | html %]</td>
+                [% ELSIF use_courses %]
+                <td></td>
+                [% END %]
+                [% IF ctx.is_staff %]
+                <td>[% copy_info.circ_modifier | html %]</td>
+                <td>
+                    [% copy_info.age_protect ?
+                        ctx.get_crahp(copy_info.age_protect).name : l('None') | html %]
+                </td>
+                <td>[% 
+                    IF ctx.get_org_setting(copy_info.circ_lib, 'circ.holds.age_protect.active_date') == 1;
+                        disp_date = copy_info.active_date ? copy_info.active_date : copy_info.create_date;
+                    ELSE;
+                        disp_date = copy_info.create_date;
+                    END;
+            
+                    IF disp_date;
+                        date.format(
+                            ctx.parse_datetime(disp_date),
+                            DATE_FORMAT
+                        );
+                    ELSE;
+                    '-';
+                    END;
+                %]</td>
+                [% END # is_staff %]
+                [% IF ctx.is_staff OR serial_holdings %]
+                <td>[%  # Show copy/volume hold links to staff (without
+                    # checking whether they have permissions to do those).
+                    overall_holdable = (
+                        copy_info.holdable == 't' AND
+                        copy_info.location_holdable == 't' AND
+                        copy_info.status_holdable == 't'
                     );
-                ELSE;
-                   '-';
-                END;
-            %]</td>
-            [% END # is_staff %]
-            [% IF ctx.is_staff OR serial_holdings %]
-            <td>[%  # Show copy/volume hold links to staff (without
-                # checking whether they have permissions to do those).
-                overall_holdable = (
-                    copy_info.holdable == 't' AND
-                    copy_info.location_holdable == 't' AND
-                    copy_info.status_holdable == 't'
-                );
-                IF overall_holdable;
-                    hold_link = '';
-                    param_sep = l(" / ");
+                    IF overall_holdable;
+                        hold_link = '';
+                        param_sep = l(" / ");
 
-                    # Only staff get to place copy or volume holds
-                    IF ctx.is_staff; 
-                        hold_link = '<a href="' _
-                            mkurl(ctx.opac_root _ '/place_hold', {
-                                hold_target => copy_info.id,
-                                hold_type => 'C',
-                                hold_source_page => mkurl()
-                            }) _ '">' _ l('Copy hold') _ '</a>';
-                        IF copy_info.call_number != last_cn;
-                            last_cn = copy_info.call_number; 
-                            hold_link = hold_link _ param_sep;
-                            hold_link = hold_link _ '<a href="' _
+                        # Only staff get to place copy or volume holds
+                        IF ctx.is_staff; 
+                            hold_link = '<a href="' _
                                 mkurl(ctx.opac_root _ '/place_hold', {
-                                    hold_target => copy_info.call_number,
-                                    hold_type => 'V',
+                                    hold_target => copy_info.id,
+                                    hold_type => 'C',
                                     hold_source_page => mkurl()
-                                }) _ '">' _ l('Volume hold') _ '</a>';
-                        END;
-                        IF serial_holdings;
-                            hold_link = hold_link _ param_sep;
+                                }) _ '">' _ l('Copy hold') _ '</a>';
+                            IF copy_info.call_number != last_cn;
+                                last_cn = copy_info.call_number; 
+                                hold_link = hold_link _ param_sep;
+                                hold_link = hold_link _ '<a href="' _
+                                    mkurl(ctx.opac_root _ '/place_hold', {
+                                        hold_target => copy_info.call_number,
+                                        hold_type => 'V',
+                                        hold_source_page => mkurl()
+                                    }) _ '">' _ l('Volume hold') _ '</a>';
+                            END;
+                            IF serial_holdings;
+                                hold_link = hold_link _ param_sep;
+                            END;
+                        END; 
+                        IF serial_holdings; 
+                            hold_link = hold_link _
+                                '<a class="rdetail-issue-place-hold" href="' _
+                                mkurl(ctx.opac_root _ '/place_hold', {
+                                    hold_target => copy_info.issuance,
+                                    hold_type => 'I',
+                                    hold_source_page => mkurl()
+                                }) _ '" rel="nofollow" vocab="">' _ l('Issue hold') _ '</a>';
                         END;
-                    END; 
-                    IF serial_holdings; 
-                        hold_link = hold_link _
-                            '<a class="rdetail-issue-place-hold" href="' _
-                            mkurl(ctx.opac_root _ '/place_hold', {
-                                hold_target => copy_info.issuance,
-                                hold_type => 'I',
-                                hold_source_page => mkurl()
-                            }) _ '" rel="nofollow" vocab="">' _ l('Issue hold') _ '</a>';
-                    END; 
-
-                    hold_link;
-                ELSE; 
-                    l("Not holdable");
-                END %]</td>
-            [%- END %]
-            <td>[%-
-                schema_copy_status.${copy_info.status_code};
-                copy_info.copy_status | html;
-            -%]</td>
-            <td>[%
-                IF copy_info.due_date;
-                    date.format(
-                        ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),
-                        DATE_FORMAT
-                    );
-                ELSE;
-                    '-';
-                END %]</td>
-            [%- IF use_courses %]
-            <td>[%- FOREACH course IN copy_info.courses %]
-                <div>[% course.course_number %]</div>
-            [% END %]</td>
-            [% END %]
-            [%- IF ctx.geo_sort && ctx.has_valid_coords %]
-               <td>[% display_ou_distance(copy_info.circ_lib) %]</td>
-            [%- END %]
-        </tr>
 
+                        hold_link;
+                    ELSE; 
+                        l("Not holdable");
+                    END %]</td>
+                [%- END %]
+                <td>[%-
+                    schema_copy_status.${copy_info.status_code};
+                    copy_info.copy_status | html;
+                -%]</td>
+                <td>[%
+                    IF copy_info.due_date;
+                        date.format(
+                            ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),
+                            DATE_FORMAT
+                        );
+                    ELSE;
+                        '-';
+                    END %]</td>
+                [%- IF use_courses %]
+                <td>[%- FOREACH course IN copy_info.courses %]
+                    <div>[% course.course_number %]</div>
+                [% END %]</td>
+                [% END %]
+                [%- IF ctx.geo_sort && ctx.has_valid_coords %]
+                   <td>[% display_ou_distance(copy_info.circ_lib) %]</td>
+                [%- END %]
+            </tr>
         [% IF copy_info.notes; %]
             [% FOREACH note IN copy_info.notes; %]
                 <tr><td>&nbsp;</td><td class="copy_note" colspan="4" property="description"><strong>[% note.title | html %]:</strong> [% note.value | html %]</td></tr>
@@ -339,7 +356,6 @@ END; # FOREACH bib
 </td></tr>
 [%- END; # FOR copy_info
 %]
-        <tr>
         [%- IF ctx.copy_offset > 0 AND NOT serial_holdings;
             new_offset = ctx.copy_offset - ctx.copy_limit;
             IF new_offset < 0; new_offset = 0; END %]
@@ -375,4 +391,5 @@ END; # FOREACH bib
         [%- END %]
     </tbody>
 </table>
+</div>
 [% END; %]