<script type="text/javascript">
    function order() {
        $("#events-table").find("tbody").sortable({
            opacity: 0.6,
            cursor: "move",
            placeholder: "placeholder",
            helper: fixHelper,
            axis: "y",
            update: function() {
                var order = $(this).sortable("serialize");
                $.post(prefix + "events/reorder", order, function(data) {
                });
            }
        });
    }

    $(function () {
        order();
    });
</script>

<section class="content-header">
    <h1><?= __('Events') ?></h1>

    <div class="actions">
        <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/events/config') ?>"><?= __('Config') ?></a>
        <a data-ajax class="btn btn-success btn-sm" href="<?= admin_url_to('/events/add') ?>"><?= __('Add') ?></a>
    </div>
</section>

<section class="content">
    <?php if (empty($events)): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No events found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default table-responsive">
            <table id="events-table" class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th><?= __('Name') ?></th>
                        <th><?= __('Category') ?></th>
                        <th width="10"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($events as $event): ?>
                        <tr id="sequence_<?= $event['id'] ?>">
                            <td>
                                <i class="fa fa-bars"></i> <?= $event['name'] ?>
                            </td>
                            <td><?= $event['category'] ?></td>
                            <td class="record-actions">
                                <a data-ajax class="btn btn-default btn-xs" href="<?= admin_url_to('/events/edit/' . $event['id']) ?>"><?= __('Edit') ?></a>
                                <a data-ajax-delete class="btn btn-danger btn-xs"href="<?= admin_url_to('/events/delete/' . $event['id']) ?>"><?= __('Delete') ?></a>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>
        </div>
    <?php endif ?>
</section>