Bugzilla – Attachment 129117 Details for
Bug 29397
Add a select2 wrapper for the API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29397: Add .kohaSelect select2 wrapper function
Bug-29397-Add-kohaSelect-select2-wrapper-function.patch (text/plain), 2.34 KB, created by
Kyle M Hall (khall)
on 2022-01-06 19:56:59 UTC
(
hide
)
Description:
Bug 29397: Add .kohaSelect select2 wrapper function
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2022-01-06 19:56:59 UTC
Size:
2.34 KB
patch
obsolete
>From 475b8ce7abd1d26ccba4a04557dc2b7c9f7e037a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 3 Nov 2021 14:37:11 +0000 >Subject: [PATCH] Bug 29397: Add .kohaSelect select2 wrapper function > >This patch adds a kohaSelect wrapper function to simplify >paging/infinite scrolling with select2 using the Koha RESTful api's. > >Invoke select2 select boxes as you normally would from JS, but instead >of calling .select2(config) use .kohaSelect(config). > >If an 'ajax' property is defined in your config object, we wrap the >transport such that responses include a pagination key as expected by >select2. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > koha-tmpl/intranet-tmpl/prog/js/select2.js | 30 ++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/select2.js b/koha-tmpl/intranet-tmpl/prog/js/select2.js >index 1d78e0a0a22..3ac63d00435 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/select2.js >+++ b/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); >-- >2.30.2
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 29397
:
127265
|
127279
|
127280
|
127281
|
127320
|
127321
|
127322
| 129117 |
130221
|
130222