Bugzilla – Attachment 173323 Details for
Bug 38222
Let staff pick a cancellation reason when canceling a booking
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38222: (QA follow-up) Show cancellation reason where applicable, appropriately handle statuses
Bug-38222-QA-follow-up-Show-cancellation-reason-wh.patch (text/plain), 7.56 KB, created by
Paul Derscheid
on 2024-10-25 09:06:00 UTC
(
hide
)
Description:
Bug 38222: (QA follow-up) Show cancellation reason where applicable, appropriately handle statuses
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2024-10-25 09:06:00 UTC
Size:
7.56 KB
patch
obsolete
>From aa9700cf09d41fdb90147052fcb1e468290f9f23 Mon Sep 17 00:00:00 2001 >From: Paul Derscheid <paul.derscheid@lmscloud.de> >Date: Fri, 25 Oct 2024 09:03:43 +0000 >Subject: [PATCH] Bug 38222: (QA follow-up) Show cancellation reason where > applicable, appropriately handle statuses >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Sponsored-by: Büchereizentrale Schleswig-Holstein <https://www.bz-sh.de/> >--- > .../prog/en/modules/bookings/list.tt | 63 ++++++++++++---- > .../intranet-tmpl/prog/js/tables/bookings.js | 72 ++++++++++++++----- > 2 files changed, 102 insertions(+), 33 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 31155c6436..979ed7ac43 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt >@@ -269,23 +269,56 @@ > orderable: false, > visible: false, > render: function (data, type, row, meta) { >- const is_expired = dayjs(row.end_date).isBefore(new Date()); >- if (is_expired) { >- return `<span class="badge rounded-pill bg-secondary"> >- ${_("Expired")} >- </span>`; >- } >+ const isExpired = date => dayjs(date).isBefore(new Date()); >+ const isActive = (startDate, endDate) => { >+ const now = dayjs(); >+ return ( >+ now.isAfter(dayjs(startDate)) && >+ now.isBefore(dayjs(endDate).add(1, "day")) >+ ); >+ }; > >- const is_cancelled = row.status === "cancelled"; >- if (is_cancelled) { >- return `<span class="badge rounded-pill bg-secondary"> >- ${_("Cancelled")} >- </span>`; >- } >+ const statusMap = { >+ new: () => { >+ if (isExpired(row.end_date)) { >+ return __("Expired"); >+ } >+ >+ if (isActive(row.start_date, row.end_date)) { >+ return __("Active"); >+ } >+ >+ if (dayjs(row.start_date).isAfter(new Date())) { >+ return __("Pending"); >+ } >+ >+ return __("New"); >+ }, >+ cancelled: () => >+ [__("Cancelled"), row.cancellation_reason] >+ .filter(Boolean) >+ .join(": "), >+ completed: () => __("Completed"), >+ }; >+ >+ const statusText = statusMap[row.status] >+ ? statusMap[row.status]() >+ : __("Unknown"); >+ >+ const classMap = [ >+ { status: __("Expired"), class: "bg-secondary" }, >+ { status: __("Cancelled"), class: "bg-secondary" }, >+ { status: __("Pending"), class: "bg-warning" }, >+ { status: __("Active"), class: "bg-primary" }, >+ { status: __("Completed"), class: "bg-info" }, >+ { status: __("New"), class: "bg-success" }, >+ ]; >+ >+ const badgeClass = >+ classMap.find(mapping => statusText.startsWith(mapping.status)) >+ ?.class || "bg-secondary"; > >- return `<span class="badge rounded-pill bg-success"> >- ${_("New")} >- </span>`; >+ return `<span class="badge rounded-pill ${badgeClass}">${statusText}</span>`; > } > }, > { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js >index a99695dc07..018ffdffb8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js >@@ -45,24 +45,7 @@ $(document).ready(function () { > name: "status", > searchable: false, > orderable: false, >- render: function (data, type, row, meta) { >- let is_expired = dayjs(row.end_date).isBefore( >- new Date() >- ); >- if (is_expired) { >- return ( >- '<span class="badge rounded-pill bg-secondary">' + >- __("Expired") + >- "</span>" >- ); >- } >- >- return ( >- '<span class="badge rounded-pill bg-success">' + >- __("Active") + >- "</span>" >- ); >- }, >+ render: renderStatus, > }, > { > data: "biblio.title", >@@ -140,6 +123,59 @@ $(document).ready(function () { > } > } > >+ function renderStatus(data, type, row, meta) { >+ const isExpired = date => dayjs(date).isBefore(new Date()); >+ const isActive = (startDate, endDate) => { >+ const now = dayjs(); >+ return ( >+ now.isAfter(dayjs(startDate)) && >+ now.isBefore(dayjs(endDate).add(1, "day")) >+ ); >+ }; >+ >+ const statusMap = { >+ new: () => { >+ if (isExpired(row.end_date)) { >+ return __("Expired"); >+ } >+ >+ if (isActive(row.start_date, row.end_date)) { >+ return __("Active"); >+ } >+ >+ if (dayjs(row.start_date).isAfter(new Date())) { >+ return __("Pending"); >+ } >+ >+ return __("New"); >+ }, >+ cancelled: () => >+ [__("Cancelled"), row.cancellation_reason] >+ .filter(Boolean) >+ .join(": "), >+ completed: () => __("Completed"), >+ }; >+ >+ const statusText = statusMap[row.status] >+ ? statusMap[row.status]() >+ : __("Unknown"); >+ >+ const classMap = [ >+ { status: _("Expired"), class: "bg-secondary" }, >+ { status: _("Cancelled"), class: "bg-secondary" }, >+ { status: _("Pending"), class: "bg-warning" }, >+ { status: _("Active"), class: "bg-primary" }, >+ { status: _("Completed"), class: "bg-info" }, >+ { status: _("New"), class: "bg-success" }, >+ ]; >+ >+ const badgeClass = >+ classMap.find(mapping => statusText.startsWith(mapping.status)) >+ ?.class || "bg-secondary"; >+ >+ return `<span class="badge rounded-pill ${badgeClass}">${statusText}</span>`; >+ } >+ > var txtActivefilter = __("Show expired"); > var txtInactivefilter = __("Hide expired"); > $("#expired_filter").on("click", function () { >-- >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 38222
:
173230
|
173231
|
173232
|
173233
|
173264
|
173265
|
173277
|
173278
|
173281
|
173282
|
173312
|
173313
|
173314
|
173315
|
173316
|
173317
|
173318
|
173319
|
173320
|
173321
|
173322
|
173323
|
173336
|
173337
|
173338
|
173339