<!-- **********************************************************************************************************************************************************
    MAIN CONTENT
    *********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb"><i class="fa fa-angle-right"></i>Change Order Sub Menu</h4>
                    <section id="unseen">
                        <div id="pesan"></div>
                        <table class="table table-bordered table-striped table-condensed">
                            <thead>
                                <tr>
                                    <th>Main Menu</th>
                                    <th>Sub Menu</th>
                                    <th>No Urut</th>
                                    <th>&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($data_sub_menu->num_rows() == 0) {
                                    echo "<tr><td colspan='4'>Data Belum Ada</td></tr>";
                                } else {
                                    foreach ($data_sub_menu->result() as $sub) {
                                        ?>
                                        <tr>
                                            <td><?= $sub->menu_name ?></td>
                                            <td><?= $sub->title ?></td>
                                            <td class="numeric">
                                                <input type="text" value="<?= $sub->order ?>" id="order_<?= $sub->id_sub_menu ?>">
                                            </td>
                                            <td class="numeric">
                                                <button type="button" class="btn btn-primary btn-xs" onclick="return changeOrder('<?= $sub->id_sub_menu ?>')">Update</button>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                        <a href="<?= base_url() ?>admin/sub_menu">
                            <button type="button" class="btn btn-default"><i class="fa fa-arrow-left"></i> Back Sub Menu</button>
                        </a>
                    </section>
                    <div style="clear: both"></div>
                </div>
            </div>
        </div><!--row -->
    </section>
</section>
<script>
    function changeOrder(id_sub_menu) {
        var order = $("#order_"+id_sub_menu).val();
        $.ajax({
            type: "POST",
            data: "id_sub_menu=" + id_sub_menu + "&order=" + order,
            url: "<?= base_url() ?>admin/sub_menu/updateOrder",
            success: function(data) {
                $("#unseen").load();
                $("#pesan").html(data);
            }
        });
    }
</script>
