<!DOCTYPE html>
<html lang="ja">
  <head>
    {% with subtitle = mainte_csv_dl.subtitle %}
    {% include '_header.html' %}
    {% endwith %}
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link href="/static/css/masterMainte.css" rel="stylesheet" />

    <script type="text/javascript">
        window.onload = function(){
            // ボタン、テキストボックス初期化
            formBtDisabled();
            // DatePickerを有効化
            enableDatePicker();
            // {% if mainte_csv_dl.is_search and mainte_csv_dl.data_count > 0 and mainte_csv_dl.is_download_file_url_empty() is false %}
            // CSV自動ダウンロード処理
            const link_tag = document.createElement("a");
            link_tag.Target="_blank";
            link_tag.id = "download_url_link";
            link_tag.style.display = 'none';
            link_tag.setAttribute("href", "{{mainte_csv_dl.download_file_url | safe}}");
            link_tag.setAttribute("download", "{{mainte_csv_dl.file_name}}");
            document.getElementById("notification").appendChild(link_tag);
            document.getElementById("download_url_link").click();
            document.getElementById("download_url_link").remove();
            // {% endif %}
        };
        function Form_Submit_Disp_Dialog(){
        var msg = 'CSVファイルを出力しますか？';
            if (confirmDialog(msg)) {
                showLoading();
                document.getElementById("csvOutputMsg").style.display = "none";
            } else {
                return false;
            }
        }
    </script>

  </head>

  <body>
    <!-- タイトルと上部ボタン -->
    <h1>
        <table class="headerTable">
            <tr>
                <td class="headerTdLeft"><h1>施設担当者データCSVダウンロード</h1></td>
                <td class="headerTdRight"><input type="button" name="back" class="header_buttonSize" value="メニューへ" onclick="backToMainteMenu('_loading_for_back')"></td>
            </tr>
        </table>
    </h1>
    <!-- 検索フォーム -->
    <form name="search" action="/masterMainte/download" method="POST" onsubmit="return Form_Submit_Disp_Dialog()">
        <table class="searchTable">
            <tbody>
                <!-- 検索フォーム1行目 -->
                <tr>
                    <!-- 領域コード -->
                    <td class="searchLabelTd">領域コード：</td>
                    <td class="searchInputTd">
                        <input class="searchTextbox" type="text" name="ctrl_ta_cd" value="{{mainte_csv_dl.ta_cd | safe}}" maxlength='3'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                    <!-- 施設コード -->
                    <td class="searchLabelTd">施設コード：</td>
                    <td class="searchInputTd">
                        <input class="searchTextbox" type="text" name="ctrl_inst_cd" value="{{mainte_csv_dl.inst_cd | safe}}" maxlength='18'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                    <!-- MUID -->
                    <td class="searchLabelTd">MUID：</td>
                    <td class="searchInputTd">
                        <input class="searchTextbox" type="text" name="ctrl_emp_cd" value="{{mainte_csv_dl.emp_cd | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                </tr>
                <!-- 検索フォーム2行目 -->
                <tr>
                    <!-- 担当者種別コード -->
                    <td class="searchLabelTd">担当者種別コード：</td>
                    <td class="searchInputTd">
                        <input class="searchTextbox" type="text" name="ctrl_emp_chg_type_cd" value="{{mainte_csv_dl.emp_chg_type_cd | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                </tr>
                <!-- 検索フォーム3行目 -->
                <tr>
                    <!-- 適用期間内 -->
                    <td class="searchLabelTd">適用期間内：</td>
                    <td class="searchInputTd">
                        <input class="searchTextbox date_picker" type="text" name="ctrl_apply_date_from" value="{{mainte_csv_dl.apply_date_from | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                    <td class="searchLabelTd">適用開始日：</td>
                    <!-- 適用開始日 -->
                    <td class="searchInputTd">
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_start_date_from" value="{{mainte_csv_dl.start_date_from | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                        ～
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_start_date_to" value="{{mainte_csv_dl.start_date_to | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                    <!-- 適用終了日 -->
                    <td class="searchLabelTd">適用終了日：</td>
                    <td class="searchInputTd">
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_end_date_from" value="{{mainte_csv_dl.end_date_from | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                        ～
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_end_date_to" value="{{mainte_csv_dl.end_date_to | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                </tr>
                <!-- 検索フォーム4行目 -->
                <tr>
                    <!-- 対象テーブル -->
                    <td class="searchLabelTd">対象テーブル：</td>
                    <td class="searchInputTd">
                        <label>
                            <input type="radio" name="radio_select_table" value="dummy"
                                {{ "checked " if mainte_csv_dl.select_table == 'dummy' or mainte_csv_dl.is_select_table_empty() }}
                            >ダミーテーブル
                        </label>
                        <label>
                            <input type="radio" name="radio_select_table" value="real"
                                {{ "checked " if mainte_csv_dl.select_table == 'real' }}
                            >本番テーブル
                        </label>
                    </td>
                    <!-- データ作成日 -->
                    <td class="searchLabelTd">データ作成日：</td>
                    <td class="search_tb">
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_create_date_from" value="{{mainte_csv_dl.create_date_from | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                        ～
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_create_date_to" value="{{mainte_csv_dl.create_date_to | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                    <!-- データ更新日 -->
                    <td class="searchLabelTd">データ更新日：</td>
                    <td class="searchInputTd">
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_update_date_from" value="{{mainte_csv_dl.update_date_from | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                        ～
                        <input class="searchDateTextbox date_picker" type="text" name="ctrl_update_date_to" value="{{mainte_csv_dl.update_date_to | safe}}" maxlength='10'
                            onchange="formBtDisabled()"
                            oninput="formBtDisabled()"
                        >
                    </td>
                </tr>
                <!-- 検索フォーム5行目 -->
                <tr>
                    <!-- 検索、クリアボタン -->
                    <td class="searchButtonTd" colspan="6">
                        <input class="buttonSize" id="clear" type="button" name="clear_bt" value="クリア" onclick="clr();">
                        <input class="buttonSize" id="search_bt" name="search_bt" value="CSV出力" type="submit">
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
    <p id="notification">
        {% if mainte_csv_dl.is_search %}
            {% if mainte_csv_dl.data_count == 0 %}
                <div id="csvOutputMsg" class="csvOutputMessage errorColor">{{mainte_csv_dl.result_msg}}</div>
            {% else %}
                <div id="csvOutputMsg" class="csvOutputMessage">{{mainte_csv_dl.result_msg}}</div>
            {% endif %}
        {% endif %}
    </p>
    <!-- ダウンロード用 -->
    {% with progress_message = '処理中...しばらくお待ち下さい。'%}
    {% include '_loading.html' %}
    {% endwith %}
    <!-- 戻るボタン用 -->
    {% with progress_message = '', id = '_loading_for_back' %}
    {% include '_loading.html' %}
    {% endwith %}
  </body>
</html>
