Mango.Nop.Plugins/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettings...

120 lines
4.4 KiB
Plaintext

@model ProductAssignToAuctionViewModel
<div class="auction-settings-box">
<h3>@T("Plugins.Misc.AuctionPlugin.Admin.AssignToAuction")</h3>
<div id="assignAuctionContainer">
<h3>Assign Product to Auction</h3>
<input type="hidden" id="productId" value="@Model.ProductId" />
<input type="hidden" id="startingPrice" value="@Model.StartingPrice" />
<input type="hidden" id="bidPrice" value="@Model.StartingPrice" />
<label for="auctionDropdown">@T("Plugins.Misc.AuctionPlugin.Admin.SelectAuction")</label>
<select id="auctionDropdown" class="form-control">
<option value="">Select an auction...</option>
@foreach (var auction in ViewBag.Auctions as List<Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Auction>)
{
<option value="@auction.Id">@auction.AuctionName</option>
}
</select>
<button id="assignAuctionButton" class="btn btn-primary mt-2">@T("Plugins.Misc.AuctionPlugin.Admin.AssignToAuctionButton")</button>
</div>
</div>
<script>
$(document).ready(function () {
// Handle button click
$("#assignAuctionButton").on("click", function () {
var productId = $("#productId").val();
var startingPrice = $("#startingPrice").val();
// var bidPrice = $("#bidPrice").val()toFixed(2);
var bidPrice = $("#bidPrice").val();
var auctionId = $("#auctionDropdown").val();
if (!auctionId) {
alert("Please select an auction.");
return;
}
var postData = {
ProductId: productId,
StartingPrice: startingPrice,
BidPrice: bidPrice,
AuctionId: auctionId
};
addAntiForgeryToken(postData);
var jsonData = JSON.stringify(postData);
console.log("postData: " + jsonData);
debugger;
// Perform AJAX call
$.ajax({
url: "/Admin/AuctionPluginAdmin/AssignProductToAuction", // Update to match your endpoint
type: "POST",
contentType: "application/json",
data: jsonData,
traditional: true,
success: function (response) {
alert("Product successfully assigned to the auction!");
console.log(response); // Optional: Log response for debugging
},
error: function (xhr, status, error) {
console.error("Error assigning product to auction:", error);
alert("Failed to assign the product to the auction. Please try again.");
}
});
});
});
// $("#assignAuctionForm").on("submit", function (event) {
// event.preventDefault(); // Prevent the default form submission behavior
// var productId = $("#productId").val();
// var startingPrice = $("startingPrice").val();
// var bidPrice = $("bidPrice").val();
// var auctionId = $("#auctionDropdown").val();
// // AJAX call or form submission logic here
// $.ajax({
// url: "/Admin/Auction/AssignProductToAuction",
// type: "POST",
// data: { productId: productId, startingPrice: startingPrice, bidPrice: bidPrice, auctionId: auctionId },
// success: function (response) {
// console.log("Product assigned to auction successfully!");
// },
// error: function (xhr, status, error) {
// console.error("Error assigning product to auction:", error);
// }
// });
// });
// $(document).ready(function () {
// $('#assignAuctionForm').on('submit', function (e) {
// e.preventDefault();
// var form = $(this);
// $.ajax({
// url: form.attr('action'),
// type: 'POST',
// data: form.serialize(),
// success: function (response) {
// toastr.success("@T("Plugins.Misc.AuctionPlugin.ProductAssignedSuccess")");
// },
// error: function (error) {
// toastr.error("@T("Plugins.Misc.AuctionPlugin.ProductAssignedError")");
// }
// });
// });
// });
</script>