</head>
<body id="circ_request" class="catalog">
+<script>
+ var select2Width = "100%";
+</script>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'circ-search.inc' %]
[% 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 %]";
});
[% 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() {
}
});
});
-
- $(".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();
- },
- });
- });
-
-
});