

<?php $__env->startSection('title','Categories'); ?>

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

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

<div class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-heading">List of Categories</div>
			<div class="panel-body">
				<?php if(count($categories)>0): ?>
				<table class="table table-striped table-responsive">
					<thead>
						<tr>
							<th>Name</th>
							<th>Image</th>
							<th>Actions</th>
						</tr>
					</thead>
					<tbody>
						<?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
						<tr>
							<td><?php echo e($category->name); ?></td>
							<td><img src="<?php echo e(asset('images/'.$category->image)); ?>" class="img-responsive img-thumbnail" alt="<?php echo e($category->name); ?>"></td>
							<td class="text-center"> <p> <a id="editBtn" data-categoryname="<?php echo e($category->name); ?>" data-id="<?php echo e($category->id); ?>" data-description="<?php echo e($category->description); ?>" data-jobtitles="<?php echo e($category->job_titles); ?>" data-categoryimage="<?php echo e(asset('images/'.$category->image)); ?>" href="#" class="btn btn-warning" data-toggle="modal" data-target="#editModal">Edit</a> </p> <p> <a id="deleteCategory" data-id="<?php echo e($category->id); ?>" href="#" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Delete</a> </p></td>
						</tr>
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
					</tbody>                                        
				</table>
				<?php echo e($categories->links()); ?>

				<?php else: ?>
				No categories found.
				<?php endif; ?>
			</div>
		</div>
	</div>
</div>

<div id="editModal" class="modal fade" role="dialog">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title">Edit category</h4>
			</div>
			<div class="modal-body">
				<?php echo $__env->make('errors.form', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
				<form id="editForm" enctype="multipart/form-data" method="POST" action="<?php echo e(url('/admin/category')); ?>">
					<?php echo e(csrf_field()); ?>

					<input type="hidden" name="_method" value="PATCH">
					<input type="hidden" id="category_id" name="category_id" value="0">
					<div class="form-group">
						<label>Category Name</label>
						<input type="text" id="current_category_name" name="name" class="form-control" required>
					</div>
					<div class="form-group">
						<label>Description</label>
						<textarea id="description" name="description" class="form-control" required></textarea>
					</div>
					<div class="form-group">
						<label>Job Titles (seperated by enter)</label>
						<textarea id="job_titles" name="job_titles" class="form-control" required></textarea>
					</div>
					<div class="form-group">
						<label>Current Category Image</label>
						<img id="current_category_image" class="img-responsive" alt="No Image Found">
					</div>
					<div class="form-group">
						<label>New Category Image</label>
						<input type="file" name="image" class="btn btn-info">
						<span class="help-block">(Do not upload new image if you do not require to change the old image.)</span>
					</div>
					<input type="submit" name="submit" value="Edit Category" class="btn btn-success">
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			</div>
		</div>
	</div>
</div>

<div id="deleteModal" class="modal fade" role="dialog">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title">Delete category</h4>
			</div>
			<div class="modal-body">
				<p>Are you sure you want to delete this category?</p>
				<form id="deleteCategoryForm" method="POST" action="<?php echo e(url('/admin/category')); ?>">
					<?php echo e(csrf_field()); ?>

					<input id="category_id" type="hidden" name="category_id" value="">
					<input type="hidden" name="_method" value="DELETE">
					<input type="submit" name="submit" value="Yes" class="btn btn-success">
					<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			</div>
		</div>
	</div>
</div>
<?php $__env->stopSection(); ?>

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

<script type="text/javascript">
	$(document).on('click','#deleteCategory',function(){
		var file = $(this).data('id');
		$("#deleteCategoryForm #category_id").val(file);
	});

	$(document).on('click','#editBtn',function(){
		var categoryId = $(this).data('id');
		var categoryName = $(this).data('categoryname');
		var description = $(this).data('description');
		var jobTitles = $(this).data('jobtitles');
		var categoryImage = $(this).data('categoryimage');
		$("#editForm #category_id").val(categoryId);
		$("#editForm #current_category_name").val(categoryName);
		$("#editForm #description").val(description);
		$("#editForm #job_titles").val(jobTitles);
		$("#editForm #current_category_image").attr('src',categoryImage);
	});
</script>

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


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