Bug 34509: Use select2 to load vendors on basket creation

This patch moves the dropdown to use select2 and avoids loading all
vendors at page load.

To test:
 1 - Create some extra vendors in your system, ideally over 20
 2 - Search for a vendor in acquisitions
 3 - Click 'New->basket'
 4 - Note the dropdown of all vendors
 5 - Choose a vendor and create a basket
 6 - Apply patch
 7 - Repeat
 8 - Note only a partial list of vendors is loaded
 9 - Search in the dropdown and confirm vendors are returned
10 - Select a vendor and create the basket

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-08-09 17:39:45 +00:00 committed by Tomas Cohen Arazi
parent b679c82211
commit 77ee1ca743
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 50 additions and 12 deletions

View file

@ -116,9 +116,6 @@ if ( $op eq 'add_form' ) {
$template->param(contractloop => \@contractloop,
basketcontractnumber => $basket->{'contractnumber'});
}
my $booksellers = Koha::Acquisition::Booksellers->search(
undef,
{ order_by => { -asc => 'name' } } );
$template->param( add_form => 1,
basketname => $basket->{'basketname'},
@ -127,7 +124,6 @@ if ( $op eq 'add_form' ) {
booksellername => $bookseller->name,
booksellerid => $booksellerid,
basketno => $basketno,
booksellers => $booksellers,
is_standing => $basket->{is_standing},
create_items => $basket->{create_items},
);

View file

@ -82,14 +82,8 @@
<li>
<label for="basketbooksellerid">Vendor: </label>
<select name="basketbooksellerid" id="basketbooksellerid">
[% FOREACH b IN booksellers %]
[% IF booksellerid == b.id %]
<option value="[% b.id | html %]" selected="selected">[% b.name | html %]</option>
[% ELSE %]
<option value="[% b.id | html %]">[% b.name | html %]</option>
[% END %]
[% END %]
</select>
<option value="[% booksellerid | html %]" selected="selected">Current vendor ([% booksellername | html %])</option>
</select>
</li>
<li>
<label for="basketnote">Internal note: </label>
@ -163,6 +157,54 @@
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/acquisitions-menu.js") | $raw %]
[% Asset.js("js/acq.js") | $raw %]
[% INCLUDE 'select2.inc' %]
<script>
$(document).ready(function() {
function display_vendor(vendor) {
var $text;
$text = $('<span>'+vendor.text+'</span>');
return $text;
};
$("#basketbooksellerid").kohaSelect({
width: '50%',
allowClear: false,
ajax: {
url: '/api/v1/acquisitions/vendors',
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
};
return query;
},
processResults: function (data) {
var results = [];
data.results.forEach( function ( vendor ) {
results.push(
{
"id": vendor.id,
"text": vendor.name.escapeHtml()
}
);
});
return { "results": results, "pagination": { "more": data.pagination.more } };
}
},
templateResult: display_vendor,
templateSelection: display_vendor
});
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]