<!-- 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(__('usertype.user_type')); ?> </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" id="ut_id" name="ut_id" >
<input type="hidden" id="branch" name="branch" 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(__('usertype.enter_usr_type')); ?></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(__('usertype.user_type')); ?> *</label>
	<input type="text" name="usertype" id="usertype" class="form-control" >
	<small class="text-danger" id="errusertype"></small>
</div>
                        
<div class="form-group">
	<label><?php echo e(__('usertype.note')); ?></label>
	<textarea class="form-control" name="description" id="description" rows="5" cols="30" ></textarea>
	<small class="text-danger" id="errdescription" ></small>
</div>
                
<div class="form-group">
	<label for="multiselect1"><?php echo e(__('usertype.status')); ?>*</label>
	<br/>
	<select name="status" id="status" class="form-control input-lg" 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="errstatus"></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(__('usertype.view_usertype')); ?></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(__('usertype.user_type')); ?></th>
										<th><?php echo e(__('usertype.note')); ?></th>
										<th><?php echo e(__('usertype.status')); ?></th>
										<th><?php echo e(__('mylanguage.action')); ?></th>
									</tr>
								</thead>
								<tbody>
								<?php $__currentLoopData = $data['UserType']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $UserType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
									<tr>
										<td><?php echo e($UserType->ut_type); ?></td>
										<td><?php echo e($UserType->ut_description); ?></td>
										<td><?php echo e($UserType->ut_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('.$UserType->ut_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('.$UserType->ut_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 branch =  $('#branch').val();
			var usertype = $("input[name='usertype']").val();
			var description = $("#description").val();
			var status = $("#status").val();			
			document.getElementById("errusertype").innerHTML = "";
			
			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: "/utype",
						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('usertype');
							}
							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);
		}
	//load branch
	$(document).ready(function(){
		var br_id = $('#br_id').val();
		$.ajax({
		type: "GET",
		url:"/loadbranch",
		dataType: "json",
		success: function (data) {
		$.each(data,function(i,obj)
		{
			if(br_id ==0)
			{
				var div_data="<option value="+obj.br_id+">"+obj.br_name+"</option>";	
			}
			else 
			{
				if(br_id == obj.br_id)
				{
					var div_data="<option value="+obj.br_id+" selected>"+obj.br_name+"</option>";	
				}
				else{
					var div_data="<option value="+obj.br_id+">"+obj.br_name+"</option>";		
				}
			}
		 $(div_data).appendTo('#branch'); 
		});  
		}
		});
	});
</script>	
<script>
	function Edit(id)
	{
		$.ajax({
			type: "GET",
			url:"/editusertype",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
				$.each(data,function(i,obj)
				{	   				
					$('#ut_id').val(obj.ut_id);
					$('#branch').val(obj.br_id);
					$('#usertype').val(obj.ut_type);
					$('#description').val(obj.ut_description);
					$('#status').val(obj.ut_status);
					// $('#btnadd').val("UPDATE"); 
				});  
			}
		});
	}
	function Delete(id)
	{
		if(confirm("Are you sure want to delete this record?") == true)
		{
			k = 0;
			if(k == 0)
			{
				k++;
				$.ajax({
					type: "GET",
					url:"/delusertype",
					dataType: "json",
					data: {
						'_token': $('input[name=_token]').val(),
						'id': id
					},
					success: function (sdata) {
						if(sdata.status == 1)
						{
							printSuccessMsg(sdata.message);
							$('#sideMenu').load('usertype');
						}
						else
						{
							printErrorMsg(sdata.message)
						}
					}
				});
			}
		}		
	}
</script>				  