{% set userData = app.session.get('userData') %}
<form method="POST" id="form-faxingOption">
    <h5>{{ page_title }}</h5>
    <div id="flash-messages-content-modal"></div>
    <div class="row max-width-initial">
        <div class="large-12 columns">
            <div class="row">
                <div class="large-6 columns">
                    {{ form_label(form.faxNo) }}
                    {{ form_widget(form.faxNo) }}
                </div>
            </div>
            <div class="row">
                <div class="large-6 columns">
                    {{ form_label(form.birth_date) }}
                    {{ form_widget(form.birth_date) }}
                </div>
                <div class="large-6 columns">
                    {{ form_label(form.patientName) }}
                    {{ form_widget(form.patientName) }}
                    {{ form_widget(form.patient) }}
                </div>
            </div>
            <div class="row">
                <div class="large-12 columns">
                    {{ form_label(form.customBody) }}
                    {{ form_widget(form.customBody) }}
                </div>
            </div>
            <div class="row">
                <div class="large-12 columns" style="margin-top: 2%">
                    <h5>Attachments(s) <a href="javascript:void(0)" id="href-new-file-field"><i class="fa fa-plus"></i></a></h5>
                    <p class="form-hint-text">Upload file(s) below</p>
                    <div id="file-field-container">
                        {% if faxingOption %}
                            {% for key,fof in faxingOption.faxingOptionFiles %}
                                {% if fof.isDeleted != true %}
                                    <div class="input-group no-margin-bottom">
                                        <input type="hidden" name="otherForm[files][{{ key }}]" value="{{ fof.idencoded }}" />
                                        <a href="{{ path('faxing_option_file_download', {id: fof.idencoded}) }}">{{ fof.filedesc }}</a>
                                        <div class="input-group-button">
                                            <button type="button" class="button secondary file-field-remove"><i class="fa fa-remove"></i></button>
                                        </div>
                                    </div>
                                {% endif %}
                            {% endfor %}
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <hr>
    <div class="row-max-width-initial">
        <div class="small-12 columns no-padding-right">
            <div class="button-container clearfix text-right">
                <a href="javascript:void(0)" class="button just-continue href-faxingOption-action float-right" data-axn="{{ action }}"
                   data-message="Are you sure you want to save this information?"
                   style="margin-left: 10px; margin-right: 0;"
                >Save</a>
                {#{% endif %}#}
                {#{% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Fax Delete' in userData.accesses) %}#}
                    {#<a href="javascript:void(0)" class="ask-continue button alert href-faxTran-action float-right" data-axn="d"#}
                       {#data-message="Are you sure you want to delete this record?"#}
                       {#style="margin-left: 10px; margin-right: 0;"#}
                    {#>Delete</a>#}
                {#{% endif %}#}
                <a href="javascript:void(0)" class="button secondary" data-close style="margin-left: 10px; margin-right: 0;">Close</a>
            </div>
        </div>
    </div>
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form._token) }}

    <script>
        jQ(document).ready(function(){
            let faxingOptionForm = {
                settings: {},
                init: function() {
                    faxingOptionForm.bindElements();
                    faxingOptionForm.fileField_arrangeIndexes();
                    faxingOptionForm.fileField_bindRemove();
                },
                bindElements: function() {
                    jQ('#href-new-file-field').unbind('click').bind('click', this.newFileField);
                },
                newFileField: function() {
                    var div_ig = jQ('<div/>'),
                        div_igb = jQ('<div/>'),
                        btn = jQ('<button/>'),
                        input_file = jQ('<input/>');

                    div_ig.addClass('input-group').addClass('no-margin-bottom');
                    div_igb.addClass('input-group-button');
                    btn.attr('type', 'button').addClass('button secondary').addClass('file-field-remove').html('<i class="fa fa-remove"></i>');
                    input_file.attr({
                        type:'file',
                        accept : 'application/pdf'
                    }).addClass('input-group-field');

                    div_igb.append(btn);
                    div_ig.append(input_file).append(div_igb);

                    jQ('#file-field-container').append(div_ig);

                    faxingOptionForm.fileField_arrangeIndexes();
                    faxingOptionForm.fileField_bindRemove();
                },
                fileField_arrangeIndexes: function() {
                    jQ('#file-field-container .input-group').each(function(key){
                        jQ(this).attr('id', 'file-field-input-group-' + key).data('key', key);
                        jQ(this).find('input[type=file]').attr('name', 'files[' + key + ']');
                        jQ(this).find('button').data('key', key);
                    });
                },
                fileField_bindRemove: function() {
                    jQ('.file-field-remove').unbind('click').bind('click', function(){
                        jQ('#file-field-input-group-' + jQ(this).data('key')).remove();
                        faxingOptionForm.fileField_arrangeIndexes();
                    });
                },
            };

            faxingOptionForm.init();

        });
    </script>
</form>