{% block body %}
    <div id="refreshTab" style="padding-top: 5px;">
        {% if incident is empty %}
            <div class="clearfix">        
                <a class="ajouter_blanc_v2 button_v2 white-tooltip" style="float: right;margin-left:5px!important;{% if (incident.TYPE == '' and incident|length != 0) %}display: none;{% endif %}" id="btnAddCompany" href="{{ path('Reception.CreationBR.creatEdit', {order: order, type: type, mode: mode, init: '0', tab: 'newIncident'}) }}">
                    <span class="infos_tooltip left">
                        {{ 'Ajouter un incident' | trad }}
                    </span>
                </a>
            </div>        
        {% endif %}
		<div id="refreshPJ">
        {% if incident %}
            <div id="incident" class="clearfix">
                <fieldset class="scheduler-border">
                    <legend class="scheduler-border">
                        {{ 'Incident'| trad }}
                    </legend>
                    <div class="row">
                        <div class="colonne2 first">
                            <div class="informations">   
                                <p>
                                    <span class="champs_label">
                                        {{ 'Type' | trad ~ colon }}
                                    </span>
                                    <span class="resultat">
                                        {{ incident.TYPE_LABEL }}
                                    </span>
                                </p>
                            </div>
                        </div>
                        <div class="colonne2 last">
                            <div class="informations">   
                                <p>
                                    <span class="champs_label">
                                        {{ 'Commentaire' | trad ~ colon }}
                                    </span>
                                    <span class="resultat">
                                        {{ incident.COMMENTAIRE_INCIDENT }}
                                    </span>
                                </p>
                            </div>
                        </div>
                        {{ hover_action('incident', 'modifier_v2' , "window.location.href ='" ~ path('Reception.CreationBR.creatEdit', {order: order, type: type, mode: mode, init: '0', tab: 'newIncident'}) ~ "'", 'float: right;margin-right:5px;') }}
                        {{ hover_action(
                            'incident', 
                            'Supprimer_v2', 
                            "popupConfirmation(\'"
                                ~ path('Ajax.Erreur.popupConfirmationSuppresion') ~ "\', 
                                \'\', 
                                \'" ~ path('Reception.Incident.ajaxDeleteIncident') ~ "\', 
                                \'" ~ ('Etes-vous sûr de vouloir supprimer l\'incident ?'| trad|e('js')|raw) ~ "\', 
                                \'refreshPJ\'
                            )", 
                            'float: right;margin-right:5px;'
                        ) }}
                    </div>
                </fieldset>
        {% endif %}
		</div>
	</div>
    {% if incidentLines|length > 0 %}
        <div class="clearfix">
            <table class="table table-hover">
                <thead class="thead-dark">
                    <tr>
                        <th scope="col" width="10%">{{ 'N° de poste'| trad }}</th>
                        <th scope="col" width="15%">{{ 'Code article'| trad }}</th>
                        <th scope="col" width="15%">{{ 'Désignation article'| trad }}</th>
                        <th scope="col" width="10%">{{ 'Unité'| trad }}</th>
                        <th scope="col" width="10%">{{ 'Ecart'| trad }}</th>
                        <th scope="col" width="5%">{{ 'Sél'| trad ~ ' ?' }}</th>
                        <th scope="col" width="15%">{{ 'Commentaire'| trad ~ ' (' ~ 'facultatif'| trad ~ ')' }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for line in incidentLines %}
                        <tr id="line{{ line.no_ligne_cde }}">
                            <td align="right">{{ line.no_ligne_cde }}</td>
                            <td>{{ line.code_art }}</td>
                            <td>{{ shortLibelle(line.design_sommaire, 45) }}</td>
                            <td>{{ line.unite_label ~ ' (' ~ line.unite ~ ')' }}</td>
                            <td align="right">{{ qteByUnite(line.ecart_quantite, line.unite) }}</td>
                            <td>
                                <input type="checkbox" class="form-control checkbox selection_box" name="selected_incident_{{ line.no_ligne_cde }}" id="input_is_incident-{{ line.no_ligne_cde }}" {% if line.is_incident | boolSql %} checked {% endif %} onclick="changeInput({{ line.no_ligne_cde }}, 'is_incident');">
                            </td>
                            <td>
                                {{ inputAdvance('TEXTAREA', {
                                    'name'                  : 'comment_inc' ~ '-' ~ line.no_ligne_cde,
                                    'value'                 : line.comment_inc,
                                    'pathValidator'         : path('Ajax.validator.isStringAvecEspace'),
                                    'paramsValidator'       : "{'sizeMin' : '0', 'sizeMax' : '3000'}",
                                    'myFuncValidator' 		: 'updateValueLineIncident',
                                    'paramFuncValidator'	: '["comment_inc' ~ '-' ~ line.no_ligne_cde ~ '", false]',
                                    'addStyle'				: line.is_incident | boolSql == false ? 'display: none;' : ''
                                }) }}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        <script>
            function updateValueLineIncident(field, bool) {
                activeLoader();
                if (bool) {
                    var value = $('#input_'+field).is(':checked');
                } else {
                    var value = $('#input_'+field).val();
                }
                $.ajax({
                    dataType : 'json',
                    url: '{{ path('Reception.Incident.ajaxUpdateLineIncident', {order: order, type: type, mode: mode, init: init, tab: tab}) }}',
                    data: {field: field, value: value},
                    type: "POST",
                    success: function(result){
                        $('#tab').html(result.incidents);
                        $('#subAriane').html(result.subAriane);
                        desactiveLoader();
                    },
                    error: function(result){

                    }
                });
            }
        </script>
    {% endif %}
{% endblock %}

