NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/Items/ItemManagementV9.js
2026-03-13 14:48:15 +08:00

120 lines
4.3 KiB
JavaScript

function renderItembtns(data, row) {
var jsonData = JSON.stringify(row).replace(/"/g, """);
var buttonsHtml = '';
buttonsHtml += '<button onclick="viewItem(' + jsonData + ')" class="btn btn-default">' +
'<i class="fa-solid fa-eye fa-xl" style="color: #008080;" aria-hidden="true"></i>' +
'</button > ';
return buttonsHtml;
}
function refreshTable() {
itemTable.ajax.reload();
}
function clearTextModal() {
document.getElementById("ItemName").value = "";
document.getElementById("ItemDescription").value = "";
document.getElementById("ItemCategory").value = "";
document.getElementById("requestTypeId").value = "";
}
function isFullFilled() {
var itemNameInput = document.getElementById('itemName').value;
var itemDescriptionInput = document.getElementById('itemDescription').value;
var itemCategoryInput = document.getElementById('itemCategoryName').value;
var itemLocalNameInput = document.getElementById('itemLocalName').value;
var uomNameInput = document.getElementById('uomName').value;
var itemQtyInput = document.getElementById('itemQty').value;
var itemClassIdInput = document.getElementById('itemClassId').value;
var packagingTypeIdInput = document.getElementById('packagingTypeId').value;
var prTypeIdInput = document.getElementById('prTypeId').value;
var itemColorIdInput = document.getElementById('itemColorId').value;
if (!itemNameInput || !itemCategoryInput || itemQtyInput === '0' || !itemDescriptionInput ||
!itemLocalNameInput || !uomNameInput || !itemClassIdInput || !packagingTypeIdInput || !prTypeIdInput || !itemColorIdInput) {
let btnAddToCart = document.getElementById('btnAddToCart');
btnAddToCart.style.display = 'none';
}
else {
let btnAddToCart = document.getElementById('btnAddToCart');
btnAddToCart.style.display = 'block';
}
}
$(document).ready(function () {
loader = $('#overlay, #loader');
let cartItemCount = $('#cartItemCount').val();
$('#cartCount').text(cartItemCount);
itemTable = $('#ItemTable').DataTable({
serverSide: true,
processing: true,
searching: false, // disable built-in search box (we drive it manually)
ajax: {
url: '/ItemMgmt/GetItemList',
type: 'GET',
data: function (d) {
var searchVal = $('#customSearch').length ? $('#customSearch').val() : '';
return {
draw: d.draw,
searchTerm: (searchVal || '').trim(),
pageNumber: Math.floor(d.start / d.length) + 1,
pageSize: d.length
};
},
dataSrc: function (json) {
return json.data; // ← extract data array here
},
beforeSend: function () { loader.show(); },
complete: function () { loader.hide(); },
},
columns: [
{ data: 'itemNo' },
{ data: 'itemName' },
{ data: 'itemDescription' },
{ data: 'itemCategoryName' },
{
data: null,
render: function (data, type, row) {
return renderItembtns(data, row);
}
}
],
order: [[0, 'desc']],
responsive: true,
language: {
emptyTable: "Type in the search box to fetch data."
}
});
// Debounce helper
function debounce(fn, delay) {
let t;
return function (...args) {
clearTimeout(t);
t = setTimeout(() => fn.apply(this, args), delay);
};
}
// Custom search box
$('#customSearch').on('keyup', debounce(function () {
if ($(this).val().trim().length === 0) {
itemTable.clear().draw(); // show nothing until user types
return;
}
itemTable.ajax.reload(); // triggers new server call with searchTerm
}, 400));
});
document.addEventListener('DOMContentLoaded', function () {
const triggers = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
triggers.forEach(el => {
new bootstrap.Tooltip(el, {
container: 'body', // append tooltip to body
boundary: 'window', // prevent clipping
});
});
});