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

<?php $__env->stopSection(); ?>
<?php $__env->startSection('footer_js'); ?>
<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('#album').addClass('active');

        var oTable = $('#photo-table').dataTable({
                responsive: true,
                "aaSorting": []
            });

        $('#tablebody').on('click','.delete-photo',function(e){
            var parent_id = '<?php echo $category->id; ?>';
            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/research/category/')); ?>"+"/"+ parent_id + '/publication/'+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/research/publication/change-status/')); ?>",
                    data:{id:id},
                    dataType: 'json',
                    success: function(response){
                        swal('Success',response.message, 'success');
                        if (response.model.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">
                Research Publications : <?php echo $category->heading; ?>

            </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.research.category.publication.create', $category->id); ?>" 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="photo-table">
                        <thead>
                            <tr>
                                <th style="width:7%;">S N</th>
                                <th style="width:30%;">Title</th>
                                <th style="width:26%;">Author</th>
                                <th style="width:15%;">Published Date</th>
                                <th style="width:10%;">Status</th>
                                <th style="width:12%;">Options</th>
                            </tr>
                        </thead>
                        <tbody id="tablebody">
                            <?php $__empty_1 = true; foreach($category->publications 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="caption"><?php echo e($record->title); ?></td>
                                <td class="caption"><?php echo e($record->author); ?></td>
                                <td class="caption"><?php echo e($record->publish_date); ?></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.research.category.publication.edit', [$category->id, $record->id]); ?>" title="Edit Publication"><i class="fa fa-edit"></i></a>&nbsp;
                                    <?php if($record->attachment && file_exists(public_path('uploads/research/'.$record->attachment) ) ) { ?>
                                    <a target="_blank" href="<?php echo route('admin.research.publication.download', [$category->id, $record->id]); ?>" title="Download Attachment"><i class="fa fa-download"></i></a>&nbsp;
                                    <?php } ?>                                    
                                    <a class="delete-photo" href="javascript:;" id="<?php echo e($record->id); ?>" title="Delete Publication"><i class="fa fa-trash-o"></i></a>
                                </td>
                            </tr>
                                <?php endforeach; if ($__empty_1): ?>
                                <tr>
                                    <td colspan="6">No record found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>S N</th>
                                <th>Title</th>
                                <th>Author</th>
                                <th>Published Date</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(); ?>