<?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('#config').addClass('active');
        $('#sidebar').find('#address').addClass('active');

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

        var oTable = $('#datatable').dataTable( {
            "responsive": true,
            // "order": [],
                // "bSort": false,
                "aaSorting": [],
            "iDisplayLength": 50
        } );

        $("#datatable").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.config.address.displayOrder')); ?>",
                dataType: 'json',
                success: function(data) {
                  if(!data['status']) {
                    swal('Oops...','Something went wrong!','error');
                  }
                }
              });
            },
        });

        $('#tablebody').on('click','.delete-page',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/config/address/')); ?>"+"/"+ 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: "POST",
                    url: "<?php echo e(url('/admin/config/address/change-status/')); ?>",
                    data:{id:id},
                    dataType: 'json',
                    success: function(response){
                        swal('Success',response.message, 'success');
                        if (response.address.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">
                Address
            </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.config.address.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="datatable">
                        <thead>
                            <tr>
                                <th>S N</th>
                                <th>Titile</th>
                                <th>Status</th>
                                <th>Options</th>
                            </tr>
                        </thead>
                        <tbody id="tablebody">
                            <?php $__empty_1 = true; foreach($addresses as $index=>$record): $__empty_1 = false; ?>
                            <tr class="gradeX" id="row_<?php echo e($record->id); ?>" >
                                <td>
                                    <?php echo e($index+1); ?>

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

                                </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.config.address.edit', $record->id); ?>" title="Edit  Page"><i class="fa fa-edit"></i></a>&nbsp;
                                    <a class="delete-page" href="javascript:;" id="<?php echo e($record->id); ?>" title="Delete  Page"><i class="fa fa-trash-o"></i></a>
                                </td>
                            </tr>
                                <?php endforeach; if ($__empty_1): ?>
                                <tr>
                                    <td colspan="4">No record found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>S N</th>
                                <th>Title</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(); ?>