<?php $__env->startSection('css_page_level'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css')); ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/select2/css/select2.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/select2/css/select2-bootstrap.min.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-select/1.12.2/bootstrap-select.min.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-select/bootstrap-select.min.css')); ?>"/>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-content-wrapper'); ?>
<div class="page-content-wrapper" id="main">
	<div class="page-content">
		<!-- BEGIN PAGE HEADER-->
		<h3 class="page-title">
		<?php $setting = app('anlutro\LaravelSettings\Facade'); ?>
		<?php echo e($setting::get('system_name','全方位建築智慧化管理系統')); ?> <small><?php echo e($setting::get('company_name','新保科技')); ?></small>
		</h3>
		<div class="page-bar">
			<ul class="page-breadcrumb">
				<li>
					<i class="fa fa-home"></i>
					<a href="<?php echo e(route('manage::index')); ?>"><?php echo app('translator')->get('messages.homepage'); ?></a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="<?php echo e(route('manage::healthcare::index')); ?>">健康照護管理</a>
					<i class="fa fa-angle-right"></i>
				</li>
				<li>
					<a href="<?php echo e(route('manage::healthcare::location')); ?>">設備位置建立</a>
				</li>
			</ul>
			<div class="page-toolbar">
			</div>
		</div>
		<!-- END PAGE HEADER-->
		<!-- BEGIN DASHBOARD STATS -->
		<div class="row">
			<div class="col-md-12">
				<!-- BEGIN EXAMPLE TABLE PORTLET-->
				<div class="portlet light bordered">
					<div class="portlet-body">
						<div class="table-toolbar">
							<div class="row">
								<div class="col-md-6">
		                            <div class="btn-group">
										<a id="btn_query" href="javascript:;"  class="btn green">
										資料建立 <i class="fa fa-plus"></i>
										</a>
		                            </div>
		                            <button id="btn_mass_delete" class="btn red" style="display:none;"> 刪除 <i class="fa fa-trash"></i></button>
								</div>
							</div>
						</div>
						<table class="table table-striped table-bordered table-hover" id="table_healthcare">
							<thead>
								<tr>
									<th>
										<input type="checkbox" id="chk_all" />
									</th>
									<th>
										ID
									</th>
									<th>
										名稱
									</th>
									<th>
										棟別
									</th>
									<th>
										樓別
									</th>
									<th>
										位置
									</th>
									<th>
										動作
									</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach($healthcare as $one): ?>
									<tr class="odd gradeX">
										<td>
											<input name="chk" class='chk_check' type="checkbox" value="<?php echo e($one->id); ?>">
										</td>
										<td>
											<?php echo e($one->id); ?>

										</td>
										<td>
											<?php echo e($one->name); ?>

										</td>
										<td>
											<?php echo e($one->b_name); ?>

										</td>
										<td>
											<?php echo e($one->floor); ?>

										</td>
										<td>
											<?php echo e($one->location); ?>

										</td>
										<td>
											<div class="btn-group">
												<button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-expand	ed="false">
												<?php echo app('translator')->get('messages.action'); ?> <i class="fa fa-angle-down"></i>
												</button>
												<ul class="dropdown-menu pull-right" role="menu">
	                                                <li>
	                                                    <a class="btn_edit" uid="<?php echo e($one->id); ?>" href="javascript:;">
	                                                    <i class="fa fa-pencil"></i>
	                                                    <?php echo app('translator')->get('messages.edit'); ?> </a>
	                                                </li>
	                                                <li class="divider">
	                                                </li>
	                                                <li>
	                                                    <a class="btn_del" uid="<?php echo e($one->id); ?>" href="javascript:;">
	                                                    <i class="fa fa-trash-o"></i>
	                                                    <?php echo app('translator')->get('messages.del'); ?> </a>
	                                                </li>
	                                            </ul>
											</div>
										</td>
									</tr>								
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
				</div>
				<!-- END EXAMPLE TABLE PORTLET-->
			</div>
		</div>
	</div>
