$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);
}
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;
my $type_dispatch = {
M => sub {
+ warn "OMG HERE\n";
# target metarecords
my $mrecs = $e->batch_retrieve_metabib_metarecord([
'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,
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');
}
}
+# 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.
}
</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">
<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 %]