<?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-daterangepicker/daterangepicker.min.css')); ?>" />
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/bootstrap-select/bootstrap-select.min.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/jquery-multi-select/css/multi-select.css')); ?>"/>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-content-wrapper'); ?>
	<style type="text/css">
		.th_display_none { display: none;}
        .disableInput {
            background-color: #ffee88 !important;
        }
        .readOnlyInput {
            background-color: #ffee88 !important;
        }
	</style>
	<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="index.html">首頁</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="#">BA管理</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="#">偵測器裝置管理</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_add_sensor" 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_list">

							</table>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
		</div>
        <div class="modal fade draggable-modal" id="modal_add_sensor" tabindex="-1" role="basic" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-blue-soft" style="color: #fff;">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                        <h4 class="modal-title">新增偵測器資料</h4>
                    </div>
                    <form id="form_add" action="" class="form-horizontal">
                        <div class="modal-body">
                            <div class="form-body">
                                <blockquote>
                                    <h4>Step 1. 偵測器基本設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">標籤</label>
                                    <div class="col-md-9">
                                        <input type="text" name="tag" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">名稱</label>
                                    <div class="col-md-9">
                                        <input type="text" name="sensor_name" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">數值單位</label>
                                    <div class="col-md-9">
                                        <input type="text" name="unit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">監控類型</label>
                                    <div class="col-md-9">
                                        <select name="monitor_type" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <option value="0">數值類</option>
                                            <option value="1">警告類</option>
                                            <option value="2">狀態類</option>
                                        </select>   
                                    </div>
                                </div>
                                <div class="form-group monitor-value">
                                    <label class="col-md-3 control-label">監控上限</label>
                                    <div class="col-md-9">
                                        <input type="text" name="upper_limit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group monitor-value">
                                    <label class="col-md-3 control-label">監控下限</label>
                                    <div class="col-md-9">
                                        <input type="text" name="lower_limit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">顯示</label>
                                    <div class="col-md-9">
                                        <div class="checkbox">
                                            <label><input type="checkbox" name="major_monitor" value="1"> 在監控面版顯示</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">警告設定</label>
                                    <div class="col-md-9">
                                        <div class="checkbox">
                                            <label><input type="checkbox" name="disable" value="1"> 不作任何的警告</label>
                                        </div>
                                    </div>
                                </div>
                                <blockquote>
                                    <h4>Step 2. 偵測器所在位置設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">所在位置</label>
                                    <div class="col-md-9">
                                        <select name="location" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($locations as $location): ?>
                                                <option value="<?php echo e($location->id); ?>"><?php echo e($location->place); ?></option>
                                            <?php endforeach; ?>
                                        </select>     
                                    </div>
                                </div>
                                <blockquote>
                                    <h4>Step 3. 偵測器分類設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">偵測器分類</label>
                                    <div class="col-md-9">
                                        <select name="category" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($categories as $category): ?>
                                                <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div>

                                <blockquote>
                                    <h4>Step 4. 綁定裝置設定(圖控)</h4>
                                </blockquote>