</div>
<input type="hidden" id="_token" name="_token" value="<?php echo e(csrf_token()); ?>">
<div class="modal fade draggable-modal" id="modal_query" tabindex="-1" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-blue-madison">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title font-white">新增位置資料</h4>
            </div>
            <form id="form_query" action="" method="post" class="form-horizontal">
                <div class="modal-body">
                    <div class="form-body">
						<div class="form-group">
                            <label class="col-md-3 control-label">位置名稱<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <input type="text" name="name" class="form-control" placeholder="請輸入位置名稱" required="required">
                            </div>
                        </div>
						<div class="form-group">
                            <label class="col-md-3 control-label">棟別<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <select id="building" name="building" class="form-control selectpicker" data-live-search="true"> 
                                    <?php foreach($building as $one): ?>
                                        <option value="<?php echo e($one->id); ?>"><?php echo e($one->name); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">位置<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                            	<select id="location" name="location" class="form-control selectpicker" data-live-search="true"> 
                                	<option value="地上">地上</option>
                                	<option value="地下">地下</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">樓別<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <select id="floor" name="floor" class="form-control selectpicker" data-live-search="true" data-size="8" disabled>
                                </select>
                            </div>
                        </div>						
                    </div>
            	</div>
	            <div class="modal-footer">
	            	<input type="hidden" id="_token" name="_token" value="<?php echo e(csrf_token()); ?>">
	                <button type="button" class="btn gray" data-dismiss="modal"><?php echo app('translator')->get('messages.close'); ?></button>
	                <button type="submit" class="btn blue" value="print">送出</button>
	            </div>
            </form>
        </div>
    </div>
</div>
<div class="modal fade draggable-modal" id="modal_edit" tabindex="-1" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-blue-madison">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title font-white">編輯位置資料</h4>
            </div>
            <form id="form_edit" method="POST" action="" class="form-horizontal">
            	<div class="modal-body">
                    <div class="form-body">
						<div class="form-group">
                            <label class="col-md-3 control-label">位置名稱<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <input type="text" id="name_edit" name="name_edit" class="form-control" placeholder="請輸入位置名稱" required="required">
                            </div>
                        </div>
						<div class="form-group">
                            <label class="col-md-3 control-label">棟別<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <select id="building_edit" name="building_edit" class="form-control selectpicker" data-live-search="true"> 
                                    <?php foreach($building as $one): ?>
                                        <option value="<?php echo e($one->id); ?>"><?php echo e($one->name); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">位置<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                            	<select id="location_edit" name="location_edit" class="form-control selectpicker" data-live-search="true"> 
                                	<option value="地上">地上</option>
                                	<option value="地下">地下</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">樓別<span class="required" aria-required="true"> * </span></label>
                            <div class="col-md-9">
                                <select id="floor_edit" name="floor_edit" class="form-control selectpicker" data-live-search="true" data-size="8" disabled>
                                </select>
                            </div>
                        </div>
                    </div>
            	</div>
	            <div class="modal-footer">
	            	<input type="hidden" name="id_edit" id="id_edit">
	            	<input type="hidden" id="_token" name="_token" value="<?php echo e(csrf_token()); ?>">
	                <button type="button" class="btn gray" data-dismiss="modal"><?php echo app('translator')->get('messages.close'); ?></button>
	                <button type="submit" class="btn blue" value="print">送出</button>
	            </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('plugins_page_level'); ?>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-validation/js/jquery.validate.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-validation/js/additional-methods.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/media/js/jquery.dataTables.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootbox/bootbox.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-TW.min.js')); ?>"></script>

