Lines 13-45
function patron_autocomplete(node, options) {
Link Here
|
13 |
on_select_callback = options['on-select-callback']; |
13 |
on_select_callback = options['on-select-callback']; |
14 |
} |
14 |
} |
15 |
} |
15 |
} |
|
|
16 |
const search_fields = ['me.surname', 'me.firstname', 'me.cardnumber']; |
16 |
return node.autocomplete({ |
17 |
return node.autocomplete({ |
17 |
source: function( request, response ) { |
18 |
source: function( request, response ) { |
18 |
let params = { |
19 |
let subquery_and = []; |
19 |
'_page': 1, |
20 |
request.term.split(' ') |
20 |
'_per_page': 10, |
21 |
.filter(function(s){ return s.length }) |
21 |
'q': JSON.stringify([ |
22 |
.forEach(function(pattern,i){ |
22 |
{"me.firstname": {"like": "%"+request.term+"%"}}, |
23 |
subquery_and.push( |
23 |
{"me.surname": {"like": "%"+request.term+"%"}}, |
24 |
[ |
24 |
{"me.cardnumber": {"like": request.term+"%"}} |
25 |
{'me.surname': {'like': '%' + pattern + '%'}}, |
25 |
]), |
26 |
{'me.firstname': {'like': '%' + pattern + '%'}}, |
26 |
'_order_by': '+me.surname,+me.firstname', |
27 |
{'me.cardnumber': {'like': pattern + '%'}}, |
27 |
}; |
28 |
] |
28 |
$.ajax({ |
29 |
); |
29 |
data: params, |
|
|
30 |
type: 'GET', |
31 |
url: '/api/v1/patrons', |
32 |
headers: { |
33 |
"x-koha-embed": "library" |
34 |
}, |
35 |
success: function(data) { |
36 |
return response(data); |
37 |
}, |
38 |
error: function() { |
39 |
alert( _("An error occurred. Check the logs") ); |
40 |
return response(); |
41 |
} |
42 |
}); |
30 |
}); |
|
|
31 |
let q = {"-and": subquery_and}; |
32 |
let params = { |
33 |
'_page': 1, |
34 |
'_per_page': 10, |
35 |
'q': JSON.stringify(q), |
36 |
'_order_by': '+me.surname,+me.firstname', |
37 |
}; |
38 |
$.ajax({ |
39 |
data: params, |
40 |
type: 'GET', |
41 |
url: '/api/v1/patrons', |
42 |
headers: { |
43 |
"x-koha-embed": "library" |
44 |
}, |
45 |
success: function(data) { |
46 |
return response(data); |
47 |
}, |
48 |
error: function() { |
49 |
alert( _("An error occurred. Check the logs") ); |
50 |
return response(); |
51 |
} |
52 |
}); |
43 |
}, |
53 |
}, |
44 |
minLength: 3, |
54 |
minLength: 3, |
45 |
select: function( event, ui ) { |
55 |
select: function( event, ui ) { |
46 |
- |
|
|