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