assetflow/static/js/itemPageHandler.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

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.empty();
2023-07-08 00:25:33 +02:00
itemList.bootstrapTable({url: "/api/v1/items", search: true, showRefresh: true, responseHandler: dataResponseHandler, sidePagination: 'server', serverSort: true, silentSort: false})
setTimeout(() => {
activateTooltips();
}, 1000);
function loadPageData() {
const itemList = $('#itemList');
// itemList.empty();
itemList.bootstrapTable('refresh')
setTimeout(() => {
activateTooltips();
}, 1000);
}
function dataResponseHandler(res) {
json = JSON.parse(res);
// 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>`
});
///// --------------------------------- /////
return {"rows": json, total: total, totalNotFiltered: totalNotFiltered, totalRows: total};
}
loadPageData()