{% extends "base.html" %}
{% block content %}

<script type="application/javascript">
    var processNotify = function(Notification) {
        document.getElementById("flash").innerHTML = "<div class=\"info\"><div>" + Notification + "{{ _(" This process may take a while, and will continue in the background if you navigate away from this page.") }}</div></div>";
        window.scrollTo(0,0);
    }

    var shutdownNotify = function(Notification) {
        document.getElementById("flash").innerHTML = "<div class=\"warning\"><div>" + Notification + "{{ _(" The Web Interface will become unresponsive momentarily. Reload this page after the Pi has started up again.") }}</div></div>";
        window.scrollTo(0,0);
    }
</script>

<section id="current-config">
<details>
    <summary class="heading">
        {{ _("Current PiSCSI Configuration") }}
    </summary>
    <ul>
        <li>{{ _("Save and load device configurations, stored as json files in <tt>%(config_dir)s</tt>", config_dir=CFG_DIR) }}</li>
        <li>{{ _("To have a particular device configuration load when PiSCSI starts, save it as <em>default</em>.") }}</li>
    </ul>
</details>

{% if env["cfg_dir_exists"] %}
<p>
<form action="/config/action" method="post" id="config-actions">
    <label for="config_load_name">{{ _("File Name:") }}</label>
    <select name="name" id="config_load_name" required="" width="14">
        {% if config_files %}
        {% for config in config_files|sort %}
        <option value="{{ config }}">
            {{ config }}
        </option>
        {% endfor %}
        {% else %}
        <option disabled>
        {{ _("No saved configurations") }}
        </option>
        {% endif %}
    </select>
    <input name="load" type="submit" value="{{ _("Load") }}" onclick="return confirm('{{ _("Detach all current device and Load configuration?") }}')">
    <input name="delete" type="submit" value="{{ _("Delete") }}" onclick="return confirm('{{ _("Delete configuration file?") }}')">
    <input name="send" type="submit" value="{{ _("Download") }}">
</form>
</p>

<p>
<form action="/config/save" method="post" id="config-save">
    <label for="config_save_name">{{ _("File Name:") }}</label>
    <input type="text" name="name" id="config_save_name" value="default" size="20">
    .{{ CONFIG_FILE_SUFFIX }}
    <input type="submit" value="{{ _("Save") }}">
</form>
</p>
{% else %}

<div class="notice">
{{ _("Please create the PiSCSI configuration dir to use configurations:")}} {{ CFG_DIR }}
</div>

{% endif %}

