@extends('admin.master')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            <!-- 指定新增的端點 -->
            <form id="EditForm" class="form-horizontal" method="post"
                  action="{{ url('/backend/dataManagement/settingManagement/store') }}">
                {{ csrf_field() }}
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <!-- 更改文案 -->
                        <h4 class="panel-title">{{ ($operdata == "") ? "Create " : "Modify " }}參數</h4>
                    </div>
                    <div class="panel-body">
                        <div>
                            <!-- 表格本體 -->
                            <table class="table" cellspacing="0" id="DetailsView1" style="border-collapse:collapse;">
                                <tbody>
                                <!-- 欄位：自增量 -->
                                @if ($operdata == "")
                                    <input type="hidden" name="mode" value="insert"/>
                                    <!-- Insert Mode -->
                                @else
                                    <!-- Edit Mode -->
                                    <tr>
                                        <td class="col-lg-2">自增量</td>
                                        <td>
                                            <input name="id" type="hidden" value="{{ $operdata['id'] }}" id="id"/>
                                            {{ $operdata['id'] }}
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：用途 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">用途</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="name" type="text" value="" maxlength="32" id="name"
                                                       class="form-control">
                                            @else
                                                <input name="name" type="text" value="{{ $operdata['name'] }}"
                                                       maxlength="32" id="name" class="form-control">
                                            @endif
                                            <label class="error" for="name"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：變數名稱 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">變數名稱</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="k" type="text" value="" maxlength="64" id="k"
                                                       class="form-control">
                                            @else
                                                <input name="k" type="text" value="{{ $operdata['k'] }}"
                                                       maxlength="64" id="k" class="form-control">
                                            @endif
                                            <label class="error" for="k"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：變數內容 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">變數內容</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="v" type="text" value="" maxlength="256" id="v"
                                                       class="form-control">
                                            @else
                                                <input name="v" type="text" value="{{ $operdata['v'] }}"
                                                       maxlength="256" id="v" class="form-control">
                                            @endif
                                            <label class="error" for="v"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：有效否 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">有效否</td>
                                    <td>
                                        @if ($operdata == "")
                                            <input id="active" type="checkbox" name="active" checked='checked' />
                                        @else
                                            <input id="active" type="checkbox"
                                                   name="active" {{ ($operdata['active'] == \App\Http\Services\ConstDef\GeneralConst::ACTIVE_YES)?"checked='checked'":"" }} />
                                        @endif
                                    </td>
                                </tr>
                                <!-- 欄位：建立日期 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">建立日期</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['cdate'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：最後修改日期 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">最後修改日期</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['mdate'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：最後修改人 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">最後修改人</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['oid'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 下控制按鈕 -->
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <div style="text-align: right">
                                        @if ($operdata == "")
                                            <!-- Insert Mode -->
                                                <input type="submit" name="btnUpdate_foot" value="Create"
                                                       id="btnUpdate_foot" class="btn btn-primary btn-xs"
                                                       onclick="submitForm();">
                                        @else
                                            <!-- Edit Mode -->
                                                <input type="submit" name="btnUpdate_foot" value="Modify"
                                                       id="btnUpdate_foot" class="btn btn-primary btn-xs"
                                                       onclick="submitForm();">
                                            @endif
                                            <input type="button" name="btnBackTo2_foot" value="Back"
                                                   id="btnBackTo2_foot" class="btn btn-default btn-xs">
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- panel-body -->
                </div>
            </form>
        </div>
    </div>
@endsection

@section('extjs')
    <script>
        $(document).ready(function () {
            $("#btnBackTo2").click(function () {
                // 上方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/settingManagement') }}';
            });
            $("#btnBackTo2_foot").click(function () {
                // 下方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/settingManagement') }}';
            });
            // 初始化需要偵錯的表格
            $('#EditForm').validate();
            // 正規表達驗證初始化
            $.validator.addMethod(
                "regex",
                function (value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }
            );
            // 各欄位
            $('#name').rules("add", {
                required: true,
                minlength: 1,
                maxlength: 32,
                messages: {
                    required: "用途 length must between 1-32",
                    minlength: "用途 length must between 1-32",
                    maxlength: "用途 length must between 1-32"
                }
            });
            $('#k').rules("add", {
                required: true,
                minlength: 1,
                maxlength: 64,
                messages: {
                    required: "變數名稱 length must between 1-64",
                    minlength: "變數名稱 length must between 1-64",
                    maxlength: "變數名稱 length must between 1-64"
                }
            });
            $('#v').rules("add", {
                required: true,
                minlength: 1,
                maxlength: 256,
                messages: {
                    required: "變數內容 length must between 1-256",
                    minlength: "變數內容 length must between 1-256",
                    maxlength: "變數內容 length must between 1-256"
                }
            });
        });

        //提交與取消按鈕
        function submitForm() {
            if (!!($("#EditForm").valid()) === false) {
                return false;
            } else {
                $(document).ready(function () {
                    $.blockUI({
                        css: {
                            border: 'none',
                            padding: '15px',
                            backgroundColor: '#000',
                            '-webkit-border-radius': '10px',
                            '-moz-border-radius': '10px',
                            opacity: .5,
                            color: '#FFF'
                        }
                    });
                });
            }
        }

        function cancelValidate() {
            $("#EditForm").validate().cancelSubmit = true;
        }

        // 日期選擇器
        $('#date_begin').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#date_final').datepicker({
            dateFormat: 'yy-mm-dd'
        });

    </script>
@endsection
