<?php

use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\CoreExtension;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\TemplateWrapper;

/* plan/notation_form.html.twig */
class __TwigTemplate_eea471a98ad64f11d9cdadea0ef1bdfe extends Template
{
    private Source $source;
    /**
     * @var array<string, Template>
     */
    private array $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'page_title' => [$this, 'block_page_title'],
            'page_content' => [$this, 'block_page_content'],
            'javascripts' => [$this, 'block_javascripts'],
            'stylesheets' => [$this, 'block_stylesheets'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 1
        return "@AdminLTE/layout/mesodd-layout.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template", "plan/notation_form.html.twig"));

        $this->parent = $this->load("@AdminLTE/layout/mesodd-layout.html.twig", 1);
        yield from $this->parent->unwrap()->yield($context, array_merge($this->blocks, $blocks));
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

    }

    // line 3
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_page_title(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "page_title"));

        yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("notation.title", [], "messages");
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    // line 6
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_page_content(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "page_content"));

        // line 7
        yield "    ";
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock((isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 7, $this->source); })()), 'form_start');
        yield "
  
        ";
        // line 9
        yield from $this->load("plan/notation_form.html.twig", 9, "1112488622")->unwrap()->yield($context);
        // line 27
        yield "     
        ";
        // line 28
        if ((((isset($context["actionId"]) || array_key_exists("actionId", $context) ? $context["actionId"] : (function () { throw new RuntimeError('Variable "actionId" does not exist.', 28, $this->source); })()) > 0) && (Twig\Extension\CoreExtension::length($this->env->getCharset(), CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 28, $this->source); })()), "notationModels", [], "any", false, false, false, 28)) > 0))) {
            // line 29
            yield "        ";
            yield from $this->load("plan/notation_form.html.twig", 29, "1639913594")->unwrap()->yield($context);
            // line 58
            yield "         ";
        } else {
            // line 59
            yield "        <div class=\"alert alert-info\" role=\"alert\">
            ";
            // line 60
            yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("Veuillez sélectionner une action  pour afficher ces activités", [], "messages");
            // line 61
            yield "        </div>
        ";
        }
        // line 63
        yield "                
    ";
        // line 64
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock((isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 64, $this->source); })()), 'form_end');
        yield "
  