<table id="attached-devices" border="black" cellpadding="3" summary="List of attached devices">
    <tbody>
        <tr>
            <th class="id" scope="col">{{ _("ID") }}</th>
            {% if units %}
            <th class="unit" scope="col">{{ _("LUN") }}</th>
            {% endif %}
            <th class="name" scope="col">{{ _("Device") }}</th>
            <th class="parameters" scope="col">{{ _("Parameters") }}</th>
            <th class="product" scope="col">{{ _("Product") }}</th>
            <th class="actions" scope="col">{{ _("Actions") }}</th>
        </tr>
        {% for device in devices | sort(attribute='id') %}
        {% if device["id"] in reserved_scsi_ids %}
        <tr class="reserved">
        {% elif device.device_type %}
        <tr class="device-assigned device-{{ device.device_type|lower }}">
        {% else %}
        <tr class="free">
        {% endif %}
            {% if device["id"] not in reserved_scsi_ids %}
            <td class="id" align="center">{{ device.id }}</td>
            {% if units %}
            <td class="unit" align="center">{{ device.unit }}</td>
            {% endif %}
            <td class="name" align="center">{{ device.device_name }}</td>
            <td class="parameters">
            {% if "No Media" in device.status %}
                <form action="/scsi/attach" method="post">
                    <label for="device_list_file_name_{{ device.id }}_{{ device.unit }}">{{ _("File:") }}</label>
                    <input name="scsi_id" type="hidden" value="{{ device.id }}">
                    <input name="unit" type="hidden" value="{{ device.unit }}">
                    <input name="type" type="hidden" value="{{ device.device_type }}">
                    <select type="select" name="file_name" id="device_list_file_name_{{ device.id }}_{{ device.unit }}">
                    {% for f in files|sort(attribute='name') %}
                    {% if device.device_type == "SCCD" %}
                    {% if f["name"].lower().endswith(env['cd_suffixes']) %}
                    <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                    {% endif %}
                    {% elif device.device_type == "SCRM" %}
                    {% if f["name"].lower().endswith(env['rm_suffixes']) %}
                    <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                    {% endif %}
                    {% elif device.device_type == "SCMO" %}
                    {% if f["name"].lower().endswith(env['mo_suffixes']) %}
                    <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                    {% endif %}
                    {% elif device.device_type == "SCTP" %}
                    {% if f["name"].lower().endswith(env['st_suffixes']) %}
                    <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                    {% endif %}
                    {% endif %}
                    {% endfor %}
                    </select>
                    <input type="submit" value="{{ _("Insert") }}">
                </form>
            {% else %}
                {% if device.params %}
                    {% for key in device.params %}
                        {% if key == "interface" %}
                            ({{device.params[key]}})
                        {% elif key == "timeout" %}
                            ({{key}}:{{device.params[key]}})
                        {% else %}
                            {{device.params[key]}}
                        {% endif %}
                    {% endfor %}
                {% elif device.file %}
                <form action="/scsi/eject" method="post" onsubmit="return confirm('{{ _("Eject Disk?  WARNING: On Mac OS, eject the Disk in the Finder instead!") }}')">
                    <label>{{ device.file }}</label>
                    {% if device.device_type in REMOVABLE_DEVICE_TYPES and "No Media" not in device.status %}
                    <input name="scsi_id" type="hidden" value="{{ device.id }}">
                    <input name="unit" type="hidden" value="{{ device.unit }}">
                    <input type="submit" value="{{ _("Eject") }}">
                    {% endif %}
                </form>
                {% endif %}
            {% endif %}
            </td>
            <td class="product" align="center">
                {% if device.vendor != "PiSCSI" %}
                {{ device.vendor }}
                {% endif %}
                {{ device.product }}
                {% if device.vendor != "PiSCSI" %}
                {{ device.revision }}
                {% endif %}
            </td>
            <td class="actions" align="center">
                {% if device.id in scsi_ids["occupied_ids"] %}
                <form action="/scsi/detach" method="post" onsubmit="return confirm('{{ _("Detach Device?") }}')">
                    <input name="scsi_id" type="hidden" value="{{ device.id }}">
                    <input name="unit" type="hidden" value="{{ device.unit }}">
                    <input type="submit" value="{{ _("Detach") }}">
                </form>
                {% else %}
                <form action="/scsi/reserve" method="post" onsubmit="var memo = prompt('{{ _("Enter a memo for this reservation") }}'); if (memo === null) event.preventDefault(); document.getElementById('memo_{{ device.id }}').value = memo;">
                    <input name="scsi_id" type="hidden" value="{{ device.id }}">
                    <input name="memo" id="memo_{{ device.id }}" type="hidden" value="">
                    <input type="submit" value="{{ _("Reserve") }}">
                </form>
                {% endif %}
            </td>
            {% else %}
            <td class="id inactive">{{ device.id }}</td>
            {% if units %}
            <td class="units inactive"></td>
            {% endif %}
            <td class="name inactive">{{ _("Reserved ID") }}</td>
            <td class="parameters inactive">{{ RESERVATIONS[device.id] }}</td>
            <td class="product inactive"></td>
            <td class="actions inactive">
                <form action="/scsi/release" method="post">
                    <input name="scsi_id" type="hidden" value="{{ device.id }}">
                    <input type="submit" value="{{ _("Release") }}">
                </form>
            </td>
            {% endif %}
        </tr>
        {% endfor %}
    </tbody>
</table>

<p>
    <form action="/scsi/detach_all" method="post" id="detach-all-devices" onsubmit="return confirm('{{ _("Detach all SCSI Devices?") }}')">
        <input type="submit" value="{{ _("Detach All Devices") }}">
    </form>
    <form action="/scsi/info" method="post" id="show-device-info">
        <input type="submit" value="{{ _("Show Device Info") }}">
    </form>
</p>
</section>

<hr/>

