<div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <span>Sistema</span>
            <i class="fa fa-circle"></i>
        </li>
        <li>
            <span>Parametros</span>
            <i class="fa fa-circle"></i>
        </li>
        <li>
            <span>Periodo</span>
            <i class="fa fa-circle"></i>
        </li>
        <li>
            <span>Lista</span>
        </li>
    </ul>
</div>
<div class="portlet">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-list"></i>
            <span class="caption-subject font-dark bold uppercase">Listando Periodos</span>
        </div>
        <div class="actions">
            <a href="painel.php?exe=sistema/periodo_create" class="btn btn-xs blue" alt="Add Nova" title="Add Nova"><i class="fa fa-plus"></i></a>
        </div>
    </div>  
    <?php
    $empty = filter_input(INPUT_GET, 'empty', FILTER_VALIDATE_BOOLEAN);
    if ($empty):
        WSErro("Você tentou editar um departamento que não existe no sistema!", WS_INFOR);
    endif;

    $delDep = filter_input(INPUT_GET, 'delete', FILTER_VALIDATE_INT);
    if ($delDep):
        require ('_models/AdminAcaoRetorno.class.php');
        $deletar = new AdminAcaoRetorno;
        $deletar->ExeDelete($delDep);

        WSErro($deletar->getError()[0], $deletar->getError()[1]);
    endif;
    ?>
    <div class="portlet-body">
        <table class="table table-striped table-bordered table-hover table-checkable order-column j_acao_retorno" id="sample_1">
            <thead>
                <tr>
                    <th> Periodo </th>
                    <th> Meses </th>
                    <th> Ação </th>
                </tr>
            </thead>
            <tbody>
                <?php
                $Read = new Read;
                $Read->ExeRead("tp_periodos");
                if (!$Read->getResult()):
                    echo '<tr>';
                    echo '<td class="text-center" colspan="3">';
                    WSErro("Sem resultados!", WS_INFOR);
                    echo '</td>';
                    echo '</tr>';
                else:
                    foreach ($Read->getResult() as $periodos):
                        extract($periodos);
                        ?>
                        <tr class="odd gradeX">
                            <td>
                                <?= $periodo_nome; ?>
                            </td>
                            <td>
                                <?= $periodo_meses; ?>
                            </td>
                            <td>
                                <a href="painel.php?exe=sistema/periodo_update&estid=<?= $periodo_id; ?>" class="btn btn-xs green"><i class="fa fa-edit"></i></a>
                                <a href="painel.php?exe=sistema/periodo_lista&delete=<?= $periodo_id; ?>" class="btn btn-xs red"><i class="fa fa-times"></i></a>                            
                            </td>
                        </tr>
                        <?php
                    endforeach;
                endif;
                ?>
            </tbody>
        </table>
    </div>

</div>

<script type="text/javascript">
    function excluirCat(id, item) {
        $(".trigger").remove();

        $.ajax({
            url: '__jsc/ajax/acao_retorno_create.php',
            type: 'POST',
            data: {acao_retorno_id: id, action: 'delet'},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                $("<div class=\"trigger " + data.error[1] + "\">" + data.error[0] + "</div>").prependTo(".j_acao_retorno");

                if (data.error[1] == 'accept') {
                    var tr = $(item).closest('tr');
                    tr.fadeOut(400, function () {
                        tr.remove();
                    })
                }
                console.log(tr);
            }
        })
    }
</script>