";
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    // line 68
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_javascripts(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "javascripts"));

        // line 69
        yield "    <script>
        let maxRate = \$('#notation_collection_model_maxRate').val()
        let minRate = \$('#notation_collection_model_minRate').val()
        let weighting = \$('#notation_collection_model_weighting').val()
        let grouping = '";
        // line 73
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((isset($context["grouping"]) || array_key_exists("grouping", $context) ? $context["grouping"] : (function () { throw new RuntimeError('Variable "grouping" does not exist.', 73, $this->source); })()), "html", null, true);
        yield "'

        window.onload = function(){
            \$(\"#notationTable tr.notation\").each(function() {
                let row = this.id
                if(grouping == 'arrondissement'){
                    \$('#'+row+'_locationType').val('arrondissement');
                }else{
                    \$('#'+row+'_locationType').val('department');
                }
                locationTypeChange(row)
                calculTargetRate(row)
                calculLocationRate(row)
            });
        };

        \$(document).on('change', '#notation_collection_model_type, #notation_collection_model_entite, #notation_collection_model_programm', function () {
            let \$type = \$('#notation_collection_model_type')
            let \$entite = \$('#notation_collection_model_entite')
            let \$form = \$(this).closest('form')

            let data = {}
            data[\$type.attr('name')] = \$type.val()
            data[\$entite.attr('name')] = \$entite.val()
            data[\$(this).attr('name')] = \$(this).val()
            
            let \$field = \$(this).attr('id')
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (\$field == 'notation_collection_model_type') {
                        \$('#notation_collection_model_entite').replaceWith(
                            \$(html).find('#notation_collection_model_entite')
                        )
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_entite') {
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_programm') {
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                }
            });
        });


        function goalChange(row, field) {
            let \$field = \$('#'+field)
            let \$goal = \$('#'+row+'_goal')
            let \$location = \$('#'+row+'_locationType')
            let \$form = \$(\$field).closest('form')
            let data = {}
            data[\$goal.attr('name')] = \$goal.val()
            data[\$location.attr('name')] = \$location.val()
            data[\$(\$field).attr('name')] = \$(\$field).val()
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (field == row+'_goal') {
                        \$('#'+row+'_target').replaceWith(
                            \$(html).find('#'+row+'_target')
                        )
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )

                        \$('#'+row+'_target').attr('required', false)
                        if (\$('#'+row+'_treated').is(':checked')) {
                            \$('#'+row+'_target').attr('required', true)
                        }                        
                    }
                    if (field == row+'_target') {
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange(row) {
            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                document.getElementById(row+'_arrondissements').disabled = true;
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                \$('#'+row+'_communes_div').hide();
                \$('#'+row+'_postes_div').show();
                document.getElementById(row+'_communes').disabled = true;
                document.getElementById(row+'_postes').disabled = false;
            } else {
                \$('#'+row+'_communes_div').show();
                \$('#'+row+'_postes_div').hide();
                document.getElementById(row+'_communes').disabled = false;
                document.getElementById(row+'_postes').disabled = true;
            }
        }

        function treatedChange(row) {
            let \$treated = \$('#'+row+'_treated')
            let \$nature = \$('#'+row+'_nature')
            let \$goal = \$('#'+row+'_goal')
            let \$target = \$('#'+row+'_target')
            let \$communes = \$('#'+row+'_communes')
            let \$postes = \$('#'+row+'_postes')

            \$nature.attr('required', false)
            \$goal.attr('required', false)
            \$target.attr('required', false)
            \$communes.attr('required', false)
            \$postes.attr('required', false)
            if (\$treated.is(':checked')) {
                \$nature.attr('required', true)
                \$goal.attr('required', true)
                \$target.attr('required', true)
                \$communes.attr('required', true)
                \$postes.attr('required', true)
            }
        }
        
        function getSelectedOptions(sel, fn) {
            var opts = [], opt;

            for (var i=0, len=sel ? sel.options.length : 0; i<len; i++) {
                opt = sel.options[i];

                if ( opt.selected ) {
                    opts.push(opt);
                    if (fn) {
                        fn(opt);
                    }
                }
            }
            return opts;
        }

        function getSelectedRate(nature) {
            let allRate = \$('#notation_collection_model_allRate').val()
            allRate = JSON.parse(allRate);
            for (var i = 0; i < allRate.length; i++) {
                if (allRate[i].id == nature){
                    return allRate[i].rate
                }
            }
        }
        
        function calculTargetRate(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())
            
            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById(row+'_goal').disabled = false;
                document.getElementById(row+'_target').disabled = false;
                document.getElementById(row+'_indicators').disabled = false;
                document.getElementById(row+'_locationType').disabled = false;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = false;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = false;
                } else {
                    document.getElementById(row+'_communes').disabled = false;
                }

                nbSelec = getSelectedOptions(document.getElementById(row+'_indicators')).length
                //nbTotal = document.getElementById(row+'_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = ((maxRate * nbSelec) + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById(row+'_goal').disabled = true;
                document.getElementById(row+'_target').disabled = true;
                document.getElementById(row+'_indicators').disabled = true;
                document.getElementById(row+'_locationType').disabled = true;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = true;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = true;
                } else {
                    document.getElementById(row+'_communes').disabled = true;
                }
            }
            \$('#'+row+'_targetRate').val(targetRate)

            calculSensitivity(row)
        }
        
        function calculLocationRate(row) {
            let locationRate = 0
            let nbTotal = 0
            let nbSelec = 0

            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_arrondissements')).length
                nbTotal = document.getElementById(row+'_arrondissements') ? document.getElementById(row+'_arrondissements').options.length : 0
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_postes')).length
                nbTotal = document.getElementById(row+'_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById(row+'_communes')).length
                nbTotal = document.getElementById(row+'_communes') ? document.getElementById(row+'_communes').options.length : 0
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#'+row+'_locationRate').val(locationRate)

            calculSensitivity(row)
        }

        function calculSensitivity(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())

            let locationRate = \$('#'+row+'_locationRate').val()
            let sensitivity = \$('#'+row+'_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = (sensitivity - ((100 - locationRate) / 10)) * weighting / 100
            }
            \$('#'+row+'_sensitivity').val(sensitivity)
            \$('#'+row+'_sensHtml').val(sensitivity)
        }
    </script>

    <script>
        \$(function () {
            \$(\"#notationTable\").DataTable({
                \"pageLength\": 25
            });
        });
    </script>

    <script src=\"";
        // line 323
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables/jquery.dataTables.js"), "html", null, true);
        yield "\"></script>
    <script src=\"";
        // line 324
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables-bs4/js/dataTables.bootstrap4.js"), "html", null, true);
        yield "\"></script>
";
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    // line 327
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_stylesheets(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "stylesheets"));

        // line 328
        yield "    <link rel=\"stylesheet\" href=\"";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables-bs4/css/dataTables.bootstrap4.css"), "html", null, true);
        yield "\">
