From 592024080bbddab9d3d716aaef9982961aaa99f3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Dec 2023 12:44:24 +0000 Subject: [PATCH] Bug 34324: Add 'Report a problem' modal This patch adds a modal for reporting opac problems. This will allow us to remove the controller and template code for the feature. --- .../en/includes/modals/problem_report.inc | 42 ++++++++++++ .../bootstrap/en/includes/opac-bottom.inc | 8 +++ .../bootstrap/js/modals/problem_report.js | 66 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/problem_report.inc create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/modals/problem_report.js diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/problem_report.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/problem_report.inc new file mode 100644 index 00000000000..4f64fb8d0a3 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/problem_report.inc @@ -0,0 +1,42 @@ + + diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index 943c862eaba..457223256cb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -30,6 +30,7 @@ [% IF Koha.Preference('OPACReportProblem') && Koha.Preference('KohaAdminEmailAddress') %]
@@ -125,6 +126,10 @@ [% INCLUDE 'modals/checkout.inc' %] [% END %] +[% IF ( Koha.Preference('OPACReportProblem') && Koha.Preference('KohaAdminEmailAddress') ) %] + [% INCLUDE 'modals/problem_report.inc' %] +[% END %] + [% IF Koha.Preference( 'CookieConsent' ) && JSConsents.all('opacConsent').size %] [% consents = JSConsents.all('opacConsent') %] @@ -261,6 +266,9 @@ $(document).ready(function() { [% IF Koha.Preference( 'CookieConsent' ) %] [% Asset.js("js/cookieconsent.js") | $raw %] [% END %] +[% IF ( Koha.Preference('OPACReportProblem') && Koha.Preference('KohaAdminEmailAddress') ) %] + [% Asset.js("js/modals/problem_report.js") | $raw %] +[% END %] [% KohaPlugins.get_plugins_opac_js | $raw %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/modals/problem_report.js b/koha-tmpl/opac-tmpl/bootstrap/js/modals/problem_report.js new file mode 100644 index 00000000000..29aa6b8bf43 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/js/modals/problem_report.js @@ -0,0 +1,66 @@ +$(document).ready(function() { + + // Detect that we were redirected here after login and re-open modal + let urlParams = new URLSearchParams(window.location.search); + if (urlParams.has('modal')) { + let modal = urlParams.get('modal'); + history.replaceState && history.replaceState( + null, '', location.pathname + location.search.replace(/[\?&]modal=[^&]+/, '').replace(/^&/, '?') + ); + if (modal == 'problem') { + $("#reportProblemModal").modal('show'); + } + } + + $('#reportProblemModal').on('show.bs.modal', function(e) { + // Redirect to login modal if not logged in + if (logged_in_user_id === "") { + $('#modalAuth').append(''); + $('#loginModal').modal('show'); + return false; + } + + $('.addConfirm').prop('disabled', false); + }); + + $('#reportProblemModal').on('click', '.addConfirm', function(e) { + let problem_title = $('#problem_subject').val(); + let problem_body = $('#problem_body').val(); + let reporter_id = $('#problem_reporter').val(); + + params = { + source: 'opac_problem', + title: problem_title, + body: problem_body, + biblio_id: null, + reporter_id: reporter_id, + extended_attributes: [ + { + field_id: 1, + value: window.location.pathname + window.location.search + } + ] + }; + + $('#problem-submit-spinner').show(); + $('.addConfirm').prop('disabled', true); + $.ajax({ + url: '/api/v1/public/tickets', + type: 'POST', + data: JSON.stringify(params), + success: function(data) { + $('#problem-submit-spinner').hide(); + $('#reportProblemModal').modal('hide'); + $('#problem_body').val(''); + $('#problem_title').val(''); + $('h1:first').before('
' + __("Your problem was sucessfully submitted.") + '
'); + }, + error: function(data) { + $('#problem-submit-spinner').hide(); + $('#reportProblemModal').modal('hide'); + $('h1:first').before('
' + __("There was an error when submitting your problem, please contact a librarian.") + '
'); + }, + contentType: "json" + }); + }); +}); -- 2.43.0