

<?php $__env->startSection('extended_css'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
	<section class="content-header">
		<h1>
			<?php echo e($title); ?>

			<?php if(!empty($smallTitle)): ?>
			<small><?php echo e($smallTitle); ?></small>
			<?php endif; ?>
		</h1>
		<ol class="breadcrumb">
			<li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
			<li>Pasangan Keluarga Sehat</li>
			<li class="active"><?php echo e($title); ?></li>
		</ol>
	</section>

	<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
		<div class="loading" align="center" style="display: none;">
			<img src="<?php echo url('dist/img/loading.gif'); ?>" width="60%">
		</div>
	</div>

	<section class="content">
		<div class="row">
			<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
				<div class="box box-success main-layer">
					<div class="col-md-4 col-sm-4 col-xs-12 form-inline main-layer p-5">
					    <?php if(Sentinel::getUser()->level_user == 6): ?>
    						<button type="button" class="btn btn-sm btn-primary" id="btn-add">
    							<span class="fa fa-plus"></span> &nbsp Tambah Data
    						</button>
    					<?php endif; ?>
					</div>
					<!-- Search -->
					<div class="col-md-8 col-sm-8 col-xs-12 form-inline main-layer panelSearch">
						<div class="form-group">
							<select class="input-sm form-control input-s-sm inline v-middle option-search" id="search-option"></select>
						</div>
						<div class="form-group">
							<input type="text" class="input-sm form-control" placeholder="Search" id="search">
						</div>
					</div>
					<div class='clearfix'></div>
					<div class="col-md-12 p-0">
						<!-- Datagrid -->
						<div class="table-responsive">
							<table class="table table-striped b-t b-light" id="datagrid"></table>
						</div>
						<footer class="panel-footer">
							<div class="row">
								<!-- Page Option -->
								<div class="col-sm-1 hidden-xs">
									<select class="input-sm form-control input-s-sm inline v-middle option-page" id="option"></select>
								</div>
								<!-- Page Info -->
								<div class="col-sm-6 text-center">
									<small class="text-muted inline m-t-sm m-b-sm" id="info"></small>
								</div>
								<!-- Paging -->
								<div class="col-sm-5 text-right text-center-xs">
									<ul class="pagination pagination-sm m-t-none m-b-none" id="paging"></ul>
								</div>
							</div>
						</footer>
					</div>
					<div class='clearfix'></div>
				</div>
				<div class="other-page"></div>
				<div class="modal-dialog"></div>
			</div>
		</div>
	</section>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
	<script type="text/javascript">
		var datagrid = $("#datagrid").datagrid({
			url                     : "<?php echo route('dtKesPasDatagrid'); ?>",
			primaryField            : 'id_kesehatan_pasangan',
			rowNumber               : true,
			rowCheck                : false,
			searchInputElement      : '#search',
			searchFieldElement      : '#search-option',
			pagingElement           : '#paging',
			optionPagingElement     : '#option',
			pageInfoElement         : '#info',
			columns                 : [
				{field: 'no_registrasi', title: 'No Registrasi', editable: false, sortable: true, width: 150, align: 'left', search: true},
				{field: 'tgl_periksa', title: 'Tanggal Pemeriksaan', editable: false, sortable: true, width: 150, align: 'left', search: true},
				{field: 'nama_suami', title: 'Nama Calon Suami', editable: false, sortable: true, width: 200, align: 'left', search: true},
				{field: 'nama_bumil', title: 'Nama Calon Istri', editable: false, sortable: true, width: 200, align: 'left', search: true},
				{field: 'nama', title: 'Nama Puskesmas', editable: false, sortable: true, width: 200, align: 'left', search: true},
				{field: 'menu', title: 'Menu', sortable: false, width: 100, align: 'center', search: false, 
					rowStyler: function(rowData, rowIndex) {
						return menu(rowData, rowIndex);
					}
				}
			]
		});

		$(document).ready(function() {
			datagrid.run();
		});

		$('#btn-add').click(function(){
			$('.loading').show();
			$('.main-layer').hide();
			$.post("<?php echo route('formAddDtKesPas'); ?>").done(function(data){
				if(data.status == 'success'){
					$('.loading').hide();
					$('.other-page').html(data.content).fadeIn();
				} else {
					$('.main-layer').show();
				}
			});
		});

		function detail(rowIndex) {
			var id = datagrid.getRowData(rowIndex).id_kesehatan_pasangan;
			$.post("<?php echo route('detailDtKesPas'); ?>", {id:id}).done(function(data){
				if(data.status == 'success'){
					$('.modal-dialog').html(data.content);
				}
			});
		}

		function updated(rowIndex) {
			var rowData = datagrid.getRowData(rowIndex);
			$('.loading').show();
			$('.main-layer').hide();
			$.post("<?php echo route('formEditDtKesPas'); ?>", {id:rowData.id_kesehatan_pasangan}).done(function(data){
				if(data.status == 'success'){
					$('.loading').hide();
					$('.other-page').html(data.content).fadeIn();
				} else {
					$('.main-layer').show();
				}
			});
		}

		function tglRegis(rowData, rowIndex){
			var tgl = rowData.tgl_registrasi.split("-")
			var tag = tgl[2]+"-"+tgl[1]+"-"+tgl[0];
			return tag;
		}

		function menu(rowData, rowIndex) {
		    var level_user = <?php echo e(Sentinel::getUser()->level_user); ?>;
			if(level_user == 6){
    			var menu = 
    				'<div class="btn-group">' + 
    				'<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i></a>' +
    				'<ul class="dropdown-menu pull-right">' +
    				'<li onclick="detail('+rowIndex+')"><a href="javascript:void(0);"><i class="fa fa-eye"></i> Detail</a></li>' +
    				'<li onclick="updated('+rowIndex+')"><a href="javascript:void(0);"><i class="fa fa-pencil"></i> Edit</a></li>'+
    				'</ul>' +
    				'</div>';
			}else{
				var menu = '<a onclick="detail('+rowIndex+')" href="javascript:void(0);" class="btn btn-xs btn-primary"><i class="fa fa-eye"></i> Detail</a>';
			}
			return menu;
		}
	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('master.layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>