<section id="files">
<details>
    <summary class="heading">
        {{ _("Image File Management") }}
    </summary>
    <ul>
        <li>{{ _("Manage image files in the active PiSCSI image directory: <tt>%(directory)s</tt> with a scan depth of %(scan_depth)s.", directory=env["image_dir"], scan_depth=scan_depth) }}</li>
        <li>{{ _("Select a valid SCSI ID and <a href=\"%(url)s\" target=\"_blank\">LUN</a> to attach to. Unless you know what you're doing, always use LUN 0.", url="https://en.wikipedia.org/wiki/Logical_unit_number") }}
        </li>
        <li>
            {{ _("Recognized image file types:") }}
            {% set comma = joiner(", ") %}
            {% for extension in valid_image_suffixes %}{{ comma() }}.{{ extension}}{% endfor %}
        </li>
        <li>
            {{ _("Recognized archive file types:") }}
            {% set comma = joiner(", ") %}
            {% for extension in ARCHIVE_FILE_SUFFIXES %}{{ comma() }}.{{ extension}}{% endfor %}
        </li>
    </ul>
</details>

{% if env["image_dir_exists"] %}
{% if files|length %}
<div>
{% for subdir, group in formatted_image_files.items() %}

<details class="subdir"{% if subdir == env["image_root_dir"] + "/" %} open{% endif %}>
    <summary class="dirname">
        {{ subdir }}
    </summary>
