From 90fa958c957e2d9dfa785dac0c6ff4f30a385b15 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Wed, 16 Apr 2025 15:41:05 +0000 Subject: [PATCH] Bug 37829: Add additional fields support to modal, tables To test: 1) Setup: a) Apply the db seed provided: koha-mysql < test_bug_37829.sql --- or --- b) Setup authorised values and additional fields manually: i) Navigate to Administration -> Authorized Values and click '+ New Category'. ii) Define a new authorised value category (e.g., prefix with BOOKINGS_ for easy identification). iii) Click '+ Add a new authorized value'. iv) Add a value, filling in at least 'Authorized Value' and 'Description'. v) Save the value. vi) Navigate to Administration -> Additional Fields. vii) Click 'Bookings (bookings)'. viii)Click '+ New field'. ix) Add a plain text field (fill 'Name' and save). x) Add a repeatable text field. xi) Add a field tied to your previously created authorized value category. xii) Add another field tied to any authorised value (e.g., YES_NO) and make it repeatable. 2) Item Configuration: Make an item bookable. Either: a) Navigate to Administration -> Item types, select an item type (e.g., BK), and check 'bookable'. b) Navigate to the 'Items' view for a specific item (catalogue/moredetail.pl) and set Priority -> Bookable -> 'Yes'. 3) Create Booking: Click the 'Place booking' button on the item's record. The configured additional fields should load dynamically in the modal. 4) Fill and Save Booking: Fill out the default booking fields and then the additional fields. Use the 'Remove' and 'New' buttons for repeatable fields. Save the booking. 5) Verify Display in Tables: Confirm that the additional fields for the booking are displayed correctly in the following locations: a) The bookings table within the bibliographic record's detail view. b) The 'Check out' view (circ/circulation.pl -> Bookings tab). c) The 'Patron's details' view (members/moremember.pl -> Bookings tab). d) The 'Bookings to collect' view (circ/pendingbookings.pl) (adjust filters if necessary). 6) Verify Edit/Move Functionality: Return to the bookings view of the bibliographic record. a) Verify the additional fields are correctly pre-filled and saved when you move the booking using the timeline component. b) Verify the additional fields are correctly pre-filled and saved when you edit the booking using the edit button in the bookings table. 7) Repeat Testing: Repeat steps 4 through 6.b with additional bookings to ensure consistency. 8) Sign-off and/or give your feedback. Here's some things I'd would still like to improve/try: - Incorporate the neighboring additional-fields-entry.js to have a single library for additional fields - Restructure the buttons to be consistent with other usage of additional fields in Koha (noticed this way to late) - Test this with the freshly added support for additional fields on branches (libraries) - Make the additional field values searchable in the table - Clean up and DRY some of the JSDoc types (but this could easily become its own tree of bugs if done from the source :D) - Use mockData.js for the mocha tests instead of hardcoding them I actually need this for a customer and the current state will be alright for that, but now it's good enough to work and improve it together. --- .../prog/en/modules/bookings/list.tt | 83 +++++++++++++++++-- .../prog/en/modules/catalogue/ISBDdetail.tt | 1 + .../prog/en/modules/catalogue/MARCdetail.tt | 1 + .../prog/en/modules/catalogue/detail.tt | 1 + .../prog/en/modules/catalogue/imageviewer.tt | 1 + .../en/modules/catalogue/labeledMARCdetail.tt | 1 + .../prog/en/modules/catalogue/moredetail.tt | 1 + .../prog/en/modules/circ/circulation.tt | 1 + .../prog/en/modules/circ/pendingbookings.tt | 34 +++++++- .../prog/en/modules/members/moremember.tt | 1 + .../prog/js/modals/place_booking.js | 43 +++++++++- .../intranet-tmpl/prog/js/tables/bookings.js | 32 ++++++- 12 files changed, 188 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index b214f681fc..d12de36f23 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -73,6 +73,7 @@ + [% Asset.js("js/additional-fields.js") | $raw %] [% Asset.js("js/modals/place_booking.js") | $raw %] [% Asset.js("js/cancel_booking_modal.js") | $raw %] [% Asset.js("js/combobox.js") | $raw %] @@ -91,11 +92,23 @@ }); var bookings = $.ajax({ url: '/api/v1/biblios/%s/bookings?_per_page=-1'.format(biblionumber), - headers: { 'x-koha-embed': 'patron' }, + headers: { 'x-koha-embed': ['patron', 'extended_attributes'] }, dataType: 'json', type: 'GET', }); - + var extended_attribute_types; + var authorised_values; + AdditionalFields.fetchAndProcessExtendedAttributes("booking") + .then(types => { + extended_attribute_types = types; + const catArray = Object.values(types) + .map(attr => attr.authorised_value_category_name) + .filter(Boolean); + return AdditionalFields.fetchAndProcessAuthorizedValues(catArray); + }) + .then(values => { + authorised_values = values; + }); $.when(items, bookings).then( function(items, bookings){ var itemsSet = new vis.DataSet([{ @@ -123,6 +136,7 @@ pickup_library: booking.pickup_library_id, start: dayjs(booking.start_date).toDate(), end: dayjs(booking.end_date).toDate(), + extended_attributes: booking.extended_attributes, content: !isActive ? `${patronContent}` : patronContent, [% IF CAN_user_circulate_manage_bookings %] editable: booking.status !== "cancelled" ? { remove: true, updateTime: true } : false, @@ -190,7 +204,23 @@ // set end datetime hours and minutes to the end of the day let endDate = dayjs(data.end).endOf('day'); - $('#placeBookingModal').modal('show', $(''.format(row.booking_id, biblionumber, row.item_id, row.patron_id, row.pickup_library_id, row.start_date, row.end_date, _("Edit")); - result += ''.format(row.booking_id, _("Cancel")); + result += ` + `; + result += ` + `; } [% END %] return result; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt index 8fdd39fb2c..6cf4f4785d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/ISBDdetail.tt @@ -85,6 +85,7 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'select2.inc' %] [% Asset.js("js/catalog.js") | $raw %] + [% Asset.js("js/additional-fields.js") | $raw %] [% Asset.js("js/modals/place_booking.js") | $raw %] [% Asset.js("js/browser.js") | $raw %] [% IF ( Koha.Preference('CatalogConcerns') ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt index 0b7138a255..b837f3176f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/MARCdetail.tt @@ -209,6 +209,7 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'select2.inc' %] [% Asset.js("js/catalog.js") | $raw %] + [% Asset.js("js/additional-fields.js") | $raw %] [% Asset.js("js/modals/place_booking.js") | $raw %] [% Asset.js("js/browser.js") | $raw %] [% IF ( Koha.Preference('CatalogConcerns') ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 801f7dad1e..8c91bc2ded 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1712,6 +1712,7 @@ [% INCLUDE 'js-patron-format.inc' %] [% INCLUDE 'js-biblio-format.inc' %] [% Asset.js("js/browser.js") | $raw %] + [% Asset.js("js/additional-fields.js") | $raw %] [% Asset.js("js/modals/place_booking.js") | $raw %]