From e83eef7e66028832122f57da06fa46556eddc6fc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 29 Dec 2023 11:53:25 +0000 Subject: [PATCH] Bug 35657: Add option to set assignee during update --- .../en/includes/modals/display_ticket.inc | 2 + .../prog/en/modules/cataloguing/concerns.tt | 1 + .../prog/js/modals/display_ticket.js | 86 ++++++++++++++++++- 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/display_ticket.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/display_ticket.inc index 5a3479a0de5..8b4768c5258 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/display_ticket.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/display_ticket.inc @@ -20,6 +20,8 @@
  • + +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt index 5826fe2cee1..046e3d936e0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt @@ -244,6 +244,7 @@ [% END %] }); + [% INCLUDE 'select2.inc' %] [% Asset.js("js/modals/display_ticket.js") | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] 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 61fecbea3ab..553aee13622 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/display_ticket.js @@ -67,16 +67,100 @@ $(document).ready(function() { // Clear any previously entered update message $('#update_message').val(''); $('#public').prop( "checked", false ); + + // Patron select2 + $("#assignee_id").kohaSelect({ + dropdownParent: $(".modal-content", "#ticketDetailsModal"), + width: '50%', + dropdownAutoWidth: true, + allowClear: true, + minimumInputLength: 3, + ajax: { + url: '/api/v1/patrons', + delay: 250, + dataType: 'json', + headers: { + "x-koha-embed": "library" + }, + data: function(params) { + let q = buildPatronSearchQuery(params.term); + let query = { + 'q': JSON.stringify(q), + '_page': params.page, + '_order_by': '+me.surname,+me.firstname', + }; + return query; + }, + processResults: function(data, params) { + let results = []; + data.results.forEach(function(patron) { + patron.id = patron.patron_id; + results.push(patron); + }); + return { + "results": results, "pagination": { "more": data.pagination.more } + }; + }, + }, + templateResult: function (patron) { + if (patron.library_id == loggedInLibrary) { + loggedInClass = "ac-currentlibrary"; + } else { + loggedInClass = ""; + } + + let $patron = $("") + .append( + "" + + (patron.surname + ? escape_str(patron.surname) + ", " + : "") + + (patron.firstname + ? escape_str(patron.firstname) + " " + : "") + + (patron.cardnumber + ? " (" + escape_str(patron.cardnumber) + ")" + : "") + + "" + + (patron.date_of_birth + ? ' ' + + $get_age(patron.date_of_birth) + + " " + + __("years") + + "" + : "") + + (patron.library ? + " " + + escape_str(patron.library.name) + + "" + : "") + + "" + ) + .addClass(loggedInClass); + return $patron; + }, + templateSelection: function (patron) { + if (!patron.surname) { + return patron.text; + } + return ( + escape_str(patron.surname) + ", " + escape_str(patron.firstname) + ); + }, + placeholder: "Search for a patron" + }); }); $('#ticketDetailsModal').on('click', '.updateSubmit', function(e) { let clicked = $(this); let ticket_id = $('#ticket_id').val(); + let assignee_id = $('#assignee_id').val(); let params = { 'public': $('#public').is(":checked"), 'message': $('#update_message').val(), 'user_id': logged_in_user_borrowernumber, - 'status': clicked.data('status') + 'status': clicked.data('status'), + 'assignee_id': assignee_id }; $('#comment-spinner').show(); -- 2.44.0