<?php $sentinel = app('Cartalyst\Sentinel\Native\Facades\Sentinel'); ?>

<!DOCTYPE html>
<!-- 
Template Name: Metronic - Responsive Admin Dashboard Template build with Twitter Bootstrap 3.3.5
Version: 4.1.0
Author: KeenThemes
Website: http://www.keenthemes.com/
Contact: support@keenthemes.com
Follow: www.twitter.com/keenthemes
Like: www.facebook.com/keenthemes
Purchase: http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes
License: You must have a valid license purchased only from themeforest(the above link) in order to legally use the theme for your project.
-->
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8"/>
<?php $CommunityPresenter = app('NSST\Presenters\CommunityPresenter'); ?>
<title>櫃台勤務系統 - <?php echo e($CommunityPresenter->comName()); ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=10.0" name="viewport"/>
<meta content="" name="description"/>
<meta content="" name="author"/>
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/font-awesome/css/font-awesome.min.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/simple-line-icons/simple-line-icons.min.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/bootstrap/css/bootstrap.min.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/uniform/css/uniform.default.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css')); ?>" rel="stylesheet" type="text/css"/>

<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL PLUGIN STYLES -->
<!--
<link href="<?php echo e(asset('assets/global/plugins/bootstrap-daterangepicker/daterangepicker-bs3.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/fullcalendar/fullcalendar.min.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/jqvmap/jqvmap/jqvmap.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/morris/morris.css')); ?>" rel="stylesheet" type="text/css">
<link href="<?php echo e(asset('assets/global/plugins/ion.rangeslider/css/ion.rangeSlider.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/plugins/ion.rangeslider/css/ion.rangeSlider.Metronic.css')); ?>" rel="stylesheet" type="text/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-toastr/toastr.min.css')); ?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/global/plugins/datatables/media/css/jquery.dataTables.min.css')); ?>"/>
<!-- END PAGE LEVEL PLUGIN STYLES -->
<!-- BEGIN PAGE STYLES -->
<link href="<?php echo e(asset('assets/pages/css/tasks.css')); ?>" rel="stylesheet" type="text/css"/>
<!-- END PAGE STYLES -->
<!-- BEGIN THEME STYLES -->
<!-- DOC: To use 'rounded corners' style just load 'components-rounded.css' stylesheet instead of 'components.css' in the below style tag -->
<link href="<?php echo e(asset('assets/global/css/components-md.css')); ?>" id="style_components" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/global/css/plugins-md.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/layouts/layout4/css/layout.css')); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo e(asset('assets/layouts/layout4/css/themes/light.css')); ?>" rel="stylesheet" type="text/css" id="style_color"/>
<link href="<?php echo e(asset('assets/layouts/layout4/css/custom.css')); ?>" rel="stylesheet" type="text/css"/>

<link href="<?php echo e(asset('assets/global/plugins/bootstrap-sweetalert/bootstrap-sweetalert.css')); ?>" rel="stylesheet" type="text/css" />
    <!-- Custom styles for this template -->

    <link rel="stylesheet" href="<?php echo e(asset('front/css/typicons.css')); ?>" />

<!-- END THEME STYLES -->
<link rel="shortcut icon" href="favicon.ico"/>
<style>
	.btn-group{
		margin-bottom:5px;
	}
	body{
		font-family:Microsoft JhengHei  !important;
		/* Margin bottom by footer height */
		margin-bottom: 60px;
	}
	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		/* Set the fixed height of the footer here */
		height: 60px;
		background: #FFFFFF;
    	border-top: 1px solid #e9ecf3;
	}
	.blockUI {
		z-index: 99999;
	}

	.tiles .tile{
		width:120px;
		height:120px !important;
		font-size:16px;
	}

	.tiles .tile .tile-object > .name{
		font-size:15px;
		text-align: center;
		width:80%;
	}
	.label.label-sm{
		font-size:18px;
	}

