buttons
This commit is contained in:
parent
a9a7e94cf2
commit
dbd203e379
|
|
@ -28,9 +28,11 @@
|
|||
|
||||
},
|
||||
bidNotification: function (data) {
|
||||
console.log(data);
|
||||
//console.log(data);
|
||||
var myObject = JSON.parse(data);
|
||||
console.log(myObject);
|
||||
//console.log(myObject);
|
||||
var productAuctionMappingId = myObject.auctionDto.productToAuctionDtos[0].id;
|
||||
//console.log(productAuctionMappingId);
|
||||
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||
|
|
@ -88,9 +90,9 @@
|
|||
});
|
||||
$('.toast-success').css("background-color", "#4caf50");
|
||||
}
|
||||
//if (publicProductBidBox) {
|
||||
// refreshPublicBidBox(myObject);
|
||||
//}
|
||||
if (publicProductBidBox) {
|
||||
handleAuctionUpdate(myObject);
|
||||
}
|
||||
if (liveScreen) {
|
||||
reloadOnUpdate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
SenderId = senderId,
|
||||
Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true))
|
||||
{
|
||||
ProductName = auctionBid.ProductId.ToString(),
|
||||
ProductName = product.Name,
|
||||
CurrentPrice = auctionBid.BidPrice,
|
||||
NextStepAmount = stepAmount,
|
||||
NextBidPrice = nextBidPrice,
|
||||
|
|
|
|||
|
|
@ -9,91 +9,93 @@
|
|||
@{
|
||||
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">
|
||||
<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>
|
||||
</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-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>
|
||||
<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>
|
||||
<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 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>
|
||||
<p>Please log in or register to participate!</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +141,7 @@
|
|||
document.getElementById("signalROpenItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
handleAuctionStatusChange(AuctionStatus.Active);
|
||||
sendAuctionStatusChange(AuctionStatus.Active);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -148,7 +150,7 @@
|
|||
document.getElementById("signalRCloseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
handleAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
|
||||
sendAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -157,7 +159,7 @@
|
|||
document.getElementById("signalRFirstWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
handleAuctionStatusChange(AuctionStatus.FirstWarning);
|
||||
sendAuctionStatusChange(AuctionStatus.FirstWarning);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -166,59 +168,280 @@
|
|||
document.getElementById("signalRSecondWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
handleAuctionStatusChange(AuctionStatus.SecondWarning);
|
||||
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 handleAuctionStatusChange(auctionStatus) {
|
||||
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
function sendAuctionStatusChange(auctionStatus) {
|
||||
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
|
||||
// Send the message via SignalR
|
||||
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
|
||||
return false;
|
||||
|
||||
// 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) {
|
||||
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 (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) {
|
||||
// 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");
|
||||
}
|
||||
|
||||
// }
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
Loading…
Reference in New Issue