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.ProductAttributeMappingModel
@{
    var area = ViewContext.RouteData.Values["area"]?.ToString();
}
@{
    Layout = "";
    //page title
    ViewBag.Title = Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.ValidationRules"];

    var attributeControlType = Model.AttributeControlTypeId;
}
<form id="ProductAttributeValidationRulesPopup" asp-area="@area" asp-controller="Product" asp-action="ProductAttributeValidationRulesPopup" enctype="multipart/form-data" method="post"
      asp-route-ProductId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["ProductId"])"
      asp-route-btnId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["btnId"])"
      asp-route-formId="@HtmlExtensions.HtmlEncodeSafe(Context.Request.Query["formId"])">

    @{
        //the rules that do not apply to this control type stay in the form - they post with it -
        //but out of sight
        var textHidden = attributeControlType != AttributeControlType.TextBox && attributeControlType != AttributeControlType.MultilineTextbox ? "d-none" : null;
        var fileHidden = attributeControlType != AttributeControlType.FileUpload ? "d-none" : null;
    }
    <admin-popup title="@Loc[$"{Scope.ResourceKeyPrefix}.Catalog.Products.ProductAttributes.Attributes.ValidationRules"]" icon="bi-ui-checks">
        <div class="grand-fields grand-fields--2col">
            <admin-field asp-for="ValidationMinLength" class="@textHidden" size="sm"/>
            <admin-field asp-for="ValidationMaxLength" class="@textHidden" size="sm"/>
            <admin-field asp-for="ValidationFileAllowedExtensions" class="@fileHidden"/>
            <admin-field asp-for="ValidationFileMaximumSize" class="@fileHidden" size="md"/>
            <admin-field asp-for="DefaultValue" class="@textHidden"/>
        </div>
        <div class="grand-popup__actions">
            <button class="btn btn-primary" type="submit" name="save">
                <i class="bi bi-check-lg"></i> @Loc[$"{Scope.ResourceKeyPrefix}.Common.Save"]
            </button>
        </div>
    </admin-popup>
    @if (!Model.ValidationRulesAllowed)
    {
        <div class="note note-danger">This attribute type cannot have validation rules</div>
    }
    <script>
        var mfp = $.magnificPopup.instance;
        $("#ProductAttributeValidationRulesPopup").submit(function (e) {
            e.preventDefault();
            var form = $(this);
            var url = form.attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data: form.serialize(),
                success: function (data) {
                    if (data == "") {
                        mfp.close();
                        $('#btnRefreshProductAttributes').click();
                    } else {
                        $.magnificPopup.open({
                            items: {
                                src: data,
                                type: 'inline'
                            },
                            callbacks: {
                                open: function () {
                                    $('.mfp-wrap').removeAttr('tabindex');
                                }
                            }
                        });
                    }
                }
            });
        });
    </script>
</form>