99 lines
3.6 KiB
Plaintext
99 lines
3.6 KiB
Plaintext
@using AyCode.Core.Extensions
|
|
@model AuctionPublicInfoModel
|
|
|
|
|
|
|
|
<script asp-location="Footer">
|
|
$(document).ready(function () {
|
|
|
|
console.log("PublicInfo ready enter; ProductId: " + @Model.ProductId);
|
|
let auctionDto = @Html.Raw(Model.AuctionDto.ToJson());
|
|
|
|
initialize@(Model.ProductId)(auctionDto);
|
|
});
|
|
|
|
function initialize@(Model.ProductId)(auctionDto) {
|
|
console.log("PublicInfo initialize" + @Model.ProductId + " enter; auctionDto: " + auctionDto);
|
|
|
|
if (!auctionDto) {
|
|
console.error("auctionDto == null");
|
|
return;
|
|
}
|
|
|
|
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
|
let productId = productToAuctionDto.productId;
|
|
let isActive = productToAuctionDto.isActiveItem;
|
|
|
|
console.log("isActiveItem: " + isActive + "; productId:" + productId + "; productToAuctionId: " + productToAuctionDto.id);
|
|
|
|
let productItem = $('.product-item[data-productid="' + productId + '"]');
|
|
let publicInfoOverlayId = "publicInfoOverlay" + productId;
|
|
|
|
console.log("publicInfoOverlayId: " + publicInfoOverlayId + "; productItem:" + productItem);
|
|
|
|
var existingOverlay = document.getElementById(publicInfoOverlayId);
|
|
if (existingOverlay) {
|
|
console.log("remove because it exists");
|
|
existingOverlay.remove();
|
|
}
|
|
|
|
// Check if element exists
|
|
if (productItem.length > 0 && productToAuctionDto.id > 0) {
|
|
console.log("Product item length:", productItem.length);
|
|
|
|
var widgetPriceElements = productItem.find('.actual-price');
|
|
//console.log("widgetPriceElements:", widgetPriceElements);
|
|
|
|
if (widgetPriceElements && widgetPriceElements.length > 0) {
|
|
widgetPriceElements[0].textContent = HUFFormatter.format(productToAuctionDto.currentPrice); // Update the price
|
|
}
|
|
|
|
let myDate = auctionDto.startDateUtc;
|
|
console.log("dates: " + myDate);
|
|
let fixedDate = new Date(myDate + 'Z');
|
|
console.log("dates: " + myDate + ", " + fixedDate);
|
|
let resultDate = new Date(fixedDate);
|
|
console.log("dates: " + myDate + ", " + fixedDate + ", " + resultDate);
|
|
|
|
// Add a new div as the first child
|
|
if (isActive) {
|
|
console.log("isActive: " + isActive);
|
|
productItem.prepend('<div id="' +
|
|
publicInfoOverlayId +
|
|
'" class="bg-success p-1 text-white text-center" style="position: absolute; width: calc(100% - 1rem); height: 50px; z-index: 1;"><p class="m-0"><i class="fa-solid fa-gavel"></i> ' +
|
|
'@T("Plugins.Misc.AuctionPlugin.LiveNow")' +
|
|
'</p><span>' +
|
|
"No.: " + productToAuctionDto.sortIndex +
|
|
'</span></div>');
|
|
} else {
|
|
console.log("isActive: " + isActive);
|
|
productItem.prepend('<div id="' +
|
|
publicInfoOverlayId +
|
|
'" class="bg-primary p-1 text-white text-center" style="position: absolute; width: calc(100% - 1rem); height: 50px; z-index: 1;"><p class="m-0"><i class="fa-solid fa-gavel"></i> ' +
|
|
resultDate.toLocaleString() +
|
|
'</p><span>' +
|
|
"No.: " + productToAuctionDto.sortIndex +
|
|
'</span></div>');
|
|
}
|
|
|
|
} else {
|
|
console.error("Product item not found with productId:", productId);
|
|
}
|
|
}
|
|
|
|
window[`refreshPublicInfo${@Model.ProductId}`] = function(auctionDto) {
|
|
|
|
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
|
|
|
console.log(auctionDto);
|
|
console.log("setting active to " + productToAuctionDto.isActiveItem);
|
|
|
|
initialize@(Model.ProductId)(auctionDto);
|
|
console.log('Function called: refreshPublicInfo' + productToAuctionDto.productId);
|
|
};
|
|
|
|
console.log(`Function refreshPublicInfo${@Model.ProductId} added to DOM:`, window[`refreshPublicInfo${@Model.ProductId}`]);
|
|
|
|
</script>
|
|
|