";
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "plan/notation_form.html.twig";
    }

    /**
     * @codeCoverageIgnore
     */
    public function isTraitable(): bool
    {
        return false;
    }

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  422 => 328,  412 => 327,  402 => 324,  398 => 323,  145 => 73,  139 => 69,  129 => 68,  118 => 64,  115 => 63,  111 => 61,  109 => 60,  106 => 59,  103 => 58,  100 => 29,  98 => 28,  95 => 27,  93 => 9,  87 => 7,  77 => 6,  60 => 3,  43 => 1,);
    }

    public function getSourceContext(): Source
    {
        return new Source("{% extends '@AdminLTE/layout/mesodd-layout.html.twig' %}

{% block page_title %}{% trans %}notation.title{% endtrans %}{% endblock %}


{% block page_content %}
    {{ form_start(form) }}
  
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                <div class=\"text-right\">
                    <a href=\"{{ path('app_evaluation', { 'id': actionId }) }}\" class=\"btn btn-primary\">
                        {% trans %}basics.appreciation{% endtrans %}  <i class=\"fas fa-angle-double-right\"></i>
                    </a>
                </div><br>
                {% if is_granted('ROLE_MANAGER') %}
                    {{ form_row(form.type) }}
                    {{ form_row(form.entite) }}
                {% endif %}
                {% if is_granted('ROLE_DDD') %}
                    {{ form_row(form.entite) }}
                {% endif %}
                {{ form_row(form.programm) }}
                {{ form_row(form.action) }}
            {% endblock %}
        {% endembed %}
     
        {% if actionId >0 and form.notationModels|length > 0 %}
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                {%
                    form_theme form.notationModels
                        'form/notation.html.twig'
                %}

                {{ form_errors(form) }}

                <table id=\"notationTable\" class=\"table table-striped notation-collection\">
                <thead>
                    <th class=\"row\">
                        <div class=\"col-2 text-center\">Nature</div>
                        <div class=\"col-6 text-center\">ODD / Cible / Indicateur</div>
                        <div class=\"col-3 text-center\">Localisation</div>
                        <div class=\"col-1 text-center\">Mesure</div>
                    </th>
                </thead>
                <tbody>
                    {% set index = 0 %}
                    {% for notation in form.notationModels %}
                        {{ form_row(notation, {'activity' : activities[index]}) }}
                        {% set index = index + 1 %}
                    {% endfor %}
                </tbody>
                </table>

            {% endblock %}
        {% endembed %}
         {% else %}
        <div class=\"alert alert-info\" role=\"alert\">
            {% trans %}Veuillez sélectionner une action  pour afficher ces activités{% endtrans %}
        </div>
        {% endif %}
                
    {{ form_end(form) }}
  
{% endblock %}

{% block javascripts %}
    <script>
        let maxRate = \$('#notation_collection_model_maxRate').val()
        let minRate = \$('#notation_collection_model_minRate').val()
        let weighting = \$('#notation_collection_model_weighting').val()
        let grouping = '{{ grouping }}'

        window.onload = function(){
            \$(\"#notationTable tr.notation\").each(function() {
                let row = this.id
                if(grouping == 'arrondissement'){
                    \$('#'+row+'_locationType').val('arrondissement');
                }else{
                    \$('#'+row+'_locationType').val('department');
                }
                locationTypeChange(row)
                calculTargetRate(row)
                calculLocationRate(row)
            });
        };

        \$(document).on('change', '#notation_collection_model_type, #notation_collection_model_entite, #notation_collection_model_programm', function () {
            let \$type = \$('#notation_collection_model_type')
            let \$entite = \$('#notation_collection_model_entite')
            let \$form = \$(this).closest('form')

            let data = {}
            data[\$type.attr('name')] = \$type.val()
            data[\$entite.attr('name')] = \$entite.val()
            data[\$(this).attr('name')] = \$(this).val()
            
            let \$field = \$(this).attr('id')
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (\$field == 'notation_collection_model_type') {
                        \$('#notation_collection_model_entite').replaceWith(
                            \$(html).find('#notation_collection_model_entite')
                        )
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_entite') {
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_programm') {
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                }
            });
        });


        function goalChange(row, field) {
            let \$field = \$('#'+field)
            let \$goal = \$('#'+row+'_goal')
            let \$location = \$('#'+row+'_locationType')
            let \$form = \$(\$field).closest('form')
            let data = {}
            data[\$goal.attr('name')] = \$goal.val()
            data[\$location.attr('name')] = \$location.val()
            data[\$(\$field).attr('name')] = \$(\$field).val()
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (field == row+'_goal') {
                        \$('#'+row+'_target').replaceWith(
                            \$(html).find('#'+row+'_target')
                        )
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )

                        \$('#'+row+'_target').attr('required', false)
                        if (\$('#'+row+'_treated').is(':checked')) {
                            \$('#'+row+'_target').attr('required', true)
                        }                        
                    }
                    if (field == row+'_target') {
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange(row) {
            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                document.getElementById(row+'_arrondissements').disabled = true;
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                \$('#'+row+'_communes_div').hide();
                \$('#'+row+'_postes_div').show();
                document.getElementById(row+'_communes').disabled = true;
                document.getElementById(row+'_postes').disabled = false;
            } else {
                \$('#'+row+'_communes_div').show();
                \$('#'+row+'_postes_div').hide();
                document.getElementById(row+'_communes').disabled = false;
                document.getElementById(row+'_postes').disabled = true;
            }
        }

        function treatedChange(row) {
            let \$treated = \$('#'+row+'_treated')
            let \$nature = \$('#'+row+'_nature')
            let \$goal = \$('#'+row+'_goal')
            let \$target = \$('#'+row+'_target')
            let \$communes = \$('#'+row+'_communes')
            let \$postes = \$('#'+row+'_postes')

            \$nature.attr('required', false)
            \$goal.attr('required', false)
            \$target.attr('required', false)
            \$communes.attr('required', false)
            \$postes.attr('required', false)
            if (\$treated.is(':checked')) {
                \$nature.attr('required', true)
                \$goal.attr('required', true)
                \$target.attr('required', true)
                \$communes.attr('required', true)
                \$postes.attr('required', true)
            }
        }
        
        function getSelectedOptions(sel, fn) {
            var opts = [], opt;

            for (var i=0, len=sel ? sel.options.length : 0; i<len; i++) {
                opt = sel.options[i];

                if ( opt.selected ) {
                    opts.push(opt);
                    if (fn) {
                        fn(opt);
                    }
                }
            }
            return opts;
        }

        function getSelectedRate(nature) {
            let allRate = \$('#notation_collection_model_allRate').val()
            allRate = JSON.parse(allRate);
            for (var i = 0; i < allRate.length; i++) {
                if (allRate[i].id == nature){
                    return allRate[i].rate
                }
            }
        }
        
        function calculTargetRate(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())
            
            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById(row+'_goal').disabled = false;
                document.getElementById(row+'_target').disabled = false;
                document.getElementById(row+'_indicators').disabled = false;
                document.getElementById(row+'_locationType').disabled = false;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = false;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = false;
                } else {
                    document.getElementById(row+'_communes').disabled = false;
                }

                nbSelec = getSelectedOptions(document.getElementById(row+'_indicators')).length
                //nbTotal = document.getElementById(row+'_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = ((maxRate * nbSelec) + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById(row+'_goal').disabled = true;
                document.getElementById(row+'_target').disabled = true;
                document.getElementById(row+'_indicators').disabled = true;
                document.getElementById(row+'_locationType').disabled = true;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = true;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = true;
                } else {
                    document.getElementById(row+'_communes').disabled = true;
                }
            }
            \$('#'+row+'_targetRate').val(targetRate)

            calculSensitivity(row)
        }
        
        function calculLocationRate(row) {
            let locationRate = 0
            let nbTotal = 0
            let nbSelec = 0

            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_arrondissements')).length
                nbTotal = document.getElementById(row+'_arrondissements') ? document.getElementById(row+'_arrondissements').options.length : 0
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_postes')).length
                nbTotal = document.getElementById(row+'_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById(row+'_communes')).length
                nbTotal = document.getElementById(row+'_communes') ? document.getElementById(row+'_communes').options.length : 0
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#'+row+'_locationRate').val(locationRate)

            calculSensitivity(row)
        }

        function calculSensitivity(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())

            let locationRate = \$('#'+row+'_locationRate').val()
            let sensitivity = \$('#'+row+'_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = (sensitivity - ((100 - locationRate) / 10)) * weighting / 100
            }
            \$('#'+row+'_sensitivity').val(sensitivity)
            \$('#'+row+'_sensHtml').val(sensitivity)
        }
    </script>

    <script>
        \$(function () {
            \$(\"#notationTable\").DataTable({
                \"pageLength\": 25
            });
        });
    </script>

    <script src=\"{{ asset('plugins/datatables/jquery.dataTables.js') }}\"></script>
    <script src=\"{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.js') }}\"></script>
{% endblock %}