</style>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<!-- DOC: Apply "page-header-fixed-mobile" and "page-footer-fixed-mobile" class to body element to force fixed header or footer in mobile devices -->
<!-- DOC: Apply "page-sidebar-closed" class to the body and "page-sidebar-menu-closed" class to the sidebar menu element to hide the sidebar by default -->
<!-- DOC: Apply "page-sidebar-hide" class to the body to make the sidebar completely hidden on toggle -->
<!-- DOC: Apply "page-sidebar-closed-hide-logo" class to the body element to make the logo hidden on sidebar toggle -->
<!-- DOC: Apply "page-sidebar-hide" class to body element to completely hide the sidebar on sidebar toggle -->
<!-- DOC: Apply "page-sidebar-fixed" class to have fixed sidebar -->
<!-- DOC: Apply "page-footer-fixed" class to the body element to have fixed footer -->
<!-- DOC: Apply "page-sidebar-reversed" class to put the sidebar on the right side -->
<!-- DOC: Apply "page-full-width" class to the body element to have full width page without the sidebar menu -->
<body class="page-md page-header-fixed page-sidebar-closed-hide-logo page-sidebar-closed-hide-logo">
<!-- BEGIN HEADER -->
<div class="page-header md-shadow-z-1-i navbar navbar-fixed-top">
	<!-- BEGIN HEADER INNER -->
	<div class="page-header-inner">
		<!-- BEGIN LOGO -->
		<div class="page-logo">
			<?php $setting = app('anlutro\LaravelSettings\Facade'); ?>
			<a target="_break" href="<?php echo e($setting::get('company_web','http://www.nsst.com.tw/')); ?>">
				<img src="<?php echo e($setting::get('logo_brancd', asset('assets/images/logo.png'))); ?>" alt="logo" class="logo" width="148px" height="75px"/>
			</a>
			<div class="menu-toggler sidebar-toggler hide">
				<!-- DOC: Remove the above "hide" to enable the sidebar toggler button on header -->
			</div>

		</div>
		<!-- END LOGO -->
		<!-- BEGIN RESPONSIVE MENU TOGGLER -->
		<a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse"></a>
		<!-- END RESPONSIVE MENU TOGGLER -->
		<!-- BEGIN PAGE ACTIONS -->
		<!-- DOC: Remove "hide" class to enable the page header actions -->
		<div class="page-actions">
			<!--<div class="alert alert-success">
				<strong>事件提醒</strong>   <span id="count_down"></span> 例行機電檢查</button>
			</div>-->
			<h3 style="margin-top:10px;"><span class="bold"><?php echo e($CommunityPresenter->comName()); ?></span> <span class="font-green"><?php echo e($setting::get('system_name','全方位建築智慧化管理系統')); ?></span></h3>

        </div>

		<!-- END PAGE ACTIONS -->
		<!-- BEGIN PAGE TOP -->
		<div class="page-top">
			<!-- BEGIN HEADER SEARCH BOX -->
			<!-- DOC: Apply "search-form-expanded" right after the "search-form" class to have half expanded search box -->
			<form class="search-form" action="extra_search.:html" method="GET">
				<div class="input-group">
					<input type="text" class="form-control input-sm" placeholder="搜尋 Search..." name="query">
					<span class="input-group-btn">
					<a href="javascript:;" class="btn submit"><i class="icon-magnifier"></i></a>
					</span>
				</div>
			</form>
			<!-- END HEADER SEARCH BOX -->
			<!-- BEGIN TOP NAVIGATION MENU -->
			<div class="top-menu">
				<ul class="nav navbar-nav pull-right">
					<li class="separator hide">
					</li>
					<li class="separator hide">
					</li>
					<!-- BEGIN TODO DROPDOWN -->
					<!-- DOC: Apply "dropdown-dark" class after below "dropdown-extended" to change the dropdown styte -->
					<li class="dropdown dropdown-extended dropdown-tasks dropdown-dark" id="header_task_bar">
						<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
						<i class="icon-envelope-open"></i>
						<?php if($unread_count == 0): ?>
						<span class="badge badge-grey">0</span>
						<?php else: ?>
						<span class="badge badge-danger"><?php echo e($unread_count); ?> </span>
						<?php endif; ?>
						</a>
						<ul class="dropdown-menu">
							<li class="external">
								<h3>你有 <span class="bold"><?php echo e($unread_count); ?>個</span>未讀訊息</h3>
								<a href="<?php echo e(route('manage::message::index')); ?>">查看全部</a>
							</li>
							<li>
								<ul class="dropdown-menu-list scroller" style="height: 275px;" data-handle-color="#637283">
									<?php foreach($top_messages as $message): ?>
									<li>
										<a href="javascript:;">
										<span class="photo">
										<img src="<?php echo e(asset('assets/layouts/layout3/img/avatar2.jpg')); ?>" class="img-circle" alt="">
										</span>
										<span class="subject">
										<span class="from">
										<?php echo e($message->send_name); ?> </span>
										<span class="time"><?php echo e($message->time); ?> </span>
										</span>
										<span class="message">
										<?php echo e(str_limit($message->title, 40)); ?></span>
										</a>
									</li>
									<?php endforeach; ?>
								</ul>
							</li>
						</ul>
					</li>
					<!-- END TODO DROPDOWN -->
					<!-- BEGIN USER LOGIN DROPDOWN -->
					<!-- DOC: Apply "dropdown-dark" class after below "dropdown-extended" to change the dropdown styte -->
					<li class="dropdown dropdown-user dropdown-dark">
						<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
							<span class="username username-hide-on-mobile"><?php echo e($sentinel::check()->name); ?></span>
							<!-- DOC: Do not remove below empty space(&nbsp;) as its purposely used -->
							<img alt="" class="img-circle" src="<?php echo e(asset('assets/layouts/layout4/img/avatar9.jpg')); ?>"/>
						</a>
						<ul class="dropdown-menu dropdown-menu-default">
							<li>
								<a href="<?php echo e(route('manage::index')); ?>">
								<i class="fa fa-laptop"></i> 回到管理後台 </a>
							</li>
							<li class="divider"></li>
							<!--
							<li>
								<a href="#">
								<i class="fa fa-database"></i> 操作紀錄查看 </a>
							</li>
							<li class="divider"></li>
							<li>
								<a href="#">
								<i class="fa fa-lock"></i> 鎖定螢幕 </a>
							</li>
							<li class="divider"></li>
							<li>
								<a href="#">
								<i class="fa fa-random"></i> 人員交接班 </a>
							</li>
							<li class="divider"></li>
							-->
							<li> 
								<a href="<?php echo e(action('LoginController@logout')); ?>">
								<i class="fa fa-power-off"></i> 登出系統 </a>
							</li>
						</ul>
					</li>
					<!-- END USER LOGIN DROPDOWN -->
				</ul>
			</div>
			<!-- END TOP NAVIGATION MENU -->
		</div>
		<!-- END PAGE TOP -->
	</div>
	<!-- END HEADER INNER -->
