<!-- MAIN CONTENT WRAPPER -->
<script src="assets/js/king-table.js"></script>

			<div class="content">
				<div class="main-content">
					<div class="row">
                    	
                        <div class="col-md-4">
							<!-- ADVANCED VALIDATION -->
							<div class="widget">
								<div class="widget-header">
									<h3><i class="fa fa-check-circle"></i> <?php echo e(__('grade.grade')); ?></h3></div>
								<div class="widget-content">
                    <form id="frmmain" name="frmmain" data-parsley-validate novalidate>
                    <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
					<input type="hidden" class="form-control" id="grd_id" name="grd_id" value="0" >
<?php echo csrf_field(); ?>           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li><?php echo e(__('grade.enter_details')); ?>...</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>
						
<div class="form-group">
	<label for="text-input1"><?php echo e(__('grade.grade')); ?>*</label>
	<input type="text" name="grd_grade" id="grd_grade" class="form-control" >
	<small class="text-danger" id="err_grd_grade"></small>
</div>
           					
<div class="form-group">
	<label for="text-input1"><?php echo e(__('grade.grade_code')); ?> (<?php echo e(__('grade.grade_code_note')); ?>)*</label>
	<input type="text" name="grd_prefix" id="grd_prefix" class="form-control" >
	<small class="text-danger" id="err_grd_prefix"></small>
</div>
             
<div class="form-group">
	<label><?php echo e(__('grade.description')); ?></label>
	<textarea class="form-control" name="grd_description" id="grd_description" rows="5" cols="30" ></textarea>
	<small class="text-danger" id="err_grd_description" ></small>
</div>
                
<div class="form-group">
	<label for="multiselect1"><?php echo e(__('grade.status')); ?>*</label>
	<br/>
	<select name="grd_status" id="grd_status" class="form-control " required>
		<option value="Active"><?php echo e(__('grade.Active')); ?></option>
		<option value="Inactive"><?php echo e(__('grade.Inactive')); ?></option>
	</select>
	<small class="text-danger" id="err_grd_status"></small>
</div>
                        <br/>
                        <button type="submit" id="submit" name="submit" class="btn btn-primary submit">Submit</button>
                    </form>
								</div>
							</div>
							<!-- END ADVANCED VALIDATION -->
						</div>
                    
						<div class="col-md-8">
							<!-- BASIC VALIDATION -->
								<div class="widget widget-table">
						<div class="widget-header">
							<h3><i class="fa fa-table"></i> <?php echo e(__('grade.grade_list')); ?></h3> 
                        </div>
						<div class="widget-content">
							<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
								<thead>
									<tr>
										<th><?php echo e(__('grade.grade')); ?></th>
										<th><?php echo e(__('grade.grade_code')); ?></th>
										<th><?php echo e(__('grade.description')); ?></th>
										<th><?php echo e(__('grade.status')); ?></th>
										<th><?php echo e(__('mylanguage.action')); ?></th>
									</tr>
								</thead>
								<tbody>
								<?php $__currentLoopData = $data['grade']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $grade): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
									<tr>
										<td><?php echo e($grade->grd_grade); ?></td>
										<td><?php echo e($grade->grd_prefix); ?></td>
										<td><?php echo e($grade->grd_description); ?></td>
										<td><?php echo e($grade->grd_status); ?></td>
										
																		<?php 
	if($data['edit']=='1' || $data['delete']=='1'){ echo'<td>';}
?>
<?php 
	if($data['edit']=='1'){echo'<button class="btn btn-default btn-xs print" onclick="Edit('.$grade->grd_id.')"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>' . __("mylanguage.edit") . '</button>'; } if($data['delete']=='1'){echo' <button class="btn btn-default btn-xs print" onclick="Delete('.$grade->grd_id.')"><i class="fa fa-trash" aria-hidden="true"></i>' . __("mylanguage.delete") . '</button>';} echo '</td>';
?>
									</tr>
								<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
								</tbody>
							</table>
							
						</div>
					</div>
							<!-- END BASIC VALIDATION -->
						</div>

					</div>
				</div>
			</div>
			<!-- /main -->

<script type="application/javascript">
i=0;
	//$(document).on('submit', '#frmmain', function()
	$('.submit').click(function()
	{
			$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
		   
			var _token = $("input[name='_token']").val();
			var grd_grade =  $("input[name='grd_grade']").val();
			var grd_prefix = $("input[name='grd_prefix']").val();
			var grd_description = $("#grd_description").val();
			var grd_status = $("#grd_status").val();			
			//document.getElementById("errusertype").innerHTML = "";
			
			/*
			if(branch == "0")
			{
				document.getElementById("errbranch").innerHTML = "Kindly select the branch...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(usertype == "")
			{
				document.getElementById("errusertype").innerHTML = "User type should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
			}
			else
			*/
			{
			  if(i==0)
			  { 
			   i++;
			   //alert(i);
					$.ajax({
						url: "/insertgrade",
						type:'POST',
						data: /* {_token:_token,branch:branch, usertype:usertype, description:description, status:status} */
						$('#frmmain').serialize(),
						success: function(data) {											
							if(data.status == 1)
							{
								printSuccessMsg(data.message);
								$('#sideMenu').load('loadgrade');
							}
							else
							{
								printErrorMsg(data.message)
							}
						}
					});					   
				}						
			}						


		return false;
	});    
		function printErrorMsg (msg) {
			$(".alert-info").css('display','none');
			$(".print-success-msg").css('display','none');
			$(".print-error-msg").find("ul").html('');
			$(".print-error-msg").css('display','block');
			$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
		}
		
		function printSuccessMsg (msg) {
			$(".alert-info").css('display','none');
			$(".print-error-msg").css('display','none');
			$(".print-success-msg").find("ul").html('');
			$(".print-success-msg").css('display','block');
			$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
			//Code to redirect page
			//var url = "/dashboard";
			//$(location).attr('href',url);
		}
</script>	
<script>
	function Edit(id)
	{
		$.ajax({
			type: "GET",
			url:"/editgrade",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
				$.each(data,function(i,obj)
				{	   				
					$('#grd_id').val(obj.grd_id);
					$('#grd_grade').val(obj.grd_grade);
					$('#grd_prefix').val(obj.grd_prefix);
					$('#grd_description').val(obj.grd_description);
					$('#grd_status').val(obj.grd_status);
				});  
			}
		});
	}
	function Delete(id)
	{
		if(confirm("Are you sure want to delete this record?") == true)
		{
			//alert(id);
			k = 0;
			if(k == 0)
			{
				k++;
				$.ajax({
					type: "GET",
					url:"/deletegrade",
					dataType: "json",
					data: {
						'_token': $('input[name=_token]').val(),
						'id': id
					},
					success: function (sdata) {
						if(sdata.status == 1)
						{
							printSuccessMsg(sdata.message);
							$('#sideMenu').load('loadgrade');
						}
						else
						{
							printErrorMsg(sdata.message)
						}
					}
				});
			}
		}
	}
</script>				  