Bugzilla – Attachment 174277 Details for
Bug 37354
Bookings should respect circulation rules for max loan periods
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37354: Fix circ rule selections
Bug-37354-Fix-circ-rule-selections.patch (text/plain), 12.09 KB, created by
Martin Renvoize (ashimema)
on 2024-11-08 15:29:16 UTC
(
hide
)
Description:
Bug 37354: Fix circ rule selections
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-11-08 15:29:16 UTC
Size:
12.09 KB
patch
obsolete
>From d56b392013400d36889bc4fd0295f99f8d63567e Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 21 Oct 2024 16:36:49 +0100 >Subject: [PATCH] Bug 37354: Fix circ rule selections > >Only expose the bookings calendar picker input if we have enough detail >already defined to pick the corresponding circulation rules. > >We currently use the item pickup location for selecting which rules to >apply, this corresponds to hard coding CircControl=ItemHomeLibrary + >ItemHomeOrHolding=holdingbranch for this use case. We can't easily >change this to match those rules dynamically without rethinking the 'Any >item' functionality and displays in the flatpickr. We may revisit this >at some point in the future should that become a requirement. > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/en/includes/modals/place_booking.inc | 6 +- > .../prog/js/modals/place_booking.js | 159 ++++++++++-------- > 2 files changed, 94 insertions(+), 71 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc >index f9b662b5a14..e15df51bc3b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/place_booking.inc >@@ -33,11 +33,7 @@ > </li> > <li> > <label for="booking_itemtype">Itemtype: </label> >- [% SET itemtypes = ItemTypes.Get() %] >- <select id="booking_itemtype" name="booking_itemtype" disabled="true"> >- [% FOREACH itemtype IN itemtypes %] >- <option value="[% itemtype.itemtype | html %]">[% itemtype.description | html%]</option> >- [% END %] >+ <select id="booking_itemtype" name="booking_itemtype" disabled="disabled"> > </select> > <li> > <label for="booking_item_id">Item: </label> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >index 728dc76d3f4..27d271f5703 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/modals/place_booking.js >@@ -129,45 +129,54 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > placeholder: __("Search for a patron"), > }); > >- // Lead and Trail days syncing >+ // Circulation rules update > let leadDays = 0; > let trailDays = 0; > let boldDates = []; > let issueLength; > let renewalLength; > let renewalsAllowed; >+ >+ // Note: For now, we apply the pickup library rules for issuelength, renewalsallowed and renewalperiod. >+ // This effectively makes these circulation rules hard coded to CircControl: ItemHomeLibrary + HomeOrHolding: holdingbranch >+ // Whilst it would be beneficial to make this follow those rules more closely, this would require some significant thinking >+ // around how to best display this in the calender component for the 'Any item' case. > function getCirculationRules() { > let rules_url = "/api/v1/circulation_rules"; >- $.ajax({ >- url: rules_url, >- type: "GET", >- dataType: "json", >- data: { >- patron_category_id: booking_patron.category_id, >- item_type_id: booking_itemtype_id, >- library_id: pickup_library_id, >- rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod", >- }, >- success: function (response) { >- let rules = response[0]; >- issueLength = rules.issuelength; >- renewalsAllowed = rules.renewalsallowed; >- renewalLength = rules.renewalperiod; >- leadDays = rules.bookings_lead_period; >- trailDays = rules.bookings_trail_period; >- >- // redraw pariodPicker taking selected item into account >- periodPicker.redraw(); >- >- // Enable flatpickr now we have data we need >- if (dataFetched) { >- $("#period_fields :input").prop("disabled", false); >- } >- }, >- error: function (xhr, status, error) { >- console.log("Circulation rules fetch failed: ", error); >- }, >- }); >+ if (booking_patron && pickup_library_id && booking_itemtype_id) { >+ $.ajax({ >+ url: rules_url, >+ type: "GET", >+ dataType: "json", >+ data: { >+ patron_category_id: booking_patron.category_id, >+ item_type_id: booking_itemtype_id, >+ library_id: pickup_library_id, >+ rules: "bookings_lead_period,bookings_trail_period,issuelength,renewalsallowed,renewalperiod", >+ }, >+ success: function (response) { >+ let rules = response[0]; >+ issueLength = rules.issuelength; >+ renewalsAllowed = rules.renewalsallowed; >+ renewalLength = rules.renewalperiod; >+ leadDays = rules.bookings_lead_period; >+ trailDays = rules.bookings_trail_period; >+ >+ // redraw pariodPicker taking selected item into account >+ periodPicker.redraw(); >+ >+ // Enable flatpickr now we have data we need >+ if (dataFetched) { >+ $("#period_fields :input").prop("disabled", false); >+ } >+ }, >+ error: function (xhr, status, error) { >+ console.log("Circulation rules fetch failed: ", error); >+ }, >+ }); >+ } else { >+ $("#period_fields :input").prop("disabled", true); >+ } > } > > // Pickup location select2 >@@ -304,6 +313,9 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > "&_per_page=-1", > dataType: "json", > type: "GET", >+ headers: { >+ "x-koha-embed": "item_type", >+ }, > }); > > // Fetch list of existing bookings >@@ -350,12 +362,10 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > > // Total bookable items > let bookable = 0; >- >- let itemtypes = new Set(); > for (item of bookable_items) { > bookable++; > >- // Populate item select (NOTE: Do we still need this check for pre-existing select option here?) >+ // Populate item select > if ( > !$("#booking_item_id").find( > "option[value='" + item.item_id + "']" >@@ -378,18 +388,25 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > $("#booking_item_id").append(newOption); > } > >- // Build list of itemtypes >- itemtypes.add(item.effective_item_type_id); >- } >- >- // Filter itemtypes >- $("#booking_itemtype option").each(function () { >- const optionValue = $(this).val(); >- if (!itemtypes.has(optionValue)) { >- $(this).remove(); >+ // Populate item types select >+ if ( >+ !$("#booking_itemtype").find( >+ "option[value='" + >+ item.item_type.item_type_id + >+ "']" >+ ).length >+ ) { >+ // Create a DOM Option and de-select by default >+ let newTypeOption = new Option( >+ escape_str(item.item_type.description), >+ item.item_type.item_type_id, >+ false, >+ false >+ ); >+ $("#booking_itemtype").append(newTypeOption); > } >- }); >- $("#booking_itemtype").trigger("change"); >+ } >+ $("#booking_itemtype").val(null).trigger("change"); > > // Set disable function for periodPicker > let disableExists = periodPicker.config.disable.filter( >@@ -572,28 +589,33 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > } > > // Setup listener for itemtype select2 >- $("#booking_itemtype").on("select2:select", function (e) { >- booking_itemtype_id = e.params.data.id >- ? e.params.data.id >- : null; >- >- // Disable items not of this itemtype >- $("#booking_item_id > option").each(function () { >- let option = $(this); >- if (option.val() != 0) { >- let item_itemtype = option.data("itemtype"); >- if (item_itemtype == booking_itemtype_id) { >- if ( >- option.data("available") && >- option.data("pickup") >- ) { >- option.prop("disabled", false); >+ $("#booking_itemtype").on("change", function (e) { >+ let selectedValue = $(this).val(); // Get selected value (null if cleared) >+ booking_itemtype_id = selectedValue ? selectedValue : null; >+ >+ // Handle item selectionue >+ if (!booking_itemtype_id) { >+ // Enable all items for selection >+ $("#booking_item_id > option").prop("disabled", false); >+ } else { >+ // Disable items not of this itemtype >+ $("#booking_item_id > option").each(function () { >+ let option = $(this); >+ if (option.val() != 0) { >+ let item_itemtype = option.data("itemtype"); >+ if (item_itemtype == booking_itemtype_id) { >+ if ( >+ option.data("available") && >+ option.data("pickup") >+ ) { >+ option.prop("disabled", false); >+ } >+ } else { >+ option.prop("disabled", true); > } >- } else { >- option.prop("disabled", true); > } >- } >- }); >+ }); >+ } > $("#booking_item_id").trigger("change.select2"); > > // Update circulation rules >@@ -671,6 +693,11 @@ $("#placeBookingModal").on("show.bs.modal", function (e) { > > // Disable patron selection change > $("#booking_patron_id").prop("disabled", true); >+ >+ pickup_library_id = $("#pickup_library_id").val(); >+ >+ // Populate circulation rules >+ getCirculationRules(); > }); > > // Set onChange for flatpickr >@@ -1230,7 +1257,7 @@ $("#placeBookingModal").on("hidden.bs.modal", function (e) { > $("#booking_item_id").prop("disabled", true); > > // Reset itemtype select >- $("#booking_itemtype").val(0).trigger("change"); >+ $("#booking_itemtype").val(null).trigger("change"); > $("#booking_itemtype").prop("disabled", true); > booking_itemtype_id = undefined; > >-- >2.47.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37354
:
168950
|
168964
|
168965
|
168966
|
168967
|
169008
|
169009
|
169590
|
169591
|
169685
|
169686
|
170066
|
170067
|
172890
|
172891
|
173137
|
173210
|
173620
|
173621
|
173622
|
173623
|
174275
|
174276
| 174277 |
174278
|
174279