Skip to content

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.

3.3 KB
Raw Blame
@model ProductModel
@{
    var area = ViewContext.RouteData.Values["area"]?.ToString();
    //a product the store may see but not change (see BaseProductController.Edit)
    bool readOnly = ViewBag.IsReadOnly == true;
}
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="grand-card">
        <partial name="Partials/WidgetZone.Recommended.Top" model="Model"/>
        <div class="grand-card__header">
            <h2 class="grand-card__title">@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Recommended"]</h2>
            @if (!readOnly)
            {
                <a id="btnAddNewRecommendedProduct" href="@(Url.Action("RecommendedProductAddPopup", "Product", new { productId = Model.Id, btnId = "btnRefreshRecommendedProducts", formId = "product-form", area = area }))" class="btn btn-outline-secondary btn-sm"><i class="bi bi-plus-lg"></i> @Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Recommended.AddNew"]</a>
                <input type="submit" id="btnRefreshRecommendedProducts" style="display: none"/>
            }
        </div>
        <div class="grand-card__body grand-card__body--flush">
            <admin-grid id="recommendedproducts-grid"
                        read-only="@readOnly"
                        read-url="@Url.Action("RecommendedProductList", "Product", new { productId = Model.Id, area = area })"
                        destroy-url="@Url.Action("RecommendedProductDelete", "Product", new { productId = Model.Id, area = area })"
                        pager="Compact"
                        auto-bind="false">
                <grid-column field="Product2Name" title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Recommended.Fields.Product"]">
                    <cell-template>
                        <a class="text-decoration-none" href="@Url.Action("Edit", "Product", new { id = "", area = area })/{{ Id }}">{{ Product2Name }}</a>
                    </cell-template>
                </grid-column>
                <grid-commands destroy="true" title="@Loc[$"{Scope.ResourceKeyPrefix}.Common.Delete"]"/>
            </admin-grid>
        </div>
        <partial name="Partials/WidgetZone.Recommended.Bottom" model="Model"/>
    </div>

    <script>
        $(document).ready(function () {
            $('#btnAddNewRecommendedProduct').magnificPopup({
                type: 'ajax',
                settings: { cache: false, async: false },
                midClick: true,
                callbacks: {
                    parseAjax: function (mfpResponse) {
                        mfpResponse.data = $('<div></div>').html(mfpResponse.data);
                    },
                    ajaxContentAdded: function () {
                        $('.mfp-wrap').removeAttr('tabindex');
                    }
                }
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $('#btnRefreshRecommendedProducts').click(function () {
                //refresh grid
                var grid = GrandAdmin.grids.get("#recommendedproducts-grid");
                grid.dataSource.read();

                //return false to don't reload a page
                return false;
            });
        });
    </script>
}
else
{
    <div class="note note-info">
        @Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.Recommended.SaveBeforeEdit"]
    </div>
}