<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-fileinput/additional-methods.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/select2/js/select2.min.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-select/1.12.2/bootstrap-select.min.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js_page_level'); ?>
<script>
$(document).ready(function(){
	var table = $('#table_healthcare');
    var oTable = table.dataTable({
        // Internationalisation. For more info refer to http://datatables.net/manual/i18n
        "language": {
            "aria": {
                "sortAscending": ": activate to sort column ascending",
                "sortDescending": ": activate to sort column descending"
            },
            "emptyTable": "<?php echo app('translator')->get('messages.datatable_no_data'); ?>",
            "info": "<?php echo app('translator')->get('messages.display_from'); ?> _START_ <?php echo app('translator')->get('messages.display_to'); ?> _END_ <?php echo app('translator')->get('messages.then_total'); ?> _TOTAL_ <?php echo app('translator')->get('messages.records'); ?>",
            "infoEmpty": "<?php echo app('translator')->get('messages.no_match'); ?>",
            "infoFiltered": "(<?php echo app('translator')->get('messages.from'); ?> _MAX_ <?php echo app('translator')->get('messages.records_filter'); ?>)",
            "lengthMenu": "<?php echo app('translator')->get('messages.show'); ?> _MENU_ <?php echo app('translator')->get('messages.records'); ?>",
            "search": "<?php echo app('translator')->get('messages.quick_filter'); ?>:",
            "zeroRecords": "<?php echo app('translator')->get('messages.no_data'); ?>",
            "paginate": {
                "previous":"<?php echo app('translator')->get('messages.last_page'); ?>",
                "next": "<?php echo app('translator')->get('messages.next_page'); ?>",
                "last": "<?php echo app('translator')->get('messages.lastest'); ?>",
                "first": "<?php echo app('translator')->get('messages.most_previous'); ?>"
            }
        },
        "aaSorting": [[1,'desc']],
        "lengthMenu": [
            [10, 20, 50, -1],
            [10, 20, 50, "All"] // change per page values here
        ],
        // set the initial value
        "pageLength": 10,            
        "pagingType": "bootstrap_full_number",
    });
});

