Lines 98-108
$(document).ready(function() {
Link Here
|
98 |
"-or": function(){ |
98 |
"-or": function(){ |
99 |
let patron = $("#illfilter_patron").val(); |
99 |
let patron = $("#illfilter_patron").val(); |
100 |
let status = $("#illfilter_status").val(); |
100 |
let status = $("#illfilter_status").val(); |
|
|
101 |
let status_alias = $("#illfilter_status_alias").val(); |
101 |
let filters = []; |
102 |
let filters = []; |
102 |
let status_sub_or = []; |
103 |
let status_sub_or = []; |
103 |
let subquery_and = []; |
104 |
let subquery_and = []; |
104 |
|
105 |
|
105 |
if (!patron && !status) return ""; |
106 |
if (!patron && !status && !status_alias) return ""; |
106 |
|
107 |
|
107 |
if(patron){ |
108 |
if(patron){ |
108 |
let patronquery = buildPatronSearchQuery( |
109 |
let patronquery = buildPatronSearchQuery( |
Lines 115-127
$(document).ready(function() {
Link Here
|
115 |
} |
116 |
} |
116 |
|
117 |
|
117 |
if(status){ |
118 |
if(status){ |
118 |
const status_search_fields = "me.status,me.status_av"; |
119 |
subquery_and.push( {"me.status":{"=": status }}); |
119 |
status_search_fields.split(',').forEach(function(attr){ |
120 |
} |
120 |
status_sub_or.push({ |
121 |
if(status_alias){ |
121 |
[attr]:{"=": status } |
122 |
subquery_and.push({"me.status_alias":{"=": status_alias }}); |
122 |
}); |
|
|
123 |
}); |
124 |
subquery_and.push(status_sub_or); |
125 |
} |
123 |
} |
126 |
|
124 |
|
127 |
filters.push({"-and": subquery_and}); |
125 |
filters.push({"-and": subquery_and}); |
Lines 455-491
$(document).ready(function() {
Link Here
|
455 |
$('#illfilter_form > fieldset > ol > li:nth-child(6) > span > a').click(); |
453 |
$('#illfilter_form > fieldset > ol > li:nth-child(6) > span > a').click(); |
456 |
$('#illfilter_form > fieldset > ol > li:nth-child(7) > span > a').click(); |
454 |
$('#illfilter_form > fieldset > ol > li:nth-child(7) > span > a').click(); |
457 |
|
455 |
|
458 |
disableStatusFilter(); |
|
|
459 |
|
460 |
redrawTable(); |
456 |
redrawTable(); |
461 |
} |
457 |
} |
462 |
|
458 |
|
463 |
function populateStatusFilter(backend) { |
459 |
function addStatusOptions(statuses){ |
464 |
$.ajax({ |
460 |
$('#illfilter_status').children().remove(); |
465 |
type: "GET", |
461 |
$('#illfilter_status').append( |
466 |
url: "/api/v1/ill/backends/"+backend, |
462 |
'<option value="">'+ill_all_statuses+'</option>' |
467 |
headers: { |
463 |
); |
468 |
'x-koha-embed': 'statuses+strings' |
464 |
statuses.sort((a, b) => a.str.localeCompare(b.str)).forEach(function(status) { |
469 |
}, |
465 |
$('#illfilter_status').append( |
470 |
success: function(response){ |
466 |
'<option value="' + status.code + |
471 |
let statuses = response.statuses |
467 |
'">' + status.str + '</option>' |
472 |
$('#illfilter_status').append( |
468 |
); |
473 |
'<option value="">'+ill_all_statuses+'</option>' |
469 |
}); |
|
|
470 |
} |
471 |
|
472 |
function addStatusAliasOptions(status_aliases){ |
473 |
$('#illfilter_status_alias').parent().remove(); |
474 |
if (status_aliases.length !== 0) { |
475 |
$('#illfilter_status').parent().after(function() { |
476 |
return '<li><label for="illfilter_status_alias">'+ill_status_aliases+':</label> <select name="illfilter_status_alias" id="illfilter_status_alias"></select></li>'; |
477 |
}); |
478 |
$('#illfilter_status_alias').append( |
479 |
'<option value="">'+ill_all_status_aliases+'</option>' |
480 |
); |
481 |
status_aliases.sort((a, b) => a.str.localeCompare(b.str)).forEach(function (status_alias) { |
482 |
$('#illfilter_status_alias').append( |
483 |
'<option value="' + status_alias.code + |
484 |
'">' + status_alias.str + '</option>' |
474 |
); |
485 |
); |
475 |
statuses.sort((a, b) => a.str.localeCompare(b.str)).forEach(function(status) { |
486 |
}); |
476 |
$('#illfilter_status').append( |
487 |
} |
477 |
'<option value="' + status.code + |
488 |
} |
478 |
'">' + status.str + '</option>' |
489 |
|
479 |
); |
490 |
function populateStatusFilter(params) { |
480 |
}); |
491 |
if(params.backend_statuses){ |
|
|
492 |
if(params.backend_statuses.statuses){ |
493 |
addStatusOptions(params.backend_statuses.statuses); |
481 |
} |
494 |
} |
482 |
}); |
495 |
if(params.backend_statuses.status_aliases){ |
|
|
496 |
addStatusAliasOptions(params.backend_statuses.status_aliases); |
497 |
} |
498 |
}else if(params.backend){ |
499 |
let backend_id = params.backend || ""; |
500 |
$.ajax({ |
501 |
type: "GET", |
502 |
url: "/api/v1/ill/backends/"+backend_id, |
503 |
headers: { |
504 |
'x-koha-embed': 'statuses+strings' |
505 |
}, |
506 |
success: function(response){ |
507 |
addStatusOptions(response.statuses.filter(status => status.type == 'ill_status')); |
508 |
addStatusAliasOptions(response.statuses.filter(status => status.type == 'av')); |
509 |
} |
510 |
}); |
511 |
} |
483 |
} |
512 |
} |
484 |
|
513 |
|
485 |
function populateBackendFilter() { |
514 |
function populateBackendFilter() { |
486 |
$.ajax({ |
515 |
$.ajax({ |
487 |
type: "GET", |
516 |
type: "GET", |
488 |
url: "/api/v1/ill/backends", |
517 |
url: "/api/v1/ill/backends", |
|
|
518 |
headers: { |
519 |
'x-koha-embed': 'statuses+strings' |
520 |
}, |
489 |
success: function(backends){ |
521 |
success: function(backends){ |
490 |
backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { |
522 |
backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { |
491 |
$('#illfilter_backend').append( |
523 |
$('#illfilter_backend').append( |
Lines 493-525
$(document).ready(function() {
Link Here
|
493 |
'">' + backend.ill_backend_id + '</option>' |
525 |
'">' + backend.ill_backend_id + '</option>' |
494 |
); |
526 |
); |
495 |
}); |
527 |
}); |
496 |
} |
|
|
497 |
}); |
498 |
} |
499 |
|
528 |
|
500 |
function disableStatusFilter() { |
529 |
let all_existing_statuses = []; |
501 |
$('#illfilter_status').children().remove(); |
530 |
backends.forEach((backend) => { |
502 |
$("#illfilter_status").attr('title', ill_manage_select_backend_first); |
531 |
let existing_statuses = backend.statuses; |
503 |
$('#illfilter_status').prop("disabled", true); |
532 |
existing_statuses.filter(status => status.type == 'ill_status').forEach((existing_status) => { |
504 |
} |
533 |
let index = all_existing_statuses.map(function(e) { return e.code; }).indexOf(existing_status.code) || false; |
|
|
534 |
if(index == -1){ |
535 |
all_existing_statuses.push(existing_status); |
536 |
} |
537 |
}); |
538 |
}); |
505 |
|
539 |
|
506 |
function enableStatusFilter() { |
540 |
let all_existing_status_aliases = []; |
507 |
$('#illfilter_status').children().remove(); |
541 |
backends.forEach((backend) => { |
508 |
$("#illfilter_status").attr('title', ''); |
542 |
let existing_status_aliases = backend.statuses; |
509 |
$('#illfilter_status').prop("disabled", false); |
543 |
existing_status_aliases.filter(status => status.type == 'av').forEach((existing_status_aliases) => { |
|
|
544 |
let index = all_existing_status_aliases.map(function(e) { return e.code; }).indexOf(existing_status_aliases.code) || false; |
545 |
if(index == -1){ |
546 |
all_existing_status_aliases.push(existing_status_aliases); |
547 |
} |
548 |
}); |
549 |
}); |
550 |
|
551 |
populateStatusFilter( |
552 |
{ backend_statuses: |
553 |
{ |
554 |
statuses : all_existing_statuses, |
555 |
status_aliases: all_existing_status_aliases |
556 |
} |
557 |
} |
558 |
) |
559 |
|
560 |
} |
561 |
}); |
510 |
} |
562 |
} |
511 |
|
563 |
|
512 |
$('#illfilter_backend').change(function() { |
564 |
$('#illfilter_backend').change(function() { |
513 |
var selected_backend = $('#illfilter_backend option:selected').val(); |
565 |
var selected_backend = $('#illfilter_backend option:selected').val(); |
514 |
if (selected_backend && selected_backend.length > 0) { |
566 |
if (selected_backend && selected_backend.length > 0) { |
515 |
populateStatusFilter(selected_backend); |
567 |
populateStatusFilter( { backend : selected_backend } ); |
516 |
enableStatusFilter(); |
568 |
} else{ |
517 |
} else { |
569 |
populateBackendFilter(); |
518 |
disableStatusFilter(); |
|
|
519 |
} |
570 |
} |
520 |
}); |
571 |
}); |
521 |
|
572 |
|
522 |
disableStatusFilter(); |
|
|
523 |
populateBackendFilter(); |
573 |
populateBackendFilter(); |
524 |
|
574 |
|
525 |
// Clear all filters |
575 |
// Clear all filters |
526 |
- |
|
|