{% extends 'page.html.twig' %}

{% block content %}
        <div class="ui top attached accordion-styled header">
            {{ _T("Choose an entry") }}
        </div>
        <div class="ui bottom attached accordion-styled segment">
            <form action="{{ url_for('changeText') }}" method="post" enctype="multipart/form-data" class="ui form">
                <div class="fields">
                    <div class="inline field">
                        <label for="sel_lang">{{ _T("Language:") }}</label>
                        <select name="sel_lang" id="sel_lang" class="ui dropdown nochosen lang">
                            {% for langue in langlist %}
                                <option value="{{ langue.getID() }}" {% if cur_lang == langue.getID() %}selected="selected"{% endif %}>{{ langue.getName() }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="inline field">
                        <label for="sel_ref">{{ _T("Reference:") }}</label>
                        <select name="sel_ref" id="sel_ref" class="ui dropdown nochosen">
                            {% for ref in reflist %}
                                <option value="{{ ref.tref }}" {% if cur_ref == ref.tref %}selected="selected"{% endif %} >{{ ref.tcomment }}</option>
                            {% endfor %}
                        </select>
                        <noscript><span><input type="submit" value="{{ _T("Change") }}" class="ui button" /></span></noscript>
                    </div>
                    {% include 'components/forms/csrf.html.twig' %}
                </div>
            </form>
        </div>

        <form action="{{ url_for('texts') }}" method="post" enctype="multipart/form-data" class="ui form">
            <div class="ui top attached accordion-styled header">
                {{ mtxt.tcomment }}
            </div>
            <div class="ui bottom attached accordion-styled segment">
                <div class="active content field">
                    <div class="field">
                        <label for="tsubject">{{ _T("Email Subject") }}</label>
                        <div class="ui corner labeled input">
                            <input type="text" name="text_subject" id="tsubject" value="{{ mtxt.tsubject }}" maxlength="255" size="32" class="codeeditor"/>
                            <div class="ui corner label"></div>
                        </div>
                        <span class="exemple">{{ _T("(Max 255 characters)") }}</span>
                    </div>
                    <div class="field">
                        <label id="body_label" for="text_body">{{ _T("Email Body:") }}</label>
                        <div class="ui corner labeled input">
                            <div class="ui corner label"></div>
                            <textarea name="text_body" id="text_body" cols="64" rows="15" class="codeeditor">{{ mtxt.tbody }}</textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ui basic center aligned segment">
                <input type="hidden" name="cur_lang"  value="{{ cur_lang }}"/>
                <input type="hidden" name="cur_ref" value="{{ cur_ref }}"/>
                <input type="hidden" name="valid" id="valid" value="1"/>
                <button type="submit" class="ui labeled icon primary button action">
                    <i class="save icon"></i> {{ _T("Save") }}
                </button>
                {% include 'components/forms/csrf.html.twig' %}
            </div>
        </form>
        {% include 'modals/replacements_legend.html.twig' with {'legends': texts.getLegend(), 'cur_ref': cur_ref} %}
{% endblock %}

{% block javascripts %}
        <script type="text/javascript">
            $(function() {
                $('#sel_ref, #sel_lang').change(function() {
                    $(':input[type="submit"]').attr('disabled', 'disabled');
                    //Change the input[@id='value'] ; we do not want to validate, but to change lang/ref
                    $('#valid').attr('value', (this.id === 'sel_lang') ? 'change_lang' : 'change_text');
                    this.form.submit();
                });

                _addLegendButton('.ui.corner.label');
                _handleLegend();
                _bindFomanticComponents();
            });
        </script>
{% endblock %}
