From cac8fba5f96422e76f8066cdcaffc23141edf870 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 13 Feb 2020 14:16:48 +0000 Subject: [PATCH] Bug 24608: Allow due date modification This patch adds the ability to modify due dates from a patron's checkouts list. --- .../intranet-tmpl/prog/en/includes/strings.inc | 1 + .../prog/en/modules/circ/circulation.tt | 4 ++ koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 58 +++++++++++++++++++++- svc/checkouts | 2 + 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc index 5ef174db7c..3d4dcbd333 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc @@ -42,6 +42,7 @@ var CANCEL = _("Cancel"); var RESUME = _("Resume"); var SUSPEND = _("Suspend"); + var SAVE = _("Save"); var SUSPEND_UNTIL = _("Suspend until:"); var SUSPEND_HOLD_ON = _("Suspend hold on"); var CLEAR_DATE_TO_SUSPEND_INDEFINITELY = _("Clear date to suspend indefinitely"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 1eeb19e3af..51ae68e75a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1050,6 +1050,10 @@ var MSG_CONFIRM_DELETE_MESSAGE = _("Are you sure you want to delete this message? This cannot be undone."); var SuspendHoldsIntranet = [% ( Koha.Preference('SuspendHoldsIntranet') ) ? 1 : 0 | html %]; + [% Asset.js("js/pages/circulation.js") | $raw %] [% Asset.js("js/checkouts.js") | $raw %] [% Asset.js("js/holds.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index c1ca172f33..2693cf014b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -268,7 +268,11 @@ $(document).ready(function() { due = "" + due + ""; } - due = "" + due + ""; + due = "
" + due + ""; + + if (canEditDueDates) { + due += " Edit
"; + } if ( oObj.lost && oObj.claims_returned ) { due += "" + oObj.lost.escapeHtml() + ""; @@ -1091,4 +1095,56 @@ $(document).ready(function() { }); + // Allow due date editing if appropriate + if (canEditDueDates) { + $(document).on('click', '.edit_due_date_btn', function(e) { + e.preventDefault(); + var date_display = $(this).siblings('.date_due'); + $('#issues-table .edit_due_date_btn').attr('disabled', '1'); + var current = date_display.text(); + date_display.hide(); + $(this).closest('div').append('' + + ' ' + SAVE + ''); + $(this).hide(); + $("#due_date_select").datetimepicker({ + onClose: function(dateText, inst) { + validate_date(dateText, inst); + }, + minDate: 1, // require that renewal date is after today + hour: 23, + minute: 59 + }).on("change", function(e) { + if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");} + }); + }); + $(document).on('click', '.save_due_date_btn', function(e) { + e.preventDefault(); + var saveBtn = $(this); + var p = saveBtn.closest('div'); + var checkoutId = p.data('issue_id'); + var due_date = saveBtn.siblings('#due_date_select')[0].value; + p.append(""); + saveBtn.hide(); + if (due_date && due_date.length > 0) { + var dt = DateTime_from_syspref(due_date); + $.ajax({ + url: `/api/v1/checkouts/${checkoutId}`, + type: 'PUT', + data: JSON.stringify({ date_due: dt.toISOString() }), + success: function( data ) { + var dateFormatted = ISO_to_syspref(data.due_date); + saveBtn.siblings('.date_due').text(dateFormatted).show(); + $('#issues-table .edit_due_date_btn').removeAttr('disabled'); + p.find('#due_date_select').remove() + p.find('.ui-datepicker-trigger').remove() + p.find('#due_date_spinner').remove(); + p.find('.edit_due_date_btn').show(); + saveBtn.remove(); + }, + contentType: "json" + }); + } + }); + } + }); diff --git a/svc/checkouts b/svc/checkouts index f8fd541f36..335c742776 100755 --- a/svc/checkouts +++ b/svc/checkouts @@ -64,6 +64,7 @@ print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); my @parameters; my $sql = ' SELECT + issue_id, issues.issuedate, issues.date_due, issues.date_due < now() as date_due_overdue, @@ -189,6 +190,7 @@ while ( my $c = $sth->fetchrow_hashref() ) { my @subtitles = split(/ \| /, $c->{'subtitle'} // '' ); my $checkout = { DT_RowId => $c->{itemnumber} . '-' . $c->{borrowernumber}, + issue_id => $c->{issue_id}, title => $c->{title}, subtitle => \@subtitles, medium => $c->{medium} // '', -- 2.11.0