<!-- 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">
	<!-- widget options:
		usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
		
		data-widget-colorbutton="false"	
		data-widget-editbutton="false"
		data-widget-togglebutton="false"
		data-widget-deletebutton="false"
		data-widget-fullscreenbutton="false"
		data-widget-custombutton="false"
		data-widget-collapsed="true" 
		data-widget-sortable="false"
		
	-->
	<header>
		<span class="widget-icon"> <i class="fa fa-edit"></i> </span>
		<h2>Mapping - Kelas</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="crud-form" class="smart-form">
				<header>
					<?php echo $header; ?>
				</header>

				<fieldset>
                	<div class="row">
						<section class="col col-3">
							<label class="label">Sekolah</label>
							<?php echo $nama_smk; ?>
						</section>
					</div>
                    <div class="row">
						<section class="col col-3">
							<label class="label">Jurusan</label>
							<?php echo $mapping; ?>
						</section>
					</div>
                    
                    
					<div class="row">
						<section class="col col-2">
							<label class="label">Kelas</label>
							<input id="id" type="hidden" name ="id" value="<?php echo @$id; ?>" />
							<?php echo $nama_kelas; ?>
						</section>
						
						<section class="col col-3">
							<label class="label">Ruang Kelas</label>
							
								<label class="input"> 
                                <div id="id-RuangKelas">
									<input id="ruang_kelas" type="text" name="ruang_kelas"  value="<?php echo @$ruang_kelas; ?>" autocomplete="off" />				
                                    </div>					
								</label>
								
						</section>	

									
					</div >
					
					<div class="row">
						<section class="col col-3">
							<label class="label">Wali Kelas</label>
							<?php echo @$wali_kelas; ?>
						</section>
					</div>
					
				</fieldset>
				<footer>
					<button type="submit" name="submit" class="btn btn-primary" value="<?php echo $submit; ?>">
						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() {
		$(".chosen-select").chosen();
		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
		$("#crud-form").validate({
			// Rules for form validation
			rules : {
				smk : {
					required : true
					//remote : '<?php echo base_url();?>index.php/login/cek_user'		
				},
				id_mapping_jur : {
					required : true
					//remote : '<?php echo base_url();?>index.php/login/cek_user'		
				},
				kelas : {
					required : true
					//remote : '<?php echo base_url();?>index.php/login/cek_user'		
				},
				id_karyawan : {
					required : true,
					remote	 : {
						url		: "<?php echo base_url();?>index.php/mapping_kelas/cekWaliKelas",
						type	: "POST",
						data: {
							ruang_kelas: function() {
								return $("#id_karyawan").val();
							},
							id : $("#id").val()
						}
					}
				},
				ruang_kelas : {
					required : true,
					remote	 : {
						url		: "<?php echo base_url();?>index.php/mapping_kelas/cekRuangKelas",
						type	: "POST",
						data: {
							ruang_kelas: function() {
								return $("#ruang_kelas").val();
							},
							id : $("#id").val(), 
							id_mapping_jur : function() {
								return $("#id_mapping_jur").val();
							},
							kelas : function() {
								return $("#kelas").val();
							}
						}
					}
					
				}
			},
			
			submitHandler : function(form) {
				
				$(form).ajaxSubmit({
					/* beforeSubmit: function() {
						$("#hiddenElement").val("false");
						$("#cancel").attr("disabled","disabled");
						$("#button_id").attr("disabled","disabled");
						//$("button[type=submit]").append('<i class="fa fa-gear fa-1x fa-spin"></i>');
						$("#button_id").append('<i class="fa fa-gear fa-1x fa-spin">');
					}, */
					dataType: 'json',
					success : function(msg) {
						window.location.hash = base_url + 'index.php/<?php echo $controller; ?>/';
						/* if (msg.msg == "noauth") {
							window.location = base_url;
						}
						else if (msg.error == true) {
							write_error_html(msg.field);
							
							//button manipulating
							$("#hiddenElement").val("true");
							$(".fa-spin").remove();
							$("#cancel").removeAttr("disabled");
							$("#button_id").removeAttr("disabled");
						} else {
							window.location.hash = base_url + 'create_agent/';
						} */
					}
				});
				
			},

			// Messages for form validation
			messages : {
				smk : {
					required : 'Silahkan Pilih SMK'
						
				},
				id_mapping_jur : {
					required : 'Silahkan Pilih Jurusan'
						
				},
				kelas : {
					required : 'Silahkan Pilih Kelas'
						
				},
				ruang_kelas : {
					required : 'Nama Ruang Kelas Tidak Boleh Kosong',
					remote   : 'Nama Ruang Kelas Sudah Di Gunakan'
						
				},
				id_karyawan : {
					required : 'Silahkan Pilih Wali Kelas',
					remote   : 'Telah Memiliki Kelas'	
				}
			},

			// Do not change code below
			errorPlacement : function(error, element) {
				error.insertAfter(element.parent());
			}
		});
	});
	
	
	function getJurusan(smk) {
		$.ajax({
			type:"POST",
			dataType: "html",
			beforeSend : function() {
				$("#id-Mapping").html("Populating data, please wait..");
			},
			url : "<?php echo site_url("/") . $controller . "/getJurusan"; ?>",
			data : "smk="+smk,
			success:function(msg){
				$("#id-Mapping").html(msg);
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	function cekKelas(id_smk, id_jur) {
		$.ajax({
			type:"POST",
			dataType: "html",
			beforeSend : function() {
				$("#id-MappingKls").html("Populating data, please wait..");
			},
			url : "<?php echo site_url("/") . $controller . "/cekKelas"; ?>",
			data : "id_smk="+id_smk+"&&id_jur="+id_jur,
			success:function(msg){
				$("#id-MappingKls").html(msg);
			},
			error:function(){
				alert("Load failed");
			}
		});
	}
	function getRuangKelas(id_kls, id_jur) {
		$.ajax({
			type:"POST",
			dataType: "html",
			beforeSend : function() {
				$("#id-RuangKelas").html("<input id='ruang_kelas' type='text' name='ruang_kelas'  value='' autocomplete='off' />");
			},
			url : "<?php echo site_url("/") . $controller . "/getRuangKelas"; ?>",
			data : "id_kls="+id_kls+"&&id_jur="+id_jur,
			success:function(msg){
				$("#id-RuangKelas").html(msg);
			},
			error:function(){
				alert("error");
			}
		});
	}
	
</script>