{% extends 'layout.twig' %}
{% block body %}
    <div class="contenu clearfix"  id="Consultation_choixFrs">
        <h1>
            {{ 'Consultations' | trad }}
        </h1>
        {{ ariane() }}
        <h2 id="divMenu" style="position:relative;">
            {{ 'Consultation' | trad }} : {{ consultation.NO_AO }} - {{ consultation.OBJET_AO }} {{ 'créé le' | trad }} {{ consultation.DTE_AO | dateTrad }} {% if AOEventCreat.NOM %} {{ 'par' | trad }} {{ AOEventCreat.NOM }} {% endif %}
            {% if canChooseFour %}
            <button type="button" class="button principal" 
                onClick="ajaxPopupV2('{{ path('Consultation.ChoixFournisseur.validateChoixFrs', {idAO:idAO}) }}', 'formChoixFrs');">
                    {{ 'Sélection finale' | trad }}
            </button>
            {% endif %}
            {{ arianeAnnuler('Retour' | trad) }}
        </h2>
        <div class="tab-content">
            <form method="post" name="formChoixFrs" id="formChoixFrs" class="clearfix padding15">   
                <div class="clearfix" style="display:flex;align-items:end;margin-bottom:10px;">
                    <div class="listeButton" style="margin-left: auto;">
                        <a onclick="ajaxPopup ('{{ path('Consultation.Consultation.popupBlocNote', {idAO:idAO}) }}', '{{ 'Bloc-note' | trad }}', '', '')"  class="bloc_note_V2 white-tooltip" style="float:right;margin-right:5px;" >
                            <span class="infos_tooltip top-left">
                                {{ 'Bloc-note de la consultation' | trad }}
                            </span>
                        </a>
                        {% if canChooseFour %}
                        <a class="pieces_jointes white-tooltip" style="float: right;margin-left:5px!important;" 
                            href="{{ path('GlobalApplication.CreationDocRattaches.ajoutDocAtt', {id: idFordoc, NO_DA: 'AO_ENTET', typeAccCadre:'JUSTIF'}) }}">
                            <span class="infos_tooltip left">
                                {{ 'Ajouter un document' | trad }}
                            </span>
                        </a>
                        {% endif %}
                    </div>
                </div>   		
                <div id="table-scroll" class="table-scroll">
                    <div class="table-wrap">
                        <table id="choixFrs" class="table table-V2 table-hover main-table" style="margin-bottom:0px;">
                            <thead>
                                <th class="auto_width" style="min-width:150px;"></th>
                                    {% for frs in listeFrs %}
                                        <th class="align-center auto_width" style="min-width:150px;">
                                            {% if frs.TYPE_FG == 'G' %}
                                                {{ frs.RS_GRP }} ({{ frs.CODE_FOU }})
                                            {% else %}
                                                {{ frs.RS }} ({{ frs.CODE_FOU }})
                                            {% endif %}
                                        </th>
                                    {% endfor %}
                                {# <th width="20px" class="entete_split fixed-side"></th>
                                {% if questionnaire %}<th width="50px">{{ 'Note' | trad }}</th>{% endif %}
                                <th width="50px">{{ 'Sélectionné' | trad }}</th> #}
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="borderRight borderBottom auto_width" style="min-width:150px;"></td>
                                    {% if canChooseFour %}
                                    {% for frs in listeFrs %}
                                        <td class="borderRight borderBottom auto_width" style="text-align:center;min-width:150px;">
                                            {% if frs.REPONSE %}
                                                <input type="checkbox" name="frsSelect{{ frs.CODE_FOU }}" 
                                                    {% if frs.FOU_RETEN | boolSql %}checked{% endif %}/>
                                            {% endif %}
                                        </td>
                                    {% endfor %}
                                    {% endif %}
                                </tr>
                            </tbody>
                            <tfoot>
                                {# Documents de la réponse #}
                                <tr>
                                    <td class="fixed-side fixed-bottom noBorderTop borderRight borderBottom auto_width" style="min-width:150px;">
                                        {{ 'Documents de la réponse' | trad }}
                                    </td>
                                    {% for frs in listeFrs %}
                                        <td class="borderRight fixed-side auto_width" style="min-width:150px;vertical-align: baseline !important;">
                                            <ul>
                                                {% for PJ in frs.docs %}
                                                    <li><a 
                                                    href="{{ path('Consultation.SaisieReponsesPJ.downloadFichier', {typeDoc:PJ.TYPE_DOC, typeFG:PJ.TYPE_FG, idAO:idAO, idFrs:PJ.CODE_FOU, idRep:PJ.DTE_REP, CV:PJ.C_V, ordre:PJ.NUM_ORDRE}) }}" target="_blank">{{ PJ.TITRE }}</a></li>
                                                {% endfor %}
                                            </ul>
                                        </td>
                                    {% endfor %}
                                </tr>
                                {# Note finale #}
                                <tr id="average_grade_{{ idAO }}">
                                    <td class="auto_width fixed-side fixed-bottom noBorderTop borderRight borderBottom" 
                                        style="min-width:150px;"
                                    >
                                        {{ 'Note finale' | trad }}
                                    </td>
                                    {% for frs in listeFrs %}
                                        <td class="auto_width fixed-side align-right borderRight borderBottom" style="min-width:150px;">
                                            {{ frs.NOTE | prix }}
                                        </td>
                                    {% endfor %}
                                </tr>
                                {# Note finale #}
                                <tr id="questionnaire_supplier_{{ idAO }}">
                                    <td 
                                        class="toggleSlide auto_width fixed-side fixed-bottom noBorderTop borderRight borderBottom" 
                                        style="min-width:150px;"
                                        onclick="eventGetData(this)"
                                        data-id = "{{ idAO }}"
                                    >
                                        {{ 'Questionnaire fournisseur' | trad }}
                                    </td>
                                    {% for frs in listeFrs %}
                                        <td class="auto_width fixed-side align-right borderRight borderBottom" style="min-width:150px;">
                                            {{ frs.NOTE_SUPPLIER | prix }}
                                        </td>
                                    {% endfor %}
                                </tr>
                                {# Questionnaire contributeur #}
                                <tr id="questionnaire_contributor_{{ idAO }}">
                                    <td 
                                        class="toggleSlide auto_width fixed-side fixed-bottom noBorderTop borderRight borderBottom" 
                                        style="min-width:150px;"
                                        onclick="showContributors(this)"
                                        data-id = "{{ idAO }}"
                                    >
                                        {{ 'Questionnaire contributeur' | trad }}
                                    </td>
                                    {% for frs in listeFrs %}
                                        <td class="auto_width fixed-side align-right borderRight borderBottom" style="min-width:150px;">
                                            {{ frs.NOTE_CONTRIB | prix }}
                                        </td>
                                    {% endfor %}
                                </tr>
                                {# <tr>
                                    <td class="auto_width fixed-side fixed-bottom noBorderTop borderRight borderBottom" style="min-width:150px;">
                                        {{ 'Note finale' | trad }}
                                    </td>
                                    {% for frs in listeFrs %}
                                        <td class="auto_width fixed-side align-right borderRight borderBottom" style="min-width:150px;">
                                            {{ frs.NOTE | prix }}
                                        </td>
                                    {% endfor %}
                                </tr> #}
                            </tfoot>
                        </table>
                    </div>
                </form> 
                <script type="text/javascript" src="{{ baseUrl('ext/tableHeadFixer/js/tableHeadFixer.js')~'?cache='~getSession('cache')  }}"></script>
                <script>
                    $('#input_visibilitePanel').change(function(){
                        showHidePanel();
                    });
                    
                    function showHidePanel()
                    {
                        if ($('#input_visibilitePanel').val() == '') {
                            $('.selected, .unselected').show();
                        } else if($('#input_visibilitePanel').val() == '1') {
                            $('.selected').show();
                            $('.unselected').hide();
                        } else if($('#input_visibilitePanel').val() == '2') {
                            $('.selected').hide();
                            $('.unselected').show();
                        } 
                    }
                    
                    function eventGetData(object)
                    {
                        let id = $(object).attr("data-id");
                        if ($(".questionnaire_supplier_" + id + 'detail').length) {
                            $(".questionnaire_supplier_" + id + 'detail').remove();
                        } else {
                            $.ajax({
                                url : '{{ path('Consultation.ChoixFournisseur.ajaxDetailSupplierQuestionnaire', { idAO: idAO }) }}',
                                type : 'POST',
                                dataType : 'html',
                                data : {'type': '{{consultation.RFI_Q}}'},
                                success : function(html){
                                    $("#questionnaire_supplier_" + id).after(html);
                                    $(object).attr("data-etat", 'open');
                                }
                            }); 
                        }
                    }

                    function showContributors(object)
                    {
                        let id = $(object).attr("data-id");
                        if ($(".questionnaire_contributor_" + id + 'detail').length) {
                            $(".questionnaire_contributor_" + id + 'detail').remove();
                        } else {
                            $.ajax({
                                url : '{{ path('Consultation.ChoixFournisseur.ajaxDetailsContributors', {idAO: idAO}) }}',
                                type : 'POST',
                                dataType : 'html',
                                data : {'type': '{{consultation.RFI_Q}}'},
                                success : function(html){
                                    $("#questionnaire_contributor_" + id).after(html);
                                    $(object).attr("data-etat", 'open');
                                }
                            }); 
                        }
                    }
                </script>                    
            </div>
        </div>		
    </div>	
{% endblock %}