From 9c49671ca84efde4e9083b6befbe3222d72f3782 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 26 Jul 2021 15:27:02 +0000 Subject: [PATCH] Bug 28720: Update the process of adding a checkout note in the OPAC This patch moves the entry of checkout notes into a modal window with the goal of making note entry easier. To test, apply the patch and make sure the AllowCheckoutNotes system preference is enabled. - Log in to the OPAC as a user with checkouts. - On the "Your summary" page, confirm that the table listing your checkouts has a "Report a problem" column with "Add note" buttons. - Click an "Add note" button. A modal window should be shown which includes the title of the item, a textarea for writing a note, and a hint, "Your note will be shown to the librarian when the item is checked in." - Add a note and submit it. - The modal should close and a note at the top of the page should tell you your note has been saved. The contents of your note should be shown below that along with an "Edit note" link. - Confirm that the "Edit note" link works as expected. - Confirm that the "Add note" button you clicked in the table of checkouts now reads "Edit note." - You should be able to click this button and edit your note. - Confirm that each note button works to add a note to the correct title. - Confirm that the "Renew selected" and "Renew all" controls work. Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../bootstrap/en/modules/opac-user.tt | 192 ++++++++++++------ 1 file changed, 135 insertions(+), 57 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index e4186b4c1b..108b2329e3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -14,7 +14,20 @@ [% INCLUDE 'doc-head-open.inc' %] Your library home › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog [% INCLUDE 'doc-head-close.inc' %] -[% BLOCK cssinclude %][% END %] +[% BLOCK cssinclude %] + [% FILTER collapse %] + + [% END %] +[% END %] [% INCLUDE 'bodytag.inc' bodyid='opac-user' bodyclass='scrollto' %] [% INCLUDE 'masthead.inc' %] @@ -440,10 +453,15 @@ [% END %] [% IF ( Koha.Preference('AllowCheckoutNotes') ) %] - -
255 characters maximum
- - + [% IF ( ISSUE.note ) -%] + [% SET note_action = "Edit note" %] + [% ELSE -%] + [% SET note_action = "Add note" %] + [% END %] + + [% note_action | html %] + + [% END %] @@ -475,6 +493,33 @@ You have nothing checked out [% END # IF issues_count %] + + + + [% IF borrower_club_enrollments.count || borrower_enrollable_clubs.count %] @@ -981,58 +1026,6 @@ } }); - $(".js_submitnote").click(function(e){ - var $self = $(this); - var title = $(this).parent().parent().find('a.title')[0].outerHTML; - var $noteinput = $(this).siblings('input[name="note"]').first(); - - var ajaxData = { - 'action': 'issuenote', - 'issue_id': $noteinput.data('issue_id'), - 'note': $noteinput.val(), - }; - - $.ajax({ - url: '/cgi-bin/koha/svc/checkout_notes/', - type: 'POST', - dataType: 'json', - data: ajaxData, - }) - .done(function(data) { - var message = ""; - if(data.status == 'saved') { - $("#notesaved").removeClass("alert-error"); - $("#notesaved").addClass("alert-info"); - $noteinput.data('origvalue', data.note); - $noteinput.val(data.note); - message = "

" + _("Your note about %s has been saved and sent to the library.").format(title) + "

"; - message += "

" + data.note + "

"; - $self.hide(); - } else if(data.status == 'removed') { - $("#notesaved").removeClass("alert-error"); - $("#notesaved").addClass("alert-info"); - $noteinput.data('origvalue', ""); - $noteinput.val(""); - message = "

" + _("Your note about %s was removed.").format(title) + "

"; - $self.hide(); - } else { - $("#notesaved").removeClass("alert-info"); - $("#notesaved").addClass("alert-error"); - message = "

" + _("Your note about %s could not be saved.").format(title) + "

"; - message += "

" + _("Something went wrong. The note has not been saved") + "

"; - } - $("#notesaved").html(message); - }) - .fail(function(data) { - $("#notesaved").removeClass("alert-info"); - $("#notesaved").addClass("alert-error"); - var message = "

" + _("Something went wrong. The note has not been saved") + "

"; - $("#notesaved").html(message); - }) - .always(function() { - $("#notesaved").show(); - }); - }); [% END %] $(".suspend-until").datepicker({ @@ -1057,8 +1050,93 @@ $('#opac-user-clubs').load('/cgi-bin/koha/clubs/clubs-tab.pl?borrowernumber=[% borrowernumber | html %]'); }); } + + $("body").on("click", ".btn-add-note", function(e){ + e.preventDefault(); + var title = $(this).data("title"); + var issue_id = $(this).data("issueid"); + var note = $(this).data("note"); + var origvalue = $(this).data("origvalue"); + $("#addNote").val( note ); + $("#addNoteIssueId").val( issue_id ); + $("#addNoteTitle").text( title ); + $("#addNoteModal").modal("show"); + }); + + $("#addNoteForm").on("submit", function(e){ + e.preventDefault(); + var title = $("#addNoteTitle").text(); + var issue_id = $("#addNoteIssueId").val(); + var note = $("#addNote").val(); + submitNote( title, issue_id, note ); + }); + + $("#addNoteModal").on("hidden.bs.modal", function(){ + $("#addNoteTitle").text(""); + $("#addNote").val(""); + }); }); + function submitNote( title, issue_id, note ){ + var self = $("#addNoteModal"); + var noteinput = $("#save_" + issue_id ); + + var ajaxData = { + 'action': 'issuenote', + 'issue_id': issue_id, + 'note': note + }; + + $.ajax({ + url: '/cgi-bin/koha/svc/checkout_notes/', + type: 'POST', + dataType: 'json', + data: ajaxData, + }) + .done(function(data) { + var message = ""; + if(data.status == 'saved') { + $("#notesaved").removeClass("alert-error"); + $("#notesaved").addClass("alert-info"); + noteinput.data('origvalue', data.note) + .data('note', data.note) + .text( _("Edit note" ) ); + message = "

" + _("Your note about %s has been saved and sent to the library.").format( em(title) ) + "

"; + message += "

" + data.note; + message += " " + _("Edit note") + ""; + message += "

"; + } else if(data.status == 'removed') { + $("#notesaved").removeClass("alert-error"); + $("#notesaved").addClass("alert-info"); + noteinput.data('origvalue', "") + .data("note", "") + .text( _("Add note") ); + message = "

" + _("Your note about %s was removed.").format( em(title) ) + "

"; + } else { + $("#notesaved").removeClass("alert-info"); + $("#notesaved").addClass("alert-error"); + message = "

" + _("Your note about %s could not be saved.").format( em(title) ) + "

"; + noteinput.text( _("Add note") ); + message += "

" + _("Something went wrong. The note has not been saved") + "

"; + } + self.modal("hide"); + $("#notesaved").html(message); + }) + .fail(function(data) { + $("#notesaved").removeClass("alert-info"); + $("#notesaved").addClass("alert-error"); + var message = "

" + _("Something went wrong. The note has not been saved") + "

"; + $("#notesaved").html(message); + }) + .always(function() { + $("#notesaved").show(); + }); + } + + function em( title ){ + return "" + title + ""; + } + var borrowernumber = "[% borrowernumber | html %]"; var MSG_YOUR_RATING = _("Your rating: %s, "); var MSG_AVERAGE_RATING = _("Average rating: %s (%s votes)"); -- 2.39.5