assetflow/static/js/itemPageHandler.js
grey ea80b4bf2b - fixed issues with jumpy actions for item view
- added AFLOW-23 support for categories and rewrote interface
2023-07-10 17:50:31 +02:00

66 lines
2.0 KiB
JavaScript

const FLAG_supports_new_data_loader = true;
/**
* Should we ever implement items in items, have a look at this:
* https://examples.bootstrap-table.com/index.html?extensions/treegrid.html#extensions/treegrid.html
*/
// Inital thing
const itemList = $('#itemList');
itemList.bootstrapTable({ url: '/api/v1/items', search: true, showRefresh: true, responseHandler: dataResponseHandler, sidePagination: 'server', serverSort: true, silentSort: false });
setTimeout(() => {
activateTooltips();
}, 1000);
function loadPageData() {
itemList.bootstrapTable('refresh')
setTimeout(() => {
activateTooltips();
}, 1000);
}
function dataResponseHandler(json) {
// console.log(json)
totalNotFiltered = json.totalNotFiltered;
total = json.total;
json = json.items;
json.forEach((item) => {
colorStatus = '';
if(item.SKU == null) item.SKU = '<i>No SKU assigned</i>';
switch (item.status) {
case 'normal':
colorStatus = 'success';
break;
case 'stolen':
colorStatus = 'danger';
break;
case 'lost':
colorStatus = 'warning';
break;
case 'borrowed':
colorStatus = 'info';
break;
default:
colorStatus = 'secondary';
}
item.status = `<span class="badge text-bg-${colorStatus}">${item.status}</span>`;
item.actions = `
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#itemModifyModal" onclick="primeEdit(); getDataForEdit('${item.id}')">
<i class="bi bi-pencil"></i>
</button>
<button class="btn btn-danger" onclick="preFillDeleteModalNxt('${item.id}','items','Item')" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
<i class="bi bi-trash"></i>
</button>`
item.SKU = `<p data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="ID: ${item.id}">${item.SKU}</p>`
});
///// --------------------------------- /////
setTimeout(() => {
activateTooltips();
}, 200);
return {"rows": json, total: total, totalNotFiltered: totalNotFiltered, totalRows: total};
}
loadPageData()