<table id="images" border="black" cellpadding="3" summary="List of files in the image directory">
    <tbody>
        <tr>
            <th scope="col">{{ _("File") }}</th>
            <th scope="col">{{ _("Size") }}</th>
            <th scope="col">{{ _("Actions") }}</th>
        </tr>
        {% for file in group|sort(attribute='name') %}
        <tr>
            {% if file["prop"] %}
            <td>
                <details class="contents">
                    <summary class="filename">
                        {{ file["name"] }}
                    </summary>
                    <ul class="inline_list">
                    {% for key in file["prop"] %}
                        <li>{{ key }}: {{ file['prop'][key] }}</li>
                    {% endfor %}
                    <form action="/files/download_config" method="post">
                        <input name="file" type="hidden" value="{{ file['name'] }}.{{ PROPERTIES_SUFFIX }}">
                        <input type="submit" value="{{ _("Properties File") }} &#8595;">
                    </form>
                    </ul>
                </details>
            </td>
            {% elif file["archive_contents"] %}
            <td>
                <details class="contents">
                    <summary class="filename">
                        {{ file["name"] }}
                    </summary>
                    <ul class="inline_list">
                        {% for member in file["archive_contents"] %}
                            {% if not member["is_properties_file"] %}
                                <li>
                                    {% if member["related_properties_file"] %}
                                        <details id="contents">
                                            <summary class="filename">
                                                <label>{{ member["path"] }}</label>
                                                <form action="/files/extract_image" method="post" class="file-extract">
                                                    <input name="archive_file" type="hidden" value="{{ file['name'] }}">
                                                    <input name="archive_members" type="hidden" value="{{ member["path"] }}|{{ member["related_properties_file"] }}">
                                                    <input type="submit" value="{{ _("Extract") }}" title="{{ _("Extract") }}" onclick="processNotify('{{ _("Extracting a single file...") }}')">
                                                </form>
                                            </summary>
                                            <ul class="inline_list">
                                                <li>{{ member["related_properties_file"] }}</li>
                                            </ul>
                                        </details>
                                    {% else %}
                                        <label>{{ member["path"] }}</label>
                                        <form action="/files/extract_image" method="post" class="file-extract">
                                            <input name="archive_file" type="hidden" value="{{ file["name"] }}">
                                            <input name="archive_members" type="hidden" value="{{ member["path"] }}">
                                            <input type="submit" value="{{ _("Extract") }}" title="{{ _("Extract") }}" onclick="processNotify('{{ _("Extracting a single file...") }}')">
                                        </form>
                                    {% endif %}
                                </li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                </details>
            </td>
            {% else %}
            <td>{{ file["name"] }}</td>
            {% endif %}
            <td align="center">
                <form action="/files/download_image" method="post">
                    <input name="file" type="hidden" value="{{ file['name'] }}">
                    <input type="submit" value="{{ file['size_mb'] }} {{ _("MiB") }} &#8595;">
                </form>
            </td>
            <td>
                {% if file["name"] in attached_images %}
                    {{ _("In use") }}
                {% else %}
                {% if file["archive_contents"] %}
                <form action="/files/extract_image" method="post" class="file-extract">
                    <input name="archive_file" type="hidden" value="{{ file['name'] }}">
                    {% set pipe = joiner("|") %}
                    <input name="archive_members" type="hidden" value="{% for member in file["archive_contents"] %}{{ pipe() }}{{ member["path"] }}{% endfor %}">
                    <input type="submit" value="{{ _("Extract") }}" title="{{ _("Extract") }}" onclick="processNotify('{{ _("Extracting all files...") }}')">
                </form>
                {% else %}
                <form action="/scsi/attach" method="post" class="file-attach">
                    <input name="file_name" type="hidden" value="{{ file['name'] }}">
                    <label for="image_list_scsi_id_{{ file["name"] }}">{{ _("ID") }}</label>
                    <select name="scsi_id" id="image_list_scsi_id_{{ file["name"] }}">
                        {% for id in scsi_ids["valid_ids"] %}
                        <option name="id" value="{{id}}"{% if id == scsi_ids["recommended_id"] %} selected{% endif %}>
                            {{ id }}
                        </option>
                        {% endfor %}
                    </select>
                    <label for="image_list_unit_{{ file["name"] }}">{{ _("LUN") }}</label>
                    <input class="lun" name="unit" id="image_list_unit_{{ file["name"] }}" type="number" value="0" min="0" max="31" step="1" size="3">
                    {% if file["detected_type"] != "UNDEFINED" %}
                        <input name="type" type="hidden" value="{{ file['detected_type'] }}">
                        {{ file['detected_type_name'] }}
                    {% else %}
                        <label for="image_list_type_{{ file["name"] }}">{{ _("Type") }}</label>
                        <select name="type" id="image_list_type_{{ file["name"] }}">
                        <option selected disabled value="">
                        {{ _("Unknown") }}
                        </option>
                        {% for key, value in device_types.items() %}
                        {% if key in DISK_DEVICE_TYPES %}
                        <option value="{{ key }}">
                            {{ value["name"] }}
                        </option>
                        {% endif %}
                        {% endfor %}
                        </select>
                    {% endif %}
                    <input type="submit" value="{{ _("Attach") }}" title="{{ _("Attach") }}">
                {% endif %}
                </form>
                <form action="/files/rename" method="post" class="file-rename" onsubmit="var new_file_name = prompt('{{ _("Enter a new file name:") }}', '{{ file["name"]|replace("'", "\\'") }}'); if (new_file_name === null) event.preventDefault(); document.getElementById('new_file_name_{{ subdir }}_{{ loop.index }}').value = new_file_name;">
                    <input name="file_name" type="hidden" value="{{ file['name'] }}">
                    <input name="new_file_name" id="new_file_name_{{ subdir }}_{{ loop.index }}" type="hidden" value="">
                    <input type="submit" value="{{ _("Rename") }}" title="{{ _("Rename") }}">
                </form>
                <form action="/files/copy" method="post" class="file-copy" onsubmit="var copy_file_name = prompt('{{ _("Enter a file name for the copy:") }}', '{{ file["name"]|replace("'", "\\'") }}'); if (copy_file_name === null) event.preventDefault(); document.getElementById('copy_file_name_{{ subdir }}_{{ loop.index }}').value = copy_file_name;">
                    <input name="file_name" type="hidden" value="{{ file['name'] }}">
                    <input name="copy_file_name" id="copy_file_name_{{ subdir }}_{{ loop.index }}" type="hidden" value="">
                    <input type="submit" value="{{ _("Copy") }}" title="{{ _("Copy") }}">
                </form>
                <form action="/files/delete" method="post" class="file-delete" onsubmit="return confirm('{{ _("Delete file: %(file_name)s?", file_name=file["name"]|replace("'", "\\'")) }}')">
                    <input name="file_name" type="hidden" value="{{ file['name'] }}">
                    <input type="submit" value="{{ _("Delete") }}" title="{{ _("Delete") }}">
                </form>
                {% endif %}
                {% if not file["archive_contents"] %}
                <form action="/files/diskinfo" method="post" class="file-info">
                    <input name="file_name" type="hidden" value="{{ file['name'] }}">
                    <input type="submit" value="{{ _("?") }}" title="{{ _("Info") }}">
                </form>
                {% endif %}
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
</details>
{% endfor %}
</div>

{% else %}

<div class="notice">
    {{ _("The images directory is currently empty.") }}
</div>
{% endif %}
<p>
    <small>{{ _("%(disk_space)s MiB disk space remaining for images", disk_space=env["free_disk_space"]) }}</small>
</p>

{% else %}

<div class="notice">
    {{ _("Please create the PiSCSI images dir to work with disk images:")}} {{ env["image_dir"] }}
</div>

{% endif %}
</section>

