From 632e280ea2118c9d74cc6427a1fa10cf7533f978 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Mar 2024 09:31:38 +0000 Subject: [PATCH] Bug 36374: Also tidy ticket and concern modals js This patch does the promised follow-up to tidy the two other recently added js files for modals. As I'm the main maintainer of those to date I'm happy to rebase any patches already submitted atop this bug. Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim Signed-off-by: Katrin Fischer --- .../prog/js/modals/add_catalog_concern.js | 65 +++--- .../prog/js/modals/display_ticket.js | 191 +++++++++++------- 2 files changed, 155 insertions(+), 101 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/add_catalog_concern.js b/koha-tmpl/intranet-tmpl/prog/js/modals/add_catalog_concern.js index 61cb26d8c0..6fdd14a769 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/add_catalog_concern.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/add_catalog_concern.js @@ -1,53 +1,62 @@ /* keep tidy */ -$(document).ready(function() { - +$(document).ready(function () { // Pre-populate empty message with template - $('#addConcernModal').on('show.bs.modal', function (e) { - $('#addConfirm').prop('disabled', false); - let concern_body = $('#concern_body'); - if ( concern_body.val() === "" ) { - let template = $('#concern_template').text(); + $("#addConcernModal").on("show.bs.modal", function (e) { + $("#addConfirm").prop("disabled", false); + let concern_body = $("#concern_body"); + if (concern_body.val() === "") { + let template = $("#concern_template").text(); concern_body.val(template); } }); - $('#addConcernModal').on('click', '#addConfirm', function(e) { - let concern_title = $('#concern_title').val(); - let concern_body = $('#concern_body').val(); - let biblio_id = $('#concern_biblio').val(); - let reporter_id = $('#concern_reporter').val(); + $("#addConcernModal").on("click", "#addConfirm", function (e) { + let concern_title = $("#concern_title").val(); + let concern_body = $("#concern_body").val(); + let biblio_id = $("#concern_biblio").val(); + let reporter_id = $("#concern_reporter").val(); let params = { - source: 'catalog', + source: "catalog", title: concern_title, body: concern_body, biblio_id: biblio_id, reporter_id: logged_in_user_borrowernumber, }; - $('#concern-submit-spinner').show(); - $('#addConfirm').prop('disabled', true); + $("#concern-submit-spinner").show(); + $("#addConfirm").prop("disabled", true); $.ajax({ - url: '/api/v1/tickets', - type: 'POST', + url: "/api/v1/tickets", + type: "POST", data: JSON.stringify(params), - success: function(data) { - $('#concern-submit-spinner').hide(); - $('#addConcernModal').modal('hide'); - $('#concern_body').val(''); - $('#concern_title').val(''); - $('#toolbar').before('
' + __("Your concern was successfully submitted.") + '
'); + success: function (data) { + $("#concern-submit-spinner").hide(); + $("#addConcernModal").modal("hide"); + $("#concern_body").val(""); + $("#concern_title").val(""); + $("#toolbar").before( + '
' + + __("Your concern was successfully submitted.") + + "
" + ); if ($.fn.dataTable.isDataTable("#table_concerns")) { $("#table_concerns").DataTable().ajax.reload(); } }, - error: function(data) { - $('#concern-submit-spinner').hide(); - $('#addConcernModal').modal('hide'); - $('#toolbar').before('
' + __("There was an error when submitting your concern, please contact a librarian.") + '
'); + error: function (data) { + $("#concern-submit-spinner").hide(); + $("#addConcernModal").modal("hide"); + $("#toolbar").before( + '
' + + __( + "There was an error when submitting your concern, please contact a librarian." + ) + + "
" + ); }, - contentType: "json" + contentType: "json", }); }); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js b/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js index 0812d7fccb..a4541bc8ca 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js @@ -1,31 +1,31 @@ /* keep tidy */ -$(document).ready(function() { - $('#ticketDetailsModal').on('show.bs.modal', function(event) { +$(document).ready(function () { + $("#ticketDetailsModal").on("show.bs.modal", function (event) { let modal = $(this); let button = $(event.relatedTarget); - let ticket_id = button.data('concern'); - let resolved = button.data('resolved'); - modal.find('.modal-footer input').val(ticket_id); + let ticket_id = button.data("concern"); + let resolved = button.data("resolved"); + modal.find(".modal-footer input").val(ticket_id); - if ( resolved ) { - $('#resolveTicket').hide(); + if (resolved) { + $("#resolveTicket").hide(); } else { - $('#resolveTicket').show(); + $("#resolveTicket").show(); } - let detail = $('#detail_' + ticket_id).text(); + let detail = $("#detail_" + ticket_id).text(); // Display ticket details let display = '
'; display += '
'; - display += '' + detail + ''; - display += '
'; + display += '' + detail + ""; + display += "
"; display += '
'; - display += '' + __("Loading updates . . .") + ''; - display += '
'; - display += ''; + display += "" + __("Loading updates . . .") + ""; + display += ""; + display += ""; - let details = modal.find('#concern-details'); + let details = modal.find("#concern-details"); details.html(display); // Load any existing updates @@ -33,89 +33,134 @@ $(document).ready(function() { url: "/api/v1/tickets/" + ticket_id + "/updates", method: "GET", headers: { - "x-koha-embed": "user" + "x-koha-embed": "user", }, - }).success(function(data) { - let updates_display = $('#concern-updates'); - let updates = ''; - data.forEach(function(item, index) { - if ( item.public ) { - updates += '
'; - updates += '' + __("Public") + ''; - } - else { - updates += '
'; - updates += '' + __("Private") + ''; - } - updates += '' + item.message + ''; - updates += '' + $patron_to_html(item.user, { - display_cardnumber: false, - url: true - }) + ' (' + $datetime(item.date) + ')'; - updates += '
'; - }); - updates_display.html(updates); - }).error(function() { - - }); + }) + .success(function (data) { + let updates_display = $("#concern-updates"); + let updates = ""; + data.forEach(function (item, index) { + if (item.public) { + updates += + '
'; + updates += + '' + + __("Public") + + ""; + } else { + updates += + '
'; + updates += + '' + + __("Private") + + ""; + } + updates += + '' + item.message + ""; + updates += + '' + + $patron_to_html(item.user, { + display_cardnumber: false, + url: true, + }) + + " (" + + $datetime(item.date) + + ")"; + updates += "
"; + }); + updates_display.html(updates); + }) + .error(function () {}); // Clear any previously entered update message - $('#update_message').val(''); - $('#public').prop( "checked", false ); + $("#update_message").val(""); + $("#public").prop("checked", false); }); - $('#ticketDetailsModal').on('click', '#updateTicket', function(e) { - let ticket_id = $('#ticket_id').val(); + $("#ticketDetailsModal").on("click", "#updateTicket", function (e) { + let ticket_id = $("#ticket_id").val(); let params = { - 'public': $('#public').is(":checked"), - message: $('#update_message').val(), - user_id: logged_in_user_borrowernumber + public: $("#public").is(":checked"), + message: $("#update_message").val(), + user_id: logged_in_user_borrowernumber, }; - $('#comment-spinner').show(); + $("#comment-spinner").show(); $.ajax({ url: "/api/v1/tickets/" + ticket_id + "/updates", method: "POST", data: JSON.stringify(params), - ontentType: "application/json; charset=utf-8" - }).success(function() { - $('#comment-spinner').hide(); - $('#ticketDetailsModal').modal('hide'); - $('#table_concerns').DataTable().ajax.reload(function(data) { - $("#concern_action_result_dialog").hide(); - $("#concern_delete_success").html(__("Concern #%s updated successfully.").format(ticket_id)).show(); + ontentType: "application/json; charset=utf-8", + }) + .success(function () { + $("#comment-spinner").hide(); + $("#ticketDetailsModal").modal("hide"); + $("#table_concerns") + .DataTable() + .ajax.reload(function (data) { + $("#concern_action_result_dialog").hide(); + $("#concern_delete_success") + .html( + __("Concern #%s updated successfully.").format( + ticket_id + ) + ) + .show(); + }); + }) + .error(function () { + $("#concern_update_error") + .html( + __( + "Error resolving concern #%s. Check the logs for details." + ).format(ticket_id) + ) + .show(); }); - }).error(function() { - $("#concern_update_error").html(__("Error resolving concern #%s. Check the logs for details.").format(ticket_id)).show(); - }); }); - $('#ticketDetailsModal').on('click', '#resolveTicket', function(e) { - let ticket_id = $('#ticket_id').val(); + $("#ticketDetailsModal").on("click", "#resolveTicket", function (e) { + let ticket_id = $("#ticket_id").val(); let params = { - 'public': $('#public').is(":checked"), - message: $('#update_message').val(), + public: $("#public").is(":checked"), + message: $("#update_message").val(), user_id: logged_in_user_borrowernumber, - state: 'resolved' + state: "resolved", }; - $('#resolve-spinner').show(); + $("#resolve-spinner").show(); $.ajax({ url: "/api/v1/tickets/" + ticket_id + "/updates", method: "POST", data: JSON.stringify(params), - ontentType: "application/json; charset=utf-8" - }).success(function() { - $('#resolve-spinner').hide(); - $("#ticketDetailsModal").modal('hide'); - $('#table_concerns').DataTable().ajax.reload(function(data) { - $("#concern_action_result_dialog").hide(); - $("#concern_delete_success").html(__("Concern #%s updated successfully.").format(ticket_id)).show(); + ontentType: "application/json; charset=utf-8", + }) + .success(function () { + $("#resolve-spinner").hide(); + $("#ticketDetailsModal").modal("hide"); + $("#table_concerns") + .DataTable() + .ajax.reload(function (data) { + $("#concern_action_result_dialog").hide(); + $("#concern_delete_success") + .html( + __("Concern #%s updated successfully.").format( + ticket_id + ) + ) + .show(); + }); + }) + .error(function () { + $("#concern_update_error") + .html( + __( + "Error resolving concern #%s. Check the logs for details." + ).format(ticket_id) + ) + .show(); }); - }).error(function() { - $("#concern_update_error").html(__("Error resolving concern #%s. Check the logs for details.").format(ticket_id)).show(); - }); }); }); -- 2.39.5