</div>
<!-- END HEADER -->
<div class="clearfix">
</div>
<!-- BEGIN CONTAINER -->
<div class="page-container">
	<!-- BEGIN CONTENT -->
    <div class="page-content" style="margin-left:0px; margin:0px;">
        <div class="row">
            <div class="col-md-2" style="text-align: right;">
	        <div style="margin-bottom: 10px;">
                  <a href="<?php echo e(route('console::sensor_list')); ?>"  class="category-button btn blue" style="width: 100%;text-align: left;">
                 回總監控首頁
                 </a>
             </div>
                <?php foreach($categories as $category): ?>
                    <div style="margin-bottom: 10px;">
                        <button type="button" class="category-button btn blue" style="width: 100%;text-align: left;" category="<?php echo e($category->id); ?>">
                            <i class="fa fa-plus"></i>
                            <?php echo e($category->name); ?>

                        </button>
                        <?php foreach($locations as $build => $floors): ?>
                            <div class="sensor-build-list" category="<?php echo e($category->id); ?>" style="margin-bottom: 5px;margin-top: 5px;">
                                <button type="button" class="build-button btn blue" style="width: 85%;text-align: left;background-color: #6C5195;" category="<?php echo e($category->id); ?>" build="<?php echo e($build); ?>">
                                        <i class="fa fa-building"></i>
                                        <?php echo e($build); ?>

                                </button>
                                <?php foreach($floors as $floor): ?>
                                    <div class="sensor-floor-list" category="<?php echo e($category->id); ?>" build="<?php echo e($build); ?>" style="margin-bottom: 5px;margin-top: 5px;">
                                        <button type="button" class="floor-button btn blue" style="width: 70%;text-align: left;background-color: #6C5195;" category="<?php echo e($category->id); ?>" build="<?php echo e($build); ?>" floor="<?php echo e($floor); ?>">
                                                <i class="fa fa-building-o"></i>
                                                <?php echo e($floor); ?>

                                        </button>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endforeach; ?>
            </div>
            <div class="col-md-10" >
            	<div id="test">
                <?php foreach($buildMonitors as $build => $buildData): ?>
                    <div class="col-md-4 build-monitor" category="<?php echo e($category); ?>" build="<?php echo e($build); ?>" style="margin-bottom: 15px;">
                        <div class="row">
                            <div class="col-md-12" style="text-align: center;">
                                <h3 style="margin-top:0px;font-weight:bold;"><?php echo e($build); ?></h3>
                            </div>
                        </div>
                        <div class="row"  id="btn-notice">
                            <div class="portlet light build-monitor" category="<?php echo e($category); ?>" build="<?php echo e($build); ?>" style="margin: 5px;">
                                <div class="portlet-body">
                                    <div class="row">
                                        <div class="col-md-6"><h3 style="width: 110px;background-color: #666;color: #fff;padding: 5px;">總監測數</h3></div>
                                        <div class="col-md-4" style="text-align: center;font-weight:bolder"><h3><?php echo e($buildData['sensor_count']); ?></h3></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6"><h3 style="width: 110px;background-color: #666;color: #fff;padding: 5px;">總警報數</h3></div>
                                        <div class="col-md-4" style="text-align: center;">
                                            <h3>
                                                <?php if($buildData['error_count'] > 0): ?>
                                                    <span class="label label-lg label-danger" style="width:50px"><?php echo e($buildData['error_count']); ?></span>
                                                <?php else: ?>
                                                    <span class="label label-sm label-info">無警報</span>
                                                <?php endif; ?>
                                            </h3>
                                        </div>
                                    </div>
                                    <div style="height: 350px;overflow-y: auto;">
                                        <table class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th >各樓層警報現況</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <?php foreach($buildData['floor'] as $floor => $floorData): ?>
                                                <tr>
                                                    <td>
                                                        <div class="col-md-6" style="font-size:18px"><?php echo e($floor); ?></div>
                                                        <div class="col-md-6" style="text-align: right;font-size:18px">
                                                            <?php if($floorData['error_count'] > 0): ?>
                                                                <span class="label label-sm label-danger"><?php echo e($floorData['error_count']); ?></span>
                                                            <?php else: ?>
                                                                <span class="label label-sm label-info">無警報</span>
                                                            <?php endif; ?>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
                </div>
                <?php foreach($categories as $category): ?>
                    <?php foreach($locations as $build => $floors): ?>
                        <?php foreach($floors as $floor): ?>
                            <div class="location-sensors" category="<?php echo e($category->id); ?>" build="<?php echo e($build); ?>" floor="<?php echo e($floor); ?>">
                                <h3 style="margin-top:0px;font-weight:bold;"><?php echo e($build.'-'.$floor); ?></h3>
                                <div class="portlet light">
                                    <div class="portlet-body">
                                        <div class="row">
                                            <?php if(isset($sensors[$category->id][$build][$floor])): ?>
                                                <?php foreach($sensors[$category->id][$build][$floor] as $sensor): ?>
                                                    <div style="padding: 0px;margin: 8px;width: 84px;float: left;">
                                                        <div class="easy-pie-chart sensor-chart" sensor-tag="<?php echo e($sensor->tag); ?>" sensor-type="<?php echo e($sensor->monitor_type); ?>" sensor-upper="<?php echo e($sensor->upper_limit); ?>" sensor-lower="<?php echo e($sensor->lower_limit); ?>" sensor-value="<?php echo e(isset($lastRecordOfSensor[$sensor->tag]) ? $lastRecordOfSensor[$sensor->tag]->value : ''); ?>" sensor-unit="<?php echo e($sensor->unit); ?>" sensor-name="<?php echo e($sensor->sensor_name); ?>" style="padding: 0px;">
                                                            <div class="number sensor-data-percent" data-percent="0" style="height: 75px;">
                                                                <span class="sensor-text"><?php echo e(isset($lastRecordOfSensor[$sensor->tag]) ? $lastRecordOfSensor[$sensor->tag]->value : '無紀錄'); ?></span>
                                                                <canvas style="height: 75px; width: 75px;"></canvas>
                                                            </div>
                                                            <div style="height: 75px;">
                                                                <a class="title demo_ba" href="javascript:;">
                                                                <?php echo e($sensor->sensor_name); ?> <i class="icon-arrow-right"></i>
                                                                </a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php endforeach; ?>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
</div>
<!-- END CONTAINER -->

<!-- BEGIN MODAL -->
<div id="ba_modal" class="modal fade in bs-modal-lg" id="large" tabindex="-1">
	<div class="modal-dialog modal-lg">
		<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">BA即時監測 - <span id="sensor_name"></span></span></h4>
			</div>
			<div class="modal-body">
                <div id="sensor_history_chart"></div>
				<div class="row">
					<div class="col-md-6">
						<div class="panel panel-default">
							<!-- Default panel contents -->
							<div class="panel-heading">
								<h3 class="panel-title">設備監測狀態</h3>
							</div>
							<!-- List group -->
                            <div id="sensor_equip_status"></div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="portlet light">
							<div class="portlet-title tabbable-line">
								<div class="caption caption-md">
									<i class="icon-globe theme-font-color hide"></i>
									<span class="caption-subject theme-font-color bold uppercase">事件通知</span>
								</div>
							</div>
							<div class="portlet-body">
								<!--BEGIN TABS-->
								<div class="tab-content">
									<div class="tab-pane active" id="sensor_event_notify"></div>
								</div>
								<!--END TABS-->
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn default" data-dismiss="modal">關閉</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- END MODAL -->
<div id="notice_modal" class="modal bs-modal-lg" id="large" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header bg-blue-soft">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
				<h4 class="modal-title font-white" id="notice_title"></h4>
			</div>
			<div class="modal-body" id="notice_content">
				 content
			</div>
			<div class="modal-footer">
				<button type="button" class="btn default" data-dismiss="modal">關閉</button>
				<!--
				<button type="button" class="btn blue">Save changes</button> 
				-->
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>

