javascript működik

This commit is contained in:
Adam 2024-11-28 09:50:50 +01:00
parent e795abfa20
commit 816eb7f378
1 changed files with 11 additions and 10 deletions

View File

@ -14,14 +14,15 @@
console.log(pageViewModel.ProductToAuctionMappingId);
// Get the element with data-productid
isActive = pageViewModel.IsActive;
initialize();
initialize@(Model.ProductId)(@Model.ProductId);
});
function initialize() {
function initialize@(Model.ProductId)(thisProductId) {
console.log("isActive = " + isActive);
var productItem = $('.product-item[data-productid="' + pageViewModel.ProductId + '"]');
console.log("productId:" + thisProductId);
var productItem = $('.product-item[data-productid="' + thisProductId + '"]');
var existingOverlay = document.getElementById(`publicInfoOverlay${pageViewModel.ProductId}`);
var existingOverlay = document.getElementById(`publicInfoOverlay${thisProductId}`);
if (existingOverlay) {
console.log("remove because it exists");
existingOverlay.remove();
@ -29,17 +30,17 @@
// Check if element exists
if (productItem.length > 0 && pageViewModel.ProductToAuctionMappingId > 0) {
console.log("Product item found:", productItem);
console.log("Product item length:", productItem.length);
// Add a new div as the first child
if (isActive) {
console.log("isActive: " + isActive);
productItem.prepend(`<div id="publicInfoOverlay${pageViewModel.ProductId}" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
+ 'LIVE RIGTH NOW' +
'</i></div>');
}
else {
console.log("isActive: " + isActive);
productItem.prepend(`<div id="publicInfoOverlay${pageViewModel.ProductId}" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
+ pageViewModel.StartDate +
'</i></div>');
}
@ -48,7 +49,7 @@
console.error("Product item not found with productId:", pageViewModel.ProductId);
}
}
window[`refreshPublicInfo${@Model.ProductId}`] = function (data) {
@ -63,10 +64,10 @@
console.log("setting active to " + isActive);
}
initialize();
initialize@(Model.ProductId)(data.auctionDto.productToAuctionDtos[0].productId);
console.log('Function called: refreshPublicInfo' + @Model.ProductId);
};
console.log(`Function refreshPublicInfo${@Model.ProductId} added to DOM:`, window[`refreshPublicInfo${@Model.ProductId}`]);
</script>