View | Details | Raw Unified | Return to bug 38222
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt (-15 / +48 lines)
Lines 269-291 Link Here
269
                orderable: false,
269
                orderable: false,
270
                visible: false,
270
                visible: false,
271
                render: function (data, type, row, meta) {
271
                render: function (data, type, row, meta) {
272
                    const is_expired = dayjs(row.end_date).isBefore(new Date());
272
                    const isExpired = date => dayjs(date).isBefore(new Date());
273
                    if (is_expired) {
273
                    const isActive = (startDate, endDate) => {
274
                        return `<span class="badge rounded-pill bg-secondary">
274
                        const now = dayjs();
275
                            ${_("Expired")}
275
                        return (
276
                        </span>`;
276
                            now.isAfter(dayjs(startDate)) &&
277
                    }
277
                            now.isBefore(dayjs(endDate).add(1, "day"))
278
                        );
279
                    };
278
280
279
                    const is_cancelled = row.status === "cancelled";
281
                    const statusMap = {
280
                    if (is_cancelled) {
282
                        new: () => {
281
                        return `<span class="badge rounded-pill bg-secondary">
283
                            if (isExpired(row.end_date)) {
282
                            ${_("Cancelled")}
284
                                return __("Expired");
283
                        </span>`;
285
                            }
284
                    }
286
287
                            if (isActive(row.start_date, row.end_date)) {
288
                                return __("Active");
289
                            }
290
291
                            if (dayjs(row.start_date).isAfter(new Date())) {
292
                                return __("Pending");
293
                            }
294
295
                            return __("New");
296
                        },
297
                        cancelled: () =>
298
                            [__("Cancelled"), row.cancellation_reason]
299
                                .filter(Boolean)
300
                                .join(": "),
301
                        completed: () => __("Completed"),
302
                    };
303
304
                    const statusText = statusMap[row.status]
305
                        ? statusMap[row.status]()
306
                        : __("Unknown");
307
308
                    const classMap = [
309
                        { status: __("Expired"), class: "bg-secondary" },
310
                        { status: __("Cancelled"), class: "bg-secondary" },
311
                        { status: __("Pending"), class: "bg-warning" },
312
                        { status: __("Active"), class: "bg-primary" },
313
                        { status: __("Completed"), class: "bg-info" },
314
                        { status: __("New"), class: "bg-success" },
315
                    ];
316
317
                    const badgeClass =
318
                        classMap.find(mapping => statusText.startsWith(mapping.status))
319
                            ?.class || "bg-secondary";
285
320
286
                    return `<span class="badge rounded-pill bg-success">
321
                    return `<span class="badge rounded-pill ${badgeClass}">${statusText}</span>`;
287
                        ${_("New")}
288
                    </span>`;
289
                }
322
                }
290
            },
323
            },
291
            {
324
            {
(-)a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js (-19 / +54 lines)
Lines 45-68 $(document).ready(function () { Link Here
45
                            name: "status",
45
                            name: "status",
46
                            searchable: false,
46
                            searchable: false,
47
                            orderable: false,
47
                            orderable: false,
48
                            render: function (data, type, row, meta) {
48
                            render: renderStatus,
49
                                let is_expired = dayjs(row.end_date).isBefore(
50
                                    new Date()
51
                                );
52
                                if (is_expired) {
53
                                    return (
54
                                        '<span class="badge rounded-pill bg-secondary">' +
55
                                        __("Expired") +
56
                                        "</span>"
57
                                    );
58
                                }
59
60
                                return (
61
                                    '<span class="badge rounded-pill bg-success">' +
62
                                    __("Active") +
63
                                    "</span>"
64
                                );
65
                            },
66
                        },
49
                        },
67
                        {
50
                        {
68
                            data: "biblio.title",
51
                            data: "biblio.title",
Lines 140-145 $(document).ready(function () { Link Here
140
        }
123
        }
141
    }
124
    }
142
125
126
    function renderStatus(data, type, row, meta) {
127
        const isExpired = date => dayjs(date).isBefore(new Date());
128
        const isActive = (startDate, endDate) => {
129
            const now = dayjs();
130
            return (
131
                now.isAfter(dayjs(startDate)) &&
132
                now.isBefore(dayjs(endDate).add(1, "day"))
133
            );
134
        };
135
136
        const statusMap = {
137
            new: () => {
138
                if (isExpired(row.end_date)) {
139
                    return __("Expired");
140
                }
141
142
                if (isActive(row.start_date, row.end_date)) {
143
                    return __("Active");
144
                }
145
146
                if (dayjs(row.start_date).isAfter(new Date())) {
147
                    return __("Pending");
148
                }
149
150
                return __("New");
151
            },
152
            cancelled: () =>
153
                [__("Cancelled"), row.cancellation_reason]
154
                    .filter(Boolean)
155
                    .join(": "),
156
            completed: () => __("Completed"),
157
        };
158
159
        const statusText = statusMap[row.status]
160
            ? statusMap[row.status]()
161
            : __("Unknown");
162
163
        const classMap = [
164
            { status: _("Expired"), class: "bg-secondary" },
165
            { status: _("Cancelled"), class: "bg-secondary" },
166
            { status: _("Pending"), class: "bg-warning" },
167
            { status: _("Active"), class: "bg-primary" },
168
            { status: _("Completed"), class: "bg-info" },
169
            { status: _("New"), class: "bg-success" },
170
        ];
171
172
        const badgeClass =
173
            classMap.find(mapping => statusText.startsWith(mapping.status))
174
                ?.class || "bg-secondary";
175
176
        return `<span class="badge rounded-pill ${badgeClass}">${statusText}</span>`;
177
    }
178
143
    var txtActivefilter = __("Show expired");
179
    var txtActivefilter = __("Show expired");
144
    var txtInactivefilter = __("Hide expired");
180
    var txtInactivefilter = __("Hide expired");
145
    $("#expired_filter").on("click", function () {
181
    $("#expired_filter").on("click", function () {
146
- 

Return to bug 38222