<!-- BEGIN FOOTER -->
<footer class="footer">
	<div class="row" style="margin-top:12px;">
		<div class="col-md-3">
			<p class="text-muted pull-right" style="margin :0 0 10px">
			<?php echo e($setting::get('copyright_2','Copyright. NSST SinBao Technology.')); ?><br> 
			<?php echo e($setting::get('copyright_company','新保科技有限公司')); ?></p>
		</div>
		<div class="col-md-6" style="text-align:center;">
			<p class="text-muted" style="margin :0 0 0px"><?php echo e($setting::get('brand','NSST')); ?>&nbsp;<?php echo e($setting::get('system_name','全方位建築智慧化管理系統')); ?></p>
              <ul class="list-inline text-amber date-list" style="color:#777">
                  <li><i class="fontello-th" style="color:#777"></i>
                  </li>
                  <li id="Date" ></li>
                  <li><i class="fontello-stopwatch" style="color:#777"></i>
                  </li>
                  <li id="hours"></li>
                  <li class="point">:</li>
                  <li id="min"></li>
                  <li class="point">:</li>
                  <li id="sec"></li>
              </ul>
		</div>
		<div class="col-md-3 pull-right">

		
			<a href="<?php echo e(action('ConsoleController@index')); ?>" type="button" class="btn btn-primary pull-right" style="margin-right:15px;">回到櫃台</a>
			<a href="<?php echo e(action('LoginController@logout')); ?>" type="button" class="btn btn-primary pull-right" style="margin-right:15px;">登出系統</a>
		</div>
	</div>
</footer>
<!-- BEGIN MODAL -->
<div id="ba_alert" class="modal fade in bs-modal-lg" id="large" tabindex="-1">
	<div class="modal-dialog modal-lg">
		<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">BA即時監測 - <span id="location"></span></span></h4>
			</div>
			<div class="modal-body">
                <div id="sensor_history_chart"></div>
				<div class="row">
					<div class="col-md-6">
						<div class="panel panel-default">
							<!-- Default panel contents -->
							<div class="panel-heading">
								<h3 class="panel-title">設備監測狀態</h3>
							</div>
							<!-- List group -->
                            <div id="sensor_equip_status"></div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="portlet light">
							<div class="portlet-title tabbable-line">
								<div class="caption caption-md">
									<i class="icon-globe theme-font-color hide"></i>
									<span class="caption-subject theme-font-color bold uppercase">事件通知</span>
								</div>
								<div class="actions">
									<a href="javascript:;" class="btn default btn-sm">
										下一頁<i class="fa fa-arrow-right"></i>
									</a>
								</div>
							</div>
							<div class="portlet-body">
								<!--BEGIN TABS-->
								<div class="tab-content">
									<div class="tab-pane active" id="sensor_event_notify"></div>
								</div>
								<!--END TABS-->
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn default" data-dismiss="modal">關閉</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- BEGIN CORE PLUGINS -->
<!--[if lt IE 9]>
<script src="<?php echo e(asset('assets/global/plugins/respond.min.js')); ?>"></script>
<script src="<?php echo e(asset('assets/global/plugins/excanvas.min.js')); ?>"></script> 
<![endif]-->
<script src="<?php echo e(asset('assets/global/plugins/jquery.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery-migrate.min.js')); ?>" type="text/javascript"></script>
<!-- IMPORTANT! Load jquery-ui.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
<script src="<?php echo e(asset('assets/global/plugins/jquery-ui/jquery-ui.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/bootstrap/js/bootstrap.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery.blockui.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery.cokie.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/countdown/jquery.countdown.min.js')); ?>"></script>

<script src="<?php echo e(asset('assets/global/plugins/uniform/jquery.uniform.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js')); ?>" type="text/javascript"></script>
<!-- END CORE PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/amcharts.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/serial.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/pie.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/radar.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/themes/light.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/themes/patterns.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amcharts/themes/chalk.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/ammap/ammap.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/ammap/maps/js/worldLow.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/amcharts/amstockcharts/amstock.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jqvmap/jqvmap/jquery.vmap.js')); ?>" type="text/javascript"></script>
<!-- IMPORTANT! fullcalendar depends on jquery-ui.min.js for drag & drop support -->
<script src="<?php echo e(asset('assets/global/plugins/morris/morris.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/morris/raphael-min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery.sparkline.min.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/global/plugins/jquery-easypiechart/jquery.easypiechart.min.js')); ?>" type="text/javascript"></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/select2/js/select2.min.js')); ?>"></script>

<script type="text/javascript" src="<?php echo e(asset('assets/global/plugins/bootstrap-toastr/toastr.min.js')); ?>"></script>

<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="<?php echo e(asset('assets/global/scripts/app.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/layouts/layout4/scripts/layout.js')); ?>" type="text/javascript"></script>
<!-- <script src="<?php echo e(asset('assets/admin/pages/scripts/index3.js')); ?>" type="text/javascript"></script> -->
<script src="<?php echo e(asset('assets/pages/scripts/tasks.js')); ?>" type="text/javascript"></script>
<script src="<?php echo e(asset('assets/pages/scripts/charts-amcharts.js')); ?>" type="text/javascript"></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>
<!-- END PAGE LEVEL SCRIPTS -->
<script src="<?php echo e(asset('assets/global/plugins/bootstrap-sweetalert/bootstrap-sweetalert.min.js')); ?>" type="text/javascript"></script>

