{% from 'forms/_form.html' import form_header, form_footer, form_row, form_rows %}

{%- block content %}
    {{ form_header(form, id='attachment-upload-form', classes=('full-width' if not existing_attachment else ''),
                   action=action) }}
    <input type="hidden" autofocus>
    {% if existing_attachment %}
        {{ form_row(form.file) }}
    {% else %}
        {{ form_row(form.files, skip_label=true) }}
    {% endif %}
    {{ form_rows(form, skip=('folder', 'protected', 'acl', 'files', 'file')) }}
    {{ form_rows(form, fields=('folder', 'protected')) }}
    {{ form_rows(form, fields=('acl',)) }}
    {{ protection_message | safe }}
    {% call form_footer(attach_form) %}
        <div class="dropzone-upload-btn">
            {% if existing_attachment -%}
                <input class="i-button big highlight js-dropzone-save" type="submit"
                       value="{% trans %}Save{% endtrans %}" data-disabled-until-change>
            {%- else -%}
                <input class="i-button big highlight js-dropzone-upload" type="submit" disabled
                   value="{% trans %}Upload{% endtrans %}" data-disabled-until-change>
            {% endif %}
            <button class="i-button big" data-button-back>{% trans %}Cancel{% endtrans %}</button>
        </div>
    {% endcall %}
    <script>
        (function() {
            'use strict';

            $('#{{ form.folder.id }}').nullableselector();
            var form = $('#attachment-upload-form');
            aclIfProtected(
                $('#{{ form.protected.id }}'),
                {% if form.acl %}$('#{{ form.acl.id }}'){% else %}null{% endif %},
                form.find('.protected-protection-message'),
                form.find('.inheriting-protection-message'),
                $('#{{ form.folder.id }}')
            );
            messageIfFolderProtected(
                $('#{{ form.protected.id }}'),
                $('#{{ form.folder.id }}'),
                {{ folders_protection_info | tojson }},
                form.find('.protected-protection-message'),
                form.find('.inheriting-protection-message'),
                form.find('.folder-protection-message')
            );
        })();
    </script>
{%- endblock %}
