Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
@model ProductModel.AddRequiredProductModel
@{
Layout = "";
var area = ViewContext.RouteData.Values["area"]?.ToString();
//page title
ViewBag.Title = Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Fields.RequiredProductIds.Choose"];
}
<admin-popup title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Fields.RequiredProductIds.Choose"]" icon="bi-boxes">
<admin-filters id="product-picker-filters" submit-id="search-products">
<filters-search>
<admin-input asp-for="SearchProductName"/>
</filters-search>
<admin-field asp-for="SearchCategoryId"/>
<admin-field asp-for="SearchBrandId"/>
<admin-field asp-for="SearchCollectionId"/>
@if (area == "Admin")
{
<admin-field asp-for="SearchStoreId" asp-items="Model.AvailableStores"/>
<admin-field asp-for="SearchVendorId" asp-items="Model.AvailableVendors"/>
}
<admin-field asp-for="SearchProductTypeId" asp-items="Model.AvailableProductTypes"/>
</admin-filters>
<admin-card flush>
<admin-grid id="products-grid"
read-url="@Url.Action("RequiredProductAddPopupList", "Product", new { area = area })"
additional-data="additionalData">
<grid-text name="select" value="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Select"]"/>
<grid-column field="Name" title="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Select"]" width="50">
<cell-template>
<input type="button" value="{{ $texts.select }}" data-grid-click="selectRequiredProductRow" class="btn btn-outline-secondary btn-sm" />
</cell-template>
</grid-column>
<grid-column field="Name" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Fields.Name"]"/>
<grid-column field="Published" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Fields.Published"]" width="100" align="Center">
<cell-template>
<i data-if="Published" class="bi bi-check-lg text-success" aria-hidden="true"></i>
<i data-else class="bi bi-x-lg text-danger" aria-hidden="true"></i>
</cell-template>
</grid-column>
</admin-grid>
</admin-card>
</admin-popup>
<script>
//the ids of the input that collects the required product ids and of the button that refreshes
//it come from the query string: serialized, never pasted into the script as raw text
var requiredProductIdsInput = @Json.Serialize(Context.Request.Query["productIdsInput"].ToString());
var requiredProductsRefreshButton = @Json.Serialize(Context.Request.Query["btnId"].ToString());
function additionalData() {
var data = {
SearchProductName: $('#@Html.IdFor(model => model.SearchProductName)').val(),
SearchCategoryId: $('#SearchCategoryId').val(),
SearchBrandId: $('#SearchBrandId').val(),
SearchCollectionId: $('#SearchCollectionId').val(),
@if (area == "Admin")
{
<text>SearchStoreId: $('#SearchStoreId').val(),
SearchVendorId: $('#SearchVendorId').val(),</text>
}
SearchProductTypeId: $('#SearchProductTypeId').val()
};
addAntiForgeryToken(data);
return data;
}
function selectRequiredProductRow(product) {
var input = document.getElementById(requiredProductIdsInput);
if (input) {
var ids = input.value ? input.value.split(',').map(function (x) { return x.trim(); }).filter(Boolean) : [];
if (ids.indexOf(product.Id) < 0) ids.push(product.Id);
input.value = ids.join(', ');
}
var refresh = document.getElementById(requiredProductsRefreshButton);
if (refresh) refresh.click();
$.magnificPopup.instance.close();
}
$('#search-products').click(function () {
GrandAdmin.grids.get('#products-grid').dataSource.page(1);
return false;
});
$('#@Html.IdFor(model => model.SearchProductName)').keydown(function (event) {
if (event.keyCode == 13) {
$('#search-products').click();
return false;
}
});
</script>