Lines 266-275
Link Here
|
266 |
</div> |
266 |
</div> |
267 |
<div class="row"> |
267 |
<div class="row"> |
268 |
<div class="col-md-12"> |
268 |
<div class="col-md-12"> |
269 |
<div id="results-wrapper"></div> |
269 |
<div id="results-wrapper"> |
|
|
270 |
|
271 |
</div> |
270 |
</div> |
272 |
</div> |
271 |
</div> |
273 |
</div> |
272 |
|
274 |
|
|
|
275 |
<form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_operations"> |
276 |
<input type="hidden" name="op" value="show" /> |
277 |
<input type="hidden" id="batch_mod_del" name="del" value="0" /> |
278 |
</form> |
279 |
|
273 |
[% MACRO jsinclude BLOCK %] |
280 |
[% MACRO jsinclude BLOCK %] |
274 |
[% INCLUDE 'datatables.inc' %] |
281 |
[% INCLUDE 'datatables.inc' %] |
275 |
[% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %] |
282 |
[% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %] |
Lines 277-282
Link Here
|
277 |
<script> |
284 |
<script> |
278 |
var authorised_values = [% authorised_values_json | $raw %]; |
285 |
var authorised_values = [% authorised_values_json | $raw %]; |
279 |
|
286 |
|
|
|
287 |
function showItemSelections( number ){ |
288 |
let caret = ' <span class="caret">'; |
289 |
if( number > 0 ){ |
290 |
$("#table_search_selections").show().find("span").text(_("Items selected: " + number ) ); |
291 |
$("#batch_mod_menu").removeClass("disabled").prop("disabled", false); |
292 |
$("#export-button").html(_("Export selected results (%s) to").format ( number ) + caret); |
293 |
} else { |
294 |
$("#table_search_selections").hide(); |
295 |
$("#batch_mod_menu").prop("disabled", true).addClass("disabled"); |
296 |
$("#batch_item_operations").empty(); |
297 |
$("#export-button").html(_("Export all results to") + caret); |
298 |
} |
299 |
} |
300 |
|
280 |
function loadAuthorisedValuesSelect(select) { |
301 |
function loadAuthorisedValuesSelect(select) { |
281 |
var selected = select.find('option:selected'); |
302 |
var selected = select.find('option:selected'); |
282 |
var category = selected.data('authorised-values-category'); |
303 |
var category = selected.data('authorised-values-category'); |
Lines 301-307
Link Here
|
301 |
} |
322 |
} |
302 |
} |
323 |
} |
303 |
|
324 |
|
304 |
function addNewField( link ) { |
325 |
function addNewField( link ) { |
305 |
var form_field = $('div.form-field-select-text').last(); |
326 |
var form_field = $('div.form-field-select-text').last(); |
306 |
var copy = form_field.clone(true); |
327 |
var copy = form_field.clone(true); |
307 |
copy.find('input,select').not('[type="hidden"]').each(function() { |
328 |
copy.find('input,select').not('[type="hidden"]').each(function() { |
Lines 309-318
Link Here
|
309 |
}); |
330 |
}); |
310 |
copy.find('.form-field-conjunction').prop('disabled', false).val('and'); |
331 |
copy.find('.form-field-conjunction').prop('disabled', false).val('and'); |
311 |
form_field.after(copy); |
332 |
form_field.after(copy); |
312 |
link.remove(); |
333 |
link.remove(); |
313 |
copy.find('select.form-field-column').change(); |
334 |
copy.find('select.form-field-column').change(); |
314 |
} |
335 |
} |
315 |
|
336 |
|
|
|
337 |
function exportItems(format) { |
338 |
let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; |
339 |
if (item_search_selections.length > 0) { |
340 |
var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format; |
341 |
href += '&itemnumber=' + Array.from( item_search_selections ).join('&itemnumber='); |
342 |
location = href; |
343 |
} else { |
344 |
$('#format-' + format).prop('checked', true); |
345 |
$('#itemsearchform').submit(); |
346 |
$('#format-html').prop('checked', true); |
347 |
} |
348 |
} |
349 |
|
350 |
function prepSelections(){ |
351 |
let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; |
352 |
if( item_search_selections.length > 0 ){ |
353 |
showItemSelections( item_search_selections.length ); |
354 |
$("#results input[type='checkbox']").each(function(){ |
355 |
var itemnumber = $(this).val(); |
356 |
if( item_search_selections.indexOf( itemnumber ) >= 0 ){ |
357 |
$(this).prop("checked", true ); |
358 |
} |
359 |
}); |
360 |
} |
361 |
} |
362 |
|
316 |
function submitForm($form) { |
363 |
function submitForm($form) { |
317 |
var tr = '' |
364 |
var tr = '' |
318 |
+ ' <tr>' |
365 |
+ ' <tr>' |
Lines 335-442
Link Here
|
335 |
+ ' <th id="items_checkouts">' + _("Checkouts") + '</th>' |
382 |
+ ' <th id="items_checkouts">' + _("Checkouts") + '</th>' |
336 |
+ ' <th id="items_date_due">' + _("Due date") + '</th>' |
383 |
+ ' <th id="items_date_due">' + _("Due date") + '</th>' |
337 |
+ ' <th id=""></th>' |
384 |
+ ' <th id=""></th>' |
338 |
+ ' </tr>' |
385 |
+ ' </tr>'; |
|
|
386 |
|
339 |
var table = '' |
387 |
var table = '' |
340 |
+ '<div class="page-section">' |
388 |
+ '<div class="page-section">' |
341 |
+ '<table id="results">' |
389 |
+ ' <div id="searchheader" class="searchheader">' |
342 |
+ ' <thead>' + tr + tr + '</thead>' |
390 |
+ ' <a href="#" id="select_all" class="btn btn-link"><i class="fa fa-check"></i> ' |
343 |
+ ' <tbody></tbody>' |
391 |
+ _("Select visible rows") |
344 |
+ '</table>' |
392 |
+ ' </a> | ' |
|
|
393 |
+ ' <a href="#" id="clear_all" class="btn btn-link"><i class="fa fa-times"></i> ' |
394 |
+ _("Clear selection") |
395 |
+ ' </a>' |
396 |
+ ' <div class="btn-group"><button class="btn btn-default btn-sm dropdown-toggle" id="export-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' + _("Export all results to") + '<span class="caret"></span></button>' |
397 |
+ ' <ul class="dropdown-menu">' |
398 |
+ ' <li><a href="#" id="csvExportLink">' + _("CSV") + '</a></li>' |
399 |
+ ' <li><a href="#" id="barcodesExportLink">' + _("Barcode file") + '</a></li>' |
400 |
+ ' </ul>' |
401 |
+ ' </div>'; |
402 |
[% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel ) %] |
403 |
table += '' |
404 |
+ ' <div class="btn-group"><button class="btn btn-default btn-sm dropdown-toggle disabled" disabled="disabled" type="button" id="batch_mod_menu"data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> ' + _("Batch operations") + ' <span class="caret"></span> </button>' |
405 |
+ ' <ul class="dropdown-menu" aria-labelledby="batch_mod_menu">'; |
406 |
[% IF ( CAN_user_tools_items_batchmod ) %] |
407 |
table += '' |
408 |
+ ' <li> <a href="#" data-submit="batch_item_modification" data-toggle="tooltip" data-placement="right" title="' + _("Send selected items to batch item modification") + '" class="batch_op send_to_item_mod">' + _("Batch item modification") + '</a> </li>'; |
409 |
[% END %] |
410 |
[% IF ( CAN_user_tools_items_batchdel ) %] |
411 |
table += '' |
412 |
+ ' <li> <a href="#" data-submit="batch_item_deletion" data-toggle="tooltip" data-placement="right" title="' + _("Send selected items to batch item deletion") + '" class="batch_op send_to_item_del">' + _("Batch item deletion") + '</a> </li>'; |
413 |
[% END %] |
414 |
table += '' |
415 |
+ ' </ul>' |
416 |
+ ' </div>'; |
417 |
[% END # /IF CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel %] |
418 |
table += '' |
419 |
+ ' <div id="table_search_selections" class="btn-group" style="display:none;">' |
420 |
+ ' <span></span>' |
421 |
+ ' <a href="#" id="clear-row-selection"><i class="fa fa-times"></i> Clear</a>' |
422 |
+ ' </div>' |
423 |
+ ' </div>' |
424 |
+ ' <table id="results">' |
425 |
+ ' <thead>' + tr + tr + '</thead>' |
426 |
+ ' <tbody></tbody>' |
427 |
+ ' </table>' |
345 |
+ '</div>'; |
428 |
+ '</div>'; |
|
|
429 |
|
346 |
var advSearchLink = $('<a>') |
430 |
var advSearchLink = $('<a>') |
347 |
.attr('href', '/cgi-bin/koha/catalogue/search.pl') |
431 |
.attr('href', '/cgi-bin/koha/catalogue/search.pl') |
348 |
.html(_("Go to advanced search")); |
432 |
.html(_("Go to advanced search")); |
|
|
433 |
|
349 |
var editSearchLink = $('<a>') |
434 |
var editSearchLink = $('<a>') |
350 |
.attr('href', '#') |
435 |
.attr('href', '#') |
351 |
.html(_("Edit search")) |
436 |
.html("<i class='fa fa-pencil'></i> " + _("Edit search") ) |
352 |
.addClass('btn btn-default btn-xs') |
437 |
.addClass('btn btn-default') |
353 |
.on('click', function(e) { |
438 |
.on('click', function(e) { |
354 |
e.preventDefault(); |
439 |
e.preventDefault(); |
355 |
$('#item-search-block').show(); |
440 |
$('#item-search-block').show(); |
356 |
}); |
441 |
}); |
357 |
|
442 |
|
358 |
function getCheckedItemnumbers () { |
|
|
359 |
var itemnumbers; |
360 |
try { |
361 |
itemnumbers = JSON.parse(sessionStorage.getItem('itemsearch_itemnumbers') || '[]'); |
362 |
} catch (e) { |
363 |
itemnumbers = []; |
364 |
} |
365 |
|
366 |
return new Set(itemnumbers); |
367 |
} |
368 |
|
369 |
function exportItems(format) { |
370 |
var itemnumbers = getCheckedItemnumbers(); |
371 |
if (itemnumbers.size > 0) { |
372 |
var href = '/cgi-bin/koha/catalogue/item-export.pl?format=' + format; |
373 |
href += '&itemnumber=' + Array.from(itemnumbers).join('&itemnumber='); |
374 |
location = href; |
375 |
} else { |
376 |
$('#format-' + format).prop('checked', true); |
377 |
$('#itemsearchform').submit(); |
378 |
$('#format-html').prop('checked', true); |
379 |
} |
380 |
} |
381 |
|
382 |
var csvExportLink = $('<a>') |
383 |
.attr('href', '#') |
384 |
.html("CSV") |
385 |
.on('click', function(e) { |
386 |
e.preventDefault(); |
387 |
exportItems('csv'); |
388 |
}); |
389 |
var barcodesExportLink = $('<a>') |
390 |
.attr('href', '#') |
391 |
.html(_("Barcodes file")) |
392 |
.on('click', function(e) { |
393 |
e.preventDefault(); |
394 |
exportItems('barcodes'); |
395 |
}); |
396 |
|
397 |
var exportButton = $('<div>') |
398 |
.addClass('btn-group') |
399 |
.append($('<button>') |
400 |
.addClass('btn btn-default btn-xs dropdown-toggle') |
401 |
.attr('id', 'export-button') |
402 |
.attr('data-toggle', 'dropdown') |
403 |
.attr('aria-haspopup', 'true') |
404 |
.attr('aria-expanded', 'false') |
405 |
.html(_("Export all results to") + ' <span class="caret"></span>')) |
406 |
.append($('<ul>') |
407 |
.addClass('dropdown-menu') |
408 |
.append($('<li>').append(csvExportLink)) |
409 |
.append($('<li>').append(barcodesExportLink))); |
410 |
|
411 |
var selectVisibleRows = $('<a>') |
412 |
.attr('href', '#') |
413 |
.append('<i class="fa fa-check"></i> ') |
414 |
.append(_("Select visible rows")) |
415 |
.on('click', function(e) { |
416 |
e.preventDefault(); |
417 |
$('#results input[type="checkbox"]').prop('checked', true).change(); |
418 |
}); |
419 |
var clearSelection = $('<a>') |
420 |
.attr('href', '#') |
421 |
.append('<i class="fa fa-times"></i> ') |
422 |
.append(_("Clear selection")) |
423 |
.on('click', function(e) { |
424 |
e.preventDefault(); |
425 |
sessionStorage.setItem('itemsearch_itemnumbers', '[]'); |
426 |
$('#results input[type="checkbox"]').prop('checked', false).change(); |
427 |
}); |
428 |
var exportLinks = $('<p>') |
429 |
.append(selectVisibleRows) |
430 |
.append(' ') |
431 |
.append(clearSelection) |
432 |
.append(' | ') |
433 |
.append(exportButton); |
434 |
|
435 |
var results_heading = $('<div>').addClass('results-heading') |
443 |
var results_heading = $('<div>').addClass('results-heading') |
436 |
.append("<h1>" + _("Item search results") + "</h1>") |
444 |
.append("<h1>" + _("Item search results") + "</h1>") |
437 |
.append($('<p>').append(advSearchLink)) |
445 |
.append($('<p>').append(advSearchLink)) |
438 |
.append($('<p>').append(editSearchLink)) |
446 |
.append($('<div>') |
439 |
.append(exportLinks); |
447 |
.addClass("btn-toolbar") |
|
|
448 |
.attr("id","toolbar") |
449 |
.append(editSearchLink) |
450 |
); |
440 |
$('#results-wrapper').empty() |
451 |
$('#results-wrapper').empty() |
441 |
.append(results_heading) |
452 |
.append(results_heading) |
442 |
.append(table); |
453 |
.append(table); |
Lines 496-501
Link Here
|
496 |
{ 'sName': 'actions', 'bSortable': false } |
507 |
{ 'sName': 'actions', 'bSortable': false } |
497 |
], |
508 |
], |
498 |
"sPaginationType": "full_numbers", |
509 |
"sPaginationType": "full_numbers", |
|
|
510 |
"drawCallback": function( settings ) { |
511 |
prepSelections(); |
512 |
}, |
499 |
fixedHeader: false // There is a bug on this view |
513 |
fixedHeader: false // There is a bug on this view |
500 |
})).columnFilter({ |
514 |
})).columnFilter({ |
501 |
'sPlaceHolder': 'head:after', |
515 |
'sPlaceHolder': 'head:after', |
Lines 546-596
Link Here
|
546 |
] |
560 |
] |
547 |
}); |
561 |
}); |
548 |
$('#results').on('draw.dt', function (e, settings) { |
562 |
$('#results').on('draw.dt', function (e, settings) { |
549 |
var itemnumbers = getCheckedItemnumbers(); |
563 |
prepSelections(); |
550 |
$(this).find('input[type="checkbox"][name="itemnumber"]').each(function () { |
564 |
var Sticky = $("#searchheader"); |
551 |
var itemnumber = this.value; |
565 |
Sticky.hcSticky({ |
552 |
if (itemnumbers.has(itemnumber)) { |
566 |
stickTo: "#results-wrapper .page-section", |
553 |
this.checked = true; |
567 |
stickyClass: "floating" |
554 |
} |
|
|
555 |
}); |
568 |
}); |
556 |
}); |
569 |
}); |
557 |
|
|
|
558 |
sessionStorage.setItem('itemsearch_itemnumbers', '[]'); |
559 |
|
560 |
$('#results').on('change', 'input[type="checkbox"]', function() { |
561 |
var itemnumber = this.value; |
562 |
var itemnumbers = getCheckedItemnumbers(); |
563 |
if (this.checked) { |
564 |
itemnumbers.add(itemnumber); |
565 |
} else { |
566 |
itemnumbers.delete(itemnumber); |
567 |
} |
568 |
sessionStorage.setItem('itemsearch_itemnumbers', JSON.stringify(Array.from(itemnumbers))); |
569 |
|
570 |
var caret = ' <span class="caret">'; |
571 |
if (itemnumbers.size > 0) { |
572 |
$('#export-button').html(_("Export selected results (%s) to").format(itemnumbers.size) + caret); |
573 |
} else { |
574 |
$('#export-button').html(_("Export all results to") + caret); |
575 |
} |
576 |
}); |
577 |
} |
570 |
} |
578 |
var Sticky; |
571 |
|
579 |
$(document).ready(function () { |
572 |
$(document).ready(function () { |
580 |
Sticky = $("#toolbar"); |
|
|
581 |
Sticky.hcSticky({ |
582 |
stickTo: "#item-search-block", |
583 |
stickyClass: "floating" |
584 |
}); |
585 |
// Add the "New field" link. |
573 |
// Add the "New field" link. |
586 |
var form_field = $('div.form-field-select-text').last() |
574 |
var form_field = $('div.form-field-select-text').last() |
587 |
var NEW_FIELD = _("New field"); |
575 |
var NEW_FIELD = _("New field"); |
588 |
var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field"><i class="fa fa-plus"></i> ' + NEW_FIELD + '</a>'); |
576 |
var button_field_new = $('<a href="#" class="button-field-new" title="Add a new field"><i class="fa fa-plus"></i> ' + NEW_FIELD + '</a>'); |
589 |
button_field_new.click(function(e) { |
577 |
button_field_new.click(function(e) { |
590 |
e.preventDefault(); |
578 |
e.preventDefault(); |
591 |
addNewField( $(this) ); |
579 |
addNewField( $(this) ); |
592 |
}); |
580 |
}); |
593 |
form_field.append(button_field_new); |
581 |
form_field.append(button_field_new); |
594 |
|
582 |
|
595 |
// If a field is linked to an authorised values list, display the list. |
583 |
// If a field is linked to an authorised values list, display the list. |
596 |
$('div.form-field-select-text select[name="f"]').change(function() { |
584 |
$('div.form-field-select-text select[name="f"]').change(function() { |
Lines 620-625
Link Here
|
620 |
return false; |
608 |
return false; |
621 |
} |
609 |
} |
622 |
}); |
610 |
}); |
|
|
611 |
|
612 |
$("body").on("click", "#select_all", function(e) { |
613 |
e.preventDefault(); |
614 |
$("#results input[type='checkbox']").each(function(){ |
615 |
if( $(this).prop("checked") == false ){ |
616 |
$(this).prop( "checked", true ).change(); |
617 |
} |
618 |
}); |
619 |
}); |
620 |
|
621 |
$("body").on("click", "#clear_all", function(e) { |
622 |
e.preventDefault(); |
623 |
$("#results input[type='checkbox']").each(function(){ |
624 |
if( $(this).prop("checked") == true ){ |
625 |
$(this).prop( "checked", false ).change(); |
626 |
} |
627 |
}); |
628 |
}); |
629 |
|
630 |
$("body").on("click", "#clear-row-selection", function(e){ |
631 |
e.preventDefault(); |
632 |
$("#results input[type='checkbox']").prop("checked" ,false ).change(); |
633 |
localStorage.removeItem("item_search_selections"); |
634 |
showItemSelections( 0 ); |
635 |
}); |
636 |
|
637 |
$("body").on('change', '#results input[type="checkbox"]', function() { |
638 |
let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; |
639 |
var itemnumber = $(this).val(); |
640 |
if( $(this).prop("checked") ){ |
641 |
item_search_selections.push( $(this).val() ); |
642 |
localStorage.setItem('item_search_selections', JSON.stringify( item_search_selections )); |
643 |
showItemSelections( item_search_selections.length ); |
644 |
} else { |
645 |
var filtered = item_search_selections.filter(function( value ){ |
646 |
return value !== itemnumber; |
647 |
}); |
648 |
if( filtered.length > 0 ){ |
649 |
localStorage.setItem('item_search_selections', JSON.stringify( filtered )); |
650 |
item_search_selections = filtered; |
651 |
showItemSelections( filtered.length ); |
652 |
} else { |
653 |
item_search_selections = []; |
654 |
localStorage.removeItem('item_search_selections'); |
655 |
showItemSelections( 0 ); |
656 |
} |
657 |
} |
658 |
}); |
659 |
|
660 |
$("body").on("click", "#csvExportLink", function(e){ |
661 |
e.preventDefault(); |
662 |
exportItems('csv'); |
663 |
}); |
664 |
|
665 |
$("body").on("click", "#barcodesExportLink", function(e){ |
666 |
e.preventDefault(); |
667 |
exportItems('barcodes'); |
668 |
}); |
669 |
|
670 |
$("body").on("click", ".batch_op", function(e){ |
671 |
e.preventDefault(); |
672 |
let batch_mod_form = $("#batch_item_operations"); |
673 |
batch_mod_form.empty(); |
674 |
batch_mod_form.append( |
675 |
$("<input>").attr("type","hidden") |
676 |
.attr("name", "op") |
677 |
.val("show") |
678 |
); |
679 |
batch_mod_form.append( |
680 |
$("<input>").attr("type","hidden") |
681 |
.attr("name", "del") |
682 |
.attr("id", "batch_mod_del") |
683 |
); |
684 |
let item_search_selections = JSON.parse( localStorage.getItem("item_search_selections") ) || []; |
685 |
// Populate batch forms with itemnumbers in local storage |
686 |
for (let item of item_search_selections){ |
687 |
var field = $("<input>").attr("type","hidden") |
688 |
.attr("name","itemnumber") |
689 |
.val( item ); |
690 |
batch_mod_form.append( field ); |
691 |
} |
692 |
if( $(this).hasClass("send_to_item_mod") ){ |
693 |
$("#batch_mod_del").val(0); |
694 |
} else if ( $(this).hasClass("send_to_item_del") ){ |
695 |
$("#batch_mod_del").val(1); |
696 |
} else { |
697 |
return false; |
698 |
} |
699 |
batch_mod_form.submit(); |
700 |
}); |
701 |
|
702 |
$("body").on('click','#results tbody td',function(e){ |
703 |
var checkbox = $(this).find("input[type=checkbox]"); |
704 |
if (e.target.type != "checkbox") { |
705 |
checkbox.prop('checked', !checkbox.prop("checked")); |
706 |
checkbox.change(); |
707 |
} |
708 |
}); |
623 |
}); |
709 |
}); |
624 |
</script> |
710 |
</script> |
625 |
[% END %] |
711 |
[% END %] |