wtf javascript error fix, ViewModel being empty on document.ready
This commit is contained in:
parent
1e1d612b0f
commit
29adf2772a
|
|
@ -144,13 +144,12 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
|
||||
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
|
||||
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
|
||||
productBidBoxViewModel.AuctionClosed = auction.Closed;
|
||||
productBidBoxViewModel.Status = productToAuctionId.FirstOrDefault().AuctionStatus;
|
||||
|
||||
productBidBoxViewModel.AuctionClosed = auction.Closed;
|
||||
productBidBoxViewModel.IsItemActive = isActive;
|
||||
productBidBoxViewModel.WidgetZone = widgetZone;
|
||||
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
||||
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
||||
productBidBoxViewModel.ProductToAuctionsId = productToAuctionId.FirstOrDefault().Id;
|
||||
productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
|
||||
productBidBoxViewModel.AuctionId = auctionId;
|
||||
productBidBoxViewModel.CustomerId = customer.Id;
|
||||
productBidBoxViewModel.ProductId = productDetailsModel.Id;
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
{
|
||||
public record ProductBidBoxViewModel: BaseNopModel
|
||||
{
|
||||
public int ProductToAuctionsId { get; set; }
|
||||
public int ProductToAuctionId { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
public bool IsGuest { get; set; }
|
||||
public int AuctionId { get; set; }
|
||||
public bool AuctionClosed { get; set; }
|
||||
public AuctionStatus Status { get; set; }
|
||||
public bool IsItemActive { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
@model ProductBidBoxViewModel
|
||||
@inject IJsonHelper JsonHelper;
|
||||
@* @inject IJsonHelper JsonHelper; *@
|
||||
|
||||
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
||||
|
||||
|
|
@ -75,32 +75,38 @@
|
|||
}
|
||||
|
||||
<script>
|
||||
var pageViewModel = undefined;
|
||||
|
||||
|
||||
var bidBoxPageViewModel;
|
||||
|
||||
$(document).ready(function () {
|
||||
$(window).load(function () {
|
||||
try {
|
||||
|
||||
pageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
console.log(pageViewModel);
|
||||
console.log(pageViewModel.WidgetZone);
|
||||
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: pageViewModel.ProductToAuctions,
|
||||
AuctionId: pageViewModel.AuctionId,
|
||||
BidPrice: pageViewModel.BidPrice,
|
||||
ProductId: pageViewModel.ProductId,
|
||||
CustomerId: pageViewModel.CustomerId
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionId: bidBoxPageViewModel.AuctionId,
|
||||
BidPrice: bidBoxPageViewModel.BidPrice,
|
||||
ProductId: bidBoxPageViewModel.ProductId,
|
||||
CustomerId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
var content = JSON.stringify(bidMessage);
|
||||
console.log(content);
|
||||
sendMessageToServer("BidRequestMessage", pageViewModel.CustomerId, content);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -111,12 +117,12 @@
|
|||
event.preventDefault();
|
||||
|
||||
var openItemMessage = {
|
||||
ProductAuctionMappingId: pageViewModel.ProductToAuctions,
|
||||
AdminId: pageViewModel.CustomerId
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AdminId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
var content = JSON.stringify(openItemMessage);
|
||||
console.log(content);
|
||||
sendMessageToServer("OpenItemRequestMessage", pageViewModel.CustomerId, content);
|
||||
sendMessageToServer("OpenItemRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -126,12 +132,12 @@
|
|||
event.preventDefault();
|
||||
|
||||
var itemFirstWarningMessage = {
|
||||
ProductAuctionMappingId: pageViewModel.ProductToAuctions,
|
||||
AdminId: pageViewModel.CustomerId
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AdminId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
var content = JSON.stringify(itemFirstWarningMessage);
|
||||
console.log(content);
|
||||
sendMessageToServer("FirstWarningMessage", pageViewModel.CustomerId, content);
|
||||
sendMessageToServer("FirstWarningMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
@ -145,23 +151,23 @@
|
|||
currency: 'HUF',
|
||||
});
|
||||
|
||||
var widgetPriceElement = document.getElementById("price-value-" + pageViewModel.ProductId);
|
||||
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.bidPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
||||
pageViewModel.BidPrice = Number(data.bidPrice) + Number(data.nextStepAmount);
|
||||
bidBoxPageViewModel.BidPrice = Number(data.bidPrice) + Number(data.nextStepAmount);
|
||||
|
||||
budButtonElement.textContent = "Bid " + HUFFormatter.format(pageViewModel.BidPrice);
|
||||
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.BidPrice);
|
||||
|
||||
|
||||
// if (pageViewModel.CustomerId == data.CustomerId) {
|
||||
// if (bidBoxPageViewModel.CustomerId == data.CustomerId) {
|
||||
|
||||
// }
|
||||
|
||||
console.log(`WidgetPrice updated to: ${data.bidPrice}`);
|
||||
console.log(`WidgetPrice updated to: ${data.bidPrice}, next bid is ${bidBoxPageViewModel.BidPrice}`);
|
||||
budButtonElement.disabled = false;
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
|
|
|
|||
Loading…
Reference in New Issue