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.

5.2 KB
Raw Blame
@using Grand.Web.AdminShared.Models.Messages
@model ContactAttributeModel
<partial name="Partials/WidgetZone.Values.Top" model="Model"/>
@{
    var isReadOnly = Model.IsReadOnly;
    var area = ViewContext.RouteData.Values["area"]?.ToString();

    if (!string.IsNullOrEmpty(Model.Id))
    {
        @* the checkout attribute values tab: a titled card with Add new in its header, the grid
           flush; a read-only attribute keeps the grid and the refresh hook but no Add new *@
        <div class="grand-card">
            <div class="grand-card__header">
                <h2 class="grand-card__title">@Loc["Admin.Catalog.Attributes.ContactAttributes.Values"]</h2>
                @if (!isReadOnly)
                {
                    <a id="btnAddNewValue" href="@(Url.Action("ValueCreatePopup", "ContactAttribute", new { contactAttributeId = Model.Id, area }))" class="btn btn-outline-secondary btn-sm"><i class="bi bi-plus-lg"></i> @Loc["Admin.Catalog.Attributes.ContactAttributes.Values.AddNew"]</a>
                }
                <input type="submit" id="btnRefresh" style="display: none"/>
            </div>
            <div class="grand-card__body grand-card__body--flush">
                <admin-grid id="contactattributevalues-grid"
                            read-url="@Url.Action("ValueList", "ContactAttribute", new { contactAttributeId = Model.Id, area })"
                            destroy-url="@(isReadOnly ? null : Url.Action("ValueDelete", "ContactAttribute", new { area }))"
                            pager="Compact"
                            confirm-destroy="true"
                            on-data-bound="@(isReadOnly ? null : "bindContactAttributeValuePopups")">
                    <grid-column field="Name" title="@Loc["Admin.Catalog.Attributes.ContactAttributes.Values.Fields.Name"]">
                        <cell-template>
                            @if (!isReadOnly)
                            {
                                <a class="text-decoration-none editvalue" href="@Url.Action("ValueEditPopup", "ContactAttribute", new { area })/{{ Id }}[email protected]">{{ Name }}</a>
                            }
                            else
                            {
                                @:{{ Name }}
                            }
                        </cell-template>
                    </grid-column>
                    <grid-column field="IsPreSelected" title="@Loc["Admin.Catalog.Attributes.ContactAttributes.Values.Fields.IsPreSelected"]" width="100" align="Center" min-screen-width="500">
                        <cell-template>
                            <i data-if="IsPreSelected" 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>
                    <grid-column field="DisplayOrder" title="@Loc["Admin.Catalog.Attributes.ContactAttributes.Values.Fields.DisplayOrder"]" width="100" align="Center"/>
                    @if (!isReadOnly)
                    {
                        <grid-commands destroy="true" title="@Loc["Admin.Common.Delete"]" width="100"/>
                    }
                </admin-grid>
            </div>
        </div>

        if (!isReadOnly)
        {
            <script>
                $(document).ready(function () {
                    $('#btnAddNewValue').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');
                            }
                        }
                    });

                    $('#btnRefresh').click(function () {
                        var grid = GrandAdmin.grids.get("#contactattributevalues-grid");
                        grid.dataSource.read();
                        return false;
                    });
                });
                function bindContactAttributeValuePopups() {
                    $('.editvalue').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>
        }
    }
    else
    {
        <div class="note note-info">
            @Loc["Admin.Catalog.Attributes.ContactAttributes.Values.SaveBeforeEdit"]
        </div>
    }
}
<partial name="Partials/WidgetZone.Values.Bottom" model="Model"/>