From 4aed2e6212110efe79287b99b7a4e635a7ec002b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 11 Mar 2021 10:46:58 -0300 Subject: [PATCH] Bug 27894: Add visual feedback on overridden pickup locations This patch takes advantage of the previous changes, and makes the select2 dropdown display a warning sign (with a tooltip) on pickup locations that, if chosen, it would mean a circ rule would be overridden. To test: 1. Have some pickup locations that are not valid for existing holds and AllowHoldPolicyOverride set to "Don't allow" 2. Visit a biblio with some holds 3. Choose a hold that cannot use some pickup location and use the dropdown => SUCCESS: Only valid pickup locations are retrieved 4. Set Allow HoldPolicyOverride to "Allow" 5. Refresh the page (I usually click on the Holds tab) 6 .Repeat 3 => SUCCESS: All pickup locations in the system are displayed => FAIL: No visual feedback on overridden pickup locations :-( 7. Apply this patch and refresh the page 8. Repeat 3 => SUCCESS: All pickup locations in the systema are displayed => SUCCESS: Visual feedback on overridden pickup locations is shown! 9. Set AllowHoldPolicyOverride to "Don't allow" 10. Repeat 3 => SUCCESS: Only valid pickup locations are retrieved => SUCCESS: No overrridden warn/symbol, as expected 11. Sign off :-D Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- .../prog/en/modules/reserve/request.tt | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index b9a39864a8..22c098ef3b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1183,6 +1183,22 @@ }); [% END %] + function display_pickup_location (state) { + var $text; + if ( state.needs_override === true ) { + $text = $( + '' + state.text + ' ' + ); + } + else { + $text = $(''+state.text+''); + } + + return $text; + }; + $(".pickup_location_dropdown").each( function () { var this_dropdown = $(this); var hold_id = $(this).data('hold_id'); @@ -1190,34 +1206,32 @@ this_dropdown.select2({ allowClear: false, ajax: { - [%- IF Koha.Preference('AllowHoldPolicyOverride') -%] - url: '/api/v1/libraries', - [%- ELSE -%] url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations', - [%- END -%] delay: 300, // wait 300 milliseconds before triggering the request dataType: 'json', data: function (params) { var search_term = (params.term === undefined) ? '' : params.term; var query = { - "q": JSON.stringify({"name":{"-like":search_term+'%'},"pickup_location":1}), + "q": JSON.stringify({"name":{"-like":search_term+'%'}}), "_order_by": "name" }; return query; }, processResults: function (data) { var results = []; - data.forEach( function ( library ) { + data.forEach( function ( pickup_location ) { results.push( { - "id": library.library_id.escapeHtml(), - "text": library.name.escapeHtml() + "id": pickup_location.library_id.escapeHtml(), + "text": pickup_location.name.escapeHtml(), + "needs_override": pickup_location.needs_override } ); }); return { "results": results }; } - } + }, + templateResult: display_pickup_location }); }); }); -- 2.11.0