

<!-- Widget ID (each widget will need unique ID)-->
<div class="jarviswidget" id="wid-id-6" data-widget-editbutton="false" data-widget-custombutton="false" data-widget-deletebutton="false">
	
	<header>
		<span class="widget-icon"> <i class="fa fa-edit"></i> </span>
		<h2>Users Management</h2>				
		
	</header>

	<!-- widget div-->
	<div>
		
		<!-- widget edit box -->
		<div class="jarviswidget-editbox">
			<!-- This area used as dropdown edit box -->
			
		</div>
		<!-- end widget edit box -->
		
		<!-- widget content -->
		<div class="widget-body no-padding">
			
			<form action="<?php echo @$action; ?>" method="post" id="user-form" class="smart-form">
				<header>
					<?php echo $header; ?>
				</header>

				<fieldset>
					<div class="row">
						<section class="col col-3">
							<label class="label">Username</label>
							<label class="input"> 
								<input id="userid" type="hidden" name ="userid" value="<?php echo @$userid; ?>" />
								<input id="username" type="text" name="username"  value="<?php echo @$username; ?>" autocomplete="off" />
							</label>
						</section>
						
						<section class="col col-3">
							<label class="label">User Alias</label>
							
								<label class="input"> 
									<input id="alias" type="text" name="alias"  value="<?php echo @$alias; ?>" autocomplete="off" />									
								</label>
								
						</section>	

									
					</div>
					<div class="row">
						<section class="col col-2">
							<label class="label">User Status</label>
							<?php echo $user_status; ?>		
						</section>	
						<section class="col col-2">
							<label class="label">Role User</label>
							<?php echo $role_id; ?>		
						</section>		
					</div>
					<div class="row">
						<section class="col col-4">
							<label class="label">Karyawan</label>
							<?php echo $id_karyawan; ?>		
						</section>
					</div>
					
				</fieldset>

				<footer>
					<button type="submit" id="myBtn" name="submit" class="btn btn-primary" value="<?php echo $submit; ?>" onclick="buttonDis()">
						Save
					</button>
					<button type="reset" id="cancel_create" name="cancel" class="btn btn-default" >
						Batal
					</button>
				</footer>

				<div class="message">
					<i class="fa fa-check fa-lg"></i>
					<p>
						Your comment was successfully added!
					</p>
				</div>
			</form>
			
		</div>
		<!-- end widget content -->
		
	</div>
	<!-- end widget div -->
				
</div>
<!-- end widget -->

<script type="text/javascript">

	function buttonDis() {
		document.getElementById("myBtn").style.visibility="hidden";
	}
	
	$(function() {
	
		alert_cancel = 'Are You Sure to cancel this form ?';
		$('#cancel_create').on('click', function () {
			if (confirm(alert_cancel)) {
				window.location.href = "<?php echo site_url('/').'home#'.$controller; ?>";
			}
		});
		
		// Validation
		$("#user-form").validate({
			// Rules for form validation
			rules : {				
				username : {
					required : true,
					remote	 : {
						url		: "<?php echo base_url();?>index.php/adm_user/cek_username",
						type	: "POST",
						data: {
							username: function() {
								return $("#username").val();
							},
							userid : $("#userid").val()
						}
					}
					//remote : '<?php echo base_url();?>index.php/login/cek_user'	
				},
				alias : {
					required : true
				},
				user_status : {
					required : true
				},
				role_id : {
					required : true
				},
				id_karyawan : {
					required : true,
					remote	 : {
						url		: "<?php echo base_url();?>index.php/adm_user/cek_karyawan",
						type	: "POST",
						data: {
							id_karyawan: function() {
								return $("#id_karyawan").val();
							},
							userid : $("#userid").val()
						}
					}
				}
			},
			
			submitHandler : function(form) {
				
				$(form).ajaxSubmit({
					
					dataType: 'json',
					success : function(msg) {
						window.location.hash = base_url + 'index.php/<?php echo $controller; ?>/';
						
					}
				});
				
			},

			// Messages for form validation
			messages : {
				username : {
					required  : 'Kolom Username Harus Di Isi',
					remote    : 'Username Sudah Di Gunakan'
						
				},
				alias : {
					required  : 'Alias Tidak Boleh Kosong'
				},
				user_status : {
					required : 'User Status Tidak Boleh Kosong'
				},
				role_id : {
					required : 'Pilih Role Untuk User'
				},
				id_karyawan : {
					required : 'Pilih Karyawan'
				}
			},

			// Do not change code below
			errorPlacement : function(error, element) {
				error.insertAfter(element.parent());
			}
		});
	});
</script>