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.

4.2 KB
Raw Blame
@model DiscountListModel
@{
    //page title
    ViewBag.Title = Loc["admin.marketing.Discounts"];
    var area = ViewContext.RouteData.Values["area"]?.ToString();
}

@* The product list's shape: Add new in the page header, the name as the quick search with the
   coupon code and the type behind the Filters toggle, and the grid in a flush card. The ids the
   script below looks up are unchanged. *@
<admin-page title="@Loc["admin.marketing.Discounts"]" icon="bi-tags">
    <page-actions>
        <partial name="Partials/WidgetZone.ListButtons"/>
        <a href="@Url.Action("Create", new { area = area })" class="btn btn-primary">
            <i class="bi bi-plus-lg"></i> @Loc["Admin.Common.AddNew"]
        </a>
    </page-actions>

    <admin-filters id="discount-filters" submit-id="search-discounts" secondary-submit="true">
        <filters-search>
            <admin-input asp-for="SearchDiscountName"/>
        </filters-search>
        <admin-field asp-for="SearchDiscountCouponCode"/>
        <admin-field asp-for="SearchDiscountTypeId" asp-items="Model.AvailableDiscountTypes"/>
    </admin-filters>

    <admin-card flush>
        <admin-grid id="discounts-grid"
                    read-url="@Url.Action("List", "Discount", new { area = area })"
                    additional-data="additionalData">
            <grid-column field="Name" title="@Loc["admin.marketing.Discounts.Fields.Name"]" width="350">
                <cell-template>
                    <a class="text-decoration-none" href="Edit/{{ Id }}">{{ Name }}</a>
                </cell-template>
            </grid-column>
            <grid-column field="DiscountTypeName" title="@Loc["admin.marketing.Discounts.Fields.DiscountType"]" width="250"/>
            <grid-column field="DiscountAmount" title="@Loc["admin.marketing.Discounts.Fields.Discount"]" width="200">
                <cell-template>
                    <span data-if="!CalculateByPlugin"><span data-if="UsePercentage">{{ DiscountPercentage }} %</span> <span data-else>{{ DiscountAmount }} {{ CurrencyCode }}</span></span>
                </cell-template>
            </grid-column>
            <grid-column field="StartDate" title="@Loc["admin.marketing.Discounts.Fields.StartDate"]" width="200" format="{0:G}"/>
            <grid-column field="EndDate" title="@Loc["admin.marketing.Discounts.Fields.EndDate"]" width="200" format="{0:G}"/>
            <grid-column field="TimesUsed" title="@Loc["admin.marketing.Discounts.Fields.TimesUsed"]" width="200"/>
            <grid-column field="IsEnabled" title="@Loc["admin.marketing.Discounts.Fields.IsEnabled"]" width="100" align="Center">
                <cell-template>
                    <i data-if="IsEnabled" 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-page>

<script>

        $(document).ready(function () {

            $('#search-discounts').click(function () {
                var grid = GrandAdmin.grids.get('#discounts-grid');
                grid.dataSource.page(1); //new search. Set page size to 1
                //grid.dataSource.read(); we already loaded the grid above using "page" function
                return false;
            });
        });

        $("#@Html.IdFor(model => model.SearchDiscountName)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-discounts").click();
                return false;
            }
        });

        $("#@Html.IdFor(model => model.SearchDiscountCouponCode)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-discounts").click();
                return false;
            }
        });

        function additionalData() {
            var data = {
                SearchDiscountTypeId: $('#@Html.IdFor(model => model.SearchDiscountTypeId)').val(),
                SearchDiscountCouponCode: $('#@Html.IdFor(model => model.SearchDiscountCouponCode)').val(),
                SearchDiscountName: $('#@Html.IdFor(model => model.SearchDiscountName)').val()
            };
            addAntiForgeryToken(data);
            return data;
        }

</script>