@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/roundManagement/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="roundName" type="text" value="" maxlength="10"
                                                       id="roundName"
                                                       class="form-control">
                                            @else
                                                <input name="roundName" type="text" value="{{ $operdata['roundName'] }}"
                                                       maxlength="10" id="roundName" class="form-control">
                                            @endif
                                            <label class="error" for="roundName"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：起日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">起日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="dateBegin" type="text"
                                                       value="" maxlength="10" id="dateBegin">
                                            @else
                                                <input class="form-control input-sm" name="dateBegin" type="text"
                                                       value="{{ $operdata['dateBegin'] }}" id="dateBegin">
                                            @endif
                                            <label class="error" for="dateBegin"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：迄日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">迄日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="dateFinal" type="text"
                                                       value="" maxlength="10" id="dateFinal">
                                            @else
                                                <input class="form-control input-sm" name="dateFinal" type="text"
                                                       value="{{ $operdata['dateFinal'] }}" id="dateFinal">
                                            @endif
                                            <label class="error" for="dateFinal"></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="redeemExtra" type="text" value="" maxlength="1"
                                                       id="redeemExtra"
                                                       class="form-control">
                                            @else
                                                <input name="redeemExtra" type="text"
                                                       value="{{ $operdata['redeemExtra'] }}"
                                                       maxlength="1" id="redeemExtra" class="form-control">
                                            @endif
                                            <label class="error" for="redeemExtra"></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/roundManagement') }}';
            });
            $("#btnBackTo2_foot").click(function () {
                // 下方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/roundManagement') }}';
            });
            // 初始化需要偵錯的表格
            $('#EditForm').validate();
            // 正規表達驗證初始化
            $.validator.addMethod(
                "regex",
                function (value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }
            );
            // 各欄位
            $('#roundName').rules("add", {
                required: true,
                minlength: 1,
                maxlength: 10,
                messages: {
                    required: "回合名稱 length must between 1-10",
                    minlength: "回合名稱 length must between 1-10",
                    maxlength: "回合名稱 length must between 1-10"
                }
            });
            $('#dateBegin').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有起日",
                    minlength: "必須要有起日",
                    maxlength: "必須要有起日"
                }
            });
            $('#dateFinal').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有迄日",
                    minlength: "必須要有迄日",
                    maxlength: "必須要有迄日"
                }
            });
            $('#redeemExtra').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 1,
                messages: {
                    required: "必須要有兌獎延長天數",
                    number: "兌獎延長天數須為數字",
                    minlength: "必須要有兌獎延長天數",
                    maxlength: "必須要有兌獎延長天數"
                }
            });
        });

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

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

    </script>
@endsection
