<?php $__env->startSection('header_css'); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('footer_js'); ?>
<!-- Table Drag and Drop -->
<script src="<?php echo e(asset('js/jquery.tablednd_0_5.js')); ?>"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#sidebar li').removeClass('active');
        $('#sidebar a').removeClass('active');
        $('#sidebar').find('#gallery').addClass('active');
        $('#sidebar').find('#banner').addClass('active');

        var oTable = $('#banner-table').dataTable({
                // stateSave: false,
                responsive: true,
                // "order": [],
                // "bSort": false,
                "aaSorting": [],
                /*"columnDefs": [{
                              "defaultContent": "-",
                              "targets": "_all"
                            }]*/
            });

        $("#banner-table").tableDnD({
            onDragClass: "tDnD_whileDrag",
            onDrop: function(table, row) {
              var rows = table.tBodies[0].rows;
              var order = '';
              for (var i=0; i<rows.length; i++) {
                order += rows[i].id+" ";
              }
              var sortOrder = new Array();
              sortOrder.push({name: 'order', value: order});
              jQuery.ajax({
                type: 'post',
                data: sortOrder,
                url: "<?php echo e(route('admin.gallery.banner.displayOrder')); ?>",
                dataType: 'json',
                success: function(data) {
                  if(!data['status']) {
                    swal('Oops...','Something went wrong!','error');
                  }
                }
              });
            },
        });

        $('#tablebody').on('click','.delete-banner',function(e){
            e.preventDefault();
            $object = $(this);
            var id = $object.attr('id');
            swal({
              title: 'Are you sure?',
              text: "You won't be able to revert this!",
              type: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes, delete it!'
            }).then(function () {
                $.ajax({
                    type: "DELETE",
                    url: "<?php echo e(url('/admin/gallery/banner/')); ?>"+"/"+ id,
                    dataType: 'json',
                    success: function(response){
                        if(response.type == 'success'){
                            var nRow = $($object).parents('tr')[0];
                            oTable.fnDeleteRow(nRow);
                            swal('Success',response.message, 'success');
                        } else {
                            swal('Warning',response.message, 'error');
                        }
                    },
                    error: function(e){
                        swal('Oops...','Something went wrong!','error');
                    }
                });
            });       
        });

        $('#tablebody').on('click','.change-status',function(e){
            e.preventDefault();
            $object = $(this);
            var id = $object.attr('id');
            swal({
              title: 'Are you sure?',
              text: "You are going to change the status!",
              type: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes, change it!'
            }).then(function () {
                $.ajax({
                    type: "PUT",
                    url: "<?php echo e(url('/admin/gallery/banner/change/status/')); ?>",
                    data:{id:id},
                    dataType: 'json',
                    success: function(response){
                        swal('Success',response.message, 'success');
                        if (response.banner.is_active == 1) {
                            $($object).children().removeClass('fa-ban');
                            $($object).children().addClass('fa-check-square-o');
                            $($object).attr('title', 'Deactivate');
                        } else {
                            $($object).children().removeClass('fa-check-square-o');
                            $($object).children().addClass('fa-ban');
                            $($object).attr('title', 'Activate');
                        }
                    },
                    error: function(e){
                        swal('Oops...','Something went wrong!','error');
                    }
                });
            });            
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('dynamicdata'); ?>

<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                Banners
            </header>
            <div class="panel-body">
                <?php echo $__env->make('layout.backend.alert', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                <div class="adv-table editable-table ">                 
                    <div class="btn-group">
                        <a href="<?php echo route('admin.gallery.banner.create'); ?>" class="btn btn-primary btn-lg">Add New <i class="fa fa-plus"></i>
                        </a>
                    </div>
                    <table class="display table table-bordered table-striped" id="banner-table">
                        <thead>
                            <tr>
                                <th>
                                    S N
                                </th>
                                <th>
                                    Caption
                                </th>
                                <th>
                                    Image
                                </th>
                                <th>
                                    Status
                                </th>
                                <th>
                                    Options
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tablebody">
                            <?php $__empty_1 = true; foreach($banners as $index=>$record): $__empty_1 = false; ?>
                            <tr class="gradeX" id="banner_<?php echo e($record->id); ?>" >
                                <td>
                                    <?php echo e($index+1); ?>

                                </td>
                                <td class="caption">
                                    <?php echo e(strip_tags($record->caption)); ?>

                                </td>
                                <td class="image">
                                    <?php if(file_exists('uploads/banners/'.$record->attachment) && $record->attachment!=''): ?>
                                        <img src="<?php echo e(asset('uploads/banners/admin_thumbs/'.$record->attachment)); ?>" alt="" width="150">
                                    <?php else: ?>
                                        <img src="<?php echo e(asset('uploads/noimage.jpg')); ?>" alt="" width="150">
                                    <?php endif; ?>
                                </td>
                                <td class="center is_active">
                                    <?php if($record->is_active == 1): ?>
                                    <a href="javascript:;" class="change-status" title="Deactivate" id="<?php echo e($record->id); ?>"><i class="fa fa-check-square-o"></i></a>
                                    <?php else: ?>
                                    <a href="javascript:;" class="change-status" title="Activate" id="<?php echo e($record->id); ?>"><i class="fa fa-ban"></i></a>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <a href="<?php echo route('admin.gallery.banner.edit', $record->id); ?>" title="Edit Banner"><i class="fa fa-edit"></i></a>&nbsp;
                                    <a class="delete-banner" href="javascript:;" id="<?php echo e($record->id); ?>" title="Delete Banner"><i class="fa fa-trash-o"></i></a>
                                </td>
                            </tr>
                                <?php endforeach; if ($__empty_1): ?>
                                <tr>
                                    <td colspan="5">No record found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>
                                    S N
                                </th>
                                <th>
                                    Caption
                                </th>
                                <th>
                                    Image
                                </th>
                                <th>
                                    Status
                                </th>
                                <th>
                                    Options
                                </th>
                            </tr>
                        </tfoot>
                    </table>

                </div>
            </div>
        </section>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.backend.containerlist', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>