<!--                                 <div class="form-group">
                                    <label class="col-md-3 control-label">裝置分類</label>
                                    <div class="col-md-9">
                                        <select name="category" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($categories as $category): ?>
                                                <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div> -->
                                <div class="form-group">
                                    <label class="col-md-3 control-label">裝置名稱</label>
                                    <div class="col-md-9">
                                        <select name="device" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($pccs_device as $one): ?>
                                                <option value="<?php echo e($one->id); ?>"><?php echo e($one->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div>

                                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn dark btn-outline" data-dismiss="modal">關閉</button>
                            <button type="submit" class="btn green btn_query_submit" value="add">新增</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
        <div class="modal fade draggable-modal" id="modal_edit_sensor" tabindex="-1" role="basic" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-blue-soft" style="color: #fff;">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                        <h4 class="modal-title">修改偵測器資料</h4>
                    </div>
                    <form id="form_edit" action="" class="form-horizontal">
                        <input type="hidden" name="id" value="" />
                        <div class="modal-body">
                            <div class="form-body">
                                <blockquote>
                                    <h4>Step 1. 偵測器基本設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">標籤</label>
                                    <div class="col-md-9">
                                        <input type="text" name="tag" class="form-control disableInput">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">名稱</label>
                                    <div class="col-md-9">
                                        <input type="text" name="sensor_name" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">數值單位</label>
                                    <div class="col-md-9">
                                        <input type="text" name="unit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">監控類型</label>
                                    <div class="col-md-9">
                                        <select name="monitor_type" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <option value="0">數值類</option>
                                            <option value="1">警告類</option>
                                            <option value="2">狀態類</option>
                                        </select>   
                                    </div>
                                </div>
                                <div class="form-group monitor-value">
                                    <label class="col-md-3 control-label">監控上限</label>
                                    <div class="col-md-9">
                                        <input type="text" name="upper_limit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group monitor-value">
                                    <label class="col-md-3 control-label">監控下限</label>
                                    <div class="col-md-9">
                                        <input type="text" name="lower_limit" class="form-control">   
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">顯示</label>
                                    <div class="col-md-9">
                                        <div class="checkbox">
                                            <label><input type="checkbox" name="major_monitor" value="1"> 在監控面版顯示</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">警告設定</label>
                                    <div class="col-md-9">
                                        <div class="checkbox">
                                            <label><input type="checkbox" name="disable" value="1"> 不作任何的警告</label>
                                        </div>
                                    </div>
                                </div>
                                <blockquote>
                                    <h4>Step 2. 偵測器所在位置設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">所在位置</label>
                                    <div class="col-md-9">
                                        <select name="location" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($locations as $location): ?>
                                                <option value="<?php echo e($location->id); ?>"><?php echo e($location->place); ?></option>
                                            <?php endforeach; ?>
                                        </select>     
                                    </div>
                                </div>
                                <blockquote>
                                    <h4>Step 3. 偵測器分類設定</h4>
                                </blockquote>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">偵測器分類</label>
                                    <div class="col-md-9">
                                        <select name="category" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($categories as $category): ?>
                                                <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div>
                                
                                <blockquote>
                                    <h4>Step 4. 綁定裝置設定(圖控)</h4>
                                </blockquote>
<!--                                 <div class="form-group">
                                    <label class="col-md-3 control-label">裝置分類</label>
                                    <div class="col-md-9">
                                        <select name="category" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($categories as $category): ?>
                                                <option value="<?php echo e($category->id); ?>"><?php echo e($category->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div> -->
                                <div class="form-group">
                                    <label class="col-md-3 control-label">裝置名稱</label>
                                    <div class="col-md-9">
                                        <select name="device" class="form-control mySelect2">
                                            <option value="">未選擇</option>
                                            <?php foreach($pccs_device as $one): ?>
                                                <option value="<?php echo e($one->id); ?>"><?php echo e($one->name); ?></option>
                                            <?php endforeach; ?>
                                        </select>   
                                    </div>
                                </div>
                                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn dark btn-outline" data-dismiss="modal">關閉</button>
                            <button type="submit" class="btn green btn_query_submit" value="add">修改</button>
                        </div>
                    </form>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </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/moment.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-daterangepicker/daterangepicker.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/bootbox/bootbox.min.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/jquery-multi-select/js/jquery.multi-select.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/select2/js/select2.full.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js_page_level'); ?>
    <script>
        $(document).ready(function(){
            callDataTable();
        });
        
        function initAction(){
            $.fn.modal.Constructor.prototype.enforceFocus = function () {};
            //$('#modal_add_sensor form').find('.form-body').html($('#formTemplate').html());
            //$('#modal_edit_sensor form').find('.form-body').html($('#formTemplate').html());
            $(".select2").select2();
            $('.disableInput').prop('disabled', true);
            $('.readOnlyInput').prop('readonly', true);
            $(document).on('click','#btn_add_sensor',function(){
                $('#modal_add_sensor').modal('show');
            });
            $(document).on('click', '#btn_mass_delete', function(){
                var ids = [];
                $('.checkboxes:checked').each(function() {
                    ids.push($(this).val());                      
                });   
                deleteRecords(ids);
            });
            $('[name="monitor_type"]').change(function() {
                var form  = $(this).parents('form');
                var value = $(this).val();
                
                if (value != 0) {
                    $('.monitor-value', form).hide();
                    $('.monitor-value[name="upper_limit"]', form).val(0);  
                    $('.monitor-value[name="lower_limit"]', form).val(0);   
                } else {
                    $('.monitor-value', form).show(); 
                }
            });
            $('.btn_delete').click(function() {
                var id = $(this).attr('uid');
                deleteRecords(id);
            });
            $('.btn_edit').click(function(){
                var uid = $(this).attr('uid');
                $.ajax({
                    type : 'GET',
                    url  : "<?php echo e(route('manage::ba::get_sensor')); ?>",
                    dataType : 'json',
                    data : {
                        'id' : uid
                    },
                    success: function(sendback){
                        $.each(sendback, function(key, value) {
                            var obj = $("#form_edit [name='" + key + "']");
                            if ($(obj).hasClass('select2')) {
                                $(obj).select2("val", value); 
                            } else if ($(obj).attr('type') == 'checkbox') {
                                $(obj).attr('checked', (value == 1));
                                if(value == 1){
                                    $(obj).parents('span').addClass('checked');        
                                }else{
                                    $(obj).parents('span').removeClass('checked');
                                }  
                            } else {
                                $(obj).val(value);     
                            } 
                        });
                        $('#modal_edit_sensor').modal('show');
                    },
                    error: function(){
                        toastr['error']('發生錯誤，請重新整理後再嘗試');
                    }
                });
            });

            $('.btn_send').click(function(){
                var uid = $(this).attr('uid');
                $.ajax({
                    type : 'POST',
                    url  : "<?php echo e(route('manage::ba::warningTest')); ?>",
                    dataType : 'json',
                    data : {
                        'id' : uid
                    },
                    success: function(sendback){
                        toastr['success'](sendback.message);
                    },
                    error: function(){
                        toastr['error']('發生錯誤，請重新整理後再嘗試');
                    }
                });
            });
            
            $('#form_add').validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block help-block-error', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",  // validate all fields including form hidden input
                rules:{
                    tag:{
                        required:true,
                        maxlength: 50
                    },
                    monitor_type:{
                        required:true
                    },
                    sensor_name:{
                        required:true,
                        maxlength: 50
                    }, 
                    location:{
                        required:true
                    }, 
                    upper_limit:{
                        number: true
                    },  
                    lower_limit:{
                        number: true
                    },
                    unit:{
                        maxlength: 50
                    }
                },
                messages:{
                    tag:{
                        required:'標籤不可以為空',
                        maxlength: '標籤字元長度不可以超過50個字元'
                    },
                    monitor_type:{
                        required:'監控類型未選擇'
                    },
                    sensor_name:{
                        required:'名稱不可以為空',
                        maxlength: '名稱字元長度不可以超過50個字元'
                    }, 
                    location:{
                        required:'裝置所在地未選擇',
                    }, 
                    upper_limit:{
                        number: '上限值必須為數字'
                    },  
                    lower_limit:{
                        number: '下限值必須為數字'
                    },
                    unit:{
                        maxlength: '數值單位長度不可以超過50個字元'
                    } 
                },

                invalidHandler: function (event, validator) { //display error alert on form submit
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                },

                highlight: function (element) { // hightlight error inputs
                   $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    $(element)
                        .closest('.form-group').removeClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label
                        .closest('.form-group').removeClass('has-error'); // set success class to the control group
                },

                submitHandler: function (form) {
                    $('#form_success_alert').show();
                    $('#form_error_alert').hide();
                    
                    var data = $("#form_add").serialize();
                    
                    //確認表單正確，Ajax送出
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: "<?php echo e(route('manage::ba::add_sensor')); ?>",
                        data: data,
                        success: function(sendback){
                            $('#modal_add_sensor').modal('hide');
                            window.location.reload();
                        },
                        error   : function ( data )
                        {
                            var errors = data.responseJSON;
                            //以下是目前測試到的可行解，但還是要實際嘗試才知道怎麼使用。
                            $.each(errors, function (key, data) {
                                console.log(key);
                                if( key == 'errors'){
                                    $.each(data, function (index, data) {
                                        $( "input[name='"+index+"']").closest('.form-group').addClass('has-error');
                                        $( "input[name='"+index+"']").closest('.form-control').after( '<span class="help-block help-block-error">'+data+'</span>' )
                                    });
                                } else if (key == 'message') {
                                    toastr['error'](data);    
                                }
                            });
                            $('#form_success_alert').hide();
                            $('#form_error_alert').show();
                            $('.modal').scrollTop($('#form_error_alert'));

                        }
                    });
                }
            });
            
            $('#form_edit').validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block help-block-error', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",  // validate all fields including form hidden input
                rules:{
                    tag:{
                        required:true,
                        maxlength: 50
                    },
                    monitor_type:{
                        required:true
                    },
                    sensor_name:{
                        required:true,
                        maxlength: 50
                    }, 
                    location:{
                        required:true
                    }, 
                    upper_limit:{
                        number: true
                    },  
                    lower_limit:{
                        number: true
                    }  
                },
                messages:{
                    tag:{
                        required:'標籤不可以為空',
                        maxlength: '標籤字元長度不可以超過50個字元'
                    },
                    monitor_type:{
                        required:'監控類型未選擇'
                    },
                    sensor_name:{
                        required:'名稱不可以為空',
                        maxlength: '名稱字元長度不可以超過50個字元'
                    }, 
                    location:{
                        required:'裝置所在地未選擇',
                    }, 
                    upper_limit:{
                        number: '上限值必須為數字'
                    },  
                    lower_limit:{
                        number: '下限值必須為數字'
                    } 
                },

                invalidHandler: function (event, validator) { //display error alert on form submit
                    $('#form_success_alert').hide();
                    $('#form_error_alert').show();
                    $('.modal').scrollTop($('#form_error_alert'));
                },

                highlight: function (element) { // hightlight error inputs
                   $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    $(element)
                        .closest('.form-group').removeClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label
                        .closest('.form-group').removeClass('has-error'); // set success class to the control group
                },

                submitHandler: function (form) {
                    $('#form_success_alert').show();
                    $('#form_error_alert').hide();
                    
                    var data = $("#form_edit").serialize();
                    
                    //確認表單正確，Ajax送出
                    $.ajax({
                        type: 'POST',
                        dataType: 'json',
                        url: "<?php echo e(route('manage::ba::update_sensor')); ?>",
                        data: data,
                        success: function(sendback){
                            $('#modal_edit_sensor').modal('hide');
                            window.location.reload();
                        },
                        error   : function ( data )
                        {
                            var errors = data.responseJSON;
                            //以下是目前測試到的可行解，但還是要實際嘗試才知道怎麼使用。
                            $.each(errors, function (key, data) {
                                console.log(key);
                                if( key == 'errors'){
                                    $.each(data, function (index, data) {
                                        $( "input[name='"+index+"']").closest('.form-group').addClass('has-error');
                                        $( "input[name='"+index+"']").closest('.form-control').after( '<span class="help-block help-block-error">'+data+'</span>' )
                                    });
                                } else if (key == 'message') {
                                    toastr['error'](data);    
                                }
                            });
                            $('#form_success_alert').hide();
                            $('#form_error_alert').show();
                            $('.modal').scrollTop($('#form_error_alert'));

                        }
                    });
                }
            });
        };

        var deleteRecords = function(id) {
            bootbox.confirm("您確定要刪除指定的偵測器資料?", function(result) {
                if(result == true){
                    $.ajax({
                        type : 'DELETE',
                        dataType : 'json',
                        url  : "<?php echo e(route('manage::ba::delete_sensor')); ?>",
                        data : {
                            _token : "<?php echo e(csrf_token()); ?>",
                            id     : id
                        },
                        success : function(sendback){
                            window.location.reload();
                        },
                        error : function(sendback){
                            toastr['error']('刪除失敗，請重新整理後再試');
                        }
                    })
                }
            }); 
        }
        
        var callDataTable = function () {
            var table = $('#table_list');
            
            table.on( 'draw.dt', function () {
                initAction();
            });
            
            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": "此列表目前沒有資料",
                    "info": "顯示第 _START_ 到第 _END_ 則 共有 _TOTAL_ 則",
                    "infoEmpty": "沒有找到符合的資料",
                    "infoFiltered": "(從 _MAX_ 筆資料中過濾)",
                    "lengthMenu": "顯示 _MENU_ 則",
                    "search": "快速篩選:",
                    "zeroRecords": "目前沒有任何資料",
                    "paginate": {
                        "previous":"上一頁",
                        "next": "下一頁",
                        "last": "最後",
                        "first": "最前"
                    }
                },
                "lengthMenu": [
                    [10, 20, 50, -1],
                    [10, 20, 50, "All"] // change per page values here
                ],
                // set the initial value
                "pageLength": 10,
                "aoColumns":[
                    {"sTitle":"<input type=\"checkbox\" class=\"group-checkable\" data-set=\"#table_list .checkboxes\"/>", "sClass" : "table-checkbox"},
                    {"sTitle":"偵測器標籤"},
                    {"sTitle":"偵測器名稱"},
                    {"sTitle":"偵測類型"},
                    {"sTitle":"上限"},
                    {"sTitle":"下限"},
                    {"sTitle":"前台顯示"},
                    {"sTitle":"動作"},
                ],
                "aaData":[<?php echo $dataArray; ?>]
            });

            $('.group-checkable', table).change(function () {
                var set     = jQuery(this).attr("data-set");
                var checked = jQuery(this).is(":checked");
                jQuery(set).each(function () {
                    if (checked) {
                        $('#btn_mass_delete').show();
                        $(this).attr("checked", true);
                    } else {
                        $('#btn_mass_delete').hide();
                        $(this).attr("checked", false);
                    }
                });
                jQuery.uniform.update(set);
            });

            $('.checkboxes', table).change(function(){
                var checkedNum = $('.checkboxes:checked').length;
                if(checkedNum > 0){
                    $('#btn_mass_delete').show();
                }else{
                    $('#btn_mass_delete').hide();
                }
            });
        }
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.manage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>