{% extends 'enseignant/base_profile.html' %}
{% load static %}
{% load custom_tag %}
{% load custom_tag_obj %}
{% block head %}{% endblock head %}
{% block page_title %}<!--({{ue.code}}) : {{ue.libelle}}--> {% endblock page_title %}
{% block content %}

<div class="row">
    <div class="col-md-12 not-lib" style="color:#179acf;font-size:26px;font-weight:bold;align:left;width:100%;margin-bottom:25px;margin-top:-35px;"
    ><br/>
        <!--<span style="margin-left:15px;">UE : {{ue.libelle}}</span><br/>-->
        <span style="margin-left:55px;">Matière : ({{ecue.code}}) {{ecue.libelle}}</span>
    </div><hr/>
    <div style="text-align:center;margin-left:55px;">
        <h4>ANNEE: <span style="color:red">{{annee}}</span> | SESSION: <span style="color:red">{{session_ini}}</span></h4>
    </div>
</div>
<div class="card">
    <div class="card-header text-white" style="background: #21618C"><h3 class="card-title">MENU</h3></div>
    <div class="card-body">
        {% if id_ecue2|check_deliberation_ecue_2:'all' or not etudiantUes %}
        <button class="btn btn-success mx-1 btn-sm" disabled><i class="fa  fa-plus"></i> Créer une évaluation</button>
        {% else %}
        <button class="btn btn-success mx-2 btn-sm" data-toggle="modal" data-target="#creval" id="delib"><i class="fa  fa-plus"></i> Créer une évaluation</button>
        {% endif %}
        {% if id_ecue2|check_deliberation_ecue_2:'all' or not etudiantUes %}
        <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#importnote" disabled><i class="fa fa-book"></i> Importer des notes</button>
        {% else %}
        <button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#importnote"><i class="fa fa-book"></i> Importer des notes</button>
        {% endif %}

        {% if not etudiantUes %}
        <button class="btn btn-warning mx-1 btn-sm" disabled><i class="fa  fa-upload"></i> Exporter la liste (CSV)</button>
        {% else %}
        <a href="{% url 'EspaceEnseignant:dr_ufr_etudiant_ecue_export' ecue.id annee.id %}" target="_blank" class="btn btn-warning btn-sm" ><i class="fa fa-upload"></i> Exporter la liste (.csv)</a>
        {% endif %}

        {% include 'EspaceEnseignant/modal_add_evaluation.html' %}
        {% include 'EspaceEnseignant/modal_deliberation.html' %}
        {% include 'EspaceEnseignant/modal.html' %}
        {% include 'EspaceEnseignant/modal_import_note.html' %}<br/><br/>

       <!--  <hr/>
       <form action="#" method="post" id="sForm">
            {% csrf_token %}
        <div class="row">
            <div class="col-md-2">
                <select id="sField" class="form-control" name="libelle" {% if not id_ecue2|check_deliberation_ecue_2:1 %} disabled {% endif %}>
                    {% for sess in Sessions %}
                    <option value="{{sess.id}}" {% if session_ini == sess %}selected{% endif %}>{{sess}}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="col-md-3">
                <button type="submit" name="sessionFilter" class="btn btn-primary btn-sm" {% if not id_ecue2|check_deliberation_ecue_2:1 %} disabled {% endif %}><i class="fa fa-filter"></i> Trier</button>
            </div>
        </div>
        </form> -->

    </div>
</div>
<div class="card card-primary">
    <div class="card-header text-white" style="background: #21618C"><h3 class="card-title">AJOUTER DES NOTES</h3></div>
</div>
<div class="table p-2">
<table class="table table-striped table-bordered">
    <tr>
        <th></th>
        <th>NCE</th>
        <th>Nom et Prénoms</th>
        {% for evaluation in EvalEns %}
            <th>{{ evaluation.libelle }}
                {% if not delib_ecue %}
                    &nbsp;<i data-toggle="modal" data-target="#delEv{{evaluation.id}}" class="fa fa-trash" style="color:#D96630;"></i>
                {% endif %}
            </th>
            {% include 'enseignant/modal/modal_delete_evaluation.html' %}
        {% endfor %}
        {% if session_ini.id != 2  %}
        <th>MU</th>
        {% endif %}
        <th>D</th>
    </tr>
    {% for etudiantUe in etudiantUes %}
        <tr class="antr">
            <td style="text-align:center;">{{forloop.counter}}</td>
            <td class="antd" style="width:100px;">{{etudiantUe.nce}}</td>
            <td>{{etudiantUe}}</td>
            {% for evaluation in EvalAnZip %}
                 <td>
                     {% if etudiantUe.id|check_evalution_noted:evaluation %}
                     <span>
                         {{ etudiantUe.id|get_evalution_note2:evaluation }}
                     </span>
                      {% if not delib_ecue %} &nbsp;<a style="color:#EEC881;" data-toggle="modal" data-target="#NoteEdit{{etudiantUe.etudiant.id}}EV{{evaluation.0.id}}"><i class="fa fa-pen"></i></a>{% endif %}
                    {% include 'enseignant/modal/modal_note_edit.html' %}
                     {% else %}
                         {% if delib_ecue %}
                        ---
                        <!-- <button class="btn btn-primary" disabled><i class="fa fa-pen"></i></button> -->
                         {% else %}
                        <!-- <a href="add_note/{{etudiantUe.etudiant.id}}/{{ evaluation.id }}/{{ evaluation.id }}" class="btn btn-primary"><i class="fa fa-pen"></i></a> -->
                         <button class="btn btn-secondary btn-sm" data-toggle="modal" data-target="#addEtNote{{etudiantUe.etudiant.id}}"><i class="fa fa-pen"></i></button>
                        {% include 'EspaceEnseignant/modal_add_note_etudiant.html' %}
                     {% endif %}
                     {% endif %}
                    <!--<input type="number" name="{{etudiantUe.etudiant.id}}" size="4" style="width:60px;" />-->
                </td>
            {% endfor %}

           <!-- <td>{{ etudiantUe.etudiant.id|get_moyenne_cc:id_ecue |stringformat:".2f" }}</td> -->
            {% if session_ini.id != 2  %}
            <td>{{ etudiantUe.id|get_moyenne_ue2:id_ecue2 |stringformat:".2f" }}</td>
            {% endif %}
            <td class="delib" style="text-transform:none;">

                <span class="badge
                {% if etudiantUe.id|get_moyenne_ue2:id_ecue2|get_decision == 'VALIDEE' %}
                badge-success
                {% else %}
                badge-danger
                {% endif%}
                ">{{ etudiantUe.id|get_moyenne_ue2:id_ecue2|get_decision }}</span>

            </td>

        </tr>
    {% empty%}
        <tr>
            <td class="h4" colspan="5" >La liste est vide ....</td>
        </tr>
    {% endfor %}

</table>
</div>


{% endblock content %}

{% block custom_js %}
<script src="{% static 'js/custom-js/save_note.js'%} "></script>
 <script src="{% static 'js/custom-js/note.js' %}"></script>
<script>
    var elements = rootElement.getElementsByClassName('delib')
    $('#sField').change(function(){
        $('#sForm1').submit()
    });
</script>
{% endblock custom_js %}