227 lines
8.0 KiB
Plaintext
227 lines
8.0 KiB
Plaintext
@using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums
|
|
@using Nop.Web.Framework.TagHelpers.Shared
|
|
@model ProductBidBoxViewModel
|
|
@* @inject IJsonHelper JsonHelper; *@
|
|
|
|
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
|
|
|
|
|
@{
|
|
if (!Model.IsGuest)
|
|
{
|
|
<div id="publicProductBidBox" class="p-3 bg-primary text-white">
|
|
<h4>This item is under auction!</h4>
|
|
<div class="d-flex justify-content-between">
|
|
<div>
|
|
<strong>Base Price:</strong>
|
|
<span class="value">
|
|
@($"{Model.BasePrice:c}")
|
|
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<strong>Bid Step:</strong>
|
|
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
|
</div>
|
|
<div>
|
|
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)">
|
|
Bid @($"{Model.NextBidPrice:c}")
|
|
</button>
|
|
@* <button id="bidButton" class="btn btn-success">
|
|
|
|
Bid @String.Format("{0:c}", Model.NextBidPrice)
|
|
</button> *@
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@* <button id="testButton" class="btn btn-success">
|
|
TestButton
|
|
</button> *@
|
|
|
|
<div id="bidFeedback" class="mt-3"></div>
|
|
</div>
|
|
|
|
|
|
if (Model.IsAdmin)
|
|
{
|
|
<div id="publicProductBidBoxAdmin" class="p-3 bg-primary text-white">
|
|
<h4>Manage auction!</h4>
|
|
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
|
|
@{
|
|
if(Model.IsItemActive)
|
|
{
|
|
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus >= AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
|
|
First warning
|
|
</button>
|
|
<button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
|
|
Second warning
|
|
</button>
|
|
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
|
Deactivate item
|
|
</button>
|
|
}
|
|
// else if(Model.)
|
|
// {
|
|
|
|
// }
|
|
else
|
|
{
|
|
<button id="signalROpenItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
|
Activate item
|
|
</button>
|
|
}
|
|
}
|
|
|
|
|
|
|
|
</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">
|
|
|
|
<p>Please log in or register to participate!</p>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
<script>
|
|
var bidBoxPageViewModel;
|
|
|
|
$(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);
|
|
|
|
$("#signalRBidButton").on("click", function () {
|
|
|
|
document.getElementById("signalRBidButton").disabled = true;
|
|
event.preventDefault();
|
|
if (!bidBoxPageViewModel) {
|
|
console.log("we need viewmodel data");
|
|
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
|
}
|
|
var bidMessage = {
|
|
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
|
AuctionId: bidBoxPageViewModel.AuctionId,
|
|
BidPrice: bidBoxPageViewModel.NextBidPrice,
|
|
ProductId: bidBoxPageViewModel.ProductId,
|
|
CustomerId: bidBoxPageViewModel.CustomerId
|
|
};
|
|
var content = JSON.stringify(bidMessage);
|
|
console.log("WTF " + content);
|
|
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
|
|
|
return false;
|
|
});
|
|
|
|
$("#signalROpenItemButton").on("click", function () {
|
|
|
|
document.getElementById("signalROpenItemButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
handleAuctionStatusChange(AuctionStatus.Active);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRCloseItemButton").on("click", function () {
|
|
|
|
document.getElementById("signalRCloseItemButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
handleAuctionStatusChange(AuctionStatus.None); //Itt SoldOut volt, átírtam Sold-ra! - J.
|
|
|
|
return false;
|
|
});
|
|
$("#signalRFirstWarningButton").on("click", function () {
|
|
|
|
document.getElementById("signalRFirstWarningButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
handleAuctionStatusChange(AuctionStatus.FirstWarning);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRSecondWarningButton").on("click", function () {
|
|
|
|
document.getElementById("signalRSecondWarningButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
handleAuctionStatusChange(AuctionStatus.SecondWarning);
|
|
|
|
return false;
|
|
});
|
|
|
|
});
|
|
|
|
function handleAuctionStatusChange(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 refreshPublicBidBox(data) {
|
|
|
|
// let HUFFormatter = new Intl.NumberFormat('hu-HU', {
|
|
// style: 'currency',
|
|
// currency: 'HUF',
|
|
// });
|
|
|
|
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
|
var budButtonElement = document.getElementById("signalRBidButton");
|
|
var licitStepElement = document.getElementById("licitStepText");
|
|
|
|
if (widgetPriceElement) {
|
|
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
|
|
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
|
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
|
|
|
|
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
|
|
|
|
|
// if (bidBoxPageViewModel.CustomerId == data.CustomerId) {
|
|
|
|
// }
|
|
|
|
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
|
budButtonElement.disabled = false;
|
|
} else {
|
|
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
|
}
|
|
}
|
|
|
|
|
|
</script> |