merge
This commit is contained in:
commit
23c1a8fb15
|
|
@ -101,7 +101,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin
|
|||
{
|
||||
ArgumentNullException.ThrowIfNull(widgetZone);
|
||||
|
||||
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
|
||||
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop) || widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoAfter))
|
||||
{
|
||||
return typeof(AuctionPublicViewComponent);
|
||||
}
|
||||
|
|
@ -130,6 +130,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin
|
|||
{
|
||||
PublicWidgetZones.ProductDetailsOverviewTop,
|
||||
PublicWidgetZones.ProductBoxAddinfoBefore,
|
||||
PublicWidgetZones.ProductBoxAddinfoAfter,
|
||||
PublicWidgetZones.BodyStartHtmlTagAfter,
|
||||
AdminWidgetZones.ProductDetailsButtons
|
||||
|
||||
|
|
|
|||
|
|
@ -86,10 +86,8 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
||||
{
|
||||
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent called");
|
||||
|
||||
//ensure that widget is active and enabled
|
||||
var customer = await _workContext.GetCurrentCustomerAsync();
|
||||
var currency = await _workContext.GetWorkingCurrencyAsync();
|
||||
var store = await _storeContext.GetCurrentStoreAsync();
|
||||
|
|
@ -97,6 +95,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
//var baseCurrency = allCurrencies.Where(x => x.Rate == 1);
|
||||
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
|
||||
|
||||
//ensure that widget is active and enabled
|
||||
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
||||
return Content(string.Empty);
|
||||
|
||||
|
|
@ -105,9 +104,24 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
//if (!_auctionSettings.Enabled)
|
||||
// return Content(string.Empty);
|
||||
|
||||
var productDetailsModel = (additionalData as ProductDetailsModel)!;
|
||||
AuctionProductModel myWIPModel = new AuctionProductModel();
|
||||
|
||||
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
|
||||
switch (additionalData)
|
||||
{
|
||||
case ProductOverviewModel productOverViewModel:
|
||||
Console.WriteLine("The object is of type A.");
|
||||
myWIPModel = await AuctionProductModel.CreateAsync(productOverViewModel, _myProductModelFactory, _productService);
|
||||
break;
|
||||
case ProductDetailsModel productDetailsModel:
|
||||
Console.WriteLine("The object is of type B.");
|
||||
myWIPModel = new AuctionProductModel(additionalData as ProductDetailsModel, _myProductModelFactory, _productService)!;
|
||||
break;
|
||||
default:
|
||||
_logger.Error("The object is neither Overview nor DetailModel.");
|
||||
break;
|
||||
}
|
||||
|
||||
await _logger.InformationAsync($"WidgetViewComponent product: {myWIPModel.Name}");
|
||||
|
||||
//if (productDetailsModel is null)
|
||||
//{
|
||||
|
|
@ -116,7 +130,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
// return Content(string.Empty);
|
||||
//}
|
||||
|
||||
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
|
||||
if (!(widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop) || widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoAfter)))
|
||||
{
|
||||
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
|
||||
return Content(string.Empty);
|
||||
|
|
@ -126,7 +140,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
|
||||
//is it under Auction?
|
||||
|
||||
var productId = productDetailsModel.Id;
|
||||
var productId = myWIPModel.Id;
|
||||
|
||||
//TODO: itt a ProductToAuctionMapping.Id-t kellene használni! - J.
|
||||
var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault();
|
||||
|
|
@ -245,4 +259,5 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
|||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||
using Nop.Services.Cms;
|
||||
using Nop.Services.Customers;
|
||||
using Nop.Services.Logging;
|
||||
using Nop.Web.Framework.Components;
|
||||
using Nop.Web.Framework.Infrastructure;
|
||||
|
|
@ -17,14 +19,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Components
|
|||
{
|
||||
|
||||
[ViewComponent(Name = "LiveAnnouncement")]
|
||||
public class LiveAnnouncementViewComponent(ILogger logger, ILockService lockService, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext<AuctionHub> auctionHubContext)
|
||||
public class LiveAnnouncementViewComponent(ILogger logger, ILockService lockService, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext<AuctionHub> auctionHubContext, ICustomerService customerService)
|
||||
: NopViewComponent
|
||||
{
|
||||
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
||||
{
|
||||
var customer = await workContext.GetCurrentCustomerAsync();
|
||||
|
||||
//await logger.InformationAsync($"LiveAnnouncementViewComponent.InvokeAsync(); Before lock; widgetZone: {widgetZone}", null, customer);
|
||||
var currency = await workContext.GetWorkingCurrencyAsync();
|
||||
await logger.InformationAsync($"LiveAnnouncementViewComponent.InvokeAsync(); Before lock; widgetZone: {widgetZone}", null, customer);
|
||||
|
||||
//using (await lockService.SemaphoreSlim.UseWaitAsync())
|
||||
//{
|
||||
|
|
@ -84,7 +86,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Components
|
|||
|
||||
return Content(string.Empty);
|
||||
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml");
|
||||
LiveAnnouncementViewModel myModel = new LiveAnnouncementViewModel();
|
||||
|
||||
myModel.CustomerId = customer.Id;
|
||||
myModel.StoreId = customer.RegisteredInStoreId; //Temporary - A.
|
||||
myModel.WorkingCurrency = currency;
|
||||
myModel.IsAdmin = await customerService.IsAdminAsync(customer);
|
||||
myModel.IsGuest = await customerService.IsGuestAsync(customer);
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml", myModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,373 @@
|
|||
window.sendBidMessage = function (ptaId, auctionId, bidPrice, productId) {
|
||||
|
||||
setBidButtonDisabledById("signalRBidButton" + ptaId, true);
|
||||
|
||||
var bidMessage = {
|
||||
ProductAuctionMappingId: ptaId,
|
||||
AuctionId: auctionId,
|
||||
BidPrice: bidPrice,
|
||||
ProductId: productId,
|
||||
CustomerId: window.CustomerId
|
||||
};
|
||||
|
||||
var content = JSON.stringify(bidMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("BidRequestMessage", window.CustomerId, content);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
window.setBidButtonDisabledById = function (bidButtonElementId, disabled, updateDisabledState = true) {
|
||||
if (!updateDisabledState) return;
|
||||
|
||||
setBidButtonDisabled(document.getElementById(bidButtonElementId), disabled, updateDisabledState);
|
||||
}
|
||||
|
||||
window.sendAuctionStatusChange = function (ptaId, auctionStatus) {
|
||||
var customerId = window.CustomerId;
|
||||
console.log("Send auctionstatus: " + customerId + ", " + ptaId);
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: ptaId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
|
||||
// Send the message via SignalR
|
||||
sendMessageToServer("AuctionProductStatusRequest", customerId, content);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
window.refreshPublicBidBox = function (bidNotification, updateBidButtonDisabledState, ptaId) {
|
||||
|
||||
//now we are refreshing any widget that has this ptaId
|
||||
|
||||
var auctionDto = bidNotification.auctionDto;
|
||||
var productToAuction = auctionDto.productToAuctionDtos[0];
|
||||
/*var productAuctionMappingId = ptaId;*/
|
||||
var winnerId = productToAuction.winnerCustomerId;
|
||||
var isMyBid;
|
||||
|
||||
|
||||
var widgetPriceElement = document.getElementById("price-value-" + productToAuction.ProductId);
|
||||
var widgetPriceElementInList = $('.product-item[data-productid="' + productToAuction.ProductId + '"]');
|
||||
var currency = window.WorkingCurrency;
|
||||
console.log(currency);
|
||||
|
||||
var bidButtonElement = document.getElementById("signalRBidButton" + ptaId);
|
||||
var storedBidPricePlaceholder = document.getElementById("bidPriceContainer" + ptaId);
|
||||
var licitStepElement = document.getElementById("licitStepText" + ptaId);
|
||||
var bidBox = document.getElementById("publicProductBidBox" + ptaId);
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle" + ptaId);
|
||||
console.log(bidNotification);
|
||||
|
||||
if (winnerId == window.CustomerId) {
|
||||
isMyBid = true;
|
||||
|
||||
}
|
||||
|
||||
console.log("ProductToAuctionId: " + ptaId);
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var status = productToAuction.auctionStatus;
|
||||
//var status = AuctionStatus.TEST;
|
||||
|
||||
|
||||
if (updateBidButtonDisabledState) {
|
||||
setButtons(status, ptaId);
|
||||
}
|
||||
|
||||
|
||||
if (widgetPriceElement || widgetPriceElementInList) {
|
||||
|
||||
if (widgetPriceElement) {
|
||||
/*if (productAuctionMappingId == ptaId) {*/
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
if (currency.CurrencyCode == "EUR") {
|
||||
widgetPriceElement.textContent = EURFormatter.format(bidNotification.currentPrice * window.WorkingCurrency.Rate); // Update the price
|
||||
//licitStepElement.textContent = EURFormatter.format(bidNotification.nextStepAmount * window.WorkingCurrency.Rate);
|
||||
}
|
||||
else {
|
||||
widgetPriceElement.textContent = HUFFormatter.format(bidNotification.currentPrice); // Update the price
|
||||
//licitStepElement.textContent = HUFFormatter.format(bidNotification.nextStepAmount);
|
||||
}
|
||||
/*}*/
|
||||
}
|
||||
|
||||
/*if (productAuctionMappingId == ptaId) {*/
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
if (currency.CurrencyCode == "EUR") {
|
||||
//widgetPriceElement.textContent = EURFormatter.format(bidNotification.currentPrice * window.WorkingCurrency.Rate); // Update the price
|
||||
licitStepElement.textContent = EURFormatter.format(bidNotification.nextStepAmount * window.WorkingCurrency.Rate);
|
||||
}
|
||||
else {
|
||||
//widgetPriceElement.textContent = HUFFormatter.format(bidNotification.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(bidNotification.nextStepAmount);
|
||||
}
|
||||
|
||||
storedBidPricePlaceholder.value = Number(bidNotification.nextBidPrice);
|
||||
setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState);
|
||||
|
||||
var list;
|
||||
if (isMyBid) {
|
||||
console.log("This is my bid");
|
||||
list = bidBox.classList;
|
||||
list.add("bg-success");
|
||||
list.remove("bg-primary");
|
||||
|
||||
bidButtonElement.textContent = window.LocalizationStrings.GoodJob;
|
||||
bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? window.LocalizationStrings.YouWin : window.LocalizationStrings.YourBidLeading;
|
||||
|
||||
if (window.IsAdmin) {
|
||||
console.log("I AM WEASEL!!! " + window.IsAdmin);
|
||||
setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState);
|
||||
} else {
|
||||
console.log("I AM NOT WEASEL!!! " + window.IsAdmin);
|
||||
setBidButtonDisabled(bidButtonElement, true, updateBidButtonDisabledState);
|
||||
}
|
||||
} else {
|
||||
list = bidBox.classList;
|
||||
list.add("bg-primary");
|
||||
list.remove("bg-success");
|
||||
bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? window.LocalizationStrings.Sold : window.LocalizationStrings.PlaceABid;
|
||||
|
||||
if (currency.CurrencyCode == "EUR") {
|
||||
bidButtonElement.textContent = window.LocalizationStrings.BidButtonPrefix + EURFormatter.format(bidBoxPageViewModel.NextBidPriceInWorkingCurrency);
|
||||
//bidButtonElement.textContent = EURFormatter.format(storedBidPricePlaceholder.value);
|
||||
} else {
|
||||
bidButtonElement.textContent = window.LocalizationStrings.BidButtonPrefix + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
//bidButtonElement.textContent = HUFFormatter.format(storedBidPricePlaceholder.value);
|
||||
}
|
||||
bidButtonElement.disabled = false;
|
||||
}
|
||||
|
||||
console.log(`WidgetPrice updated to: ${bidNotification.currentPrice}`);
|
||||
|
||||
|
||||
//} else {
|
||||
// console.log("Not for this product");
|
||||
//}
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
function setButtons(auctionStatus, ptaId) {
|
||||
console.log("SetButtons called: " + auctionStatus);
|
||||
|
||||
// Button IDs and their default states for each AuctionStatus
|
||||
//true = disabled
|
||||
var buttonStates = {
|
||||
[AuctionStatus.None]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Active]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.FirstWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.SecondWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Pause]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.Sold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.NotSold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.TEST]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// Get the states for the given auctionStatus
|
||||
var states = buttonStates[auctionStatus];
|
||||
if (!states) {
|
||||
console.error("Unknown AuctionStatus: ", auctionStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the states to each button
|
||||
Object.keys(states).forEach((buttonId) => {
|
||||
var button = document.getElementById(buttonId + ptaId);
|
||||
if (button) {
|
||||
button.disabled = states[buttonId];
|
||||
button.hidden = states[buttonId];
|
||||
} else {
|
||||
console.warn(`Button with ID ${buttonId} not found.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function handleAuctionUpdate(auctionStatusNotification, myPtaId) {
|
||||
var ids = auctionStatusNotification.auctionDto.productToAuctionDtos.map(pta => pta.id);
|
||||
ids.forEach(ptaId => {
|
||||
console.log(ptaId);
|
||||
var productToAuctionDtos = auctionStatusNotification.auctionDto.productToAuctionDtos;
|
||||
|
||||
// Find the object with the matching Id
|
||||
var matchingDto = productToAuctionDtos.find(pta => pta.id === ptaId);
|
||||
|
||||
if (matchingDto) {
|
||||
console.log('Matching ProductToAuctionDto:', matchingDto);
|
||||
UpdateBox(ptaId, matchingDto.productId, auctionStatusNotification.auctionDto, matchingDto);
|
||||
} else {
|
||||
console.log(`No ProductToAuctionDto found with Id: ${ptaId}`);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function UpdateBox(ptaId, productId, auctionDto, ptaDto) {
|
||||
var widgetPriceElement = document.getElementById("price-value-" + productId);
|
||||
var widgetPriceElementInList = $('.product-item[data-productid="' + productId + '"]');
|
||||
var bidButtonElement = document.getElementById("signalRBidButton" + ptaId);
|
||||
var licitStepElement = document.getElementById("licitStepText" + ptaId);
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle" + ptaId);
|
||||
|
||||
var productAuctionMappingId = ptaId;
|
||||
let isMyBid = false;
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
let itemStatus = ptaDto.auctionStatus;
|
||||
//var itemStatus = AuctionStatus.TEST;
|
||||
let winnerId = ptaDto.winnerCustomerId;
|
||||
if (winnerId == window.CustomerId) {
|
||||
isMyBid = true;
|
||||
|
||||
}
|
||||
console.log("handle auction update called" + productAuctionMappingId);
|
||||
console.log("auction status:" + itemStatus);
|
||||
if (widgetPriceElement || widgetPriceElementInList) {
|
||||
|
||||
/*if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {*/
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
switch (itemStatus) {
|
||||
case AuctionStatus.None:
|
||||
location.reload();
|
||||
break;
|
||||
|
||||
case AuctionStatus.Active:
|
||||
if (isMyBid) {
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.YourBidLeading;
|
||||
} else {
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.PlaceABid;
|
||||
}
|
||||
break;
|
||||
|
||||
case AuctionStatus.Pause:
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.AuctionPaused;
|
||||
break;
|
||||
|
||||
case AuctionStatus.FirstWarning:
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.FirstWarning;
|
||||
break;
|
||||
|
||||
case AuctionStatus.SecondWarning:
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.SecondWarning;
|
||||
break;
|
||||
|
||||
case AuctionStatus.Sold:
|
||||
if (isMyBid) {
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.YouWin;
|
||||
} else {
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.ItemClosed;
|
||||
}
|
||||
break;
|
||||
|
||||
case AuctionStatus.NotSold:
|
||||
bidBoxTitle.textContent = window.LocalizationStrings.ItemClosed;
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn("Unknown AuctionStatus: ", itemStatus);
|
||||
}
|
||||
|
||||
|
||||
/*console.log(`Status updated to: ${auctionStatusNotification.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);*/
|
||||
|
||||
//}
|
||||
|
||||
//else {
|
||||
// console.log("Not for this product");
|
||||
//}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
setButtons(itemStatus, ptaId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
window.RequestCount = 0;
|
||||
window.ConnectionId = "";
|
||||
/*window.CustomerId = 0;*/
|
||||
/*window.StoreId = 0;*/
|
||||
/*window.WorkingCurrency;*/
|
||||
/*window.IsAdmin = false;*/
|
||||
/*window.IsGuest = false;*/
|
||||
|
||||
// AuctionStatus Enum
|
||||
window.AuctionStatus = Object.freeze({
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
//var productAuctionMappingId = productToAuctionDto.id;
|
||||
//console.log(productAuctionMappingId);
|
||||
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox" + productToAuctionDto.id);
|
||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
console.log("isMyRequest: " + isMyRequest + "; lastRequestId: " + lastRequestId + "; messageWrapper.RequestId: " + messageWrapper.requestId);
|
||||
|
||||
refreshPublicBidBox(bidNotification, isMyRequest);
|
||||
refreshPublicBidBox(bidNotification, isMyRequest, productToAuctionDto.id);
|
||||
}
|
||||
if (publicInfo) {
|
||||
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
||||
|
|
@ -92,7 +92,10 @@
|
|||
|
||||
var auctionDto = auctionStatusNotification.auctionDto;
|
||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
//get the list of pta? should be 1
|
||||
console.log("PtaId: "+productToAuctionDto.id);
|
||||
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox" + productToAuctionDto.id);
|
||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||
|
||||
|
|
@ -163,7 +166,7 @@
|
|||
}
|
||||
|
||||
if (publicProductBidBox) {
|
||||
handleAuctionUpdate(auctionStatusNotification);
|
||||
handleAuctionUpdate(auctionStatusNotification, productToAuctionDto.id);
|
||||
}
|
||||
|
||||
if (liveScreen) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||
using Nop.Services.Catalog;
|
||||
using Nop.Web.Models.Catalog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
||||
{
|
||||
public record AuctionProductModel : ProductDetailsModel
|
||||
{
|
||||
protected readonly MyProductModelFactory _factory;
|
||||
protected readonly IProductService _productService;
|
||||
|
||||
public AuctionProductModel(){}
|
||||
|
||||
public AuctionProductModel(ProductDetailsModel dModel, MyProductModelFactory factory, IProductService productService)
|
||||
: base(dModel)
|
||||
{
|
||||
_factory = factory;
|
||||
_productService = productService;
|
||||
}
|
||||
|
||||
public static async Task<AuctionProductModel> CreateAsync(
|
||||
ProductOverviewModel oModel,
|
||||
MyProductModelFactory factory,
|
||||
IProductService productService)
|
||||
{
|
||||
|
||||
var product = await productService.GetProductByIdAsync(oModel.Id);
|
||||
var detailsModel = await factory.PrepareProductDetailsModelAsync(product);
|
||||
|
||||
return new AuctionProductModel(detailsModel, factory, productService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
using Newtonsoft.Json;
|
||||
using Nop.Core.Domain.Directory;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||
using Nop.Web.Framework.Models;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
||||
{
|
||||
public record LiveAnnouncementViewModel : BaseNopModel
|
||||
{
|
||||
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
public int StoreId { get; set; }
|
||||
|
||||
public Currency WorkingCurrency { get; set; }
|
||||
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
public bool IsGuest { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -140,6 +140,9 @@
|
|||
<None Update="Content\Images\wallpaper.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\Js\Auction.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Content\Js\MgMessageHandler.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
@using Nop.Web.Framework;
|
||||
@using Nop.Web.Framework.UI;
|
||||
@using Nop.Services.Configuration;
|
||||
@model LiveAnnouncementViewModel
|
||||
|
||||
@{
|
||||
|
||||
|
|
@ -16,6 +17,7 @@
|
|||
// NopHtml.AddScriptParts(ResourceLocation.Footer, "https://cdn.datatables.net/scroller/2.4.3/js/scroller.dataTables.js");
|
||||
NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/MgMessageHandler.js");
|
||||
NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js");
|
||||
NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/Auction.js");
|
||||
NopHtml.AddCssFileParts("~/Plugins/Misc.AuctionPlugin/Content/Css/toastr.min.css");
|
||||
NopHtml.AddCssFileParts("https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css");
|
||||
NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/toastr.js");
|
||||
|
|
@ -29,4 +31,50 @@
|
|||
text-decoration: unset !important;
|
||||
}
|
||||
</style>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
window.LocalizationStrings = {
|
||||
YourBidLeading: "@T("Plugins.Misc.AuctionPlugin.YourBidLeading")",
|
||||
PlaceABid: "@T("Plugins.Misc.AuctionPlugin.PlaceABid")",
|
||||
AuctionPaused: "@T("Plugins.Misc.AuctionPlugin.AuctionPaused")",
|
||||
FirstWarning: "@T("Plugins.Misc.AuctionPlugin.FirstWarning")",
|
||||
SecondWarning: "@T("Plugins.Misc.AuctionPlugin.SecondWarning")",
|
||||
YouWin: "@T("Plugins.Misc.AuctionPlugin.YouWin")",
|
||||
ItemClosed: "@T("Plugins.Misc.AuctionPlugin.ItemClosed")",
|
||||
GoodJob: "@T("Plugins.Misc.AuctionPlugin.GoodJob")",
|
||||
YouWin: "@T("Plugins.Misc.AuctionPlugin.YouWin")",
|
||||
YourBidLeading: "@T("Plugins.Misc.AuctionPlugin.YourBidLeading")",
|
||||
Sold: "@T("Plugins.Misc.AuctionPlugin.Sold")",
|
||||
BidButtonPrefix: "@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")"
|
||||
|
||||
};
|
||||
|
||||
var liveAnnouncementViewModel;
|
||||
|
||||
$(window).load(function () {
|
||||
try {
|
||||
// Deserialize the Razor model into JavaScript
|
||||
liveAnnouncementViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
} catch (e) {
|
||||
console.log(e); // Logs any error during deserialization
|
||||
}
|
||||
|
||||
// Ensure liveAnnouncementViewModel is defined before accessing its properties
|
||||
if (liveAnnouncementViewModel) {
|
||||
console.log("liveAnnouncementViewModel.CustomerId: " + liveAnnouncementViewModel.CustomerId);
|
||||
|
||||
// Set global variables
|
||||
window.CustomerId = liveAnnouncementViewModel.CustomerId;
|
||||
window.StoreId = liveAnnouncementViewModel.StoreId;
|
||||
window.WorkingCurrency = liveAnnouncementViewModel.WorkingCurrency;
|
||||
window.IsAdmin = liveAnnouncementViewModel.IsAdmin;
|
||||
window.IsGuest = liveAnnouncementViewModel.IsGuest;
|
||||
|
||||
console.log("Window.CustomerId: " + window.CustomerId + ", " + "window.StoreId: " + window.StoreId + "window.isAdmin: " + window.IsAdmin);
|
||||
} else {
|
||||
console.log("liveAnnouncementViewModel is undefined or null.");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
@ -7,668 +7,338 @@
|
|||
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
||||
|
||||
<style>
|
||||
.old-product-price {
|
||||
text-decoration: unset !important;
|
||||
}
|
||||
.old-product-price {
|
||||
text-decoration: unset !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
@{
|
||||
if (!Model.IsGuest)
|
||||
{
|
||||
if (Model.FirstProductToAuction != null)
|
||||
{
|
||||
if (!Model.IsGuest)
|
||||
{
|
||||
if (Model.FirstProductToAuction != null)
|
||||
{
|
||||
|
||||
var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
|
||||
var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
|
||||
var auctionStatus = Model.FirstProductToAuction.AuctionStatus;
|
||||
var lastBidIsMine = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId;
|
||||
var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
|
||||
var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
|
||||
var auctionStatus = Model.FirstProductToAuction.AuctionStatus;
|
||||
var lastBidIsMine = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId;
|
||||
|
||||
|
||||
var title = auctionStatus switch
|
||||
{
|
||||
AuctionStatus.Sold => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YouWin") : @T("Plugins.Misc.AuctionPlugin.Sold"),
|
||||
AuctionStatus.NotSold => @T("Plugins.Misc.AuctionPlugin.Finished"),
|
||||
_ => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YourBidLeading") : @T("Plugins.Misc.AuctionPlugin.PlaceABid")
|
||||
};
|
||||
var title = auctionStatus switch
|
||||
{
|
||||
AuctionStatus.Sold => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YouWin") : @T("Plugins.Misc.AuctionPlugin.Sold"),
|
||||
AuctionStatus.NotSold => @T("Plugins.Misc.AuctionPlugin.Finished"),
|
||||
_ => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YourBidLeading") : @T("Plugins.Misc.AuctionPlugin.PlaceABid")
|
||||
};
|
||||
|
||||
if (Model.WidgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
|
||||
{
|
||||
|
||||
<div class="d-flex justify-content-between" id="otherAuctionItems">
|
||||
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
@*<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">*@
|
||||
<div class="col-12">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? @T("Plugins.Misc.AuctionPlugin.StartOfList") : @T("Plugins.Misc.AuctionPlugin.BackToLast"))</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
@*<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">*@
|
||||
<div class="col-12">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? @T("Plugins.Misc.AuctionPlugin.EndOfList") : @T("Plugins.Misc.AuctionPlugin.ComingUp"))</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<div id="publicProductBidBox@(Model.ProductToAuctionId)" class="p-3 @bgClass text-white">
|
||||
<input id="bidPriceContainer@(Model.ProductToAuctionId)" value="@Model.NextBidPrice" hidden/>
|
||||
<div class="row">
|
||||
<div class="col-3"><strong>#@Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault()!.SortIndex</strong></div>
|
||||
<div class="col-9"><a target="_blank" class="btn btn-secondary btn-sm float-end" href="https://youtube.com/live/6yfnmyQE7Uw?feature=share"><i class="fa-brands fa-youtube"></i> Youtube live</a></div>
|
||||
</div>
|
||||
|
||||
<h4 id="bidBoxTitle@(Model.ProductToAuctionId)">@title</h4>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="m-auto">
|
||||
<strong>Base Price:</strong>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
|
||||
<span class="value">@($"{((decimal)Model.BasePriceInWorkingCurrency).ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="value">@($"{((decimal)Model.BasePrice).ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
<div class="d-flex justify-content-between" id="otherAuctionItems">
|
||||
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
@*<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">*@
|
||||
<div class="col-12">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? @T("Plugins.Misc.AuctionPlugin.StartOfList") : @T("Plugins.Misc.AuctionPlugin.BackToLast"))</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="m-auto">
|
||||
<strong>Bid Step:</strong>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
<span id="licitStepText@(Model.ProductToAuctionId)" class="value">@($"{Model.LicitStepInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
<span id="licitStepText@(Model.ProductToAuctionId)" class="value">@($"{Model.LicitStep.ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
}
|
||||
}
|
||||
|
||||
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
@*<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">*@
|
||||
<div class="col-12">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? @T("Plugins.Misc.AuctionPlugin.EndOfList") : @T("Plugins.Misc.AuctionPlugin.ComingUp"))</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="m-auto">
|
||||
<button id="signalRBidButton@(Model.ProductToAuctionId)" class="btn btn-success float-end" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPriceInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")
|
||||
|
||||
</div>
|
||||
<div id="publicProductBidBox" class="p-3 @bgClass text-white">
|
||||
<div class="row">
|
||||
<div class="col-3"><strong>#@Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault()!.SortIndex</strong></div>
|
||||
<div class="col-9"><a target="_blank" class="btn btn-secondary btn-sm float-end" href="https://youtube.com/live/6yfnmyQE7Uw?feature=share"><i class="fa-brands fa-youtube"></i> Youtube live</a></div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
|
||||
<h4 id="bidBoxTitle">@title</h4>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="m-auto">
|
||||
<strong>Base Price:</strong>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
|
||||
<span class="value">@($"{((decimal)Model.BasePriceInWorkingCurrency).ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="value">@($"{((decimal)Model.BasePrice).ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<div class="m-auto">
|
||||
<strong>Bid Step:</strong>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStepInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")</span>
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStep.ToString("C", new CultureInfo("hu-HU"))}")</span>
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<div class="m-auto">
|
||||
<button id="signalRBidButton" class="btn btn-success float-end" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
|
||||
@{
|
||||
if (Model.WorkingCurrency.CurrencyCode == "EUR")
|
||||
{
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPriceInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}")
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPrice.ToString("C", new CultureInfo("hu-HU"))}")
|
||||
}
|
||||
}
|
||||
@T("Plugins.Misc.AuctionPlugin.BidButtonPrefix") @($"{Model.NextBidPrice.ToString("C", new CultureInfo("hu-HU"))}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
||||
Bid @String.Format("{0:c}", Model.NextBidPrice)
|
||||
</button> *@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@* <button id="testButton" class="btn btn-success">
|
||||
@* <button id="testButton" class="btn btn-success">
|
||||
TestButton
|
||||
</button> *@
|
||||
|
||||
<div id="bidFeedback" class="mt-3"></div>
|
||||
</div>
|
||||
<div id="bidFeedback" class="mt-3"></div>
|
||||
</div>
|
||||
|
||||
|
||||
if (Model.IsAdmin)
|
||||
{
|
||||
<div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white">
|
||||
<h4>Manage auction!</h4>
|
||||
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
|
||||
if (Model.IsAdmin)
|
||||
{
|
||||
<div id="publicProductBidBoxAdmin@(Model.ProductToAuctionId)" class="p-3 bg-secondary text-white">
|
||||
<h4>Manage auction!</h4>
|
||||
<div id="bidBoxAdminButtons@(Model.ProductToAuctionId)" class="d-flex justify-content-between mb-3">
|
||||
|
||||
|
||||
<div>
|
||||
<button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled hidden")>
|
||||
Open item
|
||||
</button>
|
||||
<button id="signalRPauseItemButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.Active || Model.AuctionStatus == AuctionStatus.FirstWarning || Model.AuctionStatus == AuctionStatus.SecondWarning ? string.Empty : "disabled hidden")>
|
||||
Pause auction
|
||||
</button>
|
||||
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Revert bid
|
||||
</button>
|
||||
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Reset auction
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)>
|
||||
First warning
|
||||
</button>
|
||||
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)>
|
||||
Second warning
|
||||
</button>
|
||||
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)>
|
||||
Finished
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalROpenItemButton@(Model.ProductToAuctionId)" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled hidden")>
|
||||
Open item
|
||||
</button>
|
||||
<button id="signalRPauseItemButton@(Model.ProductToAuctionId)" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.Active || Model.AuctionStatus == AuctionStatus.FirstWarning || Model.AuctionStatus == AuctionStatus.SecondWarning ? string.Empty : "disabled hidden")>
|
||||
Pause auction
|
||||
</button>
|
||||
<button id="signalRRevertBidButton@(Model.ProductToAuctionId)" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Revert bid
|
||||
</button>
|
||||
<button id="signalRResetItemButton@(Model.ProductToAuctionId)" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Reset auction
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRFirstWarningButton@(Model.ProductToAuctionId)" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)>
|
||||
First warning
|
||||
</button>
|
||||
<button id="signalRSecondWarningButton@(Model.ProductToAuctionId)" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)>
|
||||
Second warning
|
||||
</button>
|
||||
<button id="signalRCloseItemButton@(Model.ProductToAuctionId)" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)>
|
||||
Finished
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
// <p>No access to admin level buttons</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white">
|
||||
<h4>This item is under auction!</h4>
|
||||
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3">
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
// <p>No access to admin level buttons</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div id="publicProductBidBoxGuest@(Model.ProductToAuctionId)" class="p-3 bg-primary text-white">
|
||||
<h4>This item is under auction!</h4>
|
||||
<div id="bidBoxGuestMessage@(Model.ProductToAuctionId)" class="d-flex justify-content-between mb-3">
|
||||
|
||||
<p>@T("Plugins.Misc.AuctionPlugin.PleaseLogInOrRegister")</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<p>@T("Plugins.Misc.AuctionPlugin.PleaseLogInOrRegister")</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
var bidBoxPageViewModel;
|
||||
var bidBoxPageViewModel;
|
||||
//var bidPrice;
|
||||
$(window).load(function () {
|
||||
try {
|
||||
|
||||
$(window).load(function () {
|
||||
try {
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e); // Logs the error
|
||||
}
|
||||
console.log("bidBoxPageViewModel " + bidBoxPageViewModel);
|
||||
console.log(bidBoxPageViewModel.WidgetZone);
|
||||
//console.log(typeof sendMessageToServer);
|
||||
document.getElementById("bidPriceContainer" + bidBoxPageViewModel.ProductToAuctionId).value = bidBoxPageViewModel.NextBidPrice;
|
||||
setOnClicks(bidBoxPageViewModel.ProductToAuctionId, bidBoxPageViewModel);
|
||||
//var status = bidBoxPageViewModel.productToAuctionDto.auctionStatus;
|
||||
//setButtons(status);
|
||||
});
|
||||
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e); // Logs the error
|
||||
}
|
||||
console.log("bidBoxPageViewModel " + bidBoxPageViewModel);
|
||||
console.log(bidBoxPageViewModel.WidgetZone);
|
||||
//console.log(typeof sendMessageToServer);
|
||||
function setOnClicks(ptaId, viewModel) {
|
||||
console.log("Setting onclick methods");
|
||||
$("#signalRBidButton" + ptaId).on("click", function () {
|
||||
var storedBidPrice = document.getElementById("bidPriceContainer" + ptaId).value;
|
||||
sendBidMessage(ptaId,
|
||||
viewModel.AuctionId,
|
||||
storedBidPrice,
|
||||
viewModel.ProductId
|
||||
);
|
||||
});
|
||||
|
||||
$("#signalRBidButton").on("click", function () {
|
||||
$("#signalROpenItemButton" + ptaId).on("click", function () {
|
||||
|
||||
setBidButtonDisabledById("signalRBidButton", true);
|
||||
event.preventDefault();
|
||||
this.disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
sendAuctionStatusChange(ptaId, AuctionStatus.Active);
|
||||
|
||||
var bidMessage = {
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionId: bidBoxPageViewModel.AuctionId,
|
||||
BidPrice: bidBoxPageViewModel.NextBidPrice,
|
||||
ProductId: bidBoxPageViewModel.ProductId,
|
||||
CustomerId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
return false;
|
||||
});
|
||||
$("#signalRCloseItemButton" + ptaId).on("click", function () {
|
||||
|
||||
var content = JSON.stringify(bidMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
this.disabled = true;
|
||||
/*event.preventDefault();*/
|
||||
|
||||
return false;
|
||||
});
|
||||
sendAuctionStatusChange(ptaId, AuctionStatus.Sold);
|
||||
|
||||
$("#signalROpenItemButton").on("click", function () {
|
||||
return false;
|
||||
});
|
||||
$("#signalRFirstWarningButton" + ptaId).on("click", function () {
|
||||
|
||||
document.getElementById("signalROpenItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
this.disabled = true;
|
||||
//event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Active);
|
||||
sendAuctionStatusChange(ptaId, AuctionStatus.FirstWarning);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRCloseItemButton").on("click", function () {
|
||||
return false;
|
||||
});
|
||||
$("#signalRSecondWarningButton" + ptaId).on("click", function () {
|
||||
|
||||
document.getElementById("signalRCloseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
this.disabled = true;
|
||||
//event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Sold);
|
||||
sendAuctionStatusChange(ptaId, AuctionStatus.SecondWarning);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRFirstWarningButton").on("click", function () {
|
||||
return false;
|
||||
});
|
||||
$("#signalRPauseItemButton" + ptaId).on("click", function () {
|
||||
|
||||
document.getElementById("signalRFirstWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
this.disabled = true;
|
||||
//event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.FirstWarning);
|
||||
sendAuctionStatusChange(ptaId, AuctionStatus.Pause);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRSecondWarningButton").on("click", function () {
|
||||
return false;
|
||||
});
|
||||
$("#signalRRevertBidButton" + ptaId).on("click", function () {
|
||||
|
||||
document.getElementById("signalRSecondWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
this.disabled = true;
|
||||
//event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.SecondWarning);
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = viewModel;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRPauseItemButton").on("click", function () {
|
||||
var revertMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId
|
||||
};
|
||||
|
||||
document.getElementById("signalRPauseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
var content = JSON.stringify(revertMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Pause);
|
||||
return false;
|
||||
});
|
||||
$("#signalRResetItemButton" + ptaId).on("click", function () {
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRRevertBidButton").on("click", function () {
|
||||
this.disabled = true;
|
||||
//event.preventDefault();
|
||||
|
||||
document.getElementById("signalRRevertBidButton").disabled = true;
|
||||
event.preventDefault();
|
||||
sendAuctionStatusChange(AuctionStatus.None);
|
||||
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
var revertMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId
|
||||
};
|
||||
// function SendRevertAuctionBidRequest() {
|
||||
|
||||
var content = JSON.stringify(revertMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
// var revertButtonElement = document.getElementById("signalRRevertBidButton");
|
||||
// revertButtonElement.disabled = true;
|
||||
// sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
|
||||
// }
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRResetItemButton").on("click", function () {
|
||||
|
||||
|
||||
document.getElementById("signalRResetItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
function setBidButtonDisabled(bidButtonElement, disabled, updateDisabledState = true) {
|
||||
if (!updateDisabledState) return;
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.None);
|
||||
setElementDisabled(bidButtonElement, disabled, updateDisabledState);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
//var status = bidBoxPageViewModel.productToAuctionDto.auctionStatus;
|
||||
//setButtons(status);
|
||||
});
|
||||
function setElementDisabledById(domElementId, disabled) {
|
||||
setElementDisabled(document.getElementById(domElementId), disabled);
|
||||
}
|
||||
|
||||
function sendAuctionStatusChange(auctionStatus) {
|
||||
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
|
||||
// Send the message via SignalR
|
||||
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function SendRevertAuctionBidRequest() {
|
||||
|
||||
var revertButtonElement = document.getElementById("signalRRevertBidButton");
|
||||
revertButtonElement.disabled = true;
|
||||
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
|
||||
}
|
||||
|
||||
function setBidButtonDisabledById(bidButtonElementId, disabled, updateDisabledState = true) {
|
||||
if (!updateDisabledState) return;
|
||||
|
||||
setBidButtonDisabled(document.getElementById(bidButtonElementId), disabled, updateDisabledState);
|
||||
}
|
||||
|
||||
function setBidButtonDisabled(bidButtonElement, disabled, updateDisabledState = true) {
|
||||
if (!updateDisabledState) return;
|
||||
|
||||
setElementDisabled(bidButtonElement, disabled, updateDisabledState);
|
||||
}
|
||||
|
||||
function setElementDisabledById(domElementId, disabled) {
|
||||
setElementDisabled(document.getElementById(domElementId), disabled);
|
||||
}
|
||||
|
||||
function setElementDisabled(domElement, disabled) {
|
||||
if (!domElement)
|
||||
return;
|
||||
|
||||
domElement.disabled = disabled;
|
||||
}
|
||||
|
||||
function refreshPublicBidBox(bidNotification, updateBidButtonDisabledState) {
|
||||
|
||||
//TODO: is it for me?
|
||||
// if () {
|
||||
// bidNotification.AuctionDto.
|
||||
// }
|
||||
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var currency = bidBoxPageViewModel.WorkingCurrency;
|
||||
console.log(currency);
|
||||
|
||||
var bidButtonElement = document.getElementById("signalRBidButton");
|
||||
var licitStepElement = document.getElementById("licitStepText");
|
||||
var bidBox = document.getElementById("publicProductBidBox");
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
console.log(bidNotification);
|
||||
|
||||
let auctionDto = bidNotification.auctionDto;
|
||||
let productToAuction = auctionDto.productToAuctionDtos[0];
|
||||
var productAuctionMappingId = productToAuction.id;
|
||||
var winnerId = productToAuction.winnerCustomerId;
|
||||
var isMyBid;
|
||||
|
||||
if (winnerId == bidBoxPageViewModel.CustomerId) {
|
||||
isMyBid = true;
|
||||
|
||||
}
|
||||
|
||||
console.log("ProductToAuctionId: " + productAuctionMappingId);
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var status = productToAuction.auctionStatus;
|
||||
//var status = AuctionStatus.TEST;
|
||||
|
||||
//if (status == AuctionStatus.FirstWarning) {
|
||||
if (updateBidButtonDisabledState)
|
||||
setButtons(status);
|
||||
//}
|
||||
|
||||
// if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
// console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
// }
|
||||
|
||||
if (widgetPriceElement) {
|
||||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
if(bidBoxPageViewModel.WorkingCurrency.CurrencyCode == "EUR") {
|
||||
widgetPriceElement.textContent = EURFormatter.format(bidNotification.currentPrice * bidBoxPageViewModel.WorkingCurrency.Rate); // Update the price
|
||||
licitStepElement.textContent = EURFormatter.format(bidNotification.nextStepAmount * bidBoxPageViewModel.WorkingCurrency.Rate);
|
||||
}
|
||||
else {
|
||||
widgetPriceElement.textContent = HUFFormatter.format(bidNotification.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(bidNotification.nextStepAmount);
|
||||
}
|
||||
|
||||
bidBoxPageViewModel.NextBidPrice = Number(bidNotification.nextBidPrice);
|
||||
setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState);
|
||||
|
||||
var list;
|
||||
if (isMyBid) {
|
||||
console.log("This is my bid");
|
||||
list = bidBox.classList;
|
||||
list.add("bg-success");
|
||||
list.remove("bg-primary");
|
||||
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.GoodJob"))";
|
||||
bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? "@(T("Plugins.Misc.AuctionPlugin.YouWin"))" : "@(T("Plugins.Misc.AuctionPlugin.YourBidLeading"))";
|
||||
|
||||
if (bidBoxPageViewModel.IsAdmin) {
|
||||
console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState);
|
||||
} else {
|
||||
console.log("I AM NOT WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
setBidButtonDisabled(bidButtonElement, true, updateBidButtonDisabledState);
|
||||
}
|
||||
} else {
|
||||
list = bidBox.classList;
|
||||
list.add("bg-primary");
|
||||
list.remove("bg-success");
|
||||
bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? "@(T("Plugins.Misc.AuctionPlugin.Sold"))" : "@(T("Plugins.Misc.AuctionPlugin.PlaceABid"))";
|
||||
|
||||
if (bidBoxPageViewModel.WorkingCurrency.CurrencyCode == "EUR") {
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")) " + EURFormatter.format(bidBoxPageViewModel.NextBidPriceInWorkingCurrency);
|
||||
} else {
|
||||
bidButtonElement.textContent = "@(T("Plugins.Misc.AuctionPlugin.BidButtonPrefix")) " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`WidgetPrice updated to: ${bidNotification.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
//bidButtonElement.disabled = false;
|
||||
|
||||
} else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
function handleAuctionUpdate(auctionStatusNotification) {
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var bidButtonElement = document.getElementById("signalRBidButton");
|
||||
var licitStepElement = document.getElementById("licitStepText");
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
|
||||
var auctionDto = auctionStatusNotification.auctionDto;
|
||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
var productAuctionMappingId = productToAuctionDto.id;
|
||||
let isMyBid = false;
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
let itemStatus = productToAuctionDto.auctionStatus;
|
||||
//var itemStatus = AuctionStatus.TEST;
|
||||
let winnerId = productToAuctionDto.winnerCustomerId;
|
||||
if (winnerId == bidBoxPageViewModel.CustomerId) {
|
||||
isMyBid = true;
|
||||
|
||||
}
|
||||
console.log("handle auction update called" + productAuctionMappingId);
|
||||
console.log("auction status:" + itemStatus);
|
||||
if (widgetPriceElement) {
|
||||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
switch (itemStatus) {
|
||||
case AuctionStatus.None:
|
||||
location.reload();
|
||||
// bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.AuctionNotStarted"))";
|
||||
|
||||
// bidBoxPageViewModel.NextBidPrice = Number(auctionStatusNotification.nextBidPrice);
|
||||
|
||||
// if(bidBoxPageViewModel.WorkingCurrency.CurrencyCode == "EUR") {
|
||||
// widgetPriceElement.textContent = EURFormatter.format(auctionStatusNotification.currentPrice * bidBoxPageViewModel.WorkingCurrency.Rate); // Update the price
|
||||
// licitStepElement.textContent = EURFormatter.format(auctionStatusNotification.nextStepAmount * bidBoxPageViewModel.WorkingCurrency.Rate);
|
||||
// }
|
||||
// else {
|
||||
// widgetPriceElement.textContent = HUFFormatter.format(auctionStatusNotification.currentPrice); // Update the price
|
||||
// licitStepElement.textContent = HUFFormatter.format(auctionStatusNotification.nextStepAmount);
|
||||
// }
|
||||
break;
|
||||
|
||||
case AuctionStatus.Active:
|
||||
if (isMyBid) {
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.YourBidLeading"))";
|
||||
} else {
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.PlaceABid"))";
|
||||
}
|
||||
break;
|
||||
|
||||
case AuctionStatus.Pause:
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.AuctionPaused"))";
|
||||
break;
|
||||
|
||||
case AuctionStatus.FirstWarning:
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.FirstWarning"))";
|
||||
break;
|
||||
|
||||
case AuctionStatus.SecondWarning:
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.SecondWarning"))";
|
||||
break;
|
||||
|
||||
case AuctionStatus.Sold:
|
||||
if (isMyBid) {
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.YouWin"))";
|
||||
} else {
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.ItemClosed"))";
|
||||
}
|
||||
break;
|
||||
case AuctionStatus.NotSold:
|
||||
bidBoxTitle.textContent = "@(T("Plugins.Misc.AuctionPlugin.ItemClosed"))";
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn("Unknown AuctionStatus: ", itemStatus);
|
||||
}
|
||||
|
||||
|
||||
setButtons(itemStatus);
|
||||
|
||||
console.log(`WidgetPrice updated to: ${auctionStatusNotification.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setButtons(auctionStatus) {
|
||||
console.log("SetButtons called: " + auctionStatus);
|
||||
|
||||
// Button IDs and their default states for each AuctionStatus
|
||||
//true = disabled
|
||||
var buttonStates = {
|
||||
[AuctionStatus.None]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Active]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.FirstWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.SecondWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Pause]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.Sold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.NotSold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.TEST]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// Get the states for the given auctionStatus
|
||||
var states = buttonStates[auctionStatus];
|
||||
if (!states) {
|
||||
console.error("Unknown AuctionStatus: ", auctionStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the states to each button
|
||||
Object.keys(states).forEach((buttonId) => {
|
||||
var button = document.getElementById(buttonId);
|
||||
if (button) {
|
||||
button.disabled = states[buttonId];
|
||||
button.hidden = states[buttonId];
|
||||
} else {
|
||||
console.warn(`Button with ID ${buttonId} not found.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
function setElementDisabled(domElement, disabled) {
|
||||
if (!domElement)
|
||||
return;
|
||||
|
||||
domElement.disabled = disabled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue