Bug 39533: Use select2 to select item types and libraries in biblio export

This patch updates the bibliographic export page so that item type and
library export use Select2 form fields. This change has the added
benefit of enabling the removal of a single-use include,
branch-selector.inc.

The patch also adds some JavaScript to make sure the "CSV profile" field
appears on page load if CSV is selected as the file format. This is
helpful if the user has reloaded the page or arrived at the page by
using the browser back button.

To test, apply the patch and go to Cataloging -> Export catalog data.

- Under the "Export bibliographic records" tab you should see two
  Select2-style form field under the "Select records to export" heading,
  "Item type" and "Home library."
- Confirm that the fields work correctly when adding one or more
  selections to each.
- Confirm that the selections work correctly to filter the export. I
  recommend using CSV as the file format for the export. A MARC export
  CSV profile (Tools -> CSV profiles -> New CSV profile) containing
  these fields will show the relevant information:

  Title=245$a\|Library=952$a\|Itemtype=952$y

- When you select CSV as the file format the "CSV profile" dropdown menu
  should appear. If you choose a different format, that dropdown should
  disappear.
- With CSV selected as the file format, reload the page. The "CSV
  profile" field should still be visible.

Sponsored-by: Athens County Public Libraries
Signed-off-by: Janne <janne.seppanen@lahti.fi>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Owen Leonard 2025-03-24 15:19:45 +00:00 committed by Katrin Fischer
parent ad3983c8dd
commit 1745aa69d9
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 61 additions and 64 deletions

View File

@ -67,7 +67,3 @@ input[type="text"] {
padding-left: 1.5em;
}
.select2.select2-container.select2-container--default {
flex-grow: 1;
max-width: 60%;
}

View File

@ -48,4 +48,14 @@
.select2-container--default .select2-selection--multiple .select2-selection__rendered li {
clear: none;
width: auto;
}
}
.select2.select2-container.select2-container--default {
flex-grow: 1;
max-width: 60%;
}
fieldset.rows .select2 li {
clear: none;
width: unset;
}

View File

@ -1,24 +0,0 @@
[%# To select all include with selectall = 1 %]
<div class="branchselector">
<p
><a href="#" id="checkall"> <i class="fa fa-check"></i> Select all</a> | <a href="#" id="checknone"> <i class="fa fa-times"></i> Clear all</a></p
>
[% SET branches_for_loop = branches.hash(1).keys.nsort || [] %][%# Do not modify the original variable 'branches' %]
[% WHILE branches_for_loop.size > 0 %]
<div class="branchgridrow">
[% FOREACH i IN branches_for_loop.splice(0, 4) %]
[% i = i - 1 %]
[% SET branch = branches.$i %]
<div class="branchgriditem">
[% IF branch.selected || (selectall == 1) %]
<input id="branch_[% branch.branchcode | html %]" class="branch_select" type="checkbox" name="branch" value="[% branch.branchcode | html %]" checked="checked" />
[% ELSE %]
<input id="branch_[% branch.branchcode | html %]" class="branch_select" type="checkbox" name="branch" value="[% branch.branchcode | html %]" />
[% END %]
<label for="branch_[% branch.branchcode | html %]">[% branch.branchname | html %]</label>
</div>
[% END %]
</div>
[% END %]
</div>

View File

@ -13,8 +13,8 @@
>
[% INCLUDE 'doc-head-close.inc' %]
<style>
fieldset.rows fieldset.rows {
width: 90%;
fieldset.rows li {
display: flex;
}
</style>
</head>
@ -84,7 +84,6 @@
<li>
<label for="itemtype">Item type: </label>
<select name="itemtype" id="itemtype" multiple>
<option value="">-- All --</option>
[% FOREACH itemtype IN itemtypes %]
<option value="[% itemtype.itemtype | html %]">[% itemtype.translated_description | html %]</option>
[% END %]
@ -92,38 +91,40 @@
</li>
<li>
<label>With items owned by the following libraries: </label>
[% INCLUDE 'branch-selector.inc' branches = libraries %]
<label for="select_library">Home library: </label>
<select id="select_library" name="branch" multiple>
[% PROCESS options_for_libraries libraries => Branches.all( selected => branch_limit, unfiltered => 1, do_not_select_my_library => 1 ) %]
</select>
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>Call number range</legend>
<ol>
<li>
<label for="startcn">From item call number: </label>
<input id="startcn" type="text" name="start_callnumber" size="15" />
</li>
<li>
<label for="endcn">To item call number: </label>
<input id="endcn" type="text" name="end_callnumber" size="15" />
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>Call number range</legend>
<ol>
<li>
<label for="startcn">From item call number: </label>
<input id="startcn" type="text" name="start_callnumber" size="15" />
</li>
<li>
<label for="endcn">To item call number: </label>
<input id="endcn" type="text" name="end_callnumber" size="15" />
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>Accession date (inclusive)</legend>
<ol>
<li>
<label for="from">Start date:</label>
<input type="text" size="10" id="from" name="start_accession" value="[% from | html %]" class="flatpickr" data-date_to="to" />
</li>
<li>
<label for="to">End date:</label>
<input size="10" id="to" name="end_accession" value="[% end_accession | html %]" type="text" class="flatpickr" />
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>Accession date (inclusive)</legend>
<ol>
<li>
<label for="from">Start date:</label>
<input type="text" size="10" id="from" name="start_accession" value="[% from | html %]" class="flatpickr" data-date_to="to" />
</li>
<li>
<label for="to">End date:</label>
<input size="10" id="to" name="end_accession" value="[% end_accession | html %]" type="text" class="flatpickr" />
</li>
</ol>
</fieldset>
<fieldset class="rows">
@ -327,16 +328,23 @@
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'calendar.inc' %]
[% INCLUDE 'select2.inc' %]
<script>
$(document).ready(function () {
$("li.csv_profiles").hide();
const output_format = $("#output_format");
const csv_profiles = $("li.csv_profiles");
if (output_format.val() == "csv") {
csv_profiles.show();
} else {
csv_profiles.hide();
}
$("#bibs_panel select[name='output_format']").on("change", function () {
output_format.on("change", function () {
var format = $(this).val();
if (format == "csv") {
$("#bibs_panel li.csv_profiles").show();
csv_profiles.show();
} else {
$("#bibs_panel li.csv_profiles").hide();
csv_profiles.hide();
}
});
$("#checkall").on("click", function (e) {
@ -366,6 +374,13 @@
}
$("#filename_auth").val(file_name_auth[0] + "." + extension);
});
// Apply select2 to all select fields having a "multiple" attribute
let selectFields = document.querySelectorAll("select[multiple]");
selectFields.forEach(selectField => {
selectField.style.minWidth = "320px";
$(selectField).select2();
});
});
</script>
[% END %]