Skip to content
Snippets Groups Projects
list.html.twig 13.58 KiB
{% extends 'base.html.twig' %}

{% set bodyClass = 'registry_conformite_traitement list' %}
{% set menuItem = 'registry_conformite_traitement' %}

{% block title %}{{ 'registry.conformite_traitement.title.list'|trans }} - {{ parent() }}{% endblock %}

{% block stylesheets %}
    <link rel="stylesheet" href="//cdn.datatables.net/1.10.21/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="//cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css">
{% endblock %}

{% block body_head %}
    <h1>{{ 'registry.conformite_traitement.title.list'|trans }}</h1>
{% endblock %}

{% block breadcrumb %}
    {% set breadcrumb = [
        { 'name': 'registry.conformite_traitement.breadcrumb.list'|trans }
    ] %}
    {% include '_breadcrumb.html.twig' with {'breadcrumb': breadcrumb} %}
{% endblock %}

{% block body %}
    <div class="row">
        <div class="col-xs-12 mb-1">
            {% if app.user.collectivity.hasModuleConformiteTraitement %}
            <a href="{{ path('registry_conformite_traitement_report') }}" class="btn btn-default">
                <i aria-hidden="true" class="fa fa-clipboard-list"></i>
                {{ 'global.action.report'|trans }}
            </a>
            {% endif %}
            {% if category and category.documents|length > 0 %}
                <a href="{{ path('documentation_document_index') }}?category={{ category.id }}" class="btn btn-default pull-right">
                    <i aria-hidden="true" class="fa fa-circle-info"></i>
                    {{ 'global.action.documentation'|trans }}
                </a>
            {% endif %}
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-solid">
                <div class="box-body overflow-x-auto">
                    <table id="table" class="table table-bordered table-hover">
                        <caption class="sr-only">Liste des évaluations des traitements</caption>
                        <thead>
                            <tr>
                                <th style="width:20px" scope="col"></th>
                                <th scope="col">
                                    <input class="form-control" type="text" id="search_nom" placeholder="{{ 'registry.conformite_traitement.list.traitement'|trans }}" style="width: 100%;">
                                </th>
                                {% if is_granted('ROLE_REFERENT') %}
                                    <th scope="col">
                                        <input class="form-control" type="text" id="search_collectivite" placeholder="{{ 'global.label.organization'|trans }}" style="width: 100%;">
                                    </th>
                                {% endif %}
                                {% if app.user.hasServices %}
                                    <th scope="col">
                                        <input class="form-control" type="text" id="search_service" placeholder="{{ 'global.label.service'|trans }}" style="width: 100%;">
                                    </th>
                                {% endif %}
                                <th scope="col">
                                    <input class="form-control" type="text" id="search_gestionnaire" placeholder="{{ 'registry.treatment.label.manager'|trans }}" style="width: 100%;">
                                </th>
                                <th scope="col"> <!-- Conformité Traitement -->
                                    <select class="form-control" id="search_conformite_traitement" style="width: 100%;">
                                        <option value="">{{ 'registry.conformite_traitement.label.conformite_traitement'|trans }}</option>
                                        {% for key, subject in dictionary('conformite_traitement_level') %}
                                            <option value="{{ key }}">{{ subject }}</option>
                                        {% endfor %}
                                    </select>
                                </th>
                                <th scope="col"></th>
                                <th scope="col" style="min-width:130px;position:relative;">
                                    <input class="daterangepicker form-control" type="text" id="search_eval_createdAt" placeholder="{{ 'global.placeholder.date'|trans }}" style="max-width: 130px;left: inherit!important;top: 0;font-size: 14px;border-radius: 0;padding: 0 5px;">
                                </th>
                                <th scope="col"> <!-- Avis AIPD -->
                                    <select class="form-control" id="search_avis_aipd" style="width: 100%;">
                                        <option value="">{{ 'aipd.treatment.label.avis_aipd'|trans }}</option>
                                        {% for key, subject in dictionary('registry_treatment_avis_aipd') %}
                                            <option value="{{ key }}">{{ subject }}</option>
                                        {% endfor %}
                                    </select>
                                </th>
                                <th scope="col" style="min-width:130px;position:relative;">
                                    <input class="daterangepicker form-control" type="text" id="search_aipd_created_at" placeholder="{{ 'global.placeholder.date'|trans }}" style="max-width: 130px;left: inherit!important;top: 0;font-size: 14px;border-radius: 0;padding: 0 5px;">
                                </th>
                            </tr>

                            <tr>
                                <th scope="col"></th>
                                <th scope="col">{{ 'registry.conformite_traitement.list.traitement'|trans }}</th>
                                {% if is_granted('ROLE_REFERENT') %}
                                    <th scope="col">{{ 'global.label.organization'|trans }}</th>
                                {% endif %}
                                {% if app.user.hasServices %}
                                    <th scope="col">{{ 'global.label.service'|trans }}</th>
                                {% endif %}
                                <th scope="col">{{ 'registry.treatment.label.manager'|trans }}</th>
                                <th scope="col">{{ 'registry.conformite_traitement.label.conformite_traitement'|trans }}</th>
                                <th scope="col">{{ 'registry.conformite_traitement.label.conformite_reponse'|trans }}</th>
                                <th scope="col">{{ 'registry.conformite_traitement.list.date_conformite'|trans }}</th>
                                <th scope="col">{{ 'aipd.treatment.label.avis_aipd'|trans }}</th>
                                <th scope="col">{{ 'registry.conformite_traitement.list.date_aipd'|trans }}</th>
                                {% if is_granted('ROLE_USER') %}
                                    <th scope="col">{{ 'global.label.actions'|trans }}</th>
                                {% endif %}
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascripts %}
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-throttle-debounce/1.1/jquery.ba-throttle-debounce.js"></script>

    {% set collectivityIsVisible = false %}
    {% set collectivityClassname = "noVis" %}
    {% set actionIsVisible = true %}
    {% if is_granted('ROLE_REFERENT') %}
        {% set collectivityIsVisible = true %}
        {% set collectivityClassname = "" %}
    {% endif %}

    {% if not is_granted('ROLE_USER') %}
        {% set actionIsVisible = false %}
    {% endif %}

    {% set cols = [
        {"data": "icon", "orderable": false, "className": "noVis"},
        {"data": "nom", "className": "noVis"},
        {"data": "gestionnaire", "visible": true},
        {"data": "conformite_traitement"},
        {"data": "conformite_question", "orderable": false},
        {"data": "eval_createdAt"},
        {"data": "avis_aipd","visible": true},
        {"data": "aipd_createdAt","visible": true},
        {"data": "actions", "className": "noVis actions", "visible": actionIsVisible, "orderable": false},
    ] %}
    {% if app.user.hasServices %}
        {% set cols = [
            {"data": "icon", "orderable": false, "className": "noVis"},
            {"data": "nom", "className": "noVis"},
            {"data": "service", "visible": false},
            {"data": "gestionnaire", "visible": true},
            {"data": "conformite_traitement"},
            {"data": "conformite_question", "orderable": false},
            {"data": "eval_createdAt"},
            {"data": "avis_aipd","visible": true},
            {"data": "aipd_createdAt","visible": true},
            {"data": "actions", "className": "noVis actions", "visible": actionIsVisible, "orderable": false},
        ] %}
    {% endif %}
    {% if is_granted('ROLE_REFERENT') %}
        {% set cols = [
            {"data": "icon", "orderable": false, "className": "noVis"},
            {"data": "nom", "className": "noVis"},
            {"data": "collectivite", "className": collectivityClassname, "visible": collectivityIsVisible},
            {"data": "service", "visible": false},
            {"data": "gestionnaire", "visible": true},
            {"data": "conformite_traitement"},
            {"data": "conformite_question", "orderable": false},
            {"data": "eval_createdAt"},
            {"data": "avis_aipd","visible": true},
            {"data": "aipd_createdAt","visible": true},
            {"data": "actions", "className": "noVis actions", "visible": actionIsVisible, "orderable": false},
        ] %}
    {% endif %}


    {% set dataTableOptions = {
        columns: cols,
        excludeId : true,
        order:  [
            [1, 'asc' ]
        ],
    } %}

    {{ include('_Utils/_serverside_datatable.html.twig') }}

    <script>
        function cbColRenderFunction (data, type, full, meta){
            return data
        }

        function setEvents() {
            var oTable = $('#table').DataTable();

            $('#search_eval_createdAt').show('slide',function(){
                $('input#search_eval_createdAt').val('');
            });
            $('#search_aipd_created_at').show('slide',function(){
                $('input#search_aipd_created_at').val('');
            });


            $('#delete-all').on('click', function(event) {
                event.stopPropagation();
                if ($("input[type=checkbox].select-line:checked").get().length === 0) {
                    event.preventDefault();
                    return;
                }
                //let data = oTable.rows({ selected: true }).ids(); // .toArray()
                let data = $("input[type=checkbox].select-line:checked").get().map(el => el.value).join(',');
                $('#delete-all').attr('href', function(index, href) {
                    let param = `ids=${data}`;
                    if (href.charAt(href.length - 1) === '?')
                        return href + param;
                    else if (href.indexOf('?') > 0)
                        return href + '&' + param;
                    else
                        return href + '?' + param;
                });
                event = event.originalEvent;
            })

            var col = 0;
            {% if is_granted('ROLE_REFERENT') %}
            col = 1;
            {% endif %}
            {% if app.user.hasServices %}
            col += 1;
            {% endif %}

            $('#search_nom').off('keyup');
            $('#search_nom').keyup($.debounce(250, function(){
                oTable.column('1').search($(this).val()).draw() ;
            }));
            {% if is_granted('ROLE_REFERENT') %}
            $('#search_collectivite').off('keyup');
            $('#search_collectivite').keyup($.debounce(250, function(){
                oTable.column('2').search($(this).val()).draw() ;
            }));
            {% endif %}
            {% if app.user.hasServices %}
            $('#search_service').off('keyup');
            $('#search_service').keyup($.debounce(250, function(){
                oTable.column(col+1).search($(this).val()).draw() ;
            }));
            {% endif %}

            $('#search_gestionnaire').off('keyup');
            $('#search_gestionnaire').keyup($.debounce(250, function(){
                oTable.column(col + 2).search($(this).val()).draw() ;
            }));

            $('#search_conformite_traitement').off('change');
            $('#search_conformite_traitement').change(function(){
                oTable.column(col + 3).search($(this).val()).draw() ;
            });

            $('#search_conformite_question').off('change');
            $('#search_conformite_question').change(function(){
                oTable.column(col + 4).search($(this).val()).draw() ;
            });

            $('#search_eval_createdAt').off('change');
            $('#search_eval_createdAt').change(function(){
                oTable.column(col + 5).search($(this).val()).draw();
            });

            $('#search_avis_aipd').off('change');
            $('#search_avis_aipd').change(function(){
                oTable.column(col + 6).search($(this).val()).draw() ;
            });

            $('#search_aipd_created_at').off('change');
            $('#search_aipd_created_at').change(function(){
                oTable.column(col + 7).search($(this).val()).draw();
            });
        }

        $(document).ready(function() {
            $('#table_filter').hide();
            setEvents();

        } );

        $('#table').on('column-visibility.dt', function() {
            setEvents();
        } );
    </script>
{% endblock %}