447 lines
17 KiB
Plaintext
447 lines
17 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-secondary text-white">
|
|
<h4>Manage auction!</h4>
|
|
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
|
|
|
|
<div>
|
|
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled" : string.Empty)>
|
|
First warning
|
|
</button>
|
|
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
|
|
Second warning
|
|
</button>
|
|
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled" : string.Empty)>
|
|
Finished
|
|
</button>
|
|
</div>
|
|
<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")>
|
|
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")>
|
|
Pause auction
|
|
</button>
|
|
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled" : string.Empty)>
|
|
Revert bid
|
|
</button>
|
|
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled" : string.Empty)>
|
|
Reset auction
|
|
</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">
|
|
|
|
<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();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.Active);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRCloseItemButton").on("click", function () {
|
|
|
|
document.getElementById("signalRCloseItemButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
|
|
|
|
return false;
|
|
});
|
|
$("#signalRFirstWarningButton").on("click", function () {
|
|
|
|
document.getElementById("signalRFirstWarningButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.FirstWarning);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRSecondWarningButton").on("click", function () {
|
|
|
|
document.getElementById("signalRSecondWarningButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.SecondWarning);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRPauseItemButton").on("click", function () {
|
|
|
|
document.getElementById("signalRPauseItemButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.Pause);
|
|
|
|
return false;
|
|
});
|
|
$("#signalRRevertBidButton").on("click", function () {
|
|
|
|
document.getElementById("signalRRevertBidButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
sendAuctionStatusChange(AuctionStatus.Revert);
|
|
|
|
return false;
|
|
});
|
|
|
|
});
|
|
|
|
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;
|
|
sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
|
|
}
|
|
|
|
|
|
function refreshPublicBidBox(data) {
|
|
|
|
//TODO: is it for me?
|
|
// if () {
|
|
// data.AuctionDto.
|
|
// }
|
|
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
|
var budButtonElement = document.getElementById("signalRBidButton");
|
|
var licitStepElement = document.getElementById("licitStepText");
|
|
console.log(data);
|
|
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
|
console.log(productAuctionMappingId);
|
|
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
|
//if (status == AuctionStatus.FirstWarning) {
|
|
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");
|
|
|
|
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.log("Not for this product");
|
|
}
|
|
|
|
|
|
} else {
|
|
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
|
}
|
|
}
|
|
|
|
function handleAuctionUpdate(data) {
|
|
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
|
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
|
var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
|
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");
|
|
|
|
setButtons(itemStatus);
|
|
|
|
console.log(`WidgetPrice updated to: ${data.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);
|
|
|
|
|
|
// var bidButton = document.getElementById("signalRBidButton");
|
|
// var firstWarningButton = document.getElementById("signalRFirstWarningButton");
|
|
// var secondWarningButton = document.getElementById("signalRSecondWarningButton");
|
|
// var openItemButton = document.getElementById("signalROpenItemButton");
|
|
// var closeItemButton = document.getElementById("signalRCloseItemButton");
|
|
// var pauseItemButton = document.getElementById("signalRPauseItemButton");
|
|
// var revertBidButton = document.getElementById("signalRRevertBidButton");
|
|
// var resetItemButton = document.getElementById("signalRResetItemButton");
|
|
|
|
// switch (auctionStatus) {
|
|
// case AuctionStatus.None:
|
|
// console.log("SWITCH: 0");
|
|
// bidButton.disabled = true;
|
|
// break;
|
|
// case AuctionStatus.Active:
|
|
// console.log("SWITCH: 1");
|
|
// bidButton.disabled = false;
|
|
// firstWarningButton.disabled = false;
|
|
// break;
|
|
// case AuctionStatus.FirstWarning:
|
|
// console.log("SWITCH: 1");
|
|
// bidButton.disabled = false;
|
|
// firstWarningButton.disabled = true;
|
|
// secondWarningButton.disabled = false;
|
|
// break;
|
|
// case AuctionStatus.SecondWarning:
|
|
// // code block
|
|
// break;
|
|
// case AuctionStatus.Pause:
|
|
// // code block
|
|
// break;
|
|
// case AuctionStatus.Sold:
|
|
// // code block
|
|
// break;
|
|
// case AuctionStatus.NotSold:
|
|
// // code block
|
|
// break;
|
|
// default:
|
|
// // code block
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
function setButtons(auctionStatus) {
|
|
console.log("SetButtons called: " + auctionStatus);
|
|
|
|
// Button IDs and their default states for each AuctionStatus
|
|
//true = disabled
|
|
const 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: true,
|
|
signalRResetItemButton: true,
|
|
},
|
|
[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: false,
|
|
signalRResetItemButton: false,
|
|
},
|
|
};
|
|
|
|
// Get the states for the given auctionStatus
|
|
const states = buttonStates[auctionStatus];
|
|
if (!states) {
|
|
console.error("Unknown AuctionStatus: ", auctionStatus);
|
|
return;
|
|
}
|
|
|
|
// Apply the states to each button
|
|
Object.keys(states).forEach((buttonId) => {
|
|
const button = document.getElementById(buttonId);
|
|
if (button) {
|
|
button.disabled = states[buttonId];
|
|
} else {
|
|
console.warn(`Button with ID ${buttonId} not found.`);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
</script> |