{% extends 'wgcomm/base.html' %}
{% block head %}
    {#    <link href="/static/wgcomm/bootstrap-datetimepicker.min.css" rel="stylesheet"/>#}
{% endblock %}
{% block tail %}
    <script src="static/wgcomm/js/datepicker.js"></script>
    <script src="static/wgcomm/js/wgdatepicker.js"></script>

{% endblock %}
{% block tail_min %}
    <script src="static/wgcomm/js/datepicker.min.js"></script>
    <script src="static/wgcomm/js/wgdatepicker.min.js"></script>
{% endblock %}
{% block title %}
    Edit Task
{% endblock %}

{% block main_content %}
    <!--app-content open-->
    <div class="app-content main-content mt-0">
        <div class="side-app">
            <!-- CONTAINER -->
            <div class="main-container container-fluid">

                <!-- PAGE-HEADER -->
                <div class="page-header">
                    <div>
                        <h1 class="page-title">Edit Task</h1>
                    </div>
                    <div class="ms-auto pageheader-btn">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">Configuration</li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Task</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Edit</li>
                        </ol>
                    </div>
                </div>
                <!-- PAGE-HEADER END -->
                {% with messages = get_flashed_messages() %}
                    {% if messages %}
                        <div class="form-group">
                            <ul>
                                {% for message in messages %}
                                    <li class="text-danger">{{ message }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                    {% endif %}
                {% endwith %}
                <!--ROW OPENED-->
                <div class="row">
                    <div class="col-lg-12 col-md-12">
                        <div class="card">
                            <form action="{{ url_for('wgcomm_extern_tasklist.web_extern_tasklist_edit') }}"
                                  method="post">
                                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                {{ wgform._csrf }}
                                <div class="card-header border-bottom">
                                    <h4 class="mb-0">Task Info  </h4>
                                </div>
                                <div class="card-body">
                                    <div class="form-group">
                                        {{ wgform.f_Id.label }}<br>{{ wgform.f_Id.data }}
                                        <div hidden="hidden">
                                            {{ wgform.f_Id( class="form-control") }}
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        {{ wgform.f_Notes.label }}
                                        {{ wgform.f_Notes( class="form-control") }}
                                    </div>


                                    <div class="form-group">
                                        {{ wgform.f_BeginYMD.label }}
                                        <div id="begin-datepicker" class="input-group date"
                                             data-date-format="yyyy-mm-dd">
                                                <span class="input-group-addon input-group-text bg-primary-transparent"><i
                                                        class="fe fe-calendar text-primary-dark"></i></span>
                                            <input id="f_BeginYMD" name="f_BeginYMD" class="form-control" type="text"
                                                   value={{ wgform.f_BeginYMD.data }}    placeholder="Year-Month-Day  "/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        {{ wgform.f_EndYMD.label }}
                                        <div id="end-datepicker" class="input-group date"
                                             data-date-format="yyyy-mm-dd">
                                                <span class="input-group-addon input-group-text bg-primary-transparent"><i
                                                        class="fe fe-calendar text-primary-dark"></i></span>
                                            <input id="f_EndYMD" name="f_EndYMD" class="form-control" type="text"
                                                   value={{ wgform.f_EndYMD.data }}     placeholder="Year-Month-Day  "/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        {{ wgform.f_OperateTime.label }}

                                        <input type="time" style="border-width: 1px; border-style: solid"
                                               id="f_OperateTime" name="f_OperateTime" min="00:00" max="23:59"
                                               value={{ wgform.f_OperateTime.data }}>
                                    </div>
                                    <div class="form-group">
                                        {{ wgform.f_DoorControl.label }}
                                        {#                                        {{ wgform.f_DoorControl( class="form-control") }}#}
                                        <select class="form-control  form-select  text-dark" id="f_DoorControl"
                                                name="f_DoorControl">
                                            {#                                           <option value="0" >0</option>#}
                                            {% for i in range(13) %}
                                                {#                                                {% if i!=wgform.f_DoorControl.data %}#}
                                                {#                                                <option value="{{ i }}">{{controlmod[ i ]}}</option>#}
                                                {#                                                {% endif %}#}
                                                <option value="{{ i }}"
                                                        {% if i==wgform.f_DoorControl.data %}
                                                        selected
                                                        {% endif %}
                                                >{{ controlmod[ i ] }}</option>
                                            {% endfor %}
                                        </select>
                                    </div>

                                    <div>
                                        <!-- 使用 fieldset 将相Closed的复选框分组 -->
                                        <script>
                                            function selectAll(source) {
                                                const checkboxes = document.getElementById('selectdoors');
                                                if (source.checked) {
                                                    checkboxes.hidden = true; //"hidden";//"none"; //
                                                } else {
                                                    checkboxes.hidden = false; //"";
                                                }
                                                //const checkboxes = document.getElementsByName('citys');
                                                //for (let checkbox of checkboxes) {
                                                //   checkbox.checked = !source.checked;
                                                //}
                                            }
                                        </script>
                                        {% if wgform.f_FloorNames.data == "0" %}
                                            <div class="form-group">
                                                {{ wgform.f_FloorNames.label }}

                                                <div>
                                                    <input type="checkbox" name="f_Door_All" value="1" checked
                                                           id="f_Door_All" onclick="selectAll(this)">
                                                    <label>All Doors  </label></div>
                                                <fieldset class="checkbox-group col-sm-12 col-md-12 col-xl-12"
                                                          name="selectdoors" id="selectdoors" hidden="hidden">
                                                    <!-- legend 作为这Unit分组的标题 -->
                                                    {#            <legend>请选择您喜欢的城市 (最多显示5行)：</legend>#}

                                                    <!-- 复选框的滚动容器 -->
                                                    {#            选择门#}
                                                    <div class="checkbox-container">
                                                        {% for door in doors %}

                                                            <label><input type="checkbox"
                                                                          name="f_Door_{{ door.f_DoorID }}"
                                                                          value="{{ door.f_DoorID }}"
                                                                          id="f_Door_{{ door.f_DoorID }}">{{ door.f_DoorName }}
                                                            </label>
                                                        {% endfor %}
                                                    </div>
                                                </fieldset>
                                            </div>
                                        {% else %}
                                            <div class="form-group">
                                                {{ wgform.f_FloorNames.label }}

                                                <div>
                                                    <input type="checkbox" name="f_Door_All" value="0" id="f_Door_All"
                                                           onclick="selectAll(this)">
                                                    <label>All Doors  </label></div>
                                                <fieldset class="checkbox-group col-sm-12 col-md-12 col-xl-12"
                                                          name="selectdoors" id="selectdoors">
                                                    <!-- legend 作为这Unit分组的标题 -->
                                                    {#            <legend>请选择您喜欢的城市 (最多显示5行)：</legend>#}

                                                    <!-- 复选框的滚动容器 -->
                                                    {#            选择门#}
                                                    <div class="checkbox-container">
                                                        {% for door in doors %}
                                                            {% if door.f_DoorID | in_string_list(wgform.f_FloorNames.data) %}
                                                                <label><input type="checkbox"
                                                                              name="f_Door_{{ door.f_DoorID }}" checked
                                                                              value="{{ door.f_DoorID }}"
                                                                              id="f_Door_{{ door.f_DoorID }}">{{ door.f_DoorName }}
                                                                </label>
                                                            {% else %}
                                                                <label><input type="checkbox"
                                                                              name="f_Door_{{ door.f_DoorID }}"
                                                                              value="{{ door.f_DoorID }}"
                                                                              id="f_Door_{{ door.f_DoorID }}">{{ door.f_DoorName }}
                                                                </label>
                                                            {% endif %}
                                                        {% endfor %}
                                                    </div>
                                                </fieldset>
                                            </div>
                                        {% endif %}

                                    </div>
                                    <div class="form-group">
                                        Week Options  
                                        <div>
                                            <fieldset class="checkbox-group col-sm-12 col-md-12 col-xl-12"
                                                      name="selectdoors2" id="selectdoors2">
                                                <div class="checkbox-container">
                                                    <label><input type="checkbox" name="f_Monday"
                                                            {% if wgform.f_Monday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Monday">{{ wgform.f_Monday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Tuesday"
                                                            {% if wgform.f_Tuesday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Tuesday">{{ wgform.f_Tuesday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Wednesday"
                                                            {% if wgform.f_Wednesday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Wednesday">{{ wgform.f_Wednesday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Thursday"
                                                            {% if wgform.f_Thursday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Thursday">{{ wgform.f_Thursday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Friday"
                                                            {% if wgform.f_Friday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Friday">{{ wgform.f_Friday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Saturday"
                                                            {% if wgform.f_Saturday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Saturday">{{ wgform.f_Saturday.label }}
                                                    </label>
                                                    <label><input type="checkbox" name="f_Sunday"
                                                            {% if wgform.f_Sunday.data %}
                                                                  value="1" checked
                                                            {% else %}
                                                                  value="0"
                                                            {% endif %} id="f_Sunday">{{ wgform.f_Sunday.label }}
                                                    </label>
                                                </div>
                                            </fieldset>
                                        </div>
                                    </div>
                                    {#                                    <div class="col-sm-12 col-md-12 col-xl-3 no-taskEnd-checkbox">#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Monday"#}
                                    {#                                                       name="f_Monday"#}
                                    {#                                                        {% if wgform.f_Monday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Monday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {##}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Tuesday"#}
                                    {#                                                       name="f_Tuesday"#}
                                    {#                                                        {% if wgform.f_Tuesday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Tuesday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Wednesday"#}
                                    {#                                                       name="f_Wednesday"#}
                                    {#                                                        {% if wgform.f_Wednesday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Wednesday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Thursday"#}
                                    {#                                                       name="f_Thursday"#}
                                    {#                                                        {% if wgform.f_Thursday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Thursday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Friday"#}
                                    {#                                                       name="f_Friday"#}
                                    {#                                                        {% if wgform.f_Friday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Friday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Saturday"#}
                                    {#                                                       name="f_Saturday"#}
                                    {#                                                        {% if wgform.f_Saturday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Saturday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                        <div class="form-group">#}
                                    {#                                            <label class="custom-control custom-checkbox no-taskEnd-checkbox-container">#}
                                    {#                                                <input type="checkbox" class="custom-control-input" id="f_Sunday"#}
                                    {#                                                       name="f_Sunday"#}
                                    {#                                                        {% if wgform.f_Sunday.data %}#}
                                    {#                                                       value="1" checked#}
                                    {#                                                        {% else %}#}
                                    {#                                                       value="0"#}
                                    {#                                                        {% endif %}#}
                                    {#                                                >#}
                                    {#                                                <span class="custom-control-label"> {{ wgform.f_Sunday.label }}</span>#}
                                    {#                                            </label>#}
                                    {#                                        </div>#}
                                    {#                                    </div>#}


                                    <div class="row p-5">
                                        <div class="btn-list text-end">
                                            <button id="submitcancel" name="submitcancel" class="btn btn-outline-danger"
                                                    type="submit" value="Cancel">
                                                <i class="fe fe-x-circle"></i>
                                                Cancel
                                            </button>
                                            <button id="submitsave" name="submitsave" class="btn btn-primary"
                                                    type="submit"
                                                    value="Save">
                                                <i class="fe fe-check-circle"></i>
                                                Save
                                            </button>
                                            {#                                            <button id="submitsave" name="submitsaveandadd" class="btn btn-primary"#}
                                            {#                                                    type="submit" value="Save And Continue">#}
                                            {#                                                <i class="fe fe-check-square"></i>#}
                                            {#                                                Save And Continue#}
                                            {#                                            </button>#}
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!--ROW CLOSED-->
            </div>
        </div>
    </div>
    <!-- CONTAINER CLOSED -->
{% endblock %}
