73 lines
2.8 KiB
Plaintext
73 lines
2.8 KiB
Plaintext
@model AuctionPublicInfoModel
|
|
|
|
|
|
|
|
<script asp-location="Footer">
|
|
var pageViewModel;
|
|
var isActive;
|
|
|
|
$(document).ready(function () {
|
|
// Deserialize the server-side model
|
|
pageViewModel = @Html.Raw(Json.Serialize(Model));
|
|
console.log("Page View Model:", pageViewModel);
|
|
console.log(pageViewModel.ProductId);
|
|
console.log(pageViewModel.ProductToAuctionMappingId);
|
|
// Get the element with data-productid
|
|
isActive = pageViewModel.IsActive;
|
|
initialize();
|
|
});
|
|
|
|
function initialize() {
|
|
console.log("isActive = " + isActive);
|
|
var productItem = $('.product-item[data-productid="' + pageViewModel.ProductId + '"]');
|
|
|
|
var existingOverlay = document.getElementById(`publicInfoOverlay${pageViewModel.ProductId}`);
|
|
if (existingOverlay) {
|
|
console.log("remove because it exists");
|
|
existingOverlay.remove();
|
|
}
|
|
|
|
// Check if element exists
|
|
if (productItem.length > 0 && pageViewModel.ProductToAuctionMappingId > 0) {
|
|
console.log("Product item found:", productItem);
|
|
// 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"> `
|
|
+ '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"> `
|
|
+ pageViewModel.StartDate +
|
|
'</i></div>');
|
|
}
|
|
|
|
} else {
|
|
console.error("Product item not found with productId:", pageViewModel.ProductId);
|
|
}
|
|
}
|
|
|
|
|
|
window[`refreshPublicInfo${@Model.ProductId}`] = function (data) {
|
|
|
|
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
|
if (status == AuctionStatus.Active) {
|
|
console.log(data.auctionDto);
|
|
isActive = true;
|
|
console.log("setting active to " + isActive);
|
|
}
|
|
else {
|
|
isActive = false;
|
|
console.log("setting active to " + isActive);
|
|
}
|
|
|
|
initialize();
|
|
console.log('Function called: refreshPublicInfo' + @Model.ProductId);
|
|
};
|
|
console.log(`Function refreshPublicInfo${@Model.ProductId} added to DOM:`, window[`refreshPublicInfo${@Model.ProductId}`]);
|
|
|
|
</script>
|
|
|