LP#1053397 MR holds; more formats / lang display bits
authorBill Erickson <berick@esilibrary.com>
Fri, 31 Jan 2014 22:01:50 +0000 (17:01 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 31 Jan 2014 22:01:50 +0000 (17:01 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/holds/edit.tt2
Open-ILS/src/templates/opac/parts/metarecord_hold_filters.tt2
Open-ILS/src/templates/opac/parts/place_hold.tt2

index ca0859d..6d63aa2 100644 (file)
@@ -2477,7 +2477,7 @@ sub do_possibility_checks {
 
     } elsif( $hold_type eq OILS_HOLD_TYPE_METARECORD ) {
 
-        my $recs = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats);
+        my ($recs) = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats);
         my @status = ();
         for my $rec (@$recs) {
             @status = _check_title_hold_is_possible(
@@ -4236,6 +4236,7 @@ sub mr_hold_filter_attrs {
     my ($self, $client, $mr_id, $hold_ids) = @_;
     my $e = new_editor();
 
+
     my $mr = $e->retrieve_metabib_metarecord($mr_id) or return $e->event;
     my $bre_ids = $e->json_query({
         select => {mmrsm => ['source']},
@@ -4244,6 +4245,7 @@ sub mr_hold_filter_attrs {
     });
     $bre_ids = [map {$_->{source}} @$bre_ids];
 
+    my $item_lang_attr = 'item_lang'; # configurable?
     my $format_attr = $e->retrieve_config_global_flag(
         'opac.metarecord.holds.format_attr')->value;
 
@@ -4261,7 +4263,7 @@ sub mr_hold_filter_attrs {
         });
     }
 
-    my $langs = get_batch_ccvms($e, 'item_lang', $bre_ids);
+    my $langs = get_batch_ccvms($e, $item_lang_attr, $bre_ids);
     my $formats = get_batch_ccvms($e, $format_attr, $bre_ids);
 
     $client->respond({
@@ -4273,7 +4275,8 @@ sub mr_hold_filter_attrs {
     });
 
     return unless $hold_ids;
-    my $icon_attr = $e->retrieve_config_global_flag('opac.icon_attr')->value;
+    my $icon_attr = $e->retrieve_config_global_flag('opac.icon_attr');
+    $icon_attr = $icon_attr ? $icon_attr->value : '';
 
     for my $hold_id (@$hold_ids) {
         my $hold = $e->retrieve_action_hold_request($hold_id) 
@@ -4281,14 +4284,47 @@ sub mr_hold_filter_attrs {
 
         next unless $hold->hold_type eq 'M';
 
+        my $resp = {
+            hold => {
+                id => $hold_id,
+                formats => [],
+                langs => []
+            }
+        };
+
+        # collect the ccvm's for the selected formats / language (
+        # (i.e. the holdable formats) on the MR.
+        # this assumes a two-key structure for format / language,
+        # though assumption is made about the keys themselves.
+        my $hformats = OpenSRF::Utils::JSON->JSON2perl($hold->holdable_formats);
+        my $lang_vals = [];
+        my $format_vals = [];
+        for my $val (values %$hformats) {
+            # val is either a single ccvm or an array of them
+            $val = [$val] unless ref $val eq 'ARRAY';
+            for my $node (@$val) {
+                push (@$lang_vals, $node->{_val})   
+                    if $node->{_attr} eq $item_lang_attr; 
+                push (@$format_vals, $node->{_val})   
+                    if $node->{_attr} eq $format_attr;
+            }
+        }
+
+        # fetch the ccvm's for consistency with the {metarecord} blob
+        $resp->{hold}{formats} = $e->search_config_coded_value_map({
+            ctype => $format_attr, code => $format_vals});
+        $resp->{hold}{langs} = $e->search_config_coded_value_map({
+            ctype => $item_lang_attr, code => $lang_vals});
+
         # find all of the bib records within this metarcord whose 
         # format / language match the holdable formats on the hold
-        my @bre_ids = $self->method_lookup(
+        my ($bre_ids) = $self->method_lookup(
             'open-ils.circ.holds.metarecord.filterd_records')->run(
                 $hold->target, $hold->holdable_formats);
 
-        my $icons = get_batch_ccvms($e, $icon_attr, \@bre_ids);
-        $client->respond({hold => {id => $hold_id, icons => $icons}});
+        # now find all of the 'icon' attributes for the records
+        $resp->{hold}{icons} = get_batch_ccvms($e, $icon_attr, $bre_ids);
+        $client->respond($resp);
     }
 
     return;
index 82f6013..5731e6b 100644 (file)
@@ -575,9 +575,24 @@ sub fetch_user_holds {
                     [$blob->{hold}->{bre_id}], undef, {flesh => '{mra}'}
                 );
                 $blob->{marc_xml} = $data[0]->{marc_xml};
-                my $hold = $blob->{hold}->{hold};
-                $blob->{metarecord_ccvms} = $self->get_mr_ccvms($hold->target)
-                    if $hold->hold_type eq 'M';
+
+                # in the holds edit UI, we need to know what formats and
+                # languages the user selected for this hold, plus what
+                # formats/langs are available on the MR as a whole.
+                if ($blob->{hold}{hold}->hold_type eq 'M') {
+                    my $hold = $blob->{hold}->{hold};
+
+                    my $filter_data = $U->simplereq(
+                        'open-ils.circ',
+                        'open-ils.circ.mmr.holds.filters.authoritative.atomic', 
+                        $hold->target, [$hold->id]
+                    );
+
+                    $blob->{metarecord_filters} = 
+                        $filter_data->[0]->{metarecord};
+                    $blob->{metarecord_hold_extras} = 
+                        $filter_data->[1]->{hold}->{$hold->id};
+                }
                 push(@holds, $blob);
             }
         }
@@ -792,8 +807,17 @@ sub load_place_hold {
             for my $id (@targets) {
                 my ($mr) = grep {$_->id eq $id} @$mrecs;
 
-                my $avail_attrs = $self->get_mr_ccvms($mr->id);
-                my $format_attr = $avail_attrs->{formats}{attr};
+                my $filter_data = $U->simplereq(
+                    'open-ils.circ',
+                    'open-ils.circ.mmr.holds.filters.authoritative', $mr->id);
+
+                # pull the format attr from the format info returned
+                # from the API call, instead of fetching it again from
+                # the DB.  If there are no formats, then the format attr
+                # is irrelevant.
+                my $format_attr = 
+                    $filter_data->{metarecord}->{formats}->[0]->ctype
+                    if $filter_data->{metarecord}->{formats}->[0];
 
                 # during hold placement submission, the user selects
                 # which of the available formats/langs are acceptiable.
@@ -815,8 +839,8 @@ sub load_place_hold {
                 push(@hold_data, $data_filler->({
                     target => $mr, 
                     record => $mr->master_record,
-                    metarecord_ccvms => $avail_attrs,
-                    holdable_formats => $holdable_formats
+                    holdable_formats => $holdable_formats,
+                    metarecord_filters => $filter_data->{metarecord}
                 }));
             }
         },
@@ -1108,52 +1132,6 @@ sub attempt_hold_placement {
     }
 }
 
-# fetches the CCVMs IDs representing available languages and formats 
-# for the constituent records of the selected metarecord.  
-sub get_mr_ccvms {
-    my ($self, $mr_id) = @_;
-    my $e = $self->editor;
-
-    # crad.name which defines the set of metarecord formats
-    my $format_attr = $self->ctx->{search_cgf}->( # leverage caching
-        name => 'opac.metarecord.holds.format_attr')->[0]->value;
-
-    my $bre_ids = 
-        $e->search_metabib_metarecord_source_map({metarecord => $mr_id});
-    $bre_ids = [map {$_->source} @$bre_ids];
-    
-    my $query = {
-        select => {ccvm => [{column => 'id', transform => 'distinct'}]},
-        from => {mraf => {
-            ccvm => {
-                fkey => 'attr',
-                field => 'ctype',
-                filter => {code => {'=' => {'+mraf' => 'value'}}}
-            }
-        }},
-        where => {'+mraf' => {id => $bre_ids, attr => ''}}
-    };
-
-    $query->{where}{'+mraf'}{attr} = 'item_lang';
-    my $langs = $e->json_query($query);
-
-    $query->{where}{'+mraf'}{attr} = $format_attr;
-    my $formats = $e->json_query($query);
-
-    return {
-        formats => {
-            attr => $format_attr,
-            values => [map { $_->{id} } @$formats],
-        },
-        langs => {
-            attr => 'item_lang',
-            values => [map { $_->{id} } @$langs]
-        }
-    };
-}
-
-
-
 sub fetch_user_circs {
     my $self = shift;
     my $flesh = shift; # flesh bib data, etc.
index 8e0a81d..4664e3f 100644 (file)
                 <strong>[% l('Format:') %]</strong>
                 <img src="[% attrs.format_icon %]" alt="[% attrs.format_label | html %]" title="[% attrs.format_label | html %]" />
             </p>[% END %]
-            [% IF hold.metarecord_ccvms.formats.values.size OR # should this be size > 1
-                  hold.metarecord_ccvms.langs.values.size > 1;
-                PROCESS metarecord_hold_filters_selector hold_data=hold;
-            END %]
+    
+            [% IF hold.metarecord_filters.formats.size OR # should this be size > 1
+                  hold.metarecord_filters.langs.size > 1;
+                PROCESS metarecord_hold_filters_selector hold_data=hold; END %]
             <p>
                 <strong>[% l('Status') %]</strong>: [% hold.human_status %]
             </p>
index bc36bf2..3806eb1 100644 (file)
@@ -24,22 +24,7 @@ limiting the set of desired records for a given metarecord.
   }
 </style>
 
-[% BLOCK metarecord_hold_filters_selector;
-  format_ccvms = [];
-  lang_ccvms = [];
-  # some CCVMs have search_labels, some use the value as the label
-  # instead.  Accommodate both, starting with search_label
-  FOR ccvm_id IN hold_data.metarecord_ccvms.formats.values;
-    ccvm = ctx.get_ccvm(ccvm_id);
-    CALL ccvm.search_label(ccvm.value) UNLESS ccvm.search_label;
-    format_ccvms.push(ccvm);
-  END;
-  FOR ccvm_id IN hold_data.metarecord_ccvms.langs.values;
-    ccvm = ctx.get_ccvm(ccvm_id);
-    CALL ccvm.search_label(ccvm.value) UNLESS ccvm.search_label;
-    lang_ccvms.push(ccvm);
-  END;
-%]
+[% BLOCK metarecord_hold_filters_selector %]
 
 <div class="metarecord_filters">
   <div class="metarecord_filter_container">
@@ -48,7 +33,8 @@ limiting the set of desired records for a given metarecord.
     </div>
     <select multiple='multiple' 
       name="metarecord_formats_[% hold_data.target.id %]">
-      [% FOR ccvm IN format_ccvms.sort('search_label') %]
+      [% FOR ccvm IN 
+        hold_data.metarecord_filters.formats.sort('search_label') %]
         <option value="[% ccvm.code %]">
           [% ccvm.search_label | html %]
         </option>
@@ -63,9 +49,9 @@ limiting the set of desired records for a given metarecord.
     </div>
     <select multiple='multiple' 
       name="metarecord_langs_[% hold_data.target.id %]">
-      [% FOR lang_ccvm IN lang_ccvms.sort('search_label') %]
+      [% FOR lang_ccvm IN hold_data.metarecord_filters.langs.sort('value') %]
         <option value="[% lang_ccvm.code %]">
-          [% lang_ccvm.search_label | html %]
+          [% lang_ccvm.value | html %]
         </option>
       [% END %]
     </select>
index 8366843..6a8fb79 100644 (file)
@@ -64,8 +64,8 @@
                         <input type='hidden' name='part' value=''/>
                         [% END %]
                     [% END %]
-                    [% IF hdata.metarecord_ccvms.formats.values.size OR # should this be size > 1
-                          hdata.metarecord_ccvms.langs.values.size > 1;
+                    [% IF hdata.metarecord_filters.formats.size OR # should this be size > 1
+                          hdata.metarecord_filters.langs.size > 1;
                         PROCESS metarecord_hold_filters_selector hold_data=hdata;
                     END %]
                 </td>