<hr/>

<section id="attach-devices">
<details>
    <summary class="heading">
        {{ _("Attach Device") }}
    </summary>
    <ul>
        </li>
        {% if bridge_configured %}
        <li>{{ _("The <tt>piscsi_bridge</tt> network bridge is active and ready to be used by an emulated network adapter!") }}</li>
        {% else %}
        <li>{{ _("Please configure the <tt>piscsi_bridge</tt> network bridge before attaching an emulated network adapter!") }}</li>
        {% endif %}
        <li>{{ _("Read more about <a href=\"%(url)s\" target=\"_blank\">supported device types</a> on the wiki.", url="https://github.com/PiSCSI/piscsi/wiki/Supported-Device-Types") }}
        </li>
    </ul>
</details>
<table border="black" cellpadding="3" summary="List of peripheral devices">
    <tr>
        <th scope="col">{{ _("Device") }}</th>
        <th scope="col">{{ _("Key") }}</th>
        <th scope="col">{{ _("Actions") }}</th>
    </tr>
    {% for type in device_types.keys() %}
    <tr>
        <td>
            {% if device_types[type]["name"] == type %}
            {% if type in REMOVABLE_DEVICE_TYPES %}
            <div>{{ _("Unknown Removable Disk Drive") }}</div>
            {% elif type in DISK_DEVICE_TYPES %}
            <div>{{ _("Unknown Fixed Disk Drive") }}</div>
            {% else %}
            <div>{{ _("Unknown Device") }}</div>
            {% endif %}
            {% else %}
            <div>{{ device_types[type]["name"] }}</div>
            {% endif %}
        </td>
        <td>
            <div>{{ type }}</div>
        </td>
        <td>
            <form action="/scsi/attach" method="post" class="device-attach">
                <input name="type" type="hidden" value="{{ type }}">
                {% for key, value in device_types[type]["params"] | dictsort %}
                <label for="param_{{ type }}_{{ key }}">{{ key }}:</label>
                {% if value.isnumeric() %}
                <input name="param_{{ key }}" id="param_{{ type }}_{{ key }}" type="number" value="{{ value }}">
                {% elif key == "interface" %}
                <select name="param_{{ key }}" id="param_{{ type }}_{{ key }}">
                {% for if in netinfo["ifs"] %}
                    <option value="{{ if }}">
                        {{ if }}
                    </option>
                {% endfor %}
                </select>
                {% else %}
                <input name="param_{{ key }}" id="param_{{ type }}_{{ key }}" type="text" size="{{ value|length }}" placeholder="{{ value }}">
                {% endif %}
                {% endfor %}
                {% if type in DISK_DEVICE_TYPES %}
                <label for="{{ type }}_drive_name">{{ _("Identify as:") }}</label>
                <select name="drive_name" id="{{ type }}_drive_name" class="table-dropdown">
                <option value="">
                {{ _("Generic device") }}
                </option>
                {% if type == "SCHD" %}
                {% for drive in drive_properties["hd_conf"] | sort(attribute='name') %}
                <option value="{{ drive.name }}">
                {{ drive.name }}
                </option>
                {% endfor %}
                {% endif %}
                {% if type == "SCCD" %}
                {% for drive in drive_properties["cd_conf"] | sort(attribute='name') %}
                <option value="{{ drive.name }}">
                {{ drive.name }}
                </option>
                {% endfor %}
                {% endif %}
                {% if type == "SCRM" %}
                {% for drive in drive_properties["rm_conf"] | sort(attribute='name') %}
                <option value="{{ drive.name }}">
                {{ drive.name }}
                </option>
                {% endfor %}
                {% endif %}
                {% if type == "SCMO" %}
                {% for drive in drive_properties["mo_conf"] | sort(attribute='name') %}
                <option value="{{ drive.name }}">
                {{ drive.name }}
                </option>
                {% endfor %}
                {% endif %}
                {% if type == "SCTP" %}
                {% for drive in drive_properties["st_conf"] | sort(attribute='name') %}
                <option value="{{ drive.name }}">
                {{ drive.name }}
                </option>
                {% endfor %}
                {% endif %}
                </select>
                <label for="{{ type }}_image_file_name">{{ _("Image file:") }}</label>
                <select name="file_name" id="{{ type }}_image_file_name" class="table-dropdown" {% if type not in REMOVABLE_DEVICE_TYPES %}required{% endif %}>
                <option value="" selected {% if type not in REMOVABLE_DEVICE_TYPES %}disabled{% endif %}>
                {% if type in REMOVABLE_DEVICE_TYPES %}
                {{ _("None") }}
                {% else %}
                {{ _("Choose a file...") }}
                {% endif %}
                </option>
                {% for f in files|sort(attribute='name') %}
                {% if type == "SCHD" %}
                {% if f["name"].lower().endswith(env['hd_suffixes']) %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% elif type == "SCCD" %}
                {% if f["name"].lower().endswith(env['cd_suffixes']) %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% elif type == "SCRM" %}
                {% if f["name"].lower().endswith(env['rm_suffixes']) %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% elif type == "SCMO" %}
                {% if f["name"].lower().endswith(env['mo_suffixes']) %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% elif type == "SCTP" %}
                {% if f["name"].lower().endswith(env['st_suffixes']) %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% else %}
                <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
                {% endif %}
                {% endfor %}
                </select>
                {% endif %}
                <label for="{{ type }}_scsi_id">{{ _("ID") }}</label>
                <select name="scsi_id" id="{{ type }}_scsi_id">
                {% for id in scsi_ids["valid_ids"] %}
                    <option value="{{ id }}"{% if id == scsi_ids["recommended_id"] %} selected{% endif %}>
                        {{ id }}
                    </option>
                {% endfor %}
                </select>
                <label for="{{ type }}_unit">{{ _("LUN") }}</label>
                <input class="lun" name="unit" id="{{ type }}_unit" type="number" value="0" min="0" max="31" step="1" size="3">
                <input type="submit" value="{{ _("Attach") }}" title="{{ _("Attach") }}">
            </form>
        </td>
    </tr>
    {% endfor %}
