Skip to content

Commit

Permalink
Bug 34517: Add option search patron attributes by default
Browse files Browse the repository at this point in the history
This patch moves form any staff_searchable attribute being automatically
included in the the Standard patron serch, to allowing the librarian to choose.
Current searchable attributes will be marked as 'searched_by_default'

To test:
1 - Add a searchable patron attribute type
2 - Add some values
3 - Confirm they are searched in a 'Standard' patron search
4 - Apply patch
5 - Go to admin - >patron attribute types
6 - Note new 'Searching' column
7 - Confirm attribute is 'Searched by default'
8 - Confirm searches work as before
9 - Edit the attribute type
10 - Uncheck 'searched_by_default'
11 - Save
12 - Confirm attribute not searched in 'Standard' search
13 - Select the attribute in patron search dropdowns
14 - Confirm it is correctly searched

Signed-off-by: Kelly McElligott <[email protected]>
Signed-off-by: Katrin Fischer <[email protected]>
Signed-off-by: Tomas Cohen Arazi <[email protected]>
  • Loading branch information
kidclamp authored and tomascohen committed Nov 9, 2023
1 parent 72b106d commit dc59d34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 2 additions & 0 deletions admin/patron-attr-types.pl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ sub add_update_attribute_type {
my $opac_display = $input->param('opac_display') ? 1 : 0;
my $opac_editable = $input->param('opac_editable') ? 1 : 0;
my $staff_searchable = $input->param('staff_searchable') ? 1 : 0;
my $searched_by_default = $input->param('searched_by_default') ? 1 : 0;
my $keep_for_pseudonymization = $input->param('keep_for_pseudonymization') ? 1 : 0;
my $mandatory = $input->param('mandatory') ? 1 : 0;
my $authorised_value_category = $input->param('authorised_value_category');
Expand Down Expand Up @@ -152,6 +153,7 @@ sub add_update_attribute_type {
opac_display => $opac_display,
opac_editable => $opac_editable,
staff_searchable => $staff_searchable,
searched_by_default => $searched_by_default,
keep_for_pseudonymization => $keep_for_pseudonymization,
mandatory => $mandatory,
authorised_value_category => $authorised_value_category,
Expand Down
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
}, {});

[% IF Koha.Preference('ExtendedPatronAttributes') %]
[% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1 ) ] %]
[% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) ] %]
let extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %];
[% END %]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,21 @@
[% ELSE %]
<input type="checkbox" id="staff_searchable" name="staff_searchable" />
[% END %]
<span class="hint">Check to make this attribute staff_searchable in the staff patron search.</span>
<span class="hint">
Check to make this attribute searchable in staff patron searches. If
checked, this attribute will appear in patron search dropdowns.
</span>
</li>
<li><label for="searched_by_default">Search by default: </label>
[% IF attribute_type AND attribute_type.searched_by_default %]
<input type="checkbox" id="searched_by_default" name="searched_by_default" checked="checked" />
[% ELSE %]
<input type="checkbox" id="searched_by_default" name="searched_by_default" />
[% END %]
<span class="hint">
If checked, this field will be included in 'Standard' patron searches. Requires
field to be marked as searchable above
</span>
</li>
<li><label for="mandatory">Mandatory: </label>
[% IF attribute_type AND attribute_type.mandatory %]
Expand Down Expand Up @@ -301,6 +315,7 @@
<th>Library limitation</th>
<th>Authorized value category</th>
<th>Mandatory</th>
<th>Searching</th>
<th class="NoSort noExport">Actions</th>
</tr>
</thead>
Expand Down Expand Up @@ -340,6 +355,17 @@
<span>No</span>
[% END %]
</td>
<td>
[% IF ( item.staff_searchable ) %]
[% IF( item.searched_by_default ) %]
<span>Searched by default</span>
[% ELSE %]
<span>Searchable</span>
[% END %]
[% ELSE %]
<span>Not searchable</span>
[% END %]
</td>
<td class="actions">
<a class="btn btn-default btn-xs" href="[% script_name | url %]?op=edit_attribute_type&amp;code=[% item.code | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a>
<a class="btn btn-default btn-xs" href="[% script_name | url %]?op=delete_attribute_type&amp;code=[% item.code | uri %]"><i class="fa fa-trash-can"></i> Delete</a>
Expand Down Expand Up @@ -374,6 +400,22 @@
[% INCLUDE 'columns_settings.inc' %]
<script>
$(document).ready(function() {

function toggle_search_default(){
if( $("#staff_searchable").is(":checked") ){
$("#searched_by_default").prop('disabled', false);
} else {

$("#searched_by_default").prop('disabled', true).prop('checked',false);
}
}
$("#staff_searchable").on('change',function(){
toggle_search_default();
});

toggle_search_default();


if ( $("#branches option:selected").length < 1 ) {
$("#branches option:first").attr("selected", "selected");
}
Expand Down
2 changes: 1 addition & 1 deletion koha-tmpl/intranet-tmpl/prog/js/staff-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ function buildPatronSearchQuery(term, options) {
q.push({ "-or": term_subquery_or });

// Add each pattern for each extended patron attributes
if ( typeof options !== 'undefined' && ( (options.search_fields == 'standard' && options.extended_attribute_types) || searched_attribute_fields ) && extendedPatronAttributes) {
if ( typeof options !== 'undefined' && ( (options.search_fields == 'standard' && options.extended_attribute_types) || ( searched_attribute_fields.length > 0 ) ) && extendedPatronAttributes) {
extended_attribute_codes_to_search = (searched_attribute_fields.length > 0) ? searched_attribute_fields : options.extended_attribute_types;
extended_attribute_subquery_and = [];
patterns.forEach(function (pattern, i) {
Expand Down

0 comments on commit dc59d34

Please sign in to comment.