@@ -, +, @@ --- koha-tmpl/intranet-tmpl/prog/js/select2.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) --- a/koha-tmpl/intranet-tmpl/prog/js/select2.js +++ a/koha-tmpl/intranet-tmpl/prog/js/select2.js @@ -57,3 +57,33 @@ function kohaSelect2Transport(params, success, failure) { $request.then(read_headers).then(success); $request.fail(failure); } + +/* wrapper that nests paging information into the results object for use with koha REST apis */ +(function($) { + $.fn.kohaSelect = function(config) { + if (config.hasOwnProperty('ajax')) { + config.ajax.transport = function(params, success, failure) { + var read_headers = function(data, textStatus, jqXHR) { + var more = false; + var link = jqXHR.getResponseHeader('Link') || ''; + if (link.search(/<([^>]+)>;\s*rel\s*=\s*['"]?next['"]?\s*(,|$)/i) > -1) { + more = true; + } + + return { + results: data, + pagination: { + more: more + } + }; + }; + var $request = $.ajax(params); + $request.then(read_headers).then(success); + $request.fail(failure); + + }; + } + + $(this).select2(config); + }; +})(jQuery); --