Lines 94-105
$(document).ready(function() {
Link Here
|
94 |
"-or": function(){ |
94 |
"-or": function(){ |
95 |
let patron = $("#illfilter_patron").val(); |
95 |
let patron = $("#illfilter_patron").val(); |
96 |
let status = $("#illfilter_status").val(); |
96 |
let status = $("#illfilter_status").val(); |
|
|
97 |
let status_alias = $("#illfilter_status_alias").val(); |
97 |
let filters = []; |
98 |
let filters = []; |
98 |
let patron_sub_or = []; |
99 |
let patron_sub_or = []; |
99 |
let status_sub_or = []; |
100 |
let status_sub_or = []; |
100 |
let subquery_and = []; |
101 |
let subquery_and = []; |
101 |
|
102 |
|
102 |
if (!patron && !status) return ""; |
103 |
if (!patron && !status && !status_alias) return ""; |
103 |
|
104 |
|
104 |
if(patron){ |
105 |
if(patron){ |
105 |
const patron_search_fields = "me.borrowernumber,patron.cardnumber,patron.firstname,patron.surname"; |
106 |
const patron_search_fields = "me.borrowernumber,patron.cardnumber,patron.firstname,patron.surname"; |
Lines 118-130
$(document).ready(function() {
Link Here
|
118 |
} |
119 |
} |
119 |
|
120 |
|
120 |
if(status){ |
121 |
if(status){ |
121 |
const status_search_fields = "me.status,me.status_av"; |
122 |
subquery_and.push( {"me.status":{"=": status }}); |
122 |
status_search_fields.split(',').forEach(function(attr){ |
123 |
} |
123 |
status_sub_or.push({ |
124 |
if(status_alias){ |
124 |
[attr]:{"=": status } |
125 |
subquery_and.push({"me.status_alias":{"=": status_alias }}); |
125 |
}); |
|
|
126 |
}); |
127 |
subquery_and.push(status_sub_or); |
128 |
} |
126 |
} |
129 |
|
127 |
|
130 |
filters.push({"-and": subquery_and}); |
128 |
filters.push({"-and": subquery_and}); |
Lines 432-468
$(document).ready(function() {
Link Here
|
432 |
$('#illfilter_form > fieldset > ol > li:nth-child(6) > span > a').click(); |
430 |
$('#illfilter_form > fieldset > ol > li:nth-child(6) > span > a').click(); |
433 |
$('#illfilter_form > fieldset > ol > li:nth-child(7) > span > a').click(); |
431 |
$('#illfilter_form > fieldset > ol > li:nth-child(7) > span > a').click(); |
434 |
|
432 |
|
435 |
disableStatusFilter(); |
|
|
436 |
|
437 |
redrawTable(); |
433 |
redrawTable(); |
438 |
} |
434 |
} |
439 |
|
435 |
|
440 |
function populateStatusFilter(backend) { |
436 |
function addStatusOptions(statuses){ |
441 |
$.ajax({ |
437 |
$('#illfilter_status').children().remove(); |
442 |
type: "GET", |
438 |
$('#illfilter_status').append( |
443 |
url: "/api/v1/ill/backends/"+backend, |
439 |
'<option value="">'+ill_all_statuses+'</option>' |
444 |
headers: { |
440 |
); |
445 |
'x-koha-embed': 'statuses+strings' |
441 |
statuses.sort((a, b) => a.str.localeCompare(b.str)).forEach(function(status) { |
446 |
}, |
442 |
$('#illfilter_status').append( |
447 |
success: function(response){ |
443 |
'<option value="' + status.code + |
448 |
let statuses = response.statuses |
444 |
'">' + status.str + '</option>' |
449 |
$('#illfilter_status').append( |
445 |
); |
450 |
'<option value="">'+ill_all_statuses+'</option>' |
446 |
}); |
|
|
447 |
} |
448 |
|
449 |
function addStatusAliasOptions(status_aliases){ |
450 |
$('#illfilter_status_alias').parent().remove(); |
451 |
if (status_aliases.length !== 0) { |
452 |
$('#illfilter_status').parent().after(function() { |
453 |
return '<li><label for="illfilter_status_alias">'+ill_status_aliases+':</label> <select name="illfilter_status_alias" id="illfilter_status_alias"></select></li>'; |
454 |
}); |
455 |
$('#illfilter_status_alias').append( |
456 |
'<option value="">'+ill_all_status_aliases+'</option>' |
457 |
); |
458 |
status_aliases.sort((a, b) => a.str.localeCompare(b.str)).forEach(function (status_alias) { |
459 |
$('#illfilter_status_alias').append( |
460 |
'<option value="' + status_alias.code + |
461 |
'">' + status_alias.str + '</option>' |
451 |
); |
462 |
); |
452 |
statuses.sort((a, b) => a.str.localeCompare(b.str)).forEach(function(status) { |
463 |
}); |
453 |
$('#illfilter_status').append( |
464 |
} |
454 |
'<option value="' + status.code + |
465 |
} |
455 |
'">' + status.str + '</option>' |
466 |
|
456 |
); |
467 |
function populateStatusFilter(params) { |
457 |
}); |
468 |
if(params.backend_statuses){ |
|
|
469 |
if(params.backend_statuses.statuses){ |
470 |
addStatusOptions(params.backend_statuses.statuses); |
458 |
} |
471 |
} |
459 |
}); |
472 |
if(params.backend_statuses.status_aliases){ |
|
|
473 |
addStatusAliasOptions(params.backend_statuses.status_aliases); |
474 |
} |
475 |
}else if(params.backend){ |
476 |
let backend_id = params.backend || ""; |
477 |
$.ajax({ |
478 |
type: "GET", |
479 |
url: "/api/v1/ill/backends/"+backend_id, |
480 |
headers: { |
481 |
'x-koha-embed': 'statuses+strings' |
482 |
}, |
483 |
success: function(response){ |
484 |
addStatusOptions(response.statuses.filter(status => status.type == 'ill_status')); |
485 |
addStatusAliasOptions(response.statuses.filter(status => status.type == 'av')); |
486 |
} |
487 |
}); |
488 |
} |
460 |
} |
489 |
} |
461 |
|
490 |
|
462 |
function populateBackendFilter() { |
491 |
function populateBackendFilter() { |
463 |
$.ajax({ |
492 |
$.ajax({ |
464 |
type: "GET", |
493 |
type: "GET", |
465 |
url: "/api/v1/ill/backends", |
494 |
url: "/api/v1/ill/backends", |
|
|
495 |
headers: { |
496 |
'x-koha-embed': 'statuses+strings' |
497 |
}, |
466 |
success: function(backends){ |
498 |
success: function(backends){ |
467 |
backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { |
499 |
backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { |
468 |
$('#illfilter_backend').append( |
500 |
$('#illfilter_backend').append( |
Lines 470-502
$(document).ready(function() {
Link Here
|
470 |
'">' + backend.ill_backend_id + '</option>' |
502 |
'">' + backend.ill_backend_id + '</option>' |
471 |
); |
503 |
); |
472 |
}); |
504 |
}); |
473 |
} |
|
|
474 |
}); |
475 |
} |
476 |
|
505 |
|
477 |
function disableStatusFilter() { |
506 |
let all_existing_statuses = []; |
478 |
$('#illfilter_status').children().remove(); |
507 |
backends.forEach((backend) => { |
479 |
$("#illfilter_status").attr('title', ill_manage_select_backend_first); |
508 |
let existing_statuses = backend.statuses; |
480 |
$('#illfilter_status').prop("disabled", true); |
509 |
existing_statuses.filter(status => status.type == 'ill_status').forEach((existing_status) => { |
481 |
} |
510 |
let index = all_existing_statuses.map(function(e) { return e.code; }).indexOf(existing_status.code) || false; |
|
|
511 |
if(index == -1){ |
512 |
all_existing_statuses.push(existing_status); |
513 |
} |
514 |
}); |
515 |
}); |
482 |
|
516 |
|
483 |
function enableStatusFilter() { |
517 |
let all_existing_status_aliases = []; |
484 |
$('#illfilter_status').children().remove(); |
518 |
backends.forEach((backend) => { |
485 |
$("#illfilter_status").attr('title', ''); |
519 |
let existing_status_aliases = backend.statuses; |
486 |
$('#illfilter_status').prop("disabled", false); |
520 |
existing_status_aliases.filter(status => status.type == 'av').forEach((existing_status_aliases) => { |
|
|
521 |
let index = all_existing_status_aliases.map(function(e) { return e.code; }).indexOf(existing_status_aliases.code) || false; |
522 |
if(index == -1){ |
523 |
all_existing_status_aliases.push(existing_status_aliases); |
524 |
} |
525 |
}); |
526 |
}); |
527 |
|
528 |
populateStatusFilter( |
529 |
{ backend_statuses: |
530 |
{ |
531 |
statuses : all_existing_statuses, |
532 |
status_aliases: all_existing_status_aliases |
533 |
} |
534 |
} |
535 |
) |
536 |
|
537 |
} |
538 |
}); |
487 |
} |
539 |
} |
488 |
|
540 |
|
489 |
$('#illfilter_backend').change(function() { |
541 |
$('#illfilter_backend').change(function() { |
490 |
var selected_backend = $('#illfilter_backend option:selected').val(); |
542 |
var selected_backend = $('#illfilter_backend option:selected').val(); |
491 |
if (selected_backend && selected_backend.length > 0) { |
543 |
if (selected_backend && selected_backend.length > 0) { |
492 |
populateStatusFilter(selected_backend); |
544 |
populateStatusFilter( { backend : selected_backend } ); |
493 |
enableStatusFilter(); |
545 |
} else{ |
494 |
} else { |
546 |
populateBackendFilter(); |
495 |
disableStatusFilter(); |
|
|
496 |
} |
547 |
} |
497 |
}); |
548 |
}); |
498 |
|
549 |
|
499 |
disableStatusFilter(); |
|
|
500 |
populateBackendFilter(); |
550 |
populateBackendFilter(); |
501 |
|
551 |
|
502 |
// Clear all filters |
552 |
// Clear all filters |
503 |
- |
|
|