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 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)");