<!-- 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>Reference Tahun Ajaran</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 base_url(); ?>index.php/adm_tahun_ajaran_ppd/insert_data" method="post" id="tahun_ajaran_form" class="smart-form">
				<header>
					Add Refernce Tahun Ajaran
				</header>

				<fieldset>
					<div class="row">
						<section class="col col-2">
							<label class="label">Tahun Ajaran</label>
							<label class="input"> 
								<input id="tahun_ajaran" type="text" name="tahun_ajaran" maxlength="20" autocomplete="off" />
							</label>
						</section>
						<section class="col col-2">
							<label class="label">Status</label>
							<label class="select">
								<select name="status">
									<option value="">--Select--</option>
									<option value="U">Used</option>
									<option value="N">Not Used</option>									
								</select> <i></i> 
							</label>
						</section>	
					
					</div>
					
					<div class="row">
						<section class="col col-4">
							<label class="label">Keterangan</label>
							<label class="textarea"><textarea rows="4" name="keterangan"></textarea> </label>						
						</section>	
					</div>

					
				</fieldset>

				<footer>
					<button type="submit" name="submit" id="myBtn" class="btn btn-primary" onclick="buttonDis()">
						Save
					</button>
					<button type="submit" 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";
	}
	
	var type_crud = "create";

	$(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
		$("#tahun_ajaran_form").validate({
			// Rules for form validation
			rules : {
				tahun_ajaran : {
					required : true,
					remote	 : {
						url		: "<?php echo base_url();?>index.php/adm_tahun_ajaran_ppd/cek_tahun_ajaran",
						type	: "POST",
						data: {
							tahun_ajaran: function() {
								return $("#tahun_ajaran").val();
							}
						}
					}	
					//remote : '<?php echo base_url();?>index.php/login/cek_user'		
				},
				status : {
					required : true
				}
			},
			
			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/adm_tahun_ajaran_ppd/';
						/* 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 : {
				tahun_ajaran : {
					required : 'Tahun Ajaran Tidak Boleh Kosong',
					remote	 : 'Tahun Ajaran Sudah Di Di Buat'
						
				},
				status : {
					required : 'Pilih Status Tahun Ajaran'
				}
			},

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