<script src="<?php echo e(asset('/assets/global/scripts/web_socket.js')); ?>"></script>
<script type="text/javascript">
	var ws, client_list={};
	var name = '<?php echo e($sentinel::check()->id); ?>';
	$(document).ready(function(){
		connect();
		socketAction('update_notice');
        setTimeout(function(){ location.reload(); }, 1 * 60 * 1000);
	});
    var listInit = function() {
        $('.sensor-build-list').hide();
        $('.category-sensors').hide();
        $('.location-sensors').hide();
    }
    
    var checkResultIsExist = function() {
        var displayCount = $('.location-sensors:visible').length;

        if (displayCount == 0) {
            $('#no-result').show();
        } else {
            $('#no-result').hide();
        }        
    }
    
    var refreshAllSensorStatus = function() {
        $('.sensor-chart').each(function() {
            updateSensorStatus($(this).attr('sensor-tag'), $(this).attr('sensor-value'));    
        });    
    }
    
    var updateSensorStatus = function(tag, value) {
        var sensorObj  = $('.sensor-chart[sensor-tag="' + tag + '"]');
        var percentObj = sensorObj.find('.sensor-data-percent');
        var textObj    = sensorObj.find('.sensor-text');
        var percent    = 0;
        var color      = App.getBrandColor('green');
        var text       = '';
        
        if (sensorObj.length == 0) return;
        
        if (typeof value == 'undefined') {
            value = sensorObj.attr('sensor-value');
        } else {
            sensorObj.attr('sensor-value', value);
        }

        var monitorType = sensorObj.attr('sensor-type');
        var upper       = sensorObj.attr('sensor-upper');
        var lower       = sensorObj.attr('sensor-lower');

        if (value) {
            if (monitorType != 0) {
                text    = '正常&nbsp;&nbsp;';
                percent = 100;
                if (value == 1 && monitorType != 2) {
                    text  = '異常&nbsp;&nbsp;';
                    color = App.getBrandColor('red');
                }
            } else {
                percent = ((value - lower) / (upper - lower)) * 100;
                if (percent < 0) percent = 0;
                if (percent > 100) percent = 100;
                if (percent < 20 || percent > 80) {
                    color = App.getBrandColor('yellow');
                }
                if (percent <= 0 || percent >= 100) {
                    color = App.getBrandColor('red');
                }
                text = value + ' ' + sensorObj.attr('sensor-unit');
            }
        } else {
            text = '無紀錄&nbsp;&nbsp;';    
        }
        textObj.html(text);
        
        percentObj.data('easyPieChart').update(percent).options.barColor = color;
    }
    
    // 连接服务端
    function connect() {
       // 创建websocket
       ws = new WebSocket("ws://<?php echo e(env('WS_HOST','www.nsst.tw')); ?>:<?php echo e(env('WS_PORT','7272')); ?>");
       // 当socket连接打开时，输入用户名
       ws.onopen = onopen;
       // 当有消息时根据消息类型显示不同信息
       ws.onmessage = onmessage; 
       ws.onclose = function() {
    	  console.log("關閉連線，等待重新嘗試");
          connect();
       };
       ws.onerror = function() {
     	  console.log("出現錯誤");
       };
    }

    // Send Login Message on connected.
    function onopen()
    {
        // Login
        var login_data = '{"type":"login","client_uid":"'+name+'","com_id":"<?php echo e(env('DB_DATABASE')); ?>"}';
        console.log("WebSocket shakehand success:"+login_data);
        ws.send(login_data);
    }

    // 服务端发来消息时
    function onmessage(e)
    {
        console.log(e.data);
        var data = eval("("+e.data+")");
        switch(data['type']){
            // 服务端ping客户端
            case 'ping':
                ws.send('{"type":"pong"}');
                break;;
            // 登录 更新用户列表
            // case 'login':
            //     //{"type":"login","client_id":xxx,"client_uid":"xxx","client_list":"[...]","time":"xxx"}
            //     //say(data['client_id'], data['client_uid'],  data['client_uid']+' 加入了聊天室', data['time']);
            //     toastr['info'](data['client_uid']+' 連線成功');
            //     if(data['client_list']){
            //         client_list = data['client_list'];
            //     }else{
            //         client_list[data['client_id']] = data['client_uid']; 
            //     }
            //     //flush_client_list();
            //     console.log(data['client_uid']+"登录成功");
            //     break;
            // // 发言
            // case 'say':
            //     //{"type":"say","from_client_id":xxx,"to_client_id":"all/client_id","content":"xxx","time":"xxx"}
            //     //say(data['from_client_id'], data['from_client_uid'], data['content'], data['time']);
            //     toastr['success'](data['from_client_uid']+':'+data['content']);
            //     break;
            // // 用户退出 更新用户列表
            // case 'logout':
            //     //{"type":"logout","client_id":xxx,"time":"xxx"}
            //     //say(data['from_client_id'], data['from_client_uid'], data['from_client_uid']+' 退出了', data['time']);
            //     toastr['warning'](data['client_uid']+' 離線');
            //     delete client_list[data['from_client_id']];
            //     break;
            //     //flush_client_list();
            case 'system':
            	// toastr[data['level']](data['content']);
            	break;
            case 'action':
            	socketAction(data['action']);
            	break;
        }
    }

    function socketAction(action)
    {
    	
    	if (action.indexOf(':')!=-1){
            $('#ba_alert').modal('hide');
            $.ajax({
                type : 'GET',
                url : '<?php echo e(action('SensorApiController@select_tagname_value')); ?>',
                dataTyep:'json',
                data : {
                    _token : '<?php echo e(csrf_token()); ?>',
                    tag: action
                },
                success : function(sendback){
                    updateSensorStatus(sendback.data[0].tag,sendback.data[0].value);
                    socketAction('update_notice');
                    swal({
                      title: "監測警告",
                      text: sendback.data[0].trigger_time+"\n於「"+sendback.where[0]+sendback.where[1]+"樓的"+sendback.where[2]+"-設備："+sendback.data[0].sensor_name+"發生警告」"+"\n",
                      type: "error",
                      showCancelButton: true,
                      confirmButtonClass: "btn-danger",
                      cancelButtonText: "取消",
                      confirmButtonText: "確認",
                    },
                    function(){
                      swal("Deleted!", "請與設備商聯繫！");
                    });
                    toastr['error']('監測系統發出警告，請立即查看');
                },
                error : function(sendback){
                    toastr['error']('警告系統異常，請聯繫管理員');
                }
            });
        }
    }