/* 資料建立 */
$(document).on('click','#btn_query',function(){
	var building = $('#building').val();
	var location = $('#location').val();
	getfloor(building,location);
	$('#modal_query').modal('show');
});
/* 選擇棟別 */ 
$(document).on('change','#building',function(){
	var building = $(this).val();
	var location = $('#location').val();
	getfloor(building,location);
});
/* 選擇位置 */
$(document).on('change','#location',function(){
	var building = $('#building').val();
	var location = $(this).val();
	getfloor(building,location);
});
/* 取得樓層資料(新增) */
function getfloor(building,location){
	$.ajax({
		type : 'POST',
        url  : "<?php echo e(route('manage::pccs::get_floor')); ?>",
        data : {
            'id' : building,
            'location' : location,
            _token : $('#_token').val(),
        },
        success:function(sendback){
        	$('#floor').prop('disabled',false);
        	$('#floor').empty();
        	for(var i = 0;i < sendback.floor.length;i++){
        		$('#floor').append('<option value="' + sendback.floor[i].floor + '">' + sendback.floor[i].floor + '</option>')
        	}
        	$('#floor').selectpicker('refresh');
        },
        error  :function(sendback){
			toastr['error']('發生錯誤請重新整理後再次操作。');
        }
	});
}
/* 當棟別資料變更時 */
$(document).on('change','#building_edit',function(){
	var building = $(this).val();
	var location = $('#location_edit').val();
	getfloor_edit(building,location,null);
});
/* 當位置資料變更時 */
$(document).on('change','#location_edit',function(){
	var building = $('#building_edit').val();
	var location = $(this).val();
	getfloor_edit(building,location,null);
});
/* 新增資料送出 */
$(document).on('submit','#form_query',function(){
	$(this).attr('action','<?php echo e(route("manage::healthcare::save_location")); ?>');
});
/* 編輯資料 */
$(document).on('click','.btn_edit',function(){
	var uid = $(this).attr('uid');
	$.ajax({
		type : 'POST',
		url  : "<?php echo e(route('manage::healthcare::get_location')); ?>",
		dataType : 'json',
		data : {
			id     : uid,
			_token : $('#_token').val(),
		},
		success: function(sendback){
			$.each(sendback, function (key, data) {
				if(key == 'location'){
					$("#location_edit").val(data);
					$('#location_edit').selectpicker('refresh');
				}else if(key == 'building'){
					$("#building_edit").val(data);
					$('#building_edit').selectpicker('refresh');
				}else if(key == 'floor'){
					var building = sendback['building'];
					var location = sendback['location'];
					getfloor_edit(building,location,data);
				}else{
					$("#form_edit input[name='"+key+"_edit']").val(data);
				}
			});
			$('#modal_edit').modal('show');
		},
		error: function(){
			toastr['error']("<?php echo app('translator')->get('messages.error_need_refresh'); ?>");
		}
	});
});
/* 取得樓層資料(編輯) */
function getfloor_edit(building,location,data){
	$.ajax({
		type : 'POST',
        url  : "<?php echo e(route('manage::pccs::get_floor')); ?>",
        data : {
            'id' : building,
            'location' : location,
            _token : $('#_token').val(),
        },
        success:function(sendback){
        	console.log(building);
        	console.log(location);
        	$('#floor_edit').prop('disabled',false);
        	$('#floor_edit').empty();
        	for(var i = 0;i < sendback.floor.length;i++){
        		$('#floor_edit').append('<option value="' + sendback.floor[i].floor + '">' + sendback.floor[i].floor + '</option>')
        	}
        	if(data != null){
        		$('#floor_edit').val(data);
        	}
        	$('#floor_edit').selectpicker('refresh');
        },
        error  :function(sendback){
			toastr['error']('發生錯誤請重新整理後再次操作。');
        }
	});
}
/* 編輯資料送出 */
$(document).on('submit','#form_edit',function(){
	$(this).attr('action','<?php echo e(route("manage::healthcare::update_location")); ?>');
});
/* 刪除單筆資料 */
$(document).on('click','.btn_del',function(){
	var uid = $(this).attr('uid');
	$.ajax({
		type : 'POST',
		url: "<?php echo e(route('manage::healthcare::del_location')); ?>",
		dataType : 'json',
		data : {
			id     : uid,
			_token : $('#_token').val(),
		},
		success: function(sendback){
			toastr['success']('刪除成功');
			window.location.reload();
		},
		error: function(){
			toastr['error']("<?php echo app('translator')->get('messages.error_need_refresh'); ?>");
		}
	});
});
/* 選擇後出現刪除按鈕 */
$(document).on('change','#table_healthcare .chk_check',function(){
	var checkedNum = $('.chk_check:checked').length;
	if(checkedNum > 0){
		$('#btn_mass_delete').show();
	}else{
		$('#btn_mass_delete').hide();
		$('#chk_all').attr("checked",false);
		$.uniform.update();
	}
});
/* 全部選擇 */
$(document).on('click','#chk_all',function(){
	if($(this).is(':checked')){
        $('.chk_check').attr("checked",true);
    }else{
        $('.chk_check').attr("checked",false);
    }
    $.uniform.update();
	var checkedNum = $('.chk_check:checked').length;
	if(checkedNum > 0){
		$('#btn_mass_delete').show();
	}else{
		$('#btn_mass_delete').hide();
	}
});
/* 刪除被選取資料 */
$(document).on('click','#btn_mass_delete',function(){
	var ids = $.map($('input:checkbox:checked[name="chk"]'), function(n, i){
	      return n.value;
	}).join(',');
	bootbox.confirm("<?php echo app('translator')->get('messages.sure_del'); ?>", function(result) {
		if(result == true){
			$.ajax({
				type : 'POST',
				dataType : 'json',
				url  : "<?php echo e(route('manage::healthcare::all_del_location')); ?>",
				data : {
					_token   : $('#_token').val(),
					ids : ids
				},
				success : function(sendback){
					toastr['success']("<?php echo app('translator')->get('messages.del_success'); ?>");
					window.location.reload();
				},
				error : function(sendback){
					toastr['error']("<?php echo app('translator')->get('messages.del_fail'); ?>");
				}
			});
		}
	});
});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.manage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>