{% block stylesheets %}
    <link rel=\"stylesheet\" href=\"{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.css') }}\">
{% endblock %}", "plan/notation_form.html.twig", "/var/www/vhosts/sigodd.gouv.bj/httpdocs/templates/plan/notation_form.html.twig");
    }
}


/* plan/notation_form.html.twig */
class __TwigTemplate_eea471a98ad64f11d9cdadea0ef1bdfe___1112488622 extends Template
{
    private Source $source;
    /**
     * @var array<string, Template>
     */
    private array $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'box_body' => [$this, 'block_box_body'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 9
        return "@AdminLTE/Widgets/box-widget.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template", "plan/notation_form.html.twig"));

        $this->parent = $this->load("@AdminLTE/Widgets/box-widget.html.twig", 9);
        yield from $this->parent->unwrap()->yield($context, array_merge($this->blocks, $blocks));
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

    }

    // line 10
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_box_body(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "box_body"));

        // line 11
        yield "                <div class=\"text-right\">
                    <a href=\"";
        // line 12
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("app_evaluation", ["id" => (isset($context["actionId"]) || array_key_exists("actionId", $context) ? $context["actionId"] : (function () { throw new RuntimeError('Variable "actionId" does not exist.', 12, $this->source); })())]), "html", null, true);
        yield "\" class=\"btn btn-primary\">
                        ";
        // line 13
        yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("basics.appreciation", [], "messages");
        yield "  <i class=\"fas fa-angle-double-right\"></i>
                    </a>
                </div><br>
                ";
        // line 16
        if ((($tmp = $this->extensions['Symfony\Bridge\Twig\Extension\SecurityExtension']->isGranted("ROLE_MANAGER")) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 17
            yield "                    ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 17, $this->source); })()), "type", [], "any", false, false, false, 17), 'row');
            yield "
                    ";
            // line 18
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 18, $this->source); })()), "entite", [], "any", false, false, false, 18), 'row');
            yield "
                ";
        }
        // line 20
        yield "                ";
        if ((($tmp = $this->extensions['Symfony\Bridge\Twig\Extension\SecurityExtension']->isGranted("ROLE_DDD")) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 21
            yield "                    ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 21, $this->source); })()), "entite", [], "any", false, false, false, 21), 'row');
            yield "
                ";
        }
        // line 23
        yield "                ";
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 23, $this->source); })()), "programm", [], "any", false, false, false, 23), 'row');
        yield "
                ";
        // line 24
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 24, $this->source); })()), "action", [], "any", false, false, false, 24), 'row');
        yield "
            ";
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "plan/notation_form.html.twig";
    }

    /**
     * @codeCoverageIgnore
     */
    public function isTraitable(): bool
    {
        return false;
    }

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  880 => 24,  875 => 23,  869 => 21,  866 => 20,  861 => 18,  856 => 17,  854 => 16,  848 => 13,  844 => 12,  841 => 11,  831 => 10,  814 => 9,  422 => 328,  412 => 327,  402 => 324,  398 => 323,  145 => 73,  139 => 69,  129 => 68,  118 => 64,  115 => 63,  111 => 61,  109 => 60,  106 => 59,  103 => 58,  100 => 29,  98 => 28,  95 => 27,  93 => 9,  87 => 7,  77 => 6,  60 => 3,  43 => 1,);
    }

    public function getSourceContext(): Source
    {
        return new Source("{% extends '@AdminLTE/layout/mesodd-layout.html.twig' %}

{% block page_title %}{% trans %}notation.title{% endtrans %}{% endblock %}


{% block page_content %}
    {{ form_start(form) }}
  
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                <div class=\"text-right\">
                    <a href=\"{{ path('app_evaluation', { 'id': actionId }) }}\" class=\"btn btn-primary\">
                        {% trans %}basics.appreciation{% endtrans %}  <i class=\"fas fa-angle-double-right\"></i>
                    </a>
                </div><br>
                {% if is_granted('ROLE_MANAGER') %}
                    {{ form_row(form.type) }}
                    {{ form_row(form.entite) }}
                {% endif %}
                {% if is_granted('ROLE_DDD') %}
                    {{ form_row(form.entite) }}
                {% endif %}
                {{ form_row(form.programm) }}
                {{ form_row(form.action) }}
            {% endblock %}
        {% endembed %}
     
        {% if actionId >0 and form.notationModels|length > 0 %}
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                {%
                    form_theme form.notationModels
                        'form/notation.html.twig'
                %}

                {{ form_errors(form) }}

                <table id=\"notationTable\" class=\"table table-striped notation-collection\">
                <thead>
                    <th class=\"row\">
                        <div class=\"col-2 text-center\">Nature</div>
                        <div class=\"col-6 text-center\">ODD / Cible / Indicateur</div>
                        <div class=\"col-3 text-center\">Localisation</div>
                        <div class=\"col-1 text-center\">Mesure</div>
                    </th>
                </thead>
                <tbody>
                    {% set index = 0 %}
                    {% for notation in form.notationModels %}
                        {{ form_row(notation, {'activity' : activities[index]}) }}
                        {% set index = index + 1 %}
                    {% endfor %}
                </tbody>
                </table>

            {% endblock %}
        {% endembed %}
         {% else %}
        <div class=\"alert alert-info\" role=\"alert\">
            {% trans %}Veuillez sélectionner une action  pour afficher ces activités{% endtrans %}
        </div>
        {% endif %}
                
    {{ form_end(form) }}
  
{% endblock %}

{% block javascripts %}
    <script>
        let maxRate = \$('#notation_collection_model_maxRate').val()
        let minRate = \$('#notation_collection_model_minRate').val()
        let weighting = \$('#notation_collection_model_weighting').val()
        let grouping = '{{ grouping }}'

        window.onload = function(){
            \$(\"#notationTable tr.notation\").each(function() {
                let row = this.id
                if(grouping == 'arrondissement'){
                    \$('#'+row+'_locationType').val('arrondissement');
                }else{
                    \$('#'+row+'_locationType').val('department');
                }
                locationTypeChange(row)
                calculTargetRate(row)
                calculLocationRate(row)
            });
        };

        \$(document).on('change', '#notation_collection_model_type, #notation_collection_model_entite, #notation_collection_model_programm', function () {
            let \$type = \$('#notation_collection_model_type')
            let \$entite = \$('#notation_collection_model_entite')
            let \$form = \$(this).closest('form')

            let data = {}
            data[\$type.attr('name')] = \$type.val()
            data[\$entite.attr('name')] = \$entite.val()
            data[\$(this).attr('name')] = \$(this).val()
            
            let \$field = \$(this).attr('id')
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (\$field == 'notation_collection_model_type') {
                        \$('#notation_collection_model_entite').replaceWith(
                            \$(html).find('#notation_collection_model_entite')
                        )
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_entite') {
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_programm') {
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                }
            });
        });


        function goalChange(row, field) {
            let \$field = \$('#'+field)
            let \$goal = \$('#'+row+'_goal')
            let \$location = \$('#'+row+'_locationType')
            let \$form = \$(\$field).closest('form')
            let data = {}
            data[\$goal.attr('name')] = \$goal.val()
            data[\$location.attr('name')] = \$location.val()
            data[\$(\$field).attr('name')] = \$(\$field).val()
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (field == row+'_goal') {
                        \$('#'+row+'_target').replaceWith(
                            \$(html).find('#'+row+'_target')
                        )
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )

                        \$('#'+row+'_target').attr('required', false)
                        if (\$('#'+row+'_treated').is(':checked')) {
                            \$('#'+row+'_target').attr('required', true)
                        }                        
                    }
                    if (field == row+'_target') {
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange(row) {
            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                document.getElementById(row+'_arrondissements').disabled = true;
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                \$('#'+row+'_communes_div').hide();
                \$('#'+row+'_postes_div').show();
                document.getElementById(row+'_communes').disabled = true;
                document.getElementById(row+'_postes').disabled = false;
            } else {
                \$('#'+row+'_communes_div').show();
                \$('#'+row+'_postes_div').hide();
                document.getElementById(row+'_communes').disabled = false;
                document.getElementById(row+'_postes').disabled = true;
            }
        }

        function treatedChange(row) {
            let \$treated = \$('#'+row+'_treated')
            let \$nature = \$('#'+row+'_nature')
            let \$goal = \$('#'+row+'_goal')
            let \$target = \$('#'+row+'_target')
            let \$communes = \$('#'+row+'_communes')
            let \$postes = \$('#'+row+'_postes')

            \$nature.attr('required', false)
            \$goal.attr('required', false)
            \$target.attr('required', false)
            \$communes.attr('required', false)
            \$postes.attr('required', false)
            if (\$treated.is(':checked')) {
                \$nature.attr('required', true)
                \$goal.attr('required', true)
                \$target.attr('required', true)
                \$communes.attr('required', true)
                \$postes.attr('required', true)
            }
        }
        
        function getSelectedOptions(sel, fn) {
            var opts = [], opt;

            for (var i=0, len=sel ? sel.options.length : 0; i<len; i++) {
                opt = sel.options[i];

                if ( opt.selected ) {
                    opts.push(opt);
                    if (fn) {
                        fn(opt);
                    }
                }
            }
            return opts;
        }

        function getSelectedRate(nature) {
            let allRate = \$('#notation_collection_model_allRate').val()
            allRate = JSON.parse(allRate);
            for (var i = 0; i < allRate.length; i++) {
                if (allRate[i].id == nature){
                    return allRate[i].rate
                }
            }
        }
        
        function calculTargetRate(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())
            
            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById(row+'_goal').disabled = false;
                document.getElementById(row+'_target').disabled = false;
                document.getElementById(row+'_indicators').disabled = false;
                document.getElementById(row+'_locationType').disabled = false;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = false;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = false;
                } else {
                    document.getElementById(row+'_communes').disabled = false;
                }

                nbSelec = getSelectedOptions(document.getElementById(row+'_indicators')).length
                //nbTotal = document.getElementById(row+'_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = ((maxRate * nbSelec) + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById(row+'_goal').disabled = true;
                document.getElementById(row+'_target').disabled = true;
                document.getElementById(row+'_indicators').disabled = true;
                document.getElementById(row+'_locationType').disabled = true;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = true;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = true;
                } else {
                    document.getElementById(row+'_communes').disabled = true;
                }
            }
            \$('#'+row+'_targetRate').val(targetRate)

            calculSensitivity(row)
        }
        
        function calculLocationRate(row) {
            let locationRate = 0
            let nbTotal = 0
            let nbSelec = 0

            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_arrondissements')).length
                nbTotal = document.getElementById(row+'_arrondissements') ? document.getElementById(row+'_arrondissements').options.length : 0
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_postes')).length
                nbTotal = document.getElementById(row+'_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById(row+'_communes')).length
                nbTotal = document.getElementById(row+'_communes') ? document.getElementById(row+'_communes').options.length : 0
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#'+row+'_locationRate').val(locationRate)

            calculSensitivity(row)
        }

        function calculSensitivity(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())

            let locationRate = \$('#'+row+'_locationRate').val()
            let sensitivity = \$('#'+row+'_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = (sensitivity - ((100 - locationRate) / 10)) * weighting / 100
            }
            \$('#'+row+'_sensitivity').val(sensitivity)
            \$('#'+row+'_sensHtml').val(sensitivity)
        }
    </script>

    <script>
        \$(function () {
            \$(\"#notationTable\").DataTable({
                \"pageLength\": 25
            });
        });
    </script>

    <script src=\"{{ asset('plugins/datatables/jquery.dataTables.js') }}\"></script>
    <script src=\"{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.js') }}\"></script>
{% endblock %}

