Bugzilla – Attachment 127319 Details for
Bug 29407
Make the pickup locations dropdown JS reusable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29407: Make the pickup locations dropdown JS reusable
Bug-29407-Make-the-pickup-locations-dropdown-JS-re.patch (text/plain), 17.79 KB, created by
Martin Renvoize (ashimema)
on 2021-11-04 13:45:22 UTC
(
hide
)
Description:
Bug 29407: Make the pickup locations dropdown JS reusable
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-11-04 13:45:22 UTC
Size:
17.79 KB
patch
obsolete
>From cb39fd4b024f2e5ddfe6ba9d542431b335345d79 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 3 Nov 2021 12:22:24 -0300 >Subject: [PATCH] Bug 29407: Make the pickup locations dropdown JS reusable > >This patch generates a function to be used in places where select2 >dropdowns are usesd for choosing pickup locations. This cleans >repeated/almost identical code introduced by different bugs. > >To test: >1. Make sure choosing pickup locations works >2. Apply this patch >3. Repeat 1 >=> SUCCESS: No functional changes >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > .../prog/en/includes/holds_table.inc | 6 +- > .../prog/en/modules/reserve/request.tt | 125 ++---------------- > koha-tmpl/intranet-tmpl/prog/js/holds.js | 120 +++++++++++------ > 3 files changed, 96 insertions(+), 155 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >index a712bfa4c7..dfddd9c75c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/holds_table.inc >@@ -129,7 +129,11 @@ > [%- IF Koha.Preference('IndependentBranches') && Branches.all().size == 1 -%] > [% Branches.GetName(hold.branchcode) | html %] <input type="hidden" name="pickup" value="[% hold.branchcode | html %]" /> > [%- ELSE -%] >- <select class="pickup_location_dropdown" data-selected="[% hold.branchcode | html %]" data-hold_id="[% hold.reserve_id | html %]" name="pickup"> >+ <select class="pickup_location_dropdown" >+ data-selected="[% hold.branchcode | html %]" >+ data-hold-id="[% hold.reserve_id | html %]" >+ data-pickup-location-source="hold" >+ name="pickup"> > <option selected="selected" value="[% hold.branchcode | html %]">[% Branches.GetName(hold.branchcode) | html %]</option> > <option value="" disabled="disabled" class="loading">Loading...</option> > </select> >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 7fc53d3d1c..1928610741 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >@@ -486,7 +486,10 @@ > <li> > <label for="pickup">Pickup at:</label> > [% UNLESS ( multi_hold ) %] >- <select name="pickup" id="pickup" data-biblio-id="[% biblio.biblionumber | html %]" data-patron-id="[% patron.borrowernumber | html %]"> >+ <select name="pickup" id="pickup" >+ data-biblio-id="[% biblio.biblionumber | html %]" >+ data-patron-id="[% patron.borrowernumber | html %]" >+ data-pickup-location-source="biblio"> > [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => biblionumber, patron => patron }, selected => pickup }) %] > [% ELSE %] > <select name="pickup" id="pickup_multi" data-patron-id="[% patron.borrowernumber | html %]"> >@@ -763,7 +766,8 @@ > [% IF (itemloo.pickup_locations_count > 0) %] > <select name="item_pickup_[% itemloo.itemnumber | html %]" class="pickup_locations" > data-item-id="[% itemloo.itemnumber | html %]" >- data-patron-id="[% patron.borrowernumber | html %]"> >+ data-patron-id="[% patron.borrowernumber | html %]" >+ data-pickup-location-source="item"> > [% IF (itemloo.default_pickup_location) %] > <option value="[% itemloo.default_pickup_location.branchcode | html %]" selected="selected">[% itemloo.default_pickup_location.branchname | html %]</option> > [% END %] >@@ -1292,42 +1296,7 @@ > [% END %] > > $(".pickup_location_dropdown").each( function () { >- var this_dropdown = $(this); >- var hold_id = $(this).data('hold_id'); >- >- this_dropdown.select2({ >- allowClear: false, >- ajax: { >- url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations', >- 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+'%'}}), >- "_order_by": "name", >- "_page": params.page >- }; >- >- return query; >- }, >- processResults: function (data, params) { >- var results = []; >- data.results.forEach( function ( pickup_location ) { >- results.push( >- { >- "id": pickup_location.library_id.escapeHtml(), >- "text": pickup_location.name.escapeHtml(), >- "needs_override": pickup_location.needs_override >- } >- ); >- }); >- return { "results": results, "pagination": { "more": data.pagination.more } }; >- }, >- transport: kohaSelect2Transport >- }, >- templateResult: display_pickup_location >- }); >+ $(this).pickup_locations_dropdown(); > }); > > $("#pickup_multi").select2({ >@@ -1354,83 +1323,11 @@ > }); > > $("#pickup").each( function () { >- var this_dropdown = $(this); >- var patron_id = $(this).data('patron-id'); >- var biblio_id = $(this).data('biblio-id'); >- >- this_dropdown.select2({ >- width: 'style', >- allowClear: false, >- ajax: { >- url: '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations', >- 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+'%'}}), >- "_order_by": "name", >- "patron_id": patron_id, >- "_page": params.page >- }; >- return query; >- }, >- processResults: function (data) { >- var results = []; >- data.results.forEach( function ( pickup_location ) { >- results.push( >- { >- "id": pickup_location.library_id.escapeHtml(), >- "text": pickup_location.name.escapeHtml(), >- "needs_override": pickup_location.needs_override >- } >- ); >- }); >- return { "results": results, "pagination": { "more": data.pagination.more } }; >- }, >- transport: kohaSelect2Transport, >- }, >- templateResult: display_pickup_location >- }); >+ $(this).pickup_locations_dropdown(); > }); >- $(".pickup_locations").each( function () { >- var this_dropdown = $(this); >- var patron_id = $(this).data('patron-id'); >- var item_id = $(this).data('item-id'); >- >- this_dropdown.select2({ >- allowClear: true, >- ajax: { >- url: '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations', >- 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+'%'}}), >- "_order_by": "name", >- "patron_id": patron_id, >- "_page": params.page >- }; >- return query; >- }, >- processResults: function (data) { >- var results = []; >- data.results.forEach( function ( pickup_location ) { >- results.push( >- { >- "id": pickup_location.library_id.escapeHtml(), >- "text": pickup_location.name.escapeHtml(), >- "needs_override": pickup_location.needs_override >- } >- ); >- }); >- return { "results": results, "pagination": { "more": data.pagination.more } }; >- }, >- transport: kohaSelect2Transport >- }, >- templateResult: display_pickup_location >- }); >+ >+ $(".pickup_locations").each(function () { >+ $(this).pickup_locations_dropdown(); > }); > }); > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index b03c9b388b..a022482bce 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/holds.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js >@@ -14,6 +14,84 @@ function display_pickup_location (state) { > return $text; > }; > >+(function ($) { >+ >+ /** >+ * Generate a Select2 dropdown for pickup locations >+ * >+ * It expects the select object to contain several data-* attributes >+ * - data-pickup-location-source: 'biblio', 'item' or 'hold' (default) >+ * - data-patron-id: required for 'biblio' and 'item' >+ * - data-biblio-id: required for 'biblio' only >+ * - data-item-id: required for 'item' only >+ * >+ * @return {Object} The Select2 instance >+ */ >+ >+ $.fn.pickup_locations_dropdown = function () { >+ var select = $(this); >+ var pickup_location_source = $(this).data('pickup-location-source'); >+ var patron_id = $(this).data('patron-id'); >+ var biblio_id = $(this).data('biblio-id'); >+ var item_id = $(this).data('item-id'); >+ var hold_id = $(this).data('hold-id'); >+ >+ var url; >+ >+ if ( pickup_location_source === 'biblio' ) { >+ url = '/api/v1/biblios/' + encodeURIComponent(biblio_id) + '/pickup_locations'; >+ } >+ else if ( pickup_location_source === 'item' ) { >+ url = '/api/v1/items/' + encodeURIComponent(item_id) + '/pickup_locations'; >+ } >+ else { // hold >+ url = '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations'; >+ } >+ >+ select.select2({ >+ width: 'style', >+ allowClear: false, >+ ajax: { >+ url: url, >+ delay: 300, // wait 300 milliseconds before triggering the request >+ cache: true, >+ dataType: 'json', >+ data: function (params) { >+ var search_term = (params.term === undefined) ? '' : params.term; >+ var query = { >+ "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}), >+ "_order_by": "name", >+ "_page": params.page >+ }; >+ >+ if ( pickup_location_source !== 'hold' ) { >+ query["patron_id"] = patron_id; >+ } >+ >+ return query; >+ }, >+ processResults: function (data) { >+ var results = []; >+ data.results.forEach( function ( pickup_location ) { >+ results.push( >+ { >+ "id": pickup_location.library_id.escapeHtml(), >+ "text": pickup_location.name.escapeHtml(), >+ "needs_override": pickup_location.needs_override >+ } >+ ); >+ }); >+ return { "results": results, "pagination": { "more": data.pagination.more } }; >+ }, >+ transport: kohaSelect2Transport, >+ }, >+ templateResult: display_pickup_location >+ }); >+ >+ return select; >+ }; >+})(jQuery); >+ > /* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */ > $(document).ready(function() { > var holdsTable; >@@ -94,7 +172,7 @@ $(document).ready(function() { > { > "mDataProp": function( oObj ) { > if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){ >- var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" data-hold-id="'+oObj.reserve_id+'" reserve_id="'+oObj.reserve_id+'" name="pick-location">'; >+ var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" data-hold-id="'+oObj.reserve_id+'" reserve_id="'+oObj.reserve_id+'" name="pick-location" data-pickup-location-source="hold">'; > for ( var i=0; i < oObj.branches.length; i++ ){ > var selectedbranch; > var setbranch; >@@ -235,45 +313,7 @@ $(document).ready(function() { > }); > }); > >- $(".hold_location_select").each( function () { >- var this_dropdown = $(this); >- var hold_id = $(this).data('hold-id'); >- >- this_dropdown.select2({ >- allowClear: false, >- ajax: { >- url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations', >- delay: 300, // wait 300 milliseconds before triggering the request >- dataType: 'json', >- cache: true, >- data: function (params) { >- var search_term = (params.term === undefined) ? '' : params.term; >- var query = { >- "q": JSON.stringify({"name":{"-like":'%'+search_term+'%'}}), >- "_order_by": "name", >- "_page": params.page >- }; >- return query; >- }, >- processResults: function (data) { >- var results = []; >- data.results.forEach( function ( pickup_location ) { >- results.push( >- { >- "id": pickup_location.library_id.escapeHtml(), >- "text": pickup_location.name.escapeHtml(), >- "needs_override": pickup_location.needs_override >- } >- ); >- }); >- return { "results": results, "pagination": { "more": data.pagination.more } }; >- }, >- transport: kohaSelect2Transport >- }, >- templateResult: display_pickup_location >- }); >- $('.select2-container').css('width','100%'); >- }); >+ $(".hold_location_select").each(function(){ $(this).pickup_locations_dropdown(); }); > > $(".hold_location_select").on("change", function(){ > $(this).prop("disabled",true); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29407
:
127269
|
127277
|
127278
|
127316
| 127319