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


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

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

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

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