{% block stylesheets %}
    <link rel=\"stylesheet\" href=\"{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.css') }}\">
{% endblock %}", "plan/notation_form.html.twig", "/var/www/vhosts/sigodd.gouv.bj/httpdocs/templates/plan/notation_form.html.twig");
    }
}


/* plan/notation_form.html.twig */
class __TwigTemplate_eea471a98ad64f11d9cdadea0ef1bdfe___1639913594 extends Template
{
    private Source $source;
    /**
     * @var array<string, Template>
     */
    private array $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'box_body' => [$this, 'block_box_body'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 29
        return "@AdminLTE/Widgets/box-widget.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template", "plan/notation_form.html.twig"));

        $this->parent = $this->load("@AdminLTE/Widgets/box-widget.html.twig", 29);
        yield from $this->parent->unwrap()->yield($context, array_merge($this->blocks, $blocks));
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

    }

    // line 30
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_box_body(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "box_body"));

        // line 31
        yield "                ";
        // line 32
        $this->env->getRuntime("Symfony\\Component\\Form\\FormRenderer")->setTheme(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 32, $this->source); })()), "notationModels", [], "any", false, false, false, 32), ["form/notation.html.twig"], true);
        // line 35
        yield "
                ";
        // line 36
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock((isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 36, $this->source); })()), 'errors');
        yield "

                <table id=\"notationTable\" class=\"table table-striped notation-collection\">
                <thead>
                    <th class=\"row\">
                        <div class=\"col-2 text-center\">Nature</div>
                        <div class=\"col-6 text-center\">ODD / Cible / Indicateur</div>
                        <div class=\"col-3 text-center\">Localisation</div>
                        <div class=\"col-1 text-center\">Mesure</div>
                    </th>
                </thead>
                <tbody>
                    ";
        // line 48
        $context["index"] = 0;
        // line 49
        yield "                    ";
        $context['_parent'] = $context;
        $context['_seq'] = CoreExtension::ensureTraversable(CoreExtension::getAttribute($this->env, $this->source, (isset($context["form"]) || array_key_exists("form", $context) ? $context["form"] : (function () { throw new RuntimeError('Variable "form" does not exist.', 49, $this->source); })()), "notationModels", [], "any", false, false, false, 49));
        foreach ($context['_seq'] as $context["_key"] => $context["notation"]) {
            // line 50
            yield "                        ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($context["notation"], 'row', ["activity" => CoreExtension::getAttribute($this->env, $this->source, (isset($context["activities"]) || array_key_exists("activities", $context) ? $context["activities"] : (function () { throw new RuntimeError('Variable "activities" does not exist.', 50, $this->source); })()), (isset($context["index"]) || array_key_exists("index", $context) ? $context["index"] : (function () { throw new RuntimeError('Variable "index" does not exist.', 50, $this->source); })()), [], "array", false, false, false, 50)]);
            yield "
                        ";
            // line 51
            $context["index"] = ((isset($context["index"]) || array_key_exists("index", $context) ? $context["index"] : (function () { throw new RuntimeError('Variable "index" does not exist.', 51, $this->source); })()) + 1);
            // line 52
            yield "                    ";
        }
        $_parent = $context['_parent'];
        unset($context['_seq'], $context['_key'], $context['notation'], $context['_parent']);
        $context = array_intersect_key($context, $_parent) + $_parent;
        // line 53
        yield "                </tbody>
                </table>

            ";
        
        $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);

        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "plan/notation_form.html.twig";
    }

    /**
     * @codeCoverageIgnore
     */
    public function isTraitable(): bool
    {
        return false;
    }

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  1340 => 53,  1334 => 52,  1332 => 51,  1327 => 50,  1322 => 49,  1320 => 48,  1305 => 36,  1302 => 35,  1300 => 32,  1298 => 31,  1288 => 30,  1271 => 29,  880 => 24,  875 => 23,  869 => 21,  866 => 20,  861 => 18,  856 => 17,  854 => 16,  848 => 13,  844 => 12,  841 => 11,  831 => 10,  814 => 9,  422 => 328,  412 => 327,  402 => 324,  398 => 323,  145 => 73,  139 => 69,  129 => 68,  118 => 64,  115 => 63,  111 => 61,  109 => 60,  106 => 59,  103 => 58,  100 => 29,  98 => 28,  95 => 27,  93 => 9,  87 => 7,  77 => 6,  60 => 3,  43 => 1,);
    }

    public function getSourceContext(): Source
    {
        return new Source("{% extends '@AdminLTE/layout/mesodd-layout.html.twig' %}

{% block page_title %}{% trans %}notation.title{% endtrans %}{% endblock %}


{% block page_content %}
    {{ form_start(form) }}
  
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                <div class=\"text-right\">
                    <a href=\"{{ path('app_evaluation', { 'id': actionId }) }}\" class=\"btn btn-primary\">
                        {% trans %}basics.appreciation{% endtrans %}  <i class=\"fas fa-angle-double-right\"></i>
                    </a>
                </div><br>
                {% if is_granted('ROLE_MANAGER') %}
                    {{ form_row(form.type) }}
                    {{ form_row(form.entite) }}
                {% endif %}
                {% if is_granted('ROLE_DDD') %}
                    {{ form_row(form.entite) }}
                {% endif %}
                {{ form_row(form.programm) }}
                {{ form_row(form.action) }}
            {% endblock %}
        {% endembed %}
     
        {% if actionId >0 and form.notationModels|length > 0 %}
        {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
            {% block box_body %}
                {%
                    form_theme form.notationModels
                        'form/notation.html.twig'
                %}

                {{ form_errors(form) }}

                <table id=\"notationTable\" class=\"table table-striped notation-collection\">
                <thead>
                    <th class=\"row\">
                        <div class=\"col-2 text-center\">Nature</div>
                        <div class=\"col-6 text-center\">ODD / Cible / Indicateur</div>
                        <div class=\"col-3 text-center\">Localisation</div>
                        <div class=\"col-1 text-center\">Mesure</div>
                    </th>
                </thead>
                <tbody>
                    {% set index = 0 %}
                    {% for notation in form.notationModels %}
                        {{ form_row(notation, {'activity' : activities[index]}) }}
                        {% set index = index + 1 %}
                    {% endfor %}
                </tbody>
                </table>

            {% endblock %}
        {% endembed %}
         {% else %}
        <div class=\"alert alert-info\" role=\"alert\">
            {% trans %}Veuillez sélectionner une action  pour afficher ces activités{% endtrans %}
        </div>
        {% endif %}
                
    {{ form_end(form) }}
  
{% endblock %}

{% block javascripts %}
    <script>
        let maxRate = \$('#notation_collection_model_maxRate').val()
        let minRate = \$('#notation_collection_model_minRate').val()
        let weighting = \$('#notation_collection_model_weighting').val()
        let grouping = '{{ grouping }}'

        window.onload = function(){
            \$(\"#notationTable tr.notation\").each(function() {
                let row = this.id
                if(grouping == 'arrondissement'){
                    \$('#'+row+'_locationType').val('arrondissement');
                }else{
                    \$('#'+row+'_locationType').val('department');
                }
                locationTypeChange(row)
                calculTargetRate(row)
                calculLocationRate(row)
            });
        };

        \$(document).on('change', '#notation_collection_model_type, #notation_collection_model_entite, #notation_collection_model_programm', function () {
            let \$type = \$('#notation_collection_model_type')
            let \$entite = \$('#notation_collection_model_entite')
            let \$form = \$(this).closest('form')

            let data = {}
            data[\$type.attr('name')] = \$type.val()
            data[\$entite.attr('name')] = \$entite.val()
            data[\$(this).attr('name')] = \$(this).val()
            
            let \$field = \$(this).attr('id')
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (\$field == 'notation_collection_model_type') {
                        \$('#notation_collection_model_entite').replaceWith(
                            \$(html).find('#notation_collection_model_entite')
                        )
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_entite') {
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_programm') {
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                }
            });
        });


        function goalChange(row, field) {
            let \$field = \$('#'+field)
            let \$goal = \$('#'+row+'_goal')
            let \$location = \$('#'+row+'_locationType')
            let \$form = \$(\$field).closest('form')
            let data = {}
            data[\$goal.attr('name')] = \$goal.val()
            data[\$location.attr('name')] = \$location.val()
            data[\$(\$field).attr('name')] = \$(\$field).val()
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (field == row+'_goal') {
                        \$('#'+row+'_target').replaceWith(
                            \$(html).find('#'+row+'_target')
                        )
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )

                        \$('#'+row+'_target').attr('required', false)
                        if (\$('#'+row+'_treated').is(':checked')) {
                            \$('#'+row+'_target').attr('required', true)
                        }                        
                    }
                    if (field == row+'_target') {
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange(row) {
            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                document.getElementById(row+'_arrondissements').disabled = true;
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                \$('#'+row+'_communes_div').hide();
                \$('#'+row+'_postes_div').show();
                document.getElementById(row+'_communes').disabled = true;
                document.getElementById(row+'_postes').disabled = false;
            } else {
                \$('#'+row+'_communes_div').show();
                \$('#'+row+'_postes_div').hide();
                document.getElementById(row+'_communes').disabled = false;
                document.getElementById(row+'_postes').disabled = true;
            }
        }

        function treatedChange(row) {
            let \$treated = \$('#'+row+'_treated')
            let \$nature = \$('#'+row+'_nature')
            let \$goal = \$('#'+row+'_goal')
            let \$target = \$('#'+row+'_target')
            let \$communes = \$('#'+row+'_communes')
            let \$postes = \$('#'+row+'_postes')

            \$nature.attr('required', false)
            \$goal.attr('required', false)
            \$target.attr('required', false)
            \$communes.attr('required', false)
            \$postes.attr('required', false)
            if (\$treated.is(':checked')) {
                \$nature.attr('required', true)
                \$goal.attr('required', true)
                \$target.attr('required', true)
                \$communes.attr('required', true)
                \$postes.attr('required', true)
            }
        }
        
        function getSelectedOptions(sel, fn) {
            var opts = [], opt;

            for (var i=0, len=sel ? sel.options.length : 0; i<len; i++) {
                opt = sel.options[i];

                if ( opt.selected ) {
                    opts.push(opt);
                    if (fn) {
                        fn(opt);
                    }
                }
            }
            return opts;
        }

        function getSelectedRate(nature) {
            let allRate = \$('#notation_collection_model_allRate').val()
            allRate = JSON.parse(allRate);
            for (var i = 0; i < allRate.length; i++) {
                if (allRate[i].id == nature){
                    return allRate[i].rate
                }
            }
        }
        
        function calculTargetRate(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())
            
            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById(row+'_goal').disabled = false;
                document.getElementById(row+'_target').disabled = false;
                document.getElementById(row+'_indicators').disabled = false;
                document.getElementById(row+'_locationType').disabled = false;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = false;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = false;
                } else {
                    document.getElementById(row+'_communes').disabled = false;
                }

                nbSelec = getSelectedOptions(document.getElementById(row+'_indicators')).length
                //nbTotal = document.getElementById(row+'_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = ((maxRate * nbSelec) + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById(row+'_goal').disabled = true;
                document.getElementById(row+'_target').disabled = true;
                document.getElementById(row+'_indicators').disabled = true;
                document.getElementById(row+'_locationType').disabled = true;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = true;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = true;
                } else {
                    document.getElementById(row+'_communes').disabled = true;
                }
            }
            \$('#'+row+'_targetRate').val(targetRate)

            calculSensitivity(row)
        }
        
        function calculLocationRate(row) {
            let locationRate = 0
            let nbTotal = 0
            let nbSelec = 0

            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_arrondissements')).length
                nbTotal = document.getElementById(row+'_arrondissements') ? document.getElementById(row+'_arrondissements').options.length : 0
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_postes')).length
                nbTotal = document.getElementById(row+'_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById(row+'_communes')).length
                nbTotal = document.getElementById(row+'_communes') ? document.getElementById(row+'_communes').options.length : 0
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#'+row+'_locationRate').val(locationRate)

            calculSensitivity(row)
        }

        function calculSensitivity(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())

            let locationRate = \$('#'+row+'_locationRate').val()
            let sensitivity = \$('#'+row+'_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = (sensitivity - ((100 - locationRate) / 10)) * weighting / 100
            }
            \$('#'+row+'_sensitivity').val(sensitivity)
            \$('#'+row+'_sensHtml').val(sensitivity)
        }
    </script>

    <script>
        \$(function () {
            \$(\"#notationTable\").DataTable({
                \"pageLength\": 25
            });
        });
    </script>

    <script src=\"{{ asset('plugins/datatables/jquery.dataTables.js') }}\"></script>
    <script src=\"{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.js') }}\"></script>
{% endblock %}

{% block stylesheets %}
    <link rel=\"stylesheet\" href=\"{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.css') }}\">
{% endblock %}", "plan/notation_form.html.twig", "/var/www/vhosts/sigodd.gouv.bj/httpdocs/templates/plan/notation_form.html.twig");
    }
}
