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.

2.4 KB
Raw Blame
@{
    Layout = "";
}
@using System.Text.Encodings.Web
@model DiscountRules.Standard.Models.RequirementCustomerGroupsModel

<script>
    $(document).ready(function () {
        $('#savecustomergroupsrequirement@(Model.RequirementId)').click(function () {
            var customerGroupId = $("#@Html.IdFor(model => model.CustomerGroupId)").val();
            var discountId = '@Model.DiscountId';
            var requirementId = '@Model.RequirementId';

			if(customerGroupId == "")return;

            var postData = {
                discountId: discountId,
                discountRequirementId: requirementId,
                customerGroupId: customerGroupId
            };
            addAntiForgeryToken(postData);

            $.ajax({
                cache:false,
                type: "POST",
                url: "@Url.Action("Configure", "DiscountRulesCustomerGroups")",
                data: postData,
                success: function (data) {
                    $('#pnl-save-requirement-result@(Model.RequirementId)').fadeIn("slow").delay(1000).fadeOut("slow");
                    //notify parent if it's a new requirement
                    @if (string.IsNullOrEmpty(Model.RequirementId))
                    {
                        <text>$("#discountRequirementContainer").trigger('grandnewdiscountruleadded', [data.NewRequirementId]);</text>
                    }
                },
                error:function (xhr, ajaxOptions, thrownError){
                    alert('@Html.Raw(JavaScriptEncoder.Default.Encode(Loc["admin.marketing.Discounts.Requirements.FailedToSave"]))');
                }
            });
        });
    });
</script>

@* the rule's form inside the discount's requirement card: the field, then Save for this rule
   alone (outline - the discount's own Save is the screen's primary) and the saved message the
   script fades in *@
<div class="grand-fields">
    <admin-field asp-for="CustomerGroupId" size="md" asp-items="Model.AvailableCustomerGroups"/>
    <div class="d-flex flex-wrap align-items-center gap-2">
        <input type="button" id="savecustomergroupsrequirement@(Model.RequirementId)" class="btn btn-outline-secondary btn-sm" value="@Loc["Admin.Common.Save"]"/>
        <div id="pnl-save-requirement-result@(Model.RequirementId)" class="text-success" style="display:none;">@Loc["admin.marketing.Discounts.Requirements.Saved"]</div>
    </div>
</div>