Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -35,13 +35,13 @@ async function login() {
|
|
| 35 |
document.getElementById('app-view').classList.remove('d-none');
|
| 36 |
document.getElementById('user-role-badge').innerText = `Role: ${state.role}`;
|
| 37 |
|
|
|
|
| 38 |
const btnAdd = document.getElementById('btn-add-new');
|
| 39 |
-
btnAdd.classList.remove('d-none');
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
btnAdd.disabled = false;
|
| 43 |
} else {
|
| 44 |
-
btnAdd.disabled =
|
| 45 |
}
|
| 46 |
|
| 47 |
await loadInitialData();
|
|
@@ -59,6 +59,9 @@ function logout() {
|
|
| 59 |
}
|
| 60 |
|
| 61 |
async function loadInitialData() {
|
|
|
|
|
|
|
|
|
|
| 62 |
const result = await apiCall('getData');
|
| 63 |
state.options = result.options;
|
| 64 |
state.data = result.data;
|
|
@@ -124,20 +127,29 @@ function renderTable() {
|
|
| 124 |
pageHTML += `<li class="page-item ${state.currentPage === totalPages || totalPages === 0 ? 'disabled' : ''}"><button class="page-link" onclick="changePage(${state.currentPage + 1})">›</button></li>`;
|
| 125 |
document.getElementById('paginationNav').innerHTML = pageHTML;
|
| 126 |
|
|
|
|
| 127 |
let headHTML = `<tr>
|
| 128 |
<th>Nama Supplier</th><th>Tgl Kedatangan</th><th>No. SJ Supplier</th>
|
| 129 |
<th>Item</th><th>Qty Awal</th><th>Qty Reject</th><th>Qty Nett</th>
|
| 130 |
<th>UOM</th><th>Sub Inv</th><th>No. STG Manual</th><th>Ekspedisi PIC</th>
|
| 131 |
<th>Nomer PO</th><th>Tanggal PO</th><th>No. Receive</th><th>Notes</th>
|
| 132 |
-
<th>Status</th>
|
| 133 |
-
|
| 134 |
-
headHTML += `</tr>`;
|
| 135 |
document.getElementById('tableHead').innerHTML = headHTML;
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
let bodyHTML = '';
|
| 138 |
paginated.forEach(row => {
|
| 139 |
let statColor = row.stat === 'OK' ? 'bg-success' : (row.stat === 'EDITED' ? 'bg-primary' : 'bg-secondary');
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
bodyHTML += `<tr>
|
| 143 |
<td>${row.supplier}</td>
|
|
@@ -155,21 +167,19 @@ function renderTable() {
|
|
| 155 |
<td>${displayDate(row.tglPo)}</td>
|
| 156 |
<td>${row.noReceive}</td>
|
| 157 |
<td>${row.notes}</td>
|
| 158 |
-
<td><span class="badge ${statColor}">${row.stat}</span></td>
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
bodyHTML += `<td class="text-center sticky-right">
|
| 162 |
-
<button class="btn btn-warning btn-sm text-white py-0 px-2" onclick="openEditModal(${row._rowIndex})" title="Edit" ${btnDisabled}>
|
| 163 |
<i class="bi bi-pencil-square"></i>
|
| 164 |
</button>
|
| 165 |
-
</td>
|
| 166 |
-
|
| 167 |
-
bodyHTML += `</tr>`;
|
| 168 |
});
|
| 169 |
document.getElementById('tableBody').innerHTML = bodyHTML;
|
| 170 |
}
|
| 171 |
|
| 172 |
function openAddModal() {
|
|
|
|
| 173 |
state.currentMode = 'ADD';
|
| 174 |
document.getElementById('recordForm').reset();
|
| 175 |
document.getElementById('modalTitle').innerText = "Kedatangan Baru";
|
|
@@ -185,6 +195,7 @@ function openAddModal() {
|
|
| 185 |
}
|
| 186 |
|
| 187 |
function openEditModal(rowIndex) {
|
|
|
|
| 188 |
state.currentMode = 'EDIT';
|
| 189 |
state.currentRowIndex = rowIndex;
|
| 190 |
const rowData = state.data.find(r => r._rowIndex === rowIndex);
|
|
|
|
| 35 |
document.getElementById('app-view').classList.remove('d-none');
|
| 36 |
document.getElementById('user-role-badge').innerText = `Role: ${state.role}`;
|
| 37 |
|
| 38 |
+
// Make 'Baru' button visible, but handle enablement
|
| 39 |
const btnAdd = document.getElementById('btn-add-new');
|
| 40 |
+
btnAdd.classList.remove('d-none');
|
| 41 |
+
if (state.role === 'Viewer') {
|
| 42 |
+
btnAdd.disabled = true;
|
|
|
|
| 43 |
} else {
|
| 44 |
+
btnAdd.disabled = false;
|
| 45 |
}
|
| 46 |
|
| 47 |
await loadInitialData();
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
async function loadInitialData() {
|
| 62 |
+
// Show Loading indicator in table body
|
| 63 |
+
document.getElementById('tableBody').innerHTML = `<tr><td colspan="17" class="text-center py-4"><span class="spinner-border spinner-border-sm text-warning me-2"></span>Loading data...</td></tr>`;
|
| 64 |
+
|
| 65 |
const result = await apiCall('getData');
|
| 66 |
state.options = result.options;
|
| 67 |
state.data = result.data;
|
|
|
|
| 127 |
pageHTML += `<li class="page-item ${state.currentPage === totalPages || totalPages === 0 ? 'disabled' : ''}"><button class="page-link" onclick="changePage(${state.currentPage + 1})">›</button></li>`;
|
| 128 |
document.getElementById('paginationNav').innerHTML = pageHTML;
|
| 129 |
|
| 130 |
+
// Action column header is always rendered
|
| 131 |
let headHTML = `<tr>
|
| 132 |
<th>Nama Supplier</th><th>Tgl Kedatangan</th><th>No. SJ Supplier</th>
|
| 133 |
<th>Item</th><th>Qty Awal</th><th>Qty Reject</th><th>Qty Nett</th>
|
| 134 |
<th>UOM</th><th>Sub Inv</th><th>No. STG Manual</th><th>Ekspedisi PIC</th>
|
| 135 |
<th>Nomer PO</th><th>Tanggal PO</th><th>No. Receive</th><th>Notes</th>
|
| 136 |
+
<th>Status</th><th class="text-center sticky-right">Action</th>
|
| 137 |
+
</tr>`;
|
|
|
|
| 138 |
document.getElementById('tableHead').innerHTML = headHTML;
|
| 139 |
|
| 140 |
+
if (paginated.length === 0) {
|
| 141 |
+
document.getElementById('tableBody').innerHTML = `<tr><td colspan="17" class="text-center py-4 text-muted">No data found</td></tr>`;
|
| 142 |
+
return;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
let bodyHTML = '';
|
| 146 |
paginated.forEach(row => {
|
| 147 |
let statColor = row.stat === 'OK' ? 'bg-success' : (row.stat === 'EDITED' ? 'bg-primary' : 'bg-secondary');
|
| 148 |
+
|
| 149 |
+
// Disable edit button if role is Viewer OR if status is OK
|
| 150 |
+
let isViewer = state.role === 'Viewer';
|
| 151 |
+
let btnDisabled = (isViewer || row.stat === 'OK') ? 'disabled' : '';
|
| 152 |
+
let btnClass = btnDisabled ? 'btn-secondary opacity-50' : 'btn-warning';
|
| 153 |
|
| 154 |
bodyHTML += `<tr>
|
| 155 |
<td>${row.supplier}</td>
|
|
|
|
| 167 |
<td>${displayDate(row.tglPo)}</td>
|
| 168 |
<td>${row.noReceive}</td>
|
| 169 |
<td>${row.notes}</td>
|
| 170 |
+
<td><span class="badge ${statColor}">${row.stat}</span></td>
|
| 171 |
+
<td class="text-center sticky-right">
|
| 172 |
+
<button class="btn ${btnClass} btn-sm text-white py-0 px-2" onclick="openEditModal(${row._rowIndex})" title="Edit" ${btnDisabled}>
|
|
|
|
|
|
|
| 173 |
<i class="bi bi-pencil-square"></i>
|
| 174 |
</button>
|
| 175 |
+
</td>
|
| 176 |
+
</tr>`;
|
|
|
|
| 177 |
});
|
| 178 |
document.getElementById('tableBody').innerHTML = bodyHTML;
|
| 179 |
}
|
| 180 |
|
| 181 |
function openAddModal() {
|
| 182 |
+
if (state.role === 'Viewer') return;
|
| 183 |
state.currentMode = 'ADD';
|
| 184 |
document.getElementById('recordForm').reset();
|
| 185 |
document.getElementById('modalTitle').innerText = "Kedatangan Baru";
|
|
|
|
| 195 |
}
|
| 196 |
|
| 197 |
function openEditModal(rowIndex) {
|
| 198 |
+
if (state.role === 'Viewer') return;
|
| 199 |
state.currentMode = 'EDIT';
|
| 200 |
state.currentRowIndex = rowIndex;
|
| 201 |
const rowData = state.data.find(r => r._rowIndex === rowIndex);
|