<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger">
            <?php if ($uprawnienia['ModulRejestruBezpieczenstwa']['bCzyDodawanie'] == 'true') : ?>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-right">
                            <a data-menu-action="dodaj_role" href="dodaj_role" class="btn btn-success btn-flat">
                                <span style="margin-right: 10px;"><i class="fa fa-plus"></i> Dodaj</span>
                                <label class="switch"></label>
                            </a>
                        </div>
                    </div>
                </div>
            <?php endif; ?>

            <div class="box-body table-responsive table-fixed-height" style="max-height: 85vh!important;">
                <table id="RolesTable" class="table hover-rows custom-table" data-start-height="65vh">
                    <thead>
                    <tr class="text-uppercase">
                        <th>Nazwa</th>
                        <th class="no-sortable"><i class="fa fa-wrench pull-right"></i></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if (!empty($roles['bRole'])) : ?>
                        <?php foreach ($roles['bRole']['bRola'] as $k => $role): ?>
                            <tr>
                                <td>
                                    <div class="role-name"><?php echo $role['bNazwa']; ?></div>
                                    <div
                                        class="role-description"><?php echo (!empty($role['bOpis'])) ? $role['bOpis'] : ''; ?></div>
                                </td>
                                <td>
                                    <div class="table-actions pull-right">
                                        <?php if ($uprawnienia['ModulRejestruBezpieczenstwa']['bCzyEdycja'] == 'true') : ?>
                                            <a data-menu-action="edytuj_role/<?php echo $role['bGid']; ?>"
                                               href="edytuj_role/<?php echo $role['bGid']; ?>"
                                               class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                                        <?php endif; ?>
                                        <a data-menu-action="uprawnienia_roli/<?php echo $role['bGid']; ?>"
                                           href="uprawnienia_roli/<?php echo $role['bGid']; ?>" class="btn btn-warning"><i
                                                class="fa fa-lock"></i></a>
                                        <a data-menu-action="uzytkownicy_roli/<?php echo $role['bGid']; ?>"
                                           href="uzytkownicy_roli/<?php echo $role['bGid']; ?>" class="btn btn-info"><i
                                                class="fa fa-users"></i></a>

                                        <?php if ($uprawnienia['ModulRejestruBezpieczenstwa']['bCzyUsuwanie'] == 'true') : ?>
                                            <a class="btn btn-danger" data-remove-entry
                                               data-gid="<?php echo $role['bGid']; ?>" data-url="usun_role"
                                               data-title="Na pewno usunąć rolę?"><i class="fa fa-trash"></i></a>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<script>
    $(function(){
        const elemsData = document.querySelectorAll('[data-menu-action]');
        elemsData.forEach(elem => elem.onclick = testFun);
    });

    function testFun(e) {
        e.preventDefault();

        $(this).parents('.sidebar').find('li.active:not(.treeview)').removeClass('active');
        $(this).parents('li').addClass('active');

        var url = $(this).data('menu-action');
        localStorage.setItem('menu_action', url);

        loadAjaxView(url);
    }
</script>

<?php echo $this->element('alert_close'); ?>
