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.

13.1 KB
Raw Blame
@model PermissionMappingModel
@{
    //page title
    ViewBag.Title = Loc["Admin.Configuration.Permissions"];
}
<form asp-area="@Constants.AreaAdmin" asp-controller="Permission" asp-action="Index" method="post">

    @* Save commits the matrix, so it is the one primary action; Add new opens a popup *@
    <admin-page title="@Loc["Admin.Configuration.Permissions"]" icon="bi-person-badge">
        <page-actions>
            <a href="@Url.Action("Create", new { area = Constants.AreaAdmin })" class="btn btn-outline-secondary" id="btnAddNewPermission">
                <i class="bi bi-plus-lg"></i> @Loc["Admin.Common.AddNew"]
            </a>
            <button class="btn btn-primary" type="submit" name="save">
                <i class="bi bi-check-lg"></i> @Loc["Admin.Common.Save"]
            </button>
            <vc:admin-widget widget-zone="permission_list_buttons" additional-data="null"/>
        </page-actions>

        <admin-card flush>
                                    @if (Model.AvailablePermissions.Count == 0)
                                    {
                                        <text>No permissions defined</text>
                                    }
                                    else if (Model.AvailableCustomerGroups.Count == 0)
                                    {
                                        <text>No customer groups available</text>
                                    }
                                    else
                                    {
                                        <script>
                                            function checkCategory(checkbox) {
                                                var cbox = checkbox;
                                                var input = $(checkbox).closest("td").find("ul input");
                                                $(input).each(function () {
                                                    $(this).prop('checked', $(cbox).is(':checked')).change();
                                                });
                                            }
                                            $(document).ready(function () {
                                                @foreach (var cr in Model.AvailableCustomerGroups)
                                                {
                                                    <text>
                                                        $('#selectall-@(cr.Id)').click(function () {
                                                            $('.allow_@(cr.Id)').prop('checked', $(this).is(':checked')).change();
                                                        });
                                                    </text>
                                                }
                                            });
                                    </script>
                                        <div class="permissions-table-container">
                                            <div class="table-responsive">
                                                <table class="table table-bordered tableFixHead permissions-table">
                                                    <thead>
                                                    <tr>
                                                        <th class="first-th" scope="col">
                                                            <div class="d-flex justify-content-center align-items-center">
                                                                <strong>@Loc["Admin.Configuration.Permissions.Permission"]</strong>
                                                            </div>
                                                        </th>
                                                        @foreach (var cr in Model.AvailableCustomerGroups)
                                                        {
                                                            <th scope="col">
                                                                <div class="d-flex flex-column align-items-center justify-content-center">
                                                                    <strong>@cr.Name</strong>
                                                                    <input class="form-check-input" type="checkbox" id="selectall-@(cr.Id)"/>
                                                                </div>
                                                            </th>
                                                        }
                                                    </tr>
                                                    </thead>
                                                    <tbody>

                                                    @{
                                                        var altRow = true;
                                                        var group = Model.AvailablePermissions.GroupBy(x => x.Category);
                                                    }
                                                    @foreach (var pr in group)
                                                    {
                                                        altRow = !altRow;

                                                        <tr class="@(altRow ? "altrowstyle" : "rowstyle")">
                                                            <td>
                                                                @{
                                                                    var groupList = pr.ToList();
                                                                }
                                                                <button type="button" class="btn btn-outline-secondary title" data-bs-toggle="collapse" data-bs-target=".multi-collapse-@groupList[0].Category.GetHashCode()" aria-expanded="true" aria-controls="@groupList[0].Category.GetHashCode()-collapseMain">
                                                                    @groupList[0].Category <i class="bi bi-chevron-down" aria-hidden="true"></i>
                                                                </button>
                                                                <ul id="@groupList[0].Category.GetHashCode()-collapseMain" class="collapse show multi-collapse-@groupList[0].Category.GetHashCode()">
                                                                    @foreach (var item in groupList)
                                                                    {
                                                                        <li>
                                                                            <a class="btnUpdatePermission" href="@Url.Action("Update", new { area = Constants.AreaAdmin, item.SystemName })">@item.Name</a>
                                                                        </li>
                                                                    }
                                                                </ul>
                                                            </td>
                                                            @foreach (var cr in Model.AvailableCustomerGroups)
                                                            {
                                                                <td class="checkbox-container">
                                                                    <div class="title">
                                                                        <span>@cr.Name</span>
                                                                        <input class="form-check-input" type="checkbox" onclick="checkCategory(this)"/>
                                                                    </div>
                                                                    <ul class="collapse show multi-collapse-@groupList[0].Category.GetHashCode()">
                                                                        @foreach (var item in groupList)
                                                                        {
                                                                            var allowed = Model.Allowed.ContainsKey(item.SystemName) && Model.Allowed[item.SystemName][cr.Id];
                                                                            <li>
                                                                                <input class="form-check-input allow_@(cr.Id)" type="checkbox" value="@(item.SystemName)" name="allow_@(cr.Id)" @(allowed ? " checked=checked" : null)/>
                                                                                @if (item.Actions)
                                                                                {
                                                                                    <a class='text-decoration-none permissionlink ms-2'
                                                                                       href="@Url.Action("PermissionsAction", "Permission", new { area = Constants.AreaAdmin })/?systemname=@(item.SystemName)&[email protected]">
                                                                                        <i class="bi bi-gear"></i>
                                                                                    </a>
                                                                                    <script>
                                                                                            $(document).ready(function () {
                                                                                                $('.permissionlink').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>
                                                                                }
                                                                            </li>
                                                                        }
                                                                    </ul>
                                                                </td>
                                                            }
                                                        </tr>
                                                    }
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    }
        </admin-card>
    </admin-page>
</form>


<script>
    $(document).ready(function () {
            $('#btnAddNewPermission').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');
                    }
                }
            });
            $('.btnUpdatePermission').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>