Lines 268-274
$(document).ready(function() {
Link Here
|
268 |
|
268 |
|
269 |
due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>"; |
269 |
due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>"; |
270 |
|
270 |
|
271 |
if ( oObj.lost ) { |
271 |
if ( oObj.lost && oObj.claims_returned ) { |
|
|
272 |
due += "<span class='lost claims_returned'>" + oObj.lost.escapeHtml() + "</span>"; |
273 |
} else if ( oObj.lost ) { |
272 |
due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>"; |
274 |
due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>"; |
273 |
} |
275 |
} |
274 |
|
276 |
|
Lines 538-543
$(document).ready(function() {
Link Here
|
538 |
} |
540 |
} |
539 |
} |
541 |
} |
540 |
}, |
542 |
}, |
|
|
543 |
{ |
544 |
"bVisible": ClaimReturnedLostValue ? true : false, |
545 |
"bSortable": false, |
546 |
"mDataProp": function ( oObj ) { |
547 |
let content = ""; |
548 |
|
549 |
if ( oObj.return_claim_id ) { |
550 |
content = `<span class="badge">${oObj.return_claim_created_on_formatted}</span>`; |
551 |
} else { |
552 |
content = `<a class="btn btn-default btn-xs claim-returned-btn" data-itemnumber="${oObj.itemnumber}"><i class="fa fa-exclamation-circle"></i> ${RETURN_CLAIMED_MAKE}</a>`; |
553 |
} |
554 |
return content; |
555 |
} |
556 |
}, |
541 |
{ |
557 |
{ |
542 |
"bVisible": exports_enabled == 1 ? true : false, |
558 |
"bVisible": exports_enabled == 1 ? true : false, |
543 |
"bSortable": false, |
559 |
"bSortable": false, |
Lines 808-811
$(document).ready(function() {
Link Here
|
808 |
} |
824 |
} |
809 |
} ).prop('checked', false); |
825 |
} ).prop('checked', false); |
810 |
} |
826 |
} |
|
|
827 |
|
828 |
// Handle return claims |
829 |
$(document).on("click", '.claim-returned-btn', function(e){ |
830 |
e.preventDefault(); |
831 |
itemnumber = $(this).data('itemnumber'); |
832 |
|
833 |
$('#claims-returned-itemnumber').val(itemnumber); |
834 |
$('#claims-returned-notes').val(""); |
835 |
$('#claims-returned-charge-lost-fee').attr('checked', false) |
836 |
$('#claims-returned-modal').modal() |
837 |
}); |
838 |
$(document).on("click", '#claims-returned-modal-btn-submit', function(e){ |
839 |
let itemnumber = $('#claims-returned-itemnumber').val(); |
840 |
let notes = $('#claims-returned-notes').val(); |
841 |
let fee = $('#claims-returned-charge-lost-fee').attr('checked') ? true : false; |
842 |
|
843 |
$('#claims-returned-modal').modal('hide') |
844 |
|
845 |
$(`.claim-returned-btn[data-itemnumber='${itemnumber}']`).replaceWith(`<img id='return_claim_spinner_${itemnumber}' src='${interface}/${theme}/img/spinner-small.gif' />`); |
846 |
|
847 |
params = { |
848 |
notes: notes, |
849 |
charge_lost_fee: fee, |
850 |
created_by: $.cookie("lastborrowernumber") |
851 |
}; |
852 |
|
853 |
$.post( `/api/v1/return_claims/claim/${itemnumber}`, JSON.stringify(params), function( data ) { |
854 |
|
855 |
id = "#return_claim_spinner_" + data.itemnumber; |
856 |
|
857 |
let content = ""; |
858 |
if ( data.id ) { |
859 |
console.log(data); |
860 |
content = `<span class="badge">${data.created_on_formatted}</span>`; |
861 |
$(id).parent().parent().addClass('ok'); |
862 |
} else { |
863 |
content = RETURN_CLAIMED_FAILURE; |
864 |
$(id).parent().parent().addClass('warn'); |
865 |
} |
866 |
|
867 |
$(id).replaceWith( content ); |
868 |
|
869 |
refreshReturnClaimsTable(); |
870 |
}, "json") |
871 |
|
872 |
}); |
873 |
|
874 |
|
875 |
// Don't load return claims table unless it is clicked on |
876 |
var returnClaimsTable; |
877 |
$("#return-claims-tab").click( function() { |
878 |
refreshReturnClaimsTable(); |
879 |
}); |
880 |
|
881 |
function refreshReturnClaimsTable(){ |
882 |
loadReturnClaimsTable(); |
883 |
$("#return-claims-table").DataTable().ajax.reload(); |
884 |
} |
885 |
function loadReturnClaimsTable() { |
886 |
if ( ! returnClaimsTable ) { |
887 |
returnClaimsTable = $("#return-claims-table").dataTable({ |
888 |
"bAutoWidth": false, |
889 |
"sDom": "rt", |
890 |
"aaSorting": [], |
891 |
"aoColumns": [ |
892 |
{ |
893 |
"mDataProp": "id", |
894 |
"bVisible": false, |
895 |
}, |
896 |
{ |
897 |
"mDataProp": function ( oObj ) { |
898 |
let title = `<a class="return-claim-title strong" href="/cgi-bin/koha/circ/request-rcticle.pl?biblionumber=[% rc.checkout.item.biblionumber | html %]"> |
899 |
${oObj.title} |
900 |
${oObj.enumchron || ""} |
901 |
</a>`; |
902 |
if ( oObj.author ) { |
903 |
title += `by ${oObj.author}`; |
904 |
} |
905 |
title += `<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=${oObj.biblionumber}&itemnumber=${oObj.itemnumber}">${oObj.barcode}</a>`; |
906 |
|
907 |
return title; |
908 |
} |
909 |
}, |
910 |
{ |
911 |
"sClass": "return-claim-notes-td", |
912 |
"mDataProp": function ( oObj ) { |
913 |
return ` |
914 |
<span id="return-claim-notes-static-${oObj.id}" class="return-claim-notes" data-return-claim-id="${oObj.id}">${oObj.notes}</span> |
915 |
<i style="float:right" class="fa fa-pencil-square-o" title="Double click to edit"></i> |
916 |
`; |
917 |
} |
918 |
}, |
919 |
{ |
920 |
"mDataProp": "created_on", |
921 |
}, |
922 |
{ |
923 |
"mDataProp": "updated_on", |
924 |
}, |
925 |
{ |
926 |
"mDataProp": function ( oObj ) { |
927 |
if ( ! oObj.resolution ) return ""; |
928 |
|
929 |
let desc = `<strong>${oObj.resolution_data.lib}</strong> on <i>${oObj.resolved_on_formatted}</i>`; |
930 |
if (oObj.resolved_by_data) desc += ` by <a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=${oObj.resolved_by_data.borrowernumber}">${oObj.resolved_by_data.firstname || ""} ${oObj.resolved_by_data.surname || ""}</a>`; |
931 |
return desc; |
932 |
} |
933 |
}, |
934 |
{ |
935 |
"mDataProp": function ( oObj ) { |
936 |
let delete_html = oObj.resolved_on |
937 |
? `<li><a href="#" class="return-claim-tools-delete" data-return-claim-id="${oObj.id}"><i class="fa fa-trash"></i> Delete</a></li>` |
938 |
: ""; |
939 |
let resolve_html = ! oObj.resolution |
940 |
? `<li><a href="#" class="return-claim-tools-resolve" data-return-claim-id="${oObj.id}"><i class="fa fa-check-square"></i> Resolve</a></li>` |
941 |
: ""; |
942 |
|
943 |
return ` |
944 |
<div class="btn-group"> |
945 |
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
946 |
Actions <span class="caret"></span> |
947 |
</button> |
948 |
<ul class="dropdown-menu"> |
949 |
<li><a href="#" class="return-claim-tools-editnotes" data-return-claim-id="${oObj.id}"><i class="fa fa-edit"></i> Edit notes</a></li> |
950 |
${resolve_html} |
951 |
${delete_html} |
952 |
</ul> |
953 |
</div> |
954 |
`; |
955 |
} |
956 |
}, |
957 |
], |
958 |
"bPaginate": false, |
959 |
"bProcessing": true, |
960 |
"bServerSide": false, |
961 |
"sAjaxSource": '/cgi-bin/koha/svc/return_claims', |
962 |
"fnServerData": function ( sSource, aoData, fnCallback ) { |
963 |
aoData.push( { "name": "borrowernumber", "value": borrowernumber } ); |
964 |
|
965 |
$.getJSON( sSource, aoData, function (json) { |
966 |
let resolved = json.resolved; |
967 |
let unresolved = json.unresolved; |
968 |
|
969 |
$('#return-claims-count-resolved').text(resolved); |
970 |
$('#return-claims-count-unresolved').text(unresolved); |
971 |
|
972 |
fnCallback(json) |
973 |
} ); |
974 |
}, |
975 |
}); |
976 |
} |
977 |
} |
978 |
|
979 |
$('body').on('click', '.return-claim-tools-editnotes', function() { |
980 |
let id = $(this).data('return-claim-id'); |
981 |
$(`#return-claim-notes-static-${id}`).parent().dblclick(); |
982 |
}); |
983 |
$('body').on('dblclick', '.return-claim-notes-td', function() { |
984 |
let elt = $(this).children('.return-claim-notes'); |
985 |
let id = elt.data('return-claim-id'); |
986 |
if ( $(`#return-claim-notes-editor-textarea-${id}`).length == 0 ) { |
987 |
let note = elt.text(); |
988 |
let editor = ` |
989 |
<span id="return-claim-notes-editor-${id}"> |
990 |
<textarea id="return-claim-notes-editor-textarea-${id}">${note}</textarea> |
991 |
<br/> |
992 |
<a class="btn btn-default btn-xs claim-returned-notes-editor-submit" data-return-claim-id="${id}"><i class="fa fa-save"></i> Update</a> |
993 |
<a class="claim-returned-notes-editor-cancel" data-return-claim-id="${id}" href="#">Cancel</a> |
994 |
</span> |
995 |
`; |
996 |
elt.hide(); |
997 |
$(editor).insertAfter( elt ); |
998 |
} |
999 |
}); |
1000 |
|
1001 |
$('body').on('click', '.claim-returned-notes-editor-submit', function(){ |
1002 |
let id = $(this).data('return-claim-id'); |
1003 |
let notes = $(`#return-claim-notes-editor-textarea-${id}`).val(); |
1004 |
|
1005 |
let params = { |
1006 |
notes: notes, |
1007 |
updated_by: $.cookie("lastborrowernumber") |
1008 |
}; |
1009 |
|
1010 |
$(this).parent().remove(); |
1011 |
|
1012 |
$.ajax({ |
1013 |
url: `/api/v1/return_claims/${id}/notes`, |
1014 |
type: 'PUT', |
1015 |
data: JSON.stringify(params), |
1016 |
success: function( data ) { |
1017 |
let notes = $(`#return-claim-notes-static-${id}`); |
1018 |
notes.text(data.notes); |
1019 |
notes.show(); |
1020 |
}, |
1021 |
contentType: "json" |
1022 |
}); |
1023 |
}); |
1024 |
|
1025 |
$('body').on('click', '.claim-returned-notes-editor-cancel', function(){ |
1026 |
let id = $(this).data('return-claim-id'); |
1027 |
$(this).parent().remove(); |
1028 |
$(`#return-claim-notes-static-${id}`).show(); |
1029 |
}); |
1030 |
|
1031 |
// Hanld return claim deletion |
1032 |
$('body').on('click', '.return-claim-tools-delete', function() { |
1033 |
let confirmed = confirm(CONFIRM_DELETE_RETURN_CLAIM); |
1034 |
if ( confirmed ) { |
1035 |
let id = $(this).data('return-claim-id'); |
1036 |
|
1037 |
$.ajax({ |
1038 |
url: `/api/v1/return_claims/${id}`, |
1039 |
type: 'DELETE', |
1040 |
success: function( data ) { |
1041 |
refreshReturnClaimsTable(); |
1042 |
} |
1043 |
}); |
1044 |
} |
1045 |
}); |
1046 |
|
1047 |
// Handle return claim resolution |
1048 |
$('body').on('click', '.return-claim-tools-resolve', function() { |
1049 |
let id = $(this).data('return-claim-id'); |
1050 |
|
1051 |
$('#claims-returned-resolved-modal-id').val(id); |
1052 |
$('#claims-returned-resolved-modal').modal() |
1053 |
}); |
1054 |
|
1055 |
$(document).on('click', '#claims-returned-resolved-modal-btn-submit', function(e) { |
1056 |
let resolution = $('#claims-returned-resolved-modal-resolved-code').val(); |
1057 |
let id = $('#claims-returned-resolved-modal-id').val(); |
1058 |
|
1059 |
$('#claims-returned-resolved-modal-btn-submit-spinner').show(); |
1060 |
$('#claims-returned-resolved-modal-btn-submit-icon').hide(); |
1061 |
|
1062 |
params = { |
1063 |
resolution: resolution, |
1064 |
updated_by: $.cookie("lastborrowernumber"), |
1065 |
}; |
1066 |
|
1067 |
$.ajax({ |
1068 |
url: `/api/v1/return_claims/${id}/resolve`, |
1069 |
type: 'PUT', |
1070 |
data: JSON.stringify(params), |
1071 |
success: function( data ) { |
1072 |
$('#claims-returned-resolved-modal-btn-submit-spinner').hide(); |
1073 |
$('#claims-returned-resolved-modal-btn-submit-icon').show(); |
1074 |
$('#claims-returned-resolved-modal').modal('hide') |
1075 |
|
1076 |
refreshReturnClaimsTable(); |
1077 |
}, |
1078 |
contentType: "json" |
1079 |
}); |
1080 |
|
1081 |
}); |
1082 |
|
811 |
}); |
1083 |
}); |