{# Resource upload form field that allows switching between: URL <-> Unset <-> File upload (when enabled) The "url" field is New uploaded files are saved as "upload", and "name" field is updated with the file name if not already set. When removing a file upload a special "clear_upload" field is passed data - resource form data fields errors - errors on resource form fields is_url - true if resource using url (not file upload) is_upload - true if resource using file upload (not url) is_upload_enabled - true if site supports file uploads url_label - label for URL field (default: "URL") upload_label - label for upload field (default: "File") menu_label - label for button menu (default: "Data") placeholder - placeholder text for url field #} {% import "macros/form.html" as form %} {% set first_button = 'resource-upload-button' if is_upload_enabled else 'resource-link-button' %} {% macro remove_button(js='') %} {% endmacro %}
{% block url_type_select %} {% if is_upload_enabled %} {% endif %} {% endblock %}
{% block url_type_fields %} {% if is_upload_enabled %}
{% block upload_controls %} {% if is_upload %} {# for existing uploads we show the file name in a readonly input box #}
{% set existing_name = data.get('url', '').split('/')[-1].split('?')[0].split('#')[0] %}
{% endif %}
{{ remove_button( js="$('#field-resource-upload').replaceWith($('#field-resource-upload').val('').clone(true))") }} {{ form.input( 'upload', label=upload_label or _('File'), id='field-resource-upload', type='file', classes=['control-full']) }}
{% endblock %}
{% endif %}
{% block link_controls %} {{ remove_button( js="$('#field-resource-url').val('')") }} {{ form.input( 'url', label=url_label or _('URL'), id='field-resource-url', type='url', placeholder=placeholder, value=data.get('url'), error=errors.get('url'), classes=['control-full']) }} {% endblock %}
{% endblock %}