file_upload.html.twig 3.90 KiB
{% block file_upload_progress_prototype %}
    <div class="template-upload fileinput-entry">
        <div class="progress-text" style="display: none"></div>
        <i class="fa fa-circle-o-notch fa-spin icon"></i>&nbsp;<span class="name"></span>
        <span class="size"></span>
        <span class="error"></span>
        <a href="#" class="danger cancel" title="{% trans %}button.cancel{% endtrans %}">
            {{- irstea_icon('remove') -}}
        </a>
        <div class="progress" style="display: none">
            <div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 0"></div>
        </div>
    </div>
{% endblock %}
{%- block file_upload_entry_prototype %}
    {%- set file = file|default([]) %}
    <div class="template-download fileinput-entry">
        <input class="id" type="hidden" name="{{ full_name }}{% if multiple %}[{{index|default('__index__')}}]{% endif %}[id]" value="{{ file.id|default }}"/>
        <span class="repr">{{ irstea_uploaded_file(file) }}</span>
        <input class="form-control description" type="text" placeholder="{% trans from 'file_upload' %}form.description.placeholder{% endtrans %}" name="{{ full_name }}{% if multiple %}[{{index|default('__index__')}}]{% endif %}[description]" value="{{ file.description|default }}"/>
        <span class="error"></span>
        <a href="#" class="danger delete {%- if disabled or attr.readonly|default(false) %} disabled{% endif -%}" title="{%
        trans %}button.delete{%
        endtrans %}">
            {{- irstea_icon('remove') -}}
        </a>
    </div>
{% endblock -%}
{% block file_upload_widget %}
    <div id="{{ id }}" class="form-control fileinput-{{ multiple ? "multiple" : "single" }}" {{ block('widget_container_attributes') }} {{ block('widget_only_attributes') }}
         data-download-prototype="{{ block('file_upload_entry_prototype')|e }}"
         data-upload-prototype="{{ block('file_upload_progress_prototype')|e }}"
         data-csrf-token="{{ csrf_token(constant('Irstea\\FileUploadBundle\\Controller\\UploadController::CSRF_INTENTION')) }}"
         {% if disabled %}data-disabled="disabled"{% endif -%}
         {% if attr.readonly|default(false) %}data-readonly="readonly"{% endif -%}
        <div class="fileinput-entries">
            {%- if value is not empty %}
                {%- if multiple %}
                    {% for index, file in value %}
                        {{ block('file_upload_entry_prototype') }}
                    {% endfor %}
                {%- else %}
                    {%- set file = value %}
                    {{- block('file_upload_entry_prototype') -}}
                {% endif -%}
            {% endif -%}
        </div>
        <div class="fileinput-button btn btn-default btn-xs">
            <span>{{ irstea_icon('upload') }}&nbsp;{% trans %}button.upload{% endtrans %}</span>
            <input type="file" name="_hack_{{ full_name }}" data-map-errors-to="#{{ id }}"
                {%- if multiple %} multiple="multiple"{% endif -%}
                {%- if disabled or attr.readonly|default(false) %} disabled="disabled"{% endif -%}
        </div>
        {% if multiple and widget_attr["data-max-number-of-files"] is defined %}
            &nbsp;<small>{% trans with {"%num%": widget_attr["data-max-number-of-files"]}  from 'file_upload' %}form.max_number_of_files(%num%){% endtrans %}.</small>
        {% endif %}
        {% if widget_attr["data-min-file-size"] is defined %}
            &nbsp;<small>{% trans from 'file_upload' %}form.min_file_size{% endtrans %}&nbsp;: {{ widget_attr["data-min-file-size"]|irstea_file_size(0) }}</small>
        {% endif %}
        {% if widget_attr["data-max-file-size"] is defined %}
            &nbsp;<small>{% trans from 'file_upload' %}form.max_file_size{% endtrans %}&nbsp;: {{ widget_attr["data-max-file-size"]|irstea_file_size(0) }}</small>
        {% endif %}
    </div>
{% endblock file_upload_widget %}