|
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 |
- |
|
|