<commit_before>{#=== OPTIONS ========================================================================================================#}

{% set option = {
    class:       field.class|default(''),
    label:       field.label|default(''),
    extensions:  field.extensions|default([]),
    upload:      field.upload|default(''),
    info:        field.info|default('info.upload.file')
}%}

{#=== INIT ===========================================================================================================#}

{% set items = stackitems(7, 'other,document') %}

{% set attr_filepath = {
    class:       option.class~' imageinput',
    id:          'field-'~key,
    name:        key,
    type:        'text',
    placeholder: __('field.general.allowed-filetypes') ~ ' ' ~ option.extensions|join(', ') ~ ' …',
    value:       context.content.get(key),
}%}

{% set attr_upload = {
    accept:       option.extensions ? '.'~option.extensions|join(',.') : '',
    data_upload:  {type: 'File', key: key}|json_encode(),
    data_url:     url('upload', {'handler': option.upload}),
    id:           'fileupload-'~key,
    name:         'files[]',
    type:         'file',
}%}

{#=== BLOCKS =========================================================================================================#}

{% import _self as block %}

{% macro buttons(key, paths, option, attr_upload) %}
    {% import '_macro/_macro.twig' as macro %}
    {# The fileinput-button span is used to style the file input field as button #}
    <span class="btn btn-secondary fileinput-button">
        <i class="fa fa-upload"></i>
        <span>{{ __('Upload file') }}</span>
        <input{{ macro.attr(attr_upload) }}>
    </span>

    <a data-target="#selectModal-{{ key }}" href="{{ paths.async }}browse/files{{ option.upload ? '/'~option.upload : '' }}?key={{ key }}" class="btn btn-tertiary" data-toggle="modal">
        <i class="fa fa-download"></i>
        {{ __('field.general.select-from-server') }}
    </a>
{% endmacro %}

{% macro stack(key, items) %}
    {% if items %}
        <div class="btn-group">
            <a class="btn btn-tertiary dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-paperclip"></i>
                {{ __('field.general.select-from-stack') }}<span class="caret"></span>
            </a>
            <ul class="dropdown-menu" id="stack-{{ key }}">
                {% for item in items %}
                    <li>
                        <a href="#" data-action="bolt.stack.selectFromPulldown('{{ key }}', '{{ item.filepath }}');">{{ item.basename }} <small>({{ item.filesize }}{% if item.imagesize|default() %}, {{ item.imagesize }} px{% endif %})</small></a>
                    </li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
{% endmacro %}

{% macro progress(key) %}
    <div class="progress progress-striped active" id="progress-{{ key }}">
        <div class="bar" style="width: 0%;"></div>
    </div>
{% endmacro %}

{# Modal "select from server" #}
{% macro serverselect(key) %}
    <div class="modal fade" id="selectModal-{{ key }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content"></div>
        </div>
    </div>
{% endmacro %}

{#=== FIELDSET =======================================================================================================#}

<fieldset class="file">
    <label class="col-sm-12 control-label">{{ (option.info) ? macro.infopop(labelkey, option.info) : labelkey }}</label>

    <div class="col-sm-12 dropzone clearfix" id="dropzone-{{ key }}">
        <input{{ macro.attr(attr_filepath) }}>

        <div class="button-wrap">
            {{ block.buttons(key, paths, option, attr_upload) }}
            {{ block.stack(key, items) }}
        </div>
        {{ block.progress(key) }}
        {{ block.serverselect(key, __('Cancel')) }}

        {% if not ismobileclient() %}
            <div style="clear: left;" class="hidden-xs">
                <small>{{ app.translator.trans('info.upload.filesmall', {}, 'infos') }}</small>
            </div>
        {% endif %}
    </div>

</fieldset>
<commit_msg>Use macro upload_buttons() for files<commit_after>{#=== OPTIONS ========================================================================================================#}

{% set option = {
    class:       field.class|default(''),
    label:       field.label|default(''),
    extensions:  field.extensions|default([]),
    upload:      field.upload|default(''),
    info:        field.info|default('info.upload.file')
}%}

{#=== INIT ===========================================================================================================#}

{% set items = stackitems(7, 'other,document') %}

{% set attr_filepath = {
    class:       option.class~' imageinput',
    id:          'field-'~key,
    name:        key,
    type:        'text',
    placeholder: __('field.general.allowed-filetypes') ~ ' ' ~ option.extensions|join(', ') ~ ' …',
    value:       context.content.get(key),
}%}

{% set attr_upload = {
    accept:       option.extensions ? '.'~option.extensions|join(',.') : '',
    data_upload:  {type: 'File', key: key}|json_encode(),
    data_url:     url('upload', {'handler': option.upload}),
    id:           'fileupload-'~key,
    name:         'files[]',
    type:         'file',
}%}

{#=== BLOCKS =========================================================================================================#}

{% import _self as block %}

{% macro stack(key, items) %}
    {% if items %}
        <div class="btn-group">
            <a class="btn btn-tertiary dropdown-toggle" data-toggle="dropdown">
                <i class="fa fa-paperclip"></i>
                {{ __('field.general.select-from-stack') }}<span class="caret"></span>
            </a>
            <ul class="dropdown-menu" id="stack-{{ key }}">
                {% for item in items %}
                    <li>
                        <a href="#" data-action="bolt.stack.selectFromPulldown('{{ key }}', '{{ item.filepath }}');">{{ item.basename }} <small>({{ item.filesize }}{% if item.imagesize|default() %}, {{ item.imagesize }} px{% endif %})</small></a>
                    </li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
{% endmacro %}

{% macro progress(key) %}
    <div class="progress progress-striped active" id="progress-{{ key }}">
        <div class="bar" style="width: 0%;"></div>
    </div>
{% endmacro %}

{# Modal "select from server" #}
{% macro serverselect(key) %}
    <div class="modal fade" id="selectModal-{{ key }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content"></div>
        </div>
    </div>
{% endmacro %}

{#=== FIELDSET =======================================================================================================#}

<fieldset class="file">
    <label class="col-sm-12 control-label">{{ (option.info) ? macro.infopop(labelkey, option.info) : labelkey }}</label>

    <div class="col-sm-12 dropzone clearfix" id="dropzone-{{ key }}">
        <input{{ macro.attr(attr_filepath) }}>

        <div class="button-wrap">
            {{ macro.upload_buttons(key, __('Upload file'), attr_upload, paths, option.upload) }}
            {{ block.stack(key, items) }}
        </div>
        {{ block.progress(key) }}
        {{ block.serverselect(key, __('Cancel')) }}

        {% if not ismobileclient() %}
            <div style="clear: left;" class="hidden-xs">
                <small>{{ app.translator.trans('info.upload.filesmall', {}, 'infos') }}</small>
            </div>
        {% endif %}
    </div>

</fieldset>

{'fraction_non_alphanumeric': 0.29138903126601745, 'fraction_numerical': 0.0017939518195797027, 'mean_word_length': 2.842934515017233, 'pattern_counts': {'":': 0, '<': 92, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5440128', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2214, 'n_words': 445}