@extends('admin.master')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            <div class="contentpanel">
                <form id="listForm" method="post">
                    <!-- 功能按鈕(新增/批量處理等等) -->
                    <div class="row" style="margin-bottom: 5px;">
                        <div class="col-lg-12">
                            <ol class="headermenu">
                                <li>
                                    <button class="btn btn-darkblue btn-xs" id="btnNew"><strong>新增</strong></button>
                                </li>
                            </ol>
                        </div>
                    </div>
                    <!-- 搜尋段 -->
                    <div class="panel panel-default">
                        <div class="panel-heading" data-toggle="collapse" data-target="#search_content">
                            <h3 class="panel-title">參數維護</h3>
                        </div>
                        <div id="search_content" class="collapse in">
                            <div class="panel-body">
                                <!-- 建立時間範圍 from -->
                                <div class="form-group col-xs-12 col-sm-6 col-lg-6">
                                    <label for="cDateStart">建立時間範圍(起)</label>
                                    <input type="text" class="form-control input-sm" id="cDateStart"
                                           maxlength="10">
                                </div>
                                <!-- 建立時間範圍 to -->
                                <div class="form-group col-xs-12 col-sm-6 col-lg-6">
                                    <label for="cDateFinal">建立時間範圍(迄)</label>
                                    <input type="text" class="form-control input-sm" id="cDateFinal"
                                           maxlength="10">
                                </div>
                                <!-- 用途 -->
                                <div class="form-group col-xs-12 col-sm-6 col-lg-6">
                                    <label for="name">用途</label>
                                    <input type="text" class="form-control input-sm" id="name" maxlength="32">
                                </div>
                                <!-- 有效否 -->
                                <div class="form-group col-xs-12 col-sm-6 col-lg-6">
                                    <label for="active">有效否</label>
                                    <select class="form-control input-sm" id="active">
                                        <option value="">全部</option>
                                        @foreach($active as $k => $data)
                                            <option value="{{ $k }}">{{ $data }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <!-- Search -->
                                <div class="form-group col-xs-12 col-sm-12 col-lg-12">
                                    <a class="btn btn-success btn-xs" onclick="javascript: custom_search();">
                                        <div class="glyphicon glyphicon-search"></div>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr class="search-hr"/>
                    <!-- 列表段 -->
                    <div class="row">
                        <div class="col-lg-12">
                            <table id="GridView1" class="table table-striped table-bordered" cellspacing="0">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用途</th>
                                    <th>變數名稱</th>
                                    <th>變數內容</th>
                                    <th>有效否</th>
                                    <th>建立時間</th>
                                    <th>修改時間</th>
                                    <th>修改人</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </form>
                <!-- row -->
            </div>
        </div>
    </div>
@endsection

@section('extjs')
    <script>
        $(document).ready(function () {
            var table = $('#GridView1').dataTable({
                "scrollX": true,
                "processing": true,
                "serverSide": true,
                "ajax": "settingManagement/grid",
                "paging": true,
                "ordering": true,
                "info": true,
                "order": [[1, "desc"]],
                "stateSave": true,
                "pagingType": "full",
                "bFilter": true,
                "aoColumnDefs": [{
                    'bSortable': false,
                    'aTargets': [] //不想參加排序的欄位，可指定多個，逗號分隔
                }]
            });
            // 從網址參觸發搜尋
            custom_search();
            $('#GridView1_filter').hide();
        });
        //客製化搜尋欄位
        function custom_search() {
            $('#GridView1').DataTable()
                .column(1).search($('#name').val())
                .column(2).search($('#cDateStart').val() + "\n" + $('#cDateFinal').val())
                .column(3).search($('#active').val())
            ;
            $('#GridView1').dataTable().fnDraw(true);
        }
        // 新增
        $("#btnNew").click(function () {
            location.href = 'settingManagement/create';
            return false;
        });
        //日期選擇器
        $('#cDateStart').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#cDateFinal').datepicker({
            dateFormat: 'yy-mm-dd'
        });
    </script>
@endsection
