Lines 494-536
Link Here
|
494 |
<h1>View ILL requests</h1> |
494 |
<h1>View ILL requests</h1> |
495 |
<div id="results"> |
495 |
<div id="results"> |
496 |
<h3>Details for all requests</h3> |
496 |
<h3>Details for all requests</h3> |
497 |
|
497 |
[% INCLUDE 'ill-list-table.inc' %] |
498 |
<table id="ill-requests"> |
|
|
499 |
<thead> |
500 |
<tr id="illview-header"> |
501 |
<th scope="col">Request ID</th> |
502 |
<th scope="col">Author</th> |
503 |
<th scope="col">Title</th> |
504 |
<th scope="col">Article title</th> |
505 |
<th scope="col">Issue</th> |
506 |
<th scope="col">Volume</th> |
507 |
<th scope="col">Year</th> |
508 |
<th scope="col">Pages</th> |
509 |
<th scope="col">Type</th> |
510 |
<th scope="col">Order ID</th> |
511 |
<th scope="col">Patron ID</th> |
512 |
<th scope="col" class="patron_cardnumber">Patron barcode</th> |
513 |
<th scope="col">Patron</th> |
514 |
<th scope="col">Biblio ID</th> |
515 |
<th scope="col">Branch</th> |
516 |
<th scope="col">Status</th> |
517 |
<th scope="col" class="placed"> </th> |
518 |
<th scope="col" class="placed_formatted">Placed on</th> |
519 |
<th scope="col" class="updated"> </th> |
520 |
<th scope="col" class="updated_formatted">Updated on</th> |
521 |
<th scope="col">Replied</th> |
522 |
<th scope="col">Completed on</th> |
523 |
<th scope="col">Access URL</th> |
524 |
<th scope="col">Cost</th> |
525 |
<th scope="col">OPAC notes</th> |
526 |
<th scope="col">Staff notes</th> |
527 |
<th scope="col">Backend</th> |
528 |
<th scope="col" class="actions"></th> |
529 |
</tr> |
530 |
</thead> |
531 |
<tbody id="illview-body"> |
532 |
</tbody> |
533 |
</table> |
534 |
</div> |
498 |
</div> |
535 |
[% ELSE %] |
499 |
[% ELSE %] |
536 |
<!-- Custom Backend Action --> |
500 |
<!-- Custom Backend Action --> |
Lines 543-1041
Link Here
|
543 |
</div> |
507 |
</div> |
544 |
</div> |
508 |
</div> |
545 |
|
509 |
|
546 |
[% TRY %] |
|
|
547 |
[% PROCESS backend_jsinclude %] |
548 |
[% CATCH %] |
549 |
[% END %] |
550 |
|
551 |
[% MACRO jsinclude BLOCK %] |
510 |
[% MACRO jsinclude BLOCK %] |
552 |
[% INCLUDE 'datatables.inc' %] |
511 |
[% INCLUDE 'datatables.inc' %] |
553 |
[% INCLUDE 'columns_settings.inc' %] |
512 |
[% INCLUDE 'columns_settings.inc' %] |
554 |
[% INCLUDE 'calendar.inc' %] |
513 |
[% INCLUDE 'calendar.inc' %] |
555 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
514 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
556 |
<script> |
515 |
<script> |
557 |
$(document).ready(function() { |
516 |
// Date format for datepickers |
558 |
|
517 |
var dateMap = { |
559 |
// Illview Datatable setup |
518 |
dmydot: 'dd.mm.yy', |
560 |
|
519 |
iso: 'yy-mm-dd', |
561 |
var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %]; |
520 |
metric: 'dd/mm/yy', |
562 |
|
521 |
us: 'mm/dd/yy' |
563 |
var table; |
522 |
}; |
564 |
|
523 |
var dateFormat = dateMap['[% Koha.Preference('dateformat') %]']; |
565 |
// Filters that are active |
524 |
var prefilters = '[% prefilters %]'; |
566 |
var activeFilters = {}; |
525 |
// Set column settings |
567 |
|
526 |
var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %]; |
568 |
// Fields we need to expand (flatten) |
|
|
569 |
var expand = [ |
570 |
'metadata', |
571 |
'patron', |
572 |
'library' |
573 |
]; |
574 |
|
575 |
// Expanded fields |
576 |
// This is auto populated |
577 |
var expanded = {}; |
578 |
|
579 |
// Filterable columns |
580 |
var filterable = { |
581 |
status: { |
582 |
prep: function(tableData, oData) { |
583 |
var uniques = {}; |
584 |
tableData.forEach(function(row) { |
585 |
var resolvedName = getStatusName( |
586 |
oData[0].capabilities[row.status].name, |
587 |
row |
588 |
); |
589 |
uniques[resolvedName] = 1 |
590 |
}); |
591 |
Object.keys(uniques).sort().forEach(function(unique) { |
592 |
$('#illfilter_status').append( |
593 |
'<option value="' + unique + |
594 |
'">' + unique + '</option>' |
595 |
); |
596 |
}); |
597 |
}, |
598 |
listener: function() { |
599 |
var me = 'status'; |
600 |
$('#illfilter_status').change(function() { |
601 |
var sel = $('#illfilter_status option:selected').val(); |
602 |
if (sel && sel.length > 0) { |
603 |
activeFilters[me] = function() { |
604 |
table.api().column(15).search(sel); |
605 |
} |
606 |
} else { |
607 |
if (activeFilters.hasOwnProperty(me)) { |
608 |
delete activeFilters[me]; |
609 |
} |
610 |
} |
611 |
}); |
612 |
}, |
613 |
clear: function() { |
614 |
$('#illfilter_status').val(''); |
615 |
} |
616 |
}, |
617 |
pickupBranch: { |
618 |
prep: function(tableData, oData) { |
619 |
var uniques = {}; |
620 |
tableData.forEach(function(row) { |
621 |
uniques[row.library_branchname] = 1 |
622 |
}); |
623 |
Object.keys(uniques).sort().forEach(function(unique) { |
624 |
$('#illfilter_branchname').append( |
625 |
'<option value="' + unique + |
626 |
'">' + unique + '</option>' |
627 |
); |
628 |
}); |
629 |
}, |
630 |
listener: function() { |
631 |
var me = 'pickupBranch'; |
632 |
$('#illfilter_branchname').change(function() { |
633 |
var sel = $('#illfilter_branchname option:selected').val(); |
634 |
if (sel && sel.length > 0) { |
635 |
activeFilters[me] = function() { |
636 |
table.api().column(14).search(sel); |
637 |
} |
638 |
} else { |
639 |
if (activeFilters.hasOwnProperty(me)) { |
640 |
delete activeFilters[me]; |
641 |
} |
642 |
} |
643 |
}); |
644 |
}, |
645 |
clear: function() { |
646 |
$('#illfilter_branchname').val(''); |
647 |
} |
648 |
}, |
649 |
barcode: { |
650 |
listener: function() { |
651 |
var me = 'barcode'; |
652 |
$('#illfilter_barcode').change(function() { |
653 |
var val = $('#illfilter_barcode').val(); |
654 |
if (val && val.length > 0) { |
655 |
activeFilters[me] = function() { |
656 |
table.api().column(11).search(val); |
657 |
} |
658 |
} else { |
659 |
if (activeFilters.hasOwnProperty(me)) { |
660 |
delete activeFilters[me]; |
661 |
} |
662 |
} |
663 |
}); |
664 |
}, |
665 |
clear: function() { |
666 |
$('#illfilter_barcode').val(''); |
667 |
} |
668 |
}, |
669 |
dateModified: { |
670 |
clear: function() { |
671 |
$('#illfilter_datemodified_start, #illfilter_datemodified_end').val(''); |
672 |
} |
673 |
}, |
674 |
datePlaced: { |
675 |
clear: function() { |
676 |
$('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val(''); |
677 |
} |
678 |
} |
679 |
}; |
680 |
|
681 |
// Expand any fields we're expanding |
682 |
var expandExpand = function(row) { |
683 |
expand.forEach(function(thisExpand) { |
684 |
if (row.hasOwnProperty(thisExpand)) { |
685 |
if (!expanded.hasOwnProperty(thisExpand)) { |
686 |
expanded[thisExpand] = []; |
687 |
} |
688 |
var expandObj = row[thisExpand]; |
689 |
Object.keys(expandObj).forEach( |
690 |
function(thisExpandCol) { |
691 |
var expColName = thisExpand + '_' + thisExpandCol.replace(/\s/g,'_'); |
692 |
// Keep a list of fields that have been expanded |
693 |
// so we can create toggle links for them |
694 |
if (expanded[thisExpand].indexOf(expColName) == -1) { |
695 |
expanded[thisExpand].push(expColName); |
696 |
} |
697 |
expandObj[expColName] = |
698 |
expandObj[thisExpandCol]; |
699 |
delete expandObj[thisExpandCol]; |
700 |
} |
701 |
); |
702 |
$.extend(true, row, expandObj); |
703 |
delete row[thisExpand]; |
704 |
} |
705 |
}); |
706 |
}; |
707 |
|
708 |
// Strip the expand prefix if it exists, we do this for display |
709 |
var stripPrefix = function(value) { |
710 |
expand.forEach(function(thisExpand) { |
711 |
var regex = new RegExp(thisExpand + '_', 'g'); |
712 |
value = value.replace(regex, ''); |
713 |
}); |
714 |
return value; |
715 |
}; |
716 |
|
717 |
// Our 'render' function for borrowerlink |
718 |
var createPatronLink = function(data, type, row) { |
719 |
var patronLink = '<a title="' + _("View borrower details") + '" ' + |
720 |
'href="/cgi-bin/koha/members/moremember.pl?' + |
721 |
'borrowernumber='+row.borrowernumber+'">'; |
722 |
if ( row.patron_firstname ) { |
723 |
patronLink = patronLink + row.patron_firstname + ' '; |
724 |
} |
725 |
patronLink = patronLink + row.patron_surname + '</a>'; |
726 |
return patronLink; |
727 |
}; |
728 |
|
729 |
// Our 'render' function for biblio_id |
730 |
var createBiblioLink = function(data, type, row) { |
731 |
return (row.biblio_id) ? |
732 |
'<a title="' + _("View biblio details") + '" ' + |
733 |
'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + |
734 |
row.biblio_id + '">' + |
735 |
row.biblio_id + |
736 |
'</a>' : ''; |
737 |
}; |
738 |
|
739 |
// Render function for request ID |
740 |
var createRequestId = function(data, type, row) { |
741 |
return row.id_prefix + row.illrequest_id; |
742 |
}; |
743 |
|
744 |
// Render function for type |
745 |
var createType = function(data, type, row) { |
746 |
if (!row.hasOwnProperty('metadata_Type') || !row.metadata_Type) { |
747 |
if (row.hasOwnProperty('medium') && row.medium) { |
748 |
row.metadata_Type = row.medium; |
749 |
} else { |
750 |
row.metadata_Type = null; |
751 |
} |
752 |
} |
753 |
return row.metadata_Type; |
754 |
}; |
755 |
|
756 |
// Render function for request status |
757 |
var createStatus = function(data, type, row, meta) { |
758 |
if (row.status_alias) { |
759 |
return row.status_alias.lib |
760 |
? row.status_alias.lib |
761 |
: row.status_alias.authorised_value; |
762 |
} else { |
763 |
var origData = meta.settings.oInit.originalData; |
764 |
if (origData.length > 0) { |
765 |
var status_name = meta.settings.oInit.originalData[0].capabilities[ |
766 |
row.status |
767 |
].name; |
768 |
return getStatusName(status_name, row); |
769 |
} else { |
770 |
return ''; |
771 |
} |
772 |
} |
773 |
}; |
774 |
|
775 |
var getStatusName = function(origName, row) { |
776 |
switch( origName ) { |
777 |
case "New request": |
778 |
return _("New request"); |
779 |
case "Requested": |
780 |
return _("Requested"); |
781 |
case "Requested from partners": |
782 |
var statStr = _("Requested from partners"); |
783 |
if ( |
784 |
row.hasOwnProperty('requested_partners') && |
785 |
row.requested_partners && |
786 |
row.requested_partners.length > 0 |
787 |
) { |
788 |
statStr += ' (' + row.requested_partners + ')'; |
789 |
} |
790 |
return statStr; |
791 |
case "Request reverted": |
792 |
return _("Request reverted"); |
793 |
case "Queued request": |
794 |
return _("Queued request"); |
795 |
case "Cancellation requested": |
796 |
return _("Cancellation requested"); |
797 |
case "Completed": |
798 |
return _("Completed"); |
799 |
case "Delete request": |
800 |
return _("Delete request"); |
801 |
default: |
802 |
return origName; |
803 |
} |
804 |
}; |
805 |
|
806 |
// Render function for creating a row's action link |
807 |
var createActionLink = function(data, type, row) { |
808 |
return '<a class="btn btn-default btn-sm" ' + |
809 |
'href="/cgi-bin/koha/ill/ill-requests.pl?' + |
810 |
'method=illview&illrequest_id=' + |
811 |
row.illrequest_id + |
812 |
'">' + _("Manage request") + '</a>'; |
813 |
}; |
814 |
|
815 |
// Columns that require special treatment |
816 |
var specialCols = { |
817 |
action: { |
818 |
func: createActionLink |
819 |
}, |
820 |
patron: { |
821 |
func: createPatronLink |
822 |
}, |
823 |
illrequest_id: { |
824 |
func: createRequestId |
825 |
}, |
826 |
status: { |
827 |
func: createStatus |
828 |
}, |
829 |
biblio_id: { |
830 |
name: _("Bibliograpic record ID"), |
831 |
func: createBiblioLink |
832 |
}, |
833 |
metadata_Type: { |
834 |
func: createType |
835 |
}, |
836 |
updated: { |
837 |
name: _("Updated on"), |
838 |
}, |
839 |
patron_cardnumber: { |
840 |
name: _("Patron barcode") |
841 |
} |
842 |
}; |
843 |
|
844 |
// Display the modal containing request supplier metadata |
845 |
$('#ill-request-display-log').on('click', function(e) { |
846 |
e.preventDefault(); |
847 |
$('#requestLog').modal({show:true}); |
848 |
}); |
849 |
|
850 |
// Toggle request attributes in Illview |
851 |
$('#toggle_requestattributes').on('click', function(e) { |
852 |
e.preventDefault(); |
853 |
$('#requestattributes').toggleClass('content_hidden'); |
854 |
}); |
855 |
|
856 |
// Toggle new comment form in Illview |
857 |
$('#toggle_addcomment').on('click', function(e) { |
858 |
e.preventDefault(); |
859 |
$('#addcomment').toggleClass('content_hidden'); |
860 |
}); |
861 |
|
862 |
// Filter partner list |
863 |
$('#partner_filter').keyup(function() { |
864 |
var needle = $('#partner_filter').val(); |
865 |
$('#partners > option').each(function() { |
866 |
var regex = new RegExp(needle, 'i'); |
867 |
if ( |
868 |
needle.length == 0 || |
869 |
$(this).is(':selected') || |
870 |
$(this).text().match(regex) |
871 |
) { |
872 |
$(this).show(); |
873 |
} else { |
874 |
$(this).hide(); |
875 |
} |
876 |
}); |
877 |
}); |
878 |
|
879 |
// Display the modal containing request supplier metadata |
880 |
$('#ill-request-display-metadata').on('click', function(e) { |
881 |
e.preventDefault(); |
882 |
$('#dataPreview').modal({show:true}); |
883 |
}); |
884 |
|
885 |
// Get our data from the API and process it prior to passing |
886 |
// it to datatables |
887 |
var ajax = $.ajax( |
888 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments,status_alias,requested_partners' |
889 |
).done(function() { |
890 |
var data = JSON.parse(ajax.responseText); |
891 |
// Make a copy, we'll be removing columns next and need |
892 |
// to be able to refer to data that has been removed |
893 |
var dataCopy = $.extend(true, [], data); |
894 |
// Expand columns that need it and create an array |
895 |
// of all column names |
896 |
$.each(dataCopy, function(k, row) { |
897 |
expandExpand(row); |
898 |
}); |
899 |
|
900 |
// Assemble an array of column definitions for passing |
901 |
// to datatables |
902 |
var colData = []; |
903 |
columns_settings.forEach(function(thisCol) { |
904 |
var colName = thisCol.columnname; |
905 |
// Create the base column object |
906 |
var colObj = $.extend({}, thisCol); |
907 |
colObj.name = colName; |
908 |
colObj.className = colName; |
909 |
colObj.defaultContent = ''; |
910 |
|
911 |
// We may need to process the data going in this |
912 |
// column, so do it if necessary |
913 |
if ( |
914 |
specialCols.hasOwnProperty(colName) && |
915 |
specialCols[colName].hasOwnProperty('func') |
916 |
) { |
917 |
colObj.render = specialCols[colName].func; |
918 |
} else { |
919 |
colObj.data = colName; |
920 |
} |
921 |
// Make sure properties that aren't present in the API |
922 |
// response are populated with null to avoid Datatables |
923 |
// choking on their absence |
924 |
dataCopy.forEach(function(thisData) { |
925 |
if (!thisData.hasOwnProperty(colName)) { |
926 |
thisData[colName] = null; |
927 |
} |
928 |
}); |
929 |
colData.push(colObj); |
930 |
}); |
931 |
|
932 |
// Initialise the datatable |
933 |
table = KohaTable("ill-requests", { |
934 |
'aoColumnDefs': [ |
935 |
{ // Last column shouldn't be sortable or searchable |
936 |
'aTargets': [ 'actions' ], |
937 |
'bSortable': false, |
938 |
'bSearchable': false |
939 |
}, |
940 |
{ // When sorting 'placed', we want to use the |
941 |
// unformatted column |
942 |
'aTargets': [ 'placed_formatted'], |
943 |
'iDataSort': 16 |
944 |
}, |
945 |
{ // When sorting 'updated', we want to use the |
946 |
// unformatted column |
947 |
'aTargets': [ 'updated_formatted'], |
948 |
'iDataSort': 18 |
949 |
} |
950 |
], |
951 |
'aaSorting': [[ 18, 'desc' ]], // Default sort, updated descending |
952 |
'processing': true, // Display a message when manipulating |
953 |
'sPaginationType': "full_numbers", // Pagination display |
954 |
'deferRender': true, // Improve performance on big datasets |
955 |
'data': dataCopy, |
956 |
'columns': colData, |
957 |
'originalData': data, // Enable render functions to access |
958 |
// our original data |
959 |
'initComplete': function() { |
960 |
// Prepare any filter elements that need it |
961 |
for (var el in filterable) { |
962 |
if (filterable.hasOwnProperty(el)) { |
963 |
if (filterable[el].hasOwnProperty('prep')) { |
964 |
filterable[el].prep(dataCopy, data); |
965 |
} |
966 |
if (filterable[el].hasOwnProperty('listener')) { |
967 |
filterable[el].listener(); |
968 |
} |
969 |
} |
970 |
} |
971 |
|
972 |
} |
973 |
}, columns_settings); |
974 |
|
975 |
// Custom date range filtering |
976 |
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) { |
977 |
var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate'); |
978 |
var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate'); |
979 |
var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate'); |
980 |
var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate'); |
981 |
var rowPlaced = data[16] ? new Date(data[16]) : null; |
982 |
var rowModified = data[18] ? new Date(data[18]) : null; |
983 |
var placedPassed = true; |
984 |
var modifiedPassed = true; |
985 |
if (placedStart && rowPlaced && rowPlaced < placedStart) { |
986 |
placedPassed = false |
987 |
}; |
988 |
if (placedEnd && rowPlaced && rowPlaced > placedEnd) { |
989 |
placedPassed = false; |
990 |
} |
991 |
if (modifiedStart && rowModified && rowModified < modifiedStart) { |
992 |
modifiedPassed = false |
993 |
}; |
994 |
if (modifiedEnd && rowModified && rowModified > modifiedEnd) { |
995 |
modifiedPassed = false; |
996 |
} |
997 |
|
998 |
return placedPassed && modifiedPassed; |
999 |
|
1000 |
}); |
1001 |
|
1002 |
} |
1003 |
); |
1004 |
|
1005 |
var clearSearch = function() { |
1006 |
table.api().search('').columns().search(''); |
1007 |
activeFilters = {}; |
1008 |
for (var filter in filterable) { |
1009 |
if ( |
1010 |
filterable.hasOwnProperty(filter) && |
1011 |
filterable[filter].hasOwnProperty('clear') |
1012 |
) { |
1013 |
filterable[filter].clear(); |
1014 |
} |
1015 |
} |
1016 |
table.api().draw(); |
1017 |
}; |
1018 |
|
1019 |
// Apply any search filters, or clear any previous |
1020 |
// ones |
1021 |
$('#illfilter_form').submit(function(event) { |
1022 |
event.preventDefault(); |
1023 |
table.api().search('').columns().search(''); |
1024 |
for (var active in activeFilters) { |
1025 |
if (activeFilters.hasOwnProperty(active)) { |
1026 |
activeFilters[active](); |
1027 |
} |
1028 |
} |
1029 |
table.api().draw(); |
1030 |
}); |
1031 |
|
1032 |
// Clear all filters |
1033 |
$('#clear_search').click(function() { |
1034 |
clearSearch(); |
1035 |
}); |
1036 |
|
1037 |
}); |
1038 |
</script> |
527 |
</script> |
|
|
528 |
[% Asset.js("js/ill-list-table.js") | $raw %] |
529 |
[% END %] |
530 |
|
531 |
[% TRY %] |
532 |
[% PROCESS backend_jsinclude %] |
533 |
[% CATCH %] |
1039 |
[% END %] |
534 |
[% END %] |
1040 |
|
535 |
|
1041 |
[% INCLUDE 'intranet-bottom.inc' %] |
536 |
[% INCLUDE 'intranet-bottom.inc' %] |