<!-- **********************************************************************************************************************************************************
    MAIN CONTENT
    *********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="content-panel">
                    <h4><i class="fa fa-angle-right"></i> Data Gallery Images</h4>
                    <section id="unseen" style="padding: 5px">
                        <form action="<?= base_url() ?>admin/gallery/simpanUpload" method="post" enctype="multipart/form-data" id="form-upload" class="form-horizontal">
                            <table class="table table-bordered table-striped table-condensed">
                                <thead>
                                    <tr>
                                        <td><input type="button" name="add_btn" value="Add" id="add_btn" class="btn btn-info"></td>
                                    </tr>
                                </thead>
                                <tbody id="fill">
                                    <tr>
                                        <td><label>Foto 1</label> <input name="image[]" type="file" class="form-control" /></td>
                                    </tr>
                                </tbody>
                                <tr>
                                    <td><input type="submit" id="submit-button" value="Upload" class="btn btn-primary" /></td>
                                </tr>
                            </table>
                        </form>
                    </section>
                    <div id="images" style="clear: both"></div> 

                    <div>
                        <div class="row">
                            <?php
                            if ($gallery->num_rows() > 0) {
                                foreach ($gallery->result() as $gp) {
                                    ?>

                                    <div class="col-xs-6 col-md-3">
                                        <a href="#" class="thumbnail">
                                            <img src="<?= base_url() ?>assets/gallery/<?= $gp->picture ?>" width="150" height="191">
                                        </a>
                                        <center>
                                            <a class="btn btn-danger btn-sm" href="<?= base_url() ?>admin/gallery/hapus/<?= $gp->id_picture ?>/<?= $gp->picture ?>">
                                                <i class="fa fa-trash"></i> Delete
                                            </a>
                                        </center>
                                    </div>
                                    <?php
                                }
                            } else {
                                echo "Belum ada Gambar di Gallery";
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--row -->
    </section>
</section>
<script>
    $(document).ready(function() {
        $("#image").hide();

        var count = 1;
        $("#add_btn").click(function() {
            count += 1;
            $('#fill').append('<tr class="records"><td><label>Foto ' + count + ' </label><input name="image[]" type="file" /> <a class="remove_item" href="#" >Delete</a></td></tr>');
        });

        $(".remove_item").live('click', function(ev) {
            if (ev.type == 'click') {
                $(this).parents(".records").fadeOut();
                $(this).parents(".records").remove();
            }
        });
    });
    function sukses() {
        $('#form-upload').resetForm();
        $('#submit-button').removeAttr('disabled');

    }
    function getProduct(id_kat) {
        $.ajax({
            type: "POST",
            url: "<?= base_url() ?>admin/products/getProduct",
            data: "id_kat=" + id_kat,
            success: function(data) {
                $("#product").html(data);
            }
        });
    }
    function getImage(id_prod) {
        $.ajax({
            type: "POST",
            url: "<?= base_url() ?>admin/products/getImage",
            data: "produk=" + id_prod,
            success: function(data) {
                $("#image").show();
                $("#images").html(data);
//                $("#img").attr('src', "<?= base_url() ?>assets/backend/img/portfolio/" + data);
//                $("#ahref").attr('href', "<?= base_url() ?>assets/backend/img/portfolio/" + data);
            }
        });
    }
</script>
