<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger">
            <?php echo $this->Form->create(null, ['templates' => ['submitContainer' => '{{content}}',], 'id' => 'tem:pZadanie', 'name' => 'tem:pZadanie', 'class' => 'form-horizontal']); ?>
            <div class="box-body table-fixed-height" style="max-height: 85vh!important;">
                <div class="col-xs-12">
                    <?php echo $this->Form->input('tem:pZadanie.dat:GidRoli', array('type' => 'hidden', 'value' => $this->request->getData()['tem:pZadanie']['dat:GidRoli'])); ?>
                    <table id="UsersRoleTable" data-container="table" class="custom-table table" data-start-height="65vh">
                        <thead>
                        <th>Nazwa</th>
                        <th>Opis</th>
                        <th class="no-sortable"></th>
                        </thead>
                        <?php foreach ($this->request->getData()['tem:pZadanie']['dat:Uzytkownicy']['dat:Uzytkownik'] as $userKey => $user): ?>
                            <tr>
                                <?php foreach ($user as $field => $value): ?>
                                    <?php if ($field !== 'dat:CzyZaznaczenie'): ?>
                                        <?php echo $this->Form->input('tem:pZadanie.dat:Uzytkownicy.' . $userKey . '.dat:Uzytkownik.' . $field, array('type' => 'hidden', 'value' => $value)); ?>
                                    <?php else: ?>
                                        <td>
                                            <?php echo $user['dat:Nazwa']; ?>
                                        </td>
                                        <td>
                                            <?php echo $user['dat:Opis']; ?>
                                        </td>
                                        <td class="text-right">
                                            <?php
                                            $checked = false;
                                            if ($value == 'true') {
                                                $checked = true;
                                            }
                                            ?>
                                            <?php echo $this->Form->checkbox('tem:pZadanie.dat:Uzytkownicy.' . $userKey . '.dat:Uzytkownik.' . $field, array('checked' => $checked)); ?>
                                        </td>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </tr>
                        <?php endforeach; ?>
                    </table>
                </div>

                <div class="row mt20">
                    <div class="col-xs-12">
                        <a data-menu-action="administracja_role" class="btn btn-default pull-left margin-r-5" href="administracja_role">Anuluj</a>
                        <?php echo $this->Form->submit('Zapisz', array('id' => 'submitForm-UzytkownicyRoli', 'class' => 'btn btn-success pull-left')); ?>
                    </div>
                </div>
            </div>
            <?php echo $this->Form->end(); ?>
        </div>
    </div>
</div>

<style>
    .dataTables_scrollBody {
        overflow-x: hidden!important;
    }
</style>

<script>
    $(function () {
         setTimeout(function () {
             $('#UsersRoleTable_filter').append('<label id="showAllChecked"><input type="checkbox" /> Pokaż tylko wybranych</label>');
         }, 500);
    });
</script>

<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'); ?>
