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