Bugzilla – Attachment 113791 Details for
Bug 27016
Make the pickup locations dropdowns use Select2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27016: Make the pickup locations dropdowns use Select2
Bug-27016-Make-the-pickup-locations-dropdowns-use-.patch (text/plain), 5.13 KB, created by
Nick Clemens (kidclamp)
on 2020-11-18 15:49:14 UTC
(
hide
)
Description:
Bug 27016: Make the pickup locations dropdowns use Select2
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-11-18 15:49:14 UTC
Size:
5.13 KB
patch
obsolete
>From 5b469f524e689872f1e3c3e44e568cee3e92c9bb Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 17 Nov 2020 12:08:39 -0300 >Subject: [PATCH] Bug 27016: Make the pickup locations dropdowns use Select2 > >On the shoulders of bug 27015, this patch makes the pickup locations >dropdowns use Select2 to handle both fetching the pickup location >on-deman through the API, and also searching for them. > >This provides a better user experience for really big lists. > >To test: >1. Have some holds on a biblio >=> SUCCESS: Bug 26988 works, made it load the data when you click on the >dropdowns. >2. Apply this patch >3. Reload the page >=> SUCCESS: Similar-ish behaviour >=> SUCCESS: Notice you can search for branch names and make the list >shrink >4. Sign off :-D > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/en/modules/reserve/request.tt | 37 +++++++++++++++++++++- > koha-tmpl/intranet-tmpl/prog/js/holds.js | 31 ------------------ > 2 files changed, 36 insertions(+), 32 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 f479387c7e..95f55fd960 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt >@@ -19,6 +19,9 @@ > </head> > > <body id="circ_request" class="catalog"> >+<script> >+ var select2Width = "100%"; >+</script> > [% INCLUDE 'header.inc' %] > [% INCLUDE 'circ-search.inc' %] > >@@ -985,7 +988,7 @@ > [% INCLUDE 'columns_settings.inc' %] > [% Asset.js("lib/hc-sticky.js") | $raw %] > [% Asset.js("js/circ-patron-search-results.js") | $raw %] >- [% Asset.js("js/holds.js") | $raw %] >+ [% INCLUDE 'select2.inc' %] > <script> > var Sticky; > var biblionumber = "[% biblionumber | $raw %]"; >@@ -1150,6 +1153,38 @@ > }); > [% END %] > >+ $(".pickup_location_dropdown").each( function () { >+ var this_dropdown = $(this); >+ var hold_id = $(this).data('hold_id'); >+ >+ this_dropdown.select2({ >+ ajax: { >+ url: '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations', >+ allowClear: false, >+ 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+'%'}}) >+ }; >+ return query; >+ }, >+ processResults: function (data) { >+ var results = []; >+ data.forEach( function ( library ) { >+ results.push( >+ { >+ "id": library.library_id.escapeHtml(), >+ "text": library.name.escapeHtml() >+ } >+ ); >+ }); >+ return { "results": results }; >+ } >+ } >+ }); >+ }); > }); > > function check() { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index 66dd265a14..134194bbfd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/holds.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js >@@ -301,35 +301,4 @@ $(document).ready(function() { > } > }); > }); >- >- $(".pickup_location_dropdown").on( "focus",function(){ >- var this_dropdown = $(this); >- if(this_dropdown.data('loaded')===1){ return true}; >- var hold_id = $(this).data('hold_id'); >- $(".loading_"+hold_id).show(); >- var preselected = $(this).data('selected'); >- var api_url = '/api/v1/holds/' + encodeURIComponent(hold_id) + '/pickup_locations'; >- $.ajax({ >- method: "GET", >- url: api_url, >- success: function( data ){ >- var dropdown = ""; >- $.each(data, function(index,library) { >- if( preselected == library.library_id ){ >- selected = ' selected="selected" '; >- } else { selected = ""; } >- dropdown += '<option value="' + library.library_id.escapeHtml() + '"' + selected + '>' + library.name.escapeHtml() + '</option>'; >- }); >- this_dropdown.html(dropdown); >- this_dropdown.data("loaded",1); >- $(".loading_"+hold_id).hide(); >- }, >- error: function( jqXHR, textStatus, errorThrown) { >- alert('There was an error:'+textStatus+" "+errorThrown); >- $(".loading_"+hold_id).hide(); >- }, >- }); >- }); >- >- > }); >-- >2.11.0
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 27016
:
113738
|
113740
|
113760
| 113791 |
113792
|
114807