generic API response + ICS: warehouse_balance md_rack update

This commit is contained in:
Thanakorn S
2026-04-23 16:06:19 +07:00
parent ed23c269ea
commit a75e180686
25 changed files with 934 additions and 342 deletions
+36 -4
View File
@@ -401,12 +401,34 @@ function ajax_request(options) {
isAjaxProcessing = false;
$.LoadingOverlay("hide");
// Errors re-thrown from .then() — pass through
if (xhr instanceof Error) {
throw xhr;
}
console.error("AJAX Error:", xhr?.responseText);
bootbox.alert("Server error occurred.");
// Extract server's error message from JSON response
let serverMessage = xhr?.responseJSON?.message;
// Fallback: parse responseText if responseJSON isn't set
if (!serverMessage && xhr?.responseText) {
try {
serverMessage = JSON.parse(xhr.responseText)?.message;
} catch (e) {
// Response wasn't JSON — real server crash or HTML error page
}
}
if (serverMessage) {
// Known server-reported error (HTTP 4xx/5xx with JSON body)
bootbox.alert(serverMessage);
options.onError?.(xhr, serverMessage);
} else {
// Unknown error — network failure, PHP fatal, HTML error page
console.error("AJAX Error:", xhr?.status, xhr?.responseText);
bootbox.alert("Server error occurred.");
options.onError?.(xhr, null);
}
throw xhr;
});
}
@@ -422,6 +444,7 @@ function generate_pagination(table_id, total_records, records_per_page, current_
// 1. Find the table and thead
const table = document.getElementById(table_id);
let theme_class = '';
let col_count = 1;
if (table) {
const thead = table.querySelector('thead');
@@ -433,16 +456,25 @@ function generate_pagination(table_id, total_records, records_per_page, current_
// 3. Convert "table-secondary" to "page-item-secondary"
theme_class = bootstrap_theme.replace('table-', 'page-item-');
}
// 4. Count <th> in the first row of thead
const header_row = thead.querySelector('tr');
if (header_row) {
col_count = header_row.querySelectorAll('th').length || 1;
}
}
}
const left_span = Math.floor(col_count / 2);
const right_span = Math.ceil(col_count / 2);
let pagination_html = `
<tr>
<td class="border-bottom-0">
<td colspan="${left_span}" class="border-bottom-0">
<span class="text-muted">Showing ${records_per_page} per page</span><br>
<strong>Total: ${total_records}</strong>
</td>
<td colspan="9" class="border-bottom-0">
<td colspan="${right_span}" class="border-bottom-0">
<nav aria-label="Page navigation" class="d-flex justify-content-end">
<ul class="pagination mb-0">`;