</script>

<script>
$(document).on('click','#demo_select_event',function(){
	$('#s2id_demo_select').fadeIn();
});

$('.category-button').click(function(){
	$('#test').hide();
    var category = $(this).attr('category');
    $('.category-sensors').hide();
    $('.sensor-build-list').hide();
    $('.sensor-floor-list').hide();
    $('.category-sensors[category="' + category + '"]').show();
    $('.sensor-build-list[category="' + category + '"]').show();
    $('.location-sensors').hide(); 
    $('.location-sensors[category="' + category + '"]').show();   
    checkResultIsExist();
});
    
$('.build-button').click(function(){
    var build    = $(this).attr('build');
    var category = $(this).attr('category');
    $('.category-sensors').hide();
    $('.sensor-build-list').hide();
    $('.sensor-floor-list').hide();
    $('.category-sensors[category="' + category + '"]').show();
    $('.sensor-build-list[category="' + category + '"]').show();
    $('.sensor-floor-list[category="' + category + '"][build="' + build + '"]').show();
    $('.location-sensors').hide(); 
    $('.location-sensors[category="' + category + '"][build="' + build + '"]').show();   
    checkResultIsExist();
});

$('.floor-button').click(function(){
    var floor    = $(this).attr('floor');
    var build    = $(this).attr('build');
    var category = $(this).attr('category');
    $('.category-sensors').hide();
    $('.category-sensors[category="' + category + '"]').show();
    $('.location-sensors').hide(); 
    $('.location-sensors[category="' + category + '"][build="' + build + '"][floor="' + floor + '"]').show();
    checkResultIsExist();
});
    
//設定TOKEN
$(document).ready(function(){
	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
	});
    
    $('.sensor-data-percent').easyPieChart({
        animate: 1000,
        size: 75,
        lineWidth: 3,
        barColor: App.getBrandColor('yellow')
    });
    
    /*
	$('.easy-pie-chart .number.transactions').easyPieChart({
        animate: 1000,
        size: 75,
        lineWidth: 3,
        barColor: App.getBrandColor('yellow')
    });

    $('.easy-pie-chart .number.visits').easyPieChart({
        animate: 1000,
        size: 75,
        lineWidth: 3,
        barColor: App.getBrandColor('green')
    });

    $('.easy-pie-chart .number.water').easyPieChart({
        animate: 1000,
        size: 75,
        lineWidth: 3,
        barColor: App.getBrandColor('red')
    });

    $('.easy-pie-chart-reload').click(function() {
        $('.easy-pie-chart .number').each(function() {
            var newValue = Math.floor(100 * Math.random());
            $(this).data('easyPieChart').update(newValue);
            $('span', this).text(newValue);
        });
    });
    */
    $(".select2, .select2-multiple").select2({
        width: null
    });
    
    listInit();
    
    refreshAllSensorStatus();
});

var callDataTable = function(){
	$('.data_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,
		"pagingType": "bootstrap_full_number",         

	});
}

var callMailDataTable = function () {
    var table = $('#table_mail');

    /* Formatting function for row details */
    function fnFormatDetails(oTable, nTr) {
        var aData = oTable.fnGetData(nTr);
        var sOut = '<table>';
        sOut += '<tr><td>郵件編號(條碼)</td><td>' + aData[1] + '</td></tr>';
        sOut += '<tr><td>感應卡ID</td><td>' + aData[2] + '</td></tr>';
        sOut += '<tr><td>收件經手人</td><td>' + aData[3] + '</td></tr>';
        sOut += '<tr><td>領件經手人</td><td>' + aData[4] + '</td></tr>';
        sOut += '<tr><td>領件經手人</td><td>' + aData[5] + '</td></tr>';
        sOut += '</table>';

        return sOut;
    }

    var nCloneTh = document.createElement('th');
    nCloneTh.className = "table-checkbox";

    var nCloneTd = document.createElement('td');
    nCloneTd.innerHTML = '<span class="row-details row-details-close"></span>';

    table.find('thead tr').each(function () {
        this.insertBefore(nCloneTh, this.childNodes[0]);
    });

    table.find('tbody tr').each(function () {
        this.insertBefore(nCloneTd.cloneNode(true), this.childNodes[0]);
    });

    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": "No data available in table",
		    "info": "顯示第 _START_ 到第 _END_ 則 共有 _TOTAL_ 則",
		    "infoEmpty": "沒有找到符合的資料",
		    "infoFiltered": "(filtered1 from _MAX_ total records)",
		    "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,
		"pagingType": "bootstrap_full_number",
		"columnDefs": [{  // set default column settings
		    'orderable': false,
		    'targets': [0]
		}, {
		    "searchable": false,
		    "targets": [0]
		}]
	});
    var tableWrapper = $('#table_list_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper

    /* Add event listener for opening and closing details
     * Note that the indicator for showing which row is open is not controlled by DataTables,
     * rather it is done here
     */
    table.on('click', ' tbody td .row-details', function () {
        var nTr = $(this).parents('tr')[0];
        if (oTable.fnIsOpen(nTr)) {
            /* This row is already open - close it */
            $(this).addClass("row-details-close").removeClass("row-details-open");
            oTable.fnClose(nTr);
        } else {
            /* Open this row */
            $(this).addClass("row-details-open").removeClass("row-details-close");
            oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
        }
    });
}

var callDataTable_news = function(){
	$('.data_table_news').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": "No data available in table",
		    "info": "顯示第 _START_ 到第 _END_ 則 共有 _TOTAL_ 則",
		    "infoEmpty": "沒有找到符合的資料",
		    "infoFiltered": "(filtered1 from _MAX_ total records)",
		    "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,
		"pagingType": "bootstrap_full_number",
		"columnDefs": [{  // set default column settings
		    'orderable': false,
		    'targets': [0]
		}, {
		    "searchable": false,
		    "targets": [0]
		}]
	});
}