</table>
</section>

<hr/>

<section id="download-url">
<details>
    <summary class="heading">
        {{ _("Transfer Files to the PiSCSI") }}
    </summary>
    <ul>
        <li>{{ _("Disk Images") }} = {{ env["image_dir"] }}</li>
        {% if file_server_dir_exists %}
        <li>{{ _("Shared Files") }} = {{ FILE_SERVER_DIR }}</li>
        {% else %}
        <li>{{ _("Install a file server and create the shared files directory in order to share files between the Pi and your vintage computers.") }}</li>
        {% endif %}
    </ul>
</details>

<form action="/files/download_url" method="post">
    <label for="download_url">{{ _("Download file from URL:") }}</label>
    <input name="url" id="download_url" required="" type="url">
    <label for="disk_images" class="hidden">{{ _("Disk Images") }}</label>
    <label for="images_subdir">{{ _("To directory:") }}</label>
    <input type="radio" name="destination" id="disk_images" value="disk_images" checked="checked">
    <select name="images_subdir" id="images_subdir">
    {% for dir in images_subdirs %}
    <option value="{{dir}}">{{env['image_root_dir']}}/{{dir}}</option>
    {% endfor %}
    <option value="" selected>{{env['image_root_dir']}}/</option>
    </select>
    {% if file_server_dir_exists %}
    <label for="shared_files" class="hidden">{{ _("Shared Files") }}</label>
    <input type="radio" name="destination" id="shared_files" value="shared_files">
    <label for="shared_subdir" class="hidden">{{ _("To directory:") }}</label>
    <select name="shared_subdir" id="shared_subdir">
    {% for dir in shared_subdirs %}
    <option value="{{dir}}">{{env['shared_root_dir']}}/{{dir}}</option>
    {% endfor %}
    <option value="" selected>{{env['shared_root_dir']}}/</option>
    </select>
    {% endif %}
    <input type="submit" value="{{ _("Download") }}" onclick="processNotify('{{ _("Downloading File...") }}')">
</form>
</section>

<section id="upload">
    <a href="/upload" target="_blank"><p>{{ _("Upload Files (new tab)") }}</p></a>
</section>
<noscript>
    <style type="text/css">
        section#upload { display: none; }
    </style>
    <div class="notice">
        {{ _("The file uploading functionality requires JavaScript.") }}
    </div>
</noscript>

<hr/>

<section id="create-image">
<details>
    <summary class="heading">
        {{ _("Create Empty Disk Image") }}
    </summary>
    <ul>
        <li>{{ _("Please refer to <a href=\"%(url)s\" target=\"_blank\">wiki documentation</a> to learn more about the supported image file types.", url="https://github.com/PiSCSI/piscsi/wiki/Supported-Device-Types#image-types") }}</li>
        <li>{{ _("It is not recommended to use the Lido hard disk driver with the Macintosh Plus.") }}</li>
    </ul>
