<?php $__env->startSection('content'); ?>
<div class="content-wrapper">

	<section class="content-header">
		<h1 class="pull-left">
			<?php echo e($title); ?> List
		</h1>
		<span class="pull-right">
			<a href="<?php echo e(route($route.'create')); ?>" class="btn btn-success"> <i class="fa fa-plus"></i> Add new</a>
		</span>
		<p>&nbsp;</p>
	</section>

	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<?php echo $__env->make('flash', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
				<div class="box box-info">
					<div class="box-body">
						<table id="datatable1" class="table table-bordered table-striped">
							<thead>
							<tr>
								<th>Link</th>
								
								<th width="100px">Status</th>
								<th width="100px">Action</th>
							</tr>
							</thead>
							<tbody>
							
							</tbody>
							<tfoot>
							<tr>
								<th>Link</th>
								
								<th>Status</th>
								<th>Action</th>
							</tr>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</section>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
		<!-- DataTables -->
<script type="text/javascript">

	$(document).ready(function () {
		var oTable = $('#datatable1').DataTable({
            responsive: true,
            autoWidth: false,
			stateSave: true,
			processing: true,
			serverSide: true,
			ajax: '<?php echo e(url('admin/video')); ?>',
			columns: [
				{data: 'link', name: 'link'},
				
				{data: 'status', name: 'status', searchable: false,orderable : false,className : 'text-center'},
				{data: 'action', name: 'action', searchable: false, orderable : false,className : 'text-center'},
			],
			
		});

		$('#datatable1').on('draw.dt', function () {
			$('.chk_status').each(function () {
				$(this).bootstrapToggle();
			});
		});
		$("body").on("change", ".chk_status", function () {
			var row_id = $(this).val();
			if ($(this).is(':checked')) {
				var status = $(this).attr('data-on');// If checked
			} else {
				var status = $(this).attr('data-off'); // If not checked
			}

			$.ajax({
				type: "PUT",
				url: '<?php echo e(url('admin/video')); ?>/' + row_id ,
				data: {
					"_token": "<?php echo e(csrf_token()); ?>",
					"id": row_id,
					"status": status,
				},
				beforeSend: function () {
					$('#datatable1').waitMe({effect: 'roundBounce'});
				},
				complete: function () {
					$('#datatable1').waitMe('hide');
				},
				error: function (e) {
					if (e.status == 403) {
						alert('Unauthorized: Access is denied due to invalid credentials.');
					}else{
						//alert('Error: ' + e);
						alert('internal error occurred.');
					}
				},
				success: function (result) {
					//Success Code.
				}
			});
		});

		$("#datatable1").on('click', '.data-delete', function () {
			var obj = $(this);
			var id = $(this).attr('data-id');

			if (confirm("Are you sure to Delete Data?")) {
				$.ajax({
					type: "DELETE",
					url: "<?php echo e(url('admin/video')); ?>/" + id,
					data: {
						id: id,
						_token: "<?php echo e(csrf_token()); ?>"
					},
					dataType: 'json',
					beforeSend: function () {
						$(this).attr('disabled', true);
						$('.alert .msg-content').html('');
						$('.alert').hide();
					},
					success: function (resp) {
						oTable.ajax.reload();
						alert(resp.message);
					},
					error: function (e) {
						if (e.status == 403) {
							alert('Unauthorized: Access is denied due to invalid credentials.');
						}else{
							//alert('Error: ' + e);
							alert('internal error occurred.');
						}
					}
				});
			}
		});
	});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layout.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>