@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/checkinManagement/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="day" type="text" value="" maxlength="2" id="day"
                                                       class="form-control">
                                            @else
                                                <input name="day" type="text" value="{{ $operdata['day'] }}"
                                                       maxlength="2" id="day" class="form-control">
                                            @endif
                                            <label class="error" for="day"></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="gp" type="text" value="" maxlength="2" id="gp"
                                                       class="form-control">
                                            @else
                                                <input name="gp" type="text" value="{{ $operdata['gp'] }}"
                                                       maxlength="2" id="gp" class="form-control">
                                            @endif
                                            <label class="error" for="gp"></label>
                                        </div>
                                    </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/checkinManagement') }}';
            });
            $("#btnBackTo2_foot").click(function () {
                // 下方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/checkinManagement') }}';
            });
            // 初始化需要偵錯的表格
            $('#EditForm').validate();
            // 正規表達驗證初始化
            $.validator.addMethod(
                "regex",
                function (value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }
            );
            // 各欄位
            $('#day').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 2,
                messages: {
                    required: "第幾天 length must between 1-2",
                    number: "第幾天 must number",
                    minlength: "第幾天 length must between 1-2",
                    maxlength: "第幾天 length must between 1-2"
                }
            });
            $('#gp').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 2,
                messages: {
                    required: "吉點 length must between 1-2",
                    number: "吉點 must number",
                    minlength: "吉點 length must between 1-2",
                    maxlength: "吉點 length must between 1-2"
                }
            });
        });

        //提交與取消按鈕
        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;
        }

    </script>
@endsection
