Koha/koha-tmpl/intranet-tmpl/prog/js/viewlog.js
Jonathan Druart 9309dedb53
Bug 30578: Remove circ/ysearch.pl in favor of the /patrons REST API route
This patch removes the circ/ysearch.pl script used by the jQuery autocomplete widget.
We can now use the /api/v1/patrons endpoint to retrieve the patrons and
generate the patron result list.

Prior to this patch the different occurrences were defining the style
and the list of patron's attributes to display for each option (name,
date of birth, age, address, etc.). Now they are all displaying the same
information.

To acchieve this we had to:
* Make js-date-format.inc and js-patron-get-age.inc available from js_includes.inc
and so available from everywhere, which is certainly a good move. We
could discuss why this code is in include file instead of JS files
however.
* Remove the .ajaxSetup call in tags-review.js to reduce its scope: an
underscore parameter was added to the REST API query (?)

A better solution would have been to extend the existing widget
(https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/)
but I didn't manage to do it, and I feel like there is a bug in jQuery
autocomplete. The "source" was not taken into account.
We could think about replacing the jQuery autocomplete with something
else, but that's outside the scope of this bug.

Test plan:
Search for patrons and confirm the autocomplete works and that the
"select" action works as before (either a redirect or select the
patrons) on the different views:
* Place a hold
* Search for tags (form on the left)
* In the header, "Check out" and "Search patrons"
* Add instructors to course reserves
* View logs (the "librarian" input)

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-07-18 11:01:34 -03:00

152 lines
5.2 KiB
JavaScript

var Sticky;
function tickAll(section){
$("input[type='checkbox'][name='" + section + "']").prop("checked", true);
$("#" + section.slice(0,-1) + "ALL").prop("checked", true);
$("input[type='checkbox'][name='" + section + "']").prop("disabled", true);
$("#" + section.slice(0,-1) + "ALL").prop("disabled", false);
}
function untickAll(section){
$("input[type='checkbox'][name='" + section + "']").prop("checked", false);
$("input[type='checkbox'][name='" + section + "']").prop("disabled", false);
}
function limitCheckboxes() {
var checkboxes = $(".compare");
var limit = 2;
var compare_link = '<a href="#" class="btn btn-link compare_link"><i class="fa fa-columns"></i> ' + __("View comparison") + '</a>';
checkboxes.each(function(){
$(this).on("change", function(){
var checked = [];
checkboxes.each(function () {
if( $(this).prop("checked") ){
checked.push( $(this).data("actionid") );
}
});
if (checked.length > 0) {
$("#select_none").removeClass("disabled");
} else {
$("#select_none").addClass("disabled");
$("#logst").DataTable().search("").draw();
}
if( checked.length == 1 ){
$("#logst").DataTable().search($(this).data("filter")).draw();
humanMsg.displayAlert( __("Showing results for %s").format( $(this).data("filter") ) );
}
if( checked.length == 2 ){
$("#compare_info" + checked[0]).prepend( compare_link );
$("#compare_info" + checked[1]).prepend( compare_link );
$("button.compare_link").removeClass("disabled");
} else if (checked.length > limit) {
humanMsg.displayAlert( __("You can select maximum of two checkboxes") );
$(this).prop("checked", false );
} else if (checked.length < limit) {
$("a.compare_link").remove();
$("button.compare_link").addClass("disabled");
}
});
});
}
$(document).ready(function(){
limitCheckboxes();
if( $(".compare_info").length == 0 ){
/* Remove toolbar if there are no system preference
entries to compare */
$("#toolbar").remove();
}
if ($('#toolbar').length) {
Sticky = $("#toolbar");
Sticky.hcSticky({
stickTo: "main",
stickyClass: "floating"
});
}
if ( $('input[type="checkbox"][name="modules"]:checked').length == 0 ) {
tickAll('modules');
}
$("#moduleALL").change(function(){
if ( this.checked == true ){
tickAll('modules');
} else {
untickAll('modules');
}
});
$("input[type='checkbox'][name='modules']").change(function(){
if ( $("input[name='modules']:checked").length == $("input[name='modules']").length - 1 ){
tickAll('modules');
}
});
if ( $('input[name="actions"]:checked').length == 0 ) {
tickAll('actions');
}
$("#actionALL").change(function(){
if ( this.checked == true ){
tickAll('actions');
} else {
untickAll('actions');
}
});
$("input[name='actions']").change(function(){
if ( $("input[name='actions']:checked").length == $("input[name='actions']").length - 1 ){
tickAll('actions');
}
});
if ( $('input[name="interfaces"]:checked').length == 0 ) {
tickAll('interfaces');
}
$("#interfaceALL").change(function(){
if ( this.checked == true ){
tickAll('interfaces');
} else {
untickAll('interfaces');
}
});
$("input[name='interfaces']").change(function(){
if ( $("input[name='interfaces']:checked").length == $("input[name='interfaces']").length - 1 ){
tickAll('interfaces');
}
});
var logst = KohaTable("logst", {
"autoWidth": false,
"order": [[0, "desc"]],
"pagingType" : "full"
}, table_settings);
$("body").on("click", ".compare_link", function(e){
e.preventDefault();
if( $(this).hasClass('disabled') ){
humanMsg.displayAlert( __("You must select two entries to compare") );
} else {
var firstid = $(".compare:checked").eq(0).data("actionid");
var secondid = $(".compare:checked").eq(1).data("actionid");
var firstvalue = $("#loginfo" + firstid).text();
var secondvalue = $("#loginfo" + secondid).text();
var diffs = diffString(secondvalue, firstvalue);
$("#col1 pre,#col2 pre").html(diffs);
$("#compareInfo").modal("show");
}
});
$("#compareInfo").on("hidden.bs.modal", function(){
$("#col1 pre,#col2 pre").html("");
});
$("#select_none").on("click", function(e){
e.preventDefault();
$(".compare:checked").prop("checked", false).change();
});
patron_autocomplete($("#user"), { 'on-select-callback': function ( event, ui ) {
$("#user").val( ui.item.patron_id );
return false;
}
});
});