142 lines
4.9 KiB
Plaintext
142 lines
4.9 KiB
Plaintext
@model ProductBidBoxViewModel
|
|
@inject IJsonHelper JsonHelper;
|
|
|
|
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
|
|
|
<style>
|
|
|
|
</style>
|
|
<div id="publicProductBidBox" class="bg-dark p-3">
|
|
|
|
<div class="d-flex justify-content-between mb-3">
|
|
<div>
|
|
<strong>Base Price:</strong>
|
|
<span class="value">
|
|
@String.Format("{0:c}", Model.BasePrice)
|
|
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
|
</span>
|
|
</div>
|
|
<div>
|
|
<strong>Bid Step:</strong>
|
|
<span class="value">@String.Format("{0:c}", Model.LicitStep)</span>
|
|
</div>
|
|
<div>
|
|
<button id="signalRBidButton" class="btn btn-success" type="button">
|
|
Bid @String.Format("{0:c}", Model.BidPrice)
|
|
</button>
|
|
@* <button id="bidButton" class="btn btn-success">
|
|
|
|
Bid @String.Format("{0:c}", Model.BidPrice)
|
|
</button> *@
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@* <button id="testButton" class="btn btn-success">
|
|
TestButton
|
|
</button> *@
|
|
|
|
<div id="bidFeedback" class="mt-3"></div>
|
|
</div>
|
|
|
|
<script>
|
|
var pageViewModel = undefined;
|
|
$(document).ready(function () {
|
|
|
|
pageViewModel = @Html.Raw(Json.Serialize(Model));
|
|
console.log(pageViewModel);
|
|
console.log(pageViewModel.WidgetZone);
|
|
console.log(typeof sendMessageToServer);
|
|
|
|
|
|
// $('#bidButton').click(function () {
|
|
// const bidPrice = $('#bidPrice').val();
|
|
|
|
// // Validate bid price
|
|
// if (!bidPrice || parseInt(bidPrice) < @Model.CurrentPrice + @Model.LicitStep) {
|
|
// $('#bidFeedback').text('Bid price must be at least the current price plus the licit step.')
|
|
// .addClass('text-danger');
|
|
// return;
|
|
// }
|
|
|
|
// // AJAX POST to send the bid
|
|
// $.ajax({
|
|
// url: '/Auction/PlaceBid', // Ensure this endpoint exists in your controller
|
|
// type: 'POST',
|
|
// contentType: 'application/json',
|
|
// data: JSON.stringify({
|
|
// auctionId: pageViewModel.AuctionId,
|
|
// bidPrice: bidPrice,
|
|
// customerId: dataObject.CustomerId,
|
|
// productId: dataObject.ProductId
|
|
// }),
|
|
// success: function (response) {
|
|
// $('#bidFeedback').text(response.message).removeClass('text-danger').addClass('text-success');
|
|
// },
|
|
// error: function (xhr) {
|
|
// $('#bidFeedback').text('Failed to place bid: ' + xhr.responseText)
|
|
// .addClass('text-danger');
|
|
// }
|
|
// });
|
|
// });
|
|
|
|
$("#signalRBidButton").on("click", function () {
|
|
|
|
document.getElementById("signalRBidButton").disabled = true;
|
|
event.preventDefault();
|
|
|
|
var bidMessage = {
|
|
AuctionId: pageViewModel.AuctionId.toFixed(),
|
|
BidPrice: pageViewModel.BidPrice.toFixed(2),
|
|
ProductId: pageViewModel.ProductId.toFixed(),
|
|
CustomerId: pageViewModel.CustomerId.toFixed()
|
|
};
|
|
|
|
sendMessageToServer("BidRequestMessage", bidMessage);
|
|
|
|
return false;
|
|
});
|
|
|
|
|
|
});
|
|
|
|
function refreshPublicBidBox(data) {
|
|
// $.ajax({
|
|
// url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
|
// type: 'POST',
|
|
// contentType: 'application/json',
|
|
// data: JSON.stringify({
|
|
// WidgetZone: pageViewModel.WidgetZone,
|
|
// ProductId: pageViewModel.ProductId
|
|
// }),
|
|
// success: function (response) {
|
|
// //$('#auction-widget').html(response); // Update the DOM element
|
|
// console.log("Auction widget refreshed!");
|
|
// },
|
|
// error: function (error) {
|
|
// console.error("Error refreshing auction widget:", error);
|
|
// }
|
|
// });
|
|
|
|
var widgetPriceElement = document.getElementById("price-value-"+pageViewModel.ProductId);
|
|
var budButtonElement = document.getElementById("signalRBidButton");
|
|
|
|
if (widgetPriceElement) {
|
|
widgetPriceElement.textContent = data.bidPrice; // Update the price
|
|
|
|
pageViewModel.BidPrice = Number(data.bidPrice) + Number(data.nextStepAmount);
|
|
budButtonElement.textContent = pageViewModel.BidPrice.toFixed(2);
|
|
|
|
// if (pageViewModel.CustomerId == data.CustomerId) {
|
|
|
|
// }
|
|
|
|
console.log(`WidgetPrice updated to: ${data.bidPrice}`);
|
|
budButtonElement.disabled = false;
|
|
} else {
|
|
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
|
}
|
|
}
|
|
|
|
|
|
</script> |