LP#1053397 MR TPAC filters; editing
authorBill Erickson <berick@esilibrary.com>
Mon, 3 Feb 2014 22:52:18 +0000 (17:52 -0500)
committerBill Erickson <berick@esilibrary.com>
Mon, 3 Feb 2014 22:52:18 +0000 (17:52 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
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

index 5731e6b..c4431f7 100644 (file)
@@ -590,8 +590,8 @@ sub fetch_user_holds {
 
                     $blob->{metarecord_filters} = 
                         $filter_data->[0]->{metarecord};
-                    $blob->{metarecord_hold_extras} = 
-                        $filter_data->[1]->{hold}->{$hold->id};
+                    $blob->{metarecord_selected_filters} = 
+                        $filter_data->[1]->{hold};
                 }
                 push(@holds, $blob);
             }
@@ -670,6 +670,10 @@ sub handle_hold_update {
                     m:^(\d{2})/(\d{2})/(\d{4})$:;
                 $val->{$field} = "$3-$1-$2";
             }
+
+            $val->{holdable_formats} = # no-op for non-MR holds
+                $self->compile_holdable_formats(undef, $_);
+
             $val;
         } @hold_ids;
 
@@ -796,6 +800,7 @@ sub load_place_hold {
 
     my $type_dispatch = {
         M => sub {
+            warn "OMG HERE\n";
 
             # target metarecords
             my $mrecs = $e->batch_retrieve_metabib_metarecord([
@@ -811,30 +816,10 @@ sub load_place_hold {
                     '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.
-                # Capture those here as the holdable_formats for the MR hold.
-                my @selected_formats = $cgi->param('metarecord_formats_' . $mr->id);
-                my @selected_langs = $cgi->param('metarecord_langs_' . $mr->id);
-
-                # map the selected attrs into the JSON holdable_formats structure
-                @selected_formats = map {
-                    {_attr => $format_attr, _val => $_} } @selected_formats;
-                @selected_langs = map {
-                    {_attr => 'item_lang', _val => $_} } @selected_langs;
-
-                my $holdable_formats = OpenSRF::Utils::JSON->perl2JSON({
-                    0 => \@selected_formats,
-                    1 => \@selected_langs
-                });
+                my $holdable_formats = 
+                    $self->compile_holdable_formats($mr->id);
+
+                warn "holdable formats: $holdable_formats\n";
 
                 push(@hold_data, $data_filler->({
                     target => $mr, 
@@ -1057,8 +1042,6 @@ sub attempt_hold_placement {
         if ($hold_type eq 'M') {
             $holdable_formats->{$_->{target_id}} = 
                 $_->{holdable_formats} for @hold_data;
-            # TODO: cleanup
-            warn "MR Holdable formats " . Dumper($holdable_formats) . "\n";
         }
 
         my $bses = OpenSRF::AppSession->create('open-ils.circ');
@@ -1132,6 +1115,59 @@ sub attempt_hold_placement {
     }
 }
 
+# pull the selected formats and languages for metarecord holds
+# from the CGI params and map them into the JSON holdable
+# formats...er, format.
+# if no metarecord is provided, we'll pull it from the target
+# of the provided hold.
+sub compile_holdable_formats {
+    my ($self, $mr_id, $hold_id) = @_;
+    my $e = $self->editor;
+    my $cgi = $self->cgi;
+
+    warn "MR looking at params param = $_\n" for $cgi->param;
+
+    # exit early if not needed
+    return "" unless 
+        grep /metarecord_formats_|metarecord_langs_/, 
+        $cgi->param;
+
+    # CGI params are based on the MR id, since during hold placement
+    # we have no old ID.  During hold edit, map the hold ID back to 
+    # the metarecod target.
+    $mr_id = 
+        $e->retrieve_action_hold_request($hold_id)->target 
+        unless $mr_id;
+
+    my $format_attr = $self->ctx->{get_cgf}->(
+        'opac.metarecord.holds.format_attr');
+
+    if (!$format_attr) {
+        $logger->error("Missing config.global_flag: ".
+            "opac.metarecord.holds.format_attr!");
+        return "";
+    }
+
+    $format_attr = $format_attr->value;
+
+    # during hold placement or edit submission, the user selects
+    # which of the available formats/langs are acceptable.
+    # Capture those here as the holdable_formats for the MR hold.
+    my @selected_formats = $cgi->param("metarecord_formats_$mr_id");
+    my @selected_langs = $cgi->param("metarecord_langs_$mr_id");
+
+    # map the selected attrs into the JSON holdable_formats structure
+    @selected_formats = map {
+        {_attr => $format_attr, _val => $_} } @selected_formats;
+    @selected_langs = map {
+        {_attr => 'item_lang', _val => $_} } @selected_langs;
+
+    return OpenSRF::Utils::JSON->perl2JSON({
+        0 => \@selected_formats,
+        1 => \@selected_langs
+    });
+}
+
 sub fetch_user_circs {
     my $self = shift;
     my $flesh = shift; # flesh bib data, etc.
index 4664e3f..d34eb89 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_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>
                         </td>
                     </tr>
                     [% END %]
+                     
+                    <tr><td colspan='2'>
+                    [% IF hold.metarecord_filters.formats.size OR
+                        hold.metarecord_filters.langs.size > 1;
+                            PROCESS metarecord_hold_filters_selector 
+                                hold_data=hold; END %]
+                    </td></tr>
+
                     <tr>
                         <td colspan="2" class="hold-editor-controls">
                             <a href="[% ctx.opac_root %]/myopac/holds"><button 
index 3806eb1..9615ca8 100644 (file)
@@ -24,7 +24,21 @@ limiting the set of desired records for a given metarecord.
   }
 </style>
 
-[% BLOCK metarecord_hold_filters_selector %]
+[% BLOCK metarecord_hold_filters_selector;
+    # in edit mode, pull the target from the existing hold
+    target_id = hold_data.target.id || hold_data.hold.hold.target;
+
+    selected_formats = {};
+    selected_langs = {};
+    FOR fmt IN hold_data.metarecord_selected_filters.formats;
+        code = fmt.code;
+        selected_formats.$code = fmt;
+    END;
+    FOR lang IN hold_data.metarecord_selected_filters.langs;
+        code = lang.code;
+        selected_langs.$code = lang;
+    END;
+%]
 
 <div class="metarecord_filters">
   <div class="metarecord_filter_container">
@@ -32,25 +46,25 @@ limiting the set of desired records for a given metarecord.
       <div>[% l('Select your desired format(s).') %]</div>
     </div>
     <select multiple='multiple' 
-      name="metarecord_formats_[% hold_data.target.id %]">
+      name="metarecord_formats_[% target_id %]">
       [% FOR ccvm IN 
         hold_data.metarecord_filters.formats.sort('search_label') %]
-        <option value="[% ccvm.code %]">
+        <option value="[% ccvm.code %]"[%- code = ccvm.code; 
+            IF selected_formats.$code %] selected='selected'[% END -%]>
           [% ccvm.search_label | html %]
         </option>
       [% END %]
     </select>
-    <input type="hidden" 
-      name="metarecord_format_attr" value="[% format_ccvms.0.ctype %]"/>
   </div>
   <div class="metarecord_filter_container">
     <div class="metarecord_filter_header">
       [% l('Select your desired language(s)') %]
     </div>
     <select multiple='multiple' 
-      name="metarecord_langs_[% hold_data.target.id %]">
+      name="metarecord_langs_[% target_id %]">
       [% FOR lang_ccvm IN hold_data.metarecord_filters.langs.sort('value') %]
-        <option value="[% lang_ccvm.code %]">
+        <option value="[% lang_ccvm.code %]"[%- code = lang_ccvm.code; 
+            IF selected_langs.$code %]selected='selected'[% END -%]>
           [% lang_ccvm.value | html %]
         </option>
       [% END %]