
<div class="row">
    <div class="col-xs-12">
        <div class="box box-danger mb0">
            <div class="box-body table-responsive table-fixed-height">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="kategoriaFilter">Filtruj kategorię:</label>
                            <select id="kategoriaFilter" class="form-control">
                                <option value="">WSZYSTKIE</option>
                                <option value="TEST I">TEST I</option>
                                <option value="TEST 2">TEST 2</option>
                                <option value="INNE">INNE</option>
                            </select>
                        </div>
                    </div>
                </div>
                <table id="DokumentyTable" class="table hover-rows custom-table FullTable" data-start-sort="2"
                       data-start-sort-direction="desc" data-start-height="50vh">
                    <thead>
                    <tr class="text-uppercase">
                        <th>Nazwa dokumentu</th>
                        <th>Data publikacji</th>
                        <th>Kategoria dokumentu</th>
                        <th class="no-sortable"></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if (isset($documents['bDokumenty']['bDokument'])): ?>
                        <?php foreach ($documents['bDokumenty']['bDokument'] as $k => $document): ?>
                            <tr
                                <?php if (!empty($document['bInformacjeDodatkowe'])): ?>
                                    class="more-info-append" data-append-to="#more-info-container"
                                    data-more-info="<?php echo $document['bInformacjeDodatkowe']; ?>"
                                <?php endif; ?>
                            >
                                <td class="info-addon"><?php echo $document['bNazwa']; ?></td>
                                <td><span class="span-date"><?php echo $document['bDataPublikacji']; ?></span></td>
                                <td><?php echo ($document['bKategoriaKodOpis'] ?: 'INNE'); ?></td>
                                <td class="text-right">
                                    <div class="btn-group mr5">
                                        <a data-ajax-action="<?php echo $local_url; ?>dokument_historia/<?php echo $document['bGid']; ?>"
                                           class="btn btn-success">
                                            <i class="fa fa-history"></i>
                                        </a>
                                        <a data-open-tab="true"
                                           data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>?rodzaj=<?php echo $document['bRodzaj']; ?>"
                                           class="btn btn-primary">
                                            <i class="fa fa-eye"></i>
                                        </a>
                                        <a data-open-tab="true"
                                           data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>/download?rodzaj=<?php echo $document['bRodzaj']; ?>"
                                           class="btn btn-warning">
                                            <i class="fa fa-download"></i>
                                            <span><?php echo strtoupper($document['bRozszerzenie']); ?></span>
                                        </a>
                                    </div>
                                    <div class="btn-group">
                                        <?php if ($document['bCzyTrescUPO'] == 'true') : ?>
                                            <a data-open-tab="true"
                                               data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>?format=upo&rodzaj=<?php echo $document['bRodzaj']; ?>"
                                               class="btn btn-primary">
                                                <i class="fa fa-eye"></i>
                                            </a>
                                            <a data-open-tab="true"
                                               data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>/download?format=upo&rodzaj=<?php echo $document['bRodzaj']; ?>"
                                               class="btn btn-warning">
                                                <i class="fa fa-download"></i> <span>UPO</span>
                                            </a>
                                        <?php endif; ?>

                                        <?php if ($document['bCzyTrescXADES'] == 'true') : ?>
                                            <a data-open-tab="true"
                                               data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>/download?format=xades&rodzaj=<?php echo $document['bRodzaj']; ?>"
                                               class="btn btn-warning">
                                                <i class="fa fa-download"></i> <span>XADES</span>
                                            </a>
                                        <?php endif; ?>

                                        <?php if ($document['bCzyTrescXML'] == 'true') : ?>
                                            <a data-open-tab="true"
                                               data-href="<?php echo $local_url; ?>dokument/<?php echo $document['bGid']; ?>/download?format=xml&rodzaj=<?php echo $document['bRodzaj']; ?>"
                                               class="btn btn-warning">
                                                <i class="fa fa-download"></i> <span>XML</span>
                                            </a>
                                        <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="row more-info-container">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h2 class="box-title">Informacje dodatkowe</h2>
            </div>
            <div class="box-body" id="more-info-container">

            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.page-name:first-of-type').html('<?php echo $pageName; ?>');

        // Filter for the 3rd column (Kategoria dokumentu)
        $('#kategoriaFilter').on('change', function() {
            var table = $('#DokumentyTable').DataTable();
            var value = $(this).val();

            // If "WSZYSTKIE" is selected (empty value), clear the filter
            if (value === '') {
                table.column(2).search('').draw();
            } else {
                // Filter for exact match
                table.column(2).search('^' + value + '$', true, false).draw();
            }
        });

        $('[data-ajax-action]').click(function () {
            $('#table-loading2[data-main-loader]').css('visibility', 'visible');
            $('#table-loading2[data-main-loader]').css('opacity', '1');
            $('#table-loading2[data-main-loader]').css('display', 'block');
            var u = $(this).data('ajax-action');
            $.ajax({
                url: local_url + u
            }).done(function (resp) {
                $('#table-loading2[data-main-loader]').css('visibility', 'hidden');
                $('#table-loading2[data-main-loader]').css('opacity', '0');
                $('#table-loading2[data-main-loader]').css('display', 'none');
                $('#modal-history-show .modal-body').html(resp);
                $('#modal-history-show').modal('show');
            })
        });
        initiateDataTable(2);
    })
</script>

<div class="modal fade" id="modal-history-show">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Historia przetwarzania</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Zamknij</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

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