//BA展示範例
$(document).on('click','.demo_ba',function(){
    var chart = $(this).parents('.sensor-chart');
    var tag   = chart.attr('sensor-tag');
    $('#sensor_name').text(chart.attr('sensor-name'));
    $('#sensor_history_chart').html('<div style="text-align:center;">Loading...</div>');
    $('#sensor_equip_status').html('<div style="text-align:center;">Loading...</div>');
    $('#sensor_event_notify').html('<div style="text-align:center;">Loading...</div>');
    $.ajax({
        type : 'GET',
        url : '<?php echo e(route('console::getChart2')); ?>',
        dataTyep:'html',
        data: {id: tag},
        success : function(sendback){
            $('#sensor_history_chart').html(sendback);
        },
        error : function(sendback){

        }
    });
    
    $.ajax({
        type : 'GET',
        url : '<?php echo e(route('console::getEquipStatus')); ?>',
        dataTyep:'html',
        data: {id: tag},
        success : function(sendback){
            $('#sensor_equip_status').html(sendback);
        },
        error : function(sendback){

        }
    });
    
    $.ajax({
        type : 'GET',
        url : '<?php echo e(route('console::getEventNotify')); ?>',
        dataTyep:'html',
        data: {id: tag},
        success : function(sendback){
            $('#sensor_event_notify').html(sendback);
        },
        error : function(sendback){

        }
    });
    
	$('#ba_modal').modal('show');
});

$(document).on('click','#btn-notice',function(){
	$('#notice_title').html('');
	$('#notice_content').html('');
	var id = $(this).attr('notice-id');
	var title = $(this).attr('notice-name');
	$('#notice_modal').modal('show');
	App.blockUI({
        target: '#notice_content',
        boxed: true,
        overlayColor: 'none',
        message: '讀取資料中...',
        textOnly: true
    });

	$.ajax({
		url:'<?php echo e(route("console::notice_list")); ?>',
		type:'GET',
		data:{
			id : "BA",
		},
		success: function(sendback){
			$('#notice_title').html(title);
			$('#notice_content').html(sendback);
			App.unblockUI('#notice_content');
			if(id == 'mail'){
				callMailDataTable();
			}else{
				callDataTable();
			}
		},
		error: function(sendback){
			toastr['warning']('此項目目前尚未開放');
			App.unblockUI('#notice_content');
			$('#notice_modal').modal('hide');
		}
	});
});

$(document).on('click','.btn_filter',function(){
	console.log('test');
	var id = $(this).data('notice');
	var filter = $(this).data('filter');

	$.ajax({
		url:'<?php echo e(route("console::notice_list")); ?>',
		type:'GET',
		data:{
			id : id,
			filter : filter
		},
		success: function(sendback){
			$('#notice_content').html(sendback);
			callDataTable();
		},
		error: function(sendback){
			toastr['warning']('此項目目前尚未開放');
			$('#notice_modal').modal('hide');
		}
	});
});

$(document).on('click','.btn-function',function(){
	switch($(this).attr('function')){
		case 'mail':
			$('#function_quick_content').html('<iframe src="<?php echo e(url("quicks/mail")); ?>" style="width:100%;height:90vh;"></iframe>');
			$('#modal_function_quick').modal('show');
			break;
		case 'guest':
			$('#function_quick_content').html('<iframe src="<?php echo e(url("quicks/quick/#/guest/")); ?>" style="width:100%;height:90vh;"></iframe>');
			$('#modal_function_quick').modal('show');
			break;
		case 'keeper':
			$('#function_quick_content').html('<iframe src="<?php echo e(url("quicks/quick/#/keeper/")); ?>" style="width:100%;height:90vh;"></iframe>');
			$('#modal_function_quick').modal('show');
			break;
		case 'news':
			$.ajax({
				type:'GET',
				url: '<?php echo e(route("console::function")); ?>',
				data:{
					function : 'news'
				},
				success: function(sendback){
					$('#modal_function_news_content').html(sendback);
					$('#modal_function_news').modal('show');
					callDataTable_news();
				},
				error: function(sendback){
					toastr['error']('操作錯誤，請聯繫開發人員');
				}
			});
			break;
		case 'record':
			clear_record_display();
			$('#modal_function_record').modal('show');
			break;
		case 'meal':
			$('#function_quick_content').html('<iframe src="<?php echo e(action('MealController@meal')); ?>" style="width:100%;height:90vh;"></iframe>');
			$('#modal_function_quick').modal('show');
			break;
		case 'setcard':
			cardset_init();
			cardset_step_1();
			cardset_var_init();
			$('#modal_function_cardset').modal('show');
			break;
	}
});

$(document).on('click','.btn_news_view',function(){
	uid = $(this).attr('uid');
	$.ajax({
		type : 'GET',
		url : "<?php echo e(action('ConsoleController@viewNews',['id'=>''])); ?>/"+uid,
		success : function(sendback){
			$('#modal_function_news_view_content').html(sendback);
			$('#modal_function_news_view').modal('show');
		},
		error : function(sendback){
			toastr['error']('操作錯誤，請重新整理後再試');
		}
	})
});

$('#modal_function_quick').on('hidden.bs.modal',function(){
	$('#function_quick_content').html('');
});

$('#modal_function_news').on('hidden.bs.modal',function(){
	$('#modal_function_news_content').html('');
});

$(document).on('click','.btn_home_service_handle',function(){
	$.ajax({
		type: 'GET',
		dataType: 'json',
		url: $(this).attr('url'),
		success: function(sendback){
			$.each(sendback, function (key, data) {
				$( "#div_view_home_service .view_input[name='"+key+"']").html(data);
				if(key == 'id'){
					$('#uid').val(data);
				}
				if(key == 'handle' && data != ''){
					$('#home_service_handle_event').html(data);
				}
				if(key == 'status'){
					if(data == 1){
						$('#btn_unhandle_home_service').show();
					}
					else{
						$('#btn_unhandle_home_service').hide();
					}
				}
			});

			$('#modal_home_service_handle').modal('show');
		},
		error:function(sendback){
			toastr['error']('操作錯誤，請聯繫開發人員');
		}
	});
});