</details>

<form action="/files/create" method="post">
    <label for="image_create_file_name">{{ _("File Name:") }}</label>
    <input name="file_name" id="image_create_file_name" required="" type="text">
    <label for="image_create_type">{{ _("Type:") }}</label>
    <select name="type" id="image_create_type">
        {% for key, value in image_suffixes_to_create.items() %}
        <option value="{{ key }}">
        {{ value }} [.{{ key }}]
        </option>
        {% endfor %}
    </select>
    <label for="image_create_size">{{ _("Size:") }}</label>
    <input name="size" id="image_create_size" type="number" placeholder="{{ _("MiB") }}" min="1" max="262144" required>
    <label for="image_create_drive_name">{{ _("Identify as:") }}</label>
    <select name="drive_name" id="image_create_drive_name">
    <option value="">
    {{ _("Generic device") }}
    </option>
    {% for drive in drive_properties["hd_conf"] | sort(attribute='name') %}
    <option value="{{ drive.name }}">
    {{ drive.name }}
    </option>
    {% endfor %}
    </select>
    <label for="drive_format">{{ _("Format as:") }}</label>
    <select name="drive_format" id="drive_format">
    <option value="">
    {{ _("Unformatted") }}
    </option>
    <option value="Lido 7.56">
    HFS + Lido
    </option>
    <option value="SpeedTools 3.6">
    HFS + SpeedTools
    </option>
    <option value="FAT16">
    FAT16
    </option>
    <option value="FAT32">
    FAT32
    </option>
    </select>
    <input type="submit" value="{{ _("Create") }}">
</form>
</section>

<section id="create-drive">
    <a href="/drive/list"><p>{{ _("Create Disk Image With Properties") }}</p></a>
</section>

<hr/>

<section id="create-iso">
<details>
    <summary class="heading">
        {{ _("Create CD-ROM Image") }}
    </summary>
    <ul>
        <li>{{ _("HFS is for Mac OS, Joliet for Windows, and Rock Ridge for POSIX.") }}</li>
        <li>{{ _("If the downloaded file is a zip archive, we will attempt to unzip it and store the resulting files.") }}</li>
    </ul>
</details>

<div>
<form action="/files/create_iso" method="post">
    <label for="iso_url">{{ _("Download file from URL:") }}</label>
    <input name="url" id="iso_url" required="" type="url">
    <label for="iso_url_type">{{ _("Type:") }}</label>
    <select name="type" id="iso_url_type">
        <option value="HFS">
            HFS
        </option>
        <option value="ISO-9660 Level 1">
            ISO-9660 Level 1
        </option>
        <option value="ISO-9660 Level 2">
            ISO-9660 Level 2
        </option>
        <option value="ISO-9660 Level 3">
            ISO-9660 Level 3
        </option>
        <option value="Joliet">
            Joliet
        </option>
        <option value="Rock Ridge">
            Rock Ridge
        </option>
    </select>
    <input type="submit" value="{{ _("Create") }}" onclick="processNotify('{{ _("Downloading file and generating CD-ROM image...") }}')">
</form>
</div>
<div>
<form action="/files/create_iso" method="post">
    <label for="iso_file">{{ _("Use local file:") }}</label>
    <select name="file" id="iso_file">
        {% for f in files|sort(attribute='name') %}
            <option value="{{ f["name"] }}">{{ f["name"].replace(env["image_dir"], '') }}</option>
        {% endfor %}
    </select>
    <label for="iso_file_type">{{ _("Type:") }}</label>
    <select name="type" id="iso_file_type">
        <option value="HFS">
            HFS
        </option>
        <option value="ISO-9660 Level 1">
            ISO-9660 Level 1
        </option>
        <option value="ISO-9660 Level 2">
            ISO-9660 Level 2
        </option>
        <option value="ISO-9660 Level 3">
            ISO-9660 Level 3
        </option>
        <option value="Joliet">
            Joliet
        </option>
        <option value="Rock Ridge">
            Rock Ridge
        </option>
    </select>
    <input type="submit" value="{{ _("Create") }}" onclick="processNotify('{{ _("Generating CD-ROM image...") }}')">
</form>
</div>
</section>

<hr/>

{% endblock content %}