$(document).on('click','.btn_home_service_event',function(){
	var handle_event = $(this).html();
	var id = $('#div_view_home_service #uid').val();
	$.ajax({
		type:'POST',
		url:"<?php echo e(action('ConsoleController@handleHomeService')); ?>",
		data:{
			_token:'<?php echo e(csrf_token()); ?>',
			id:id,
			event:handle_event
		},
		success:function(sendback){
			$('#home_service_handle_event').html(sendback);
		},
		error:function(sendback){
			toastr['error']('操作錯誤，請聯繫開發人員');
		}
	});
});

$(document).on('click','.btn_lost_thing_handle',function(){
	//$('#notice_modal').modal('hide');
	$.ajax({
		type: 'GET',
		dataType: 'json',
		url: $(this).attr('url'),
		success: function(sendback){
			$.each(sendback, function (key, data) {
				$( "#div_view_lost_thing .view_input[name='"+key+"']").html(data);
				if(key == 'id'){
					$('#div_view_lost_thing input[name="id"]').val(data);
				}
			});

			$('#modal_lost_thing_handle').modal('show');
		},
		error:function(sendback){
			toastr['error']('操作錯誤，請聯繫開發人員');
		}
	});
});

$(document).on('keypress','#record_user_query',function(e){
	if(e.which == 13){
		record_user_query();
	}
});
$(document).on('click','#btn_record_user_query',function(){
	record_user_query();
});

$(document).on('change','#record_user_query_id',function(){
	var username = $(this).val();
	$('#record_user_query').val(username);
	record_user_query();
});
var record_user_query = function(){
	var user = $('#record_user_query').val();
	$.ajax({
		type: 'GET',
		url: '<?php echo e(route("console::get_record_user")); ?>',
		dataType:'json',
		data:{
			user : user
		},
		success: function(sendback){
			$('#record_display_username').html(sendback.username+' - '+sendback.name);
			$('#record_user_id').val(sendback.user_id);
			$('#record_display').show();
			console.log(sendback);
		},
		error: function(sendback){
			clear_record_display();
			toastr["error"](sendback.responseText);
		}

	});
}

$(document).on('keypress','#record_value',function(e){
	if(e.which == 13){
		record_send();
	}
});

$(document).on('click','#btn_record_send',function(){
	record_send();
});

var record_send = function(){
	var user_id = $('#record_user_id').val();
	var record_id = $('#record_id').val();
	var value = $('#record_value').val();
	$.ajax({
		type:'POST',
		url:'<?php echo e(route("console::post_record_send")); ?>',
		dataType:'json',
		data:{
			_token:'<?php echo e(csrf_token()); ?>',
			user_id : user_id,
			record_id : record_id,
			value : value
		},
		success: function(sendback){
			clear_record_display();
			toastr["success"]('成功送出抄錶');
		},
		error: function(sendback){
			toastr["error"]('抄錶送出失敗');
		}
	});
}
var clear_record_display = function(){
	$('#record_display_username').html('');
	$('#record_user_query').val('');
	$('#record_user_id').val('');
	$('#record_value').val('');
	$('#record_display').hide();
}

$(document).on('click','#btn_send_mail_sms',function(){
	$(this).addClass('disabled');
	$.ajax({
		type : 'GET',
		url : '<?php echo e(action('ConsoleController@send_mail_sms_check')); ?>',
		dataType: 'json',
		success : function(sendback){
			if(sendback.count > 0){
				toastr["info"]('本次簡訊共花費'+sendback.count+'點，是否確認傳送簡訊提醒?<br /><br /><button id="btn_send_mail_sms_confirm" type="button" class="btn btn-success clear">確定</button>');
			}else{
				toastr['error'](sendback.message);
			}
			$('#btn_send_mail_sms').removeClass('disabled');
		},
		error : function(sendback){
			toastr['error']('錯誤');
		}
	});
});	

$(document).on('click','#btn_send_mail_sms_confirm',function(){
	$.ajax({
		type: 'POST',
		url : '<?php echo e(action('ConsoleController@send_mail_sms_confirm')); ?>',
		data : {
			_token:'<?php echo e(csrf_token()); ?>'
		},
		dataType:'json',
		success : function(sendback){
			toastr['success']('郵件提醒簡訊發送成功');
		},
		error : function(sendback){
			toastr['error']('郵件提醒簡訊發送失敗');
		}
	});
});

//SetCard Function
$(document).on('click','#btn_setcard_submit',function(){
	var user_id = $('#setcard_user_select').val();
	var card_no = $('#setcard_card_no').val();
	$('#setcard_card_no').val('');
	$.ajax({
		type: 'POST',
		url: '<?php echo e(action('ConsoleController@setcard')); ?>',
		dataType:'json',
		data:{
			mode : 'step1',
			user_id : user_id,
			card_no : card_no,
			_token : '<?php echo e(csrf_token()); ?>'
		},
		success : function(sendback){
			toastr['success']('成功設定');
			$('#setcard_active').show();
		},
		error : function(sendback){
			toastr['error'](sendback.message);
		}
	})
});

$(document).on('click','#btn_setcard_active',function(){
	var key = $('#setcard_active_key').val();
	$('#setcard_active_key').val('');
	$.ajax({
		type : 'POST',
		url : '<?php echo e(action('ConsoleController@setcard')); ?>',
		dataType: 'json',
		data : {
			mode:'step2',
			key : key,
			_token: '<?php echo e(csrf_token()); ?>'
		},
		success : function(sendback){
			toastr['success']('驗證碼驗證成功');
			$('#setcard_active').hide();
		},
		error : function(sendback){
			toastr['error'](sendback.message);
		}
	});
});
</script>

<?php echo $__env->make('console.js.cardset', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

    <!--
    ================================================== -->
    <!-- Main jQuery Plugins -->
    <script type='text/javascript' src="<?php echo e(asset('front/js/date.js')); ?>"></script>


<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>