From cff95b4c91fbf993b14b3ad85aa1b0ea90483c30 Mon Sep 17 00:00:00 2001
From: tguillon <theo.guillon@libriciel.coop>
Date: Tue, 18 Oct 2022 15:31:27 +0200
Subject: [PATCH] Correction : pb duplication Correction : pb user

---
 app/Locale/fra/LC_MESSAGES/fiche.po           |  3 ++
 .../Fiches/modal/modalDupliquerTraitement.ctp | 43 +++++++++++--------
 app/View/Users/edit.ctp                       | 21 +++++----
 docker-compose.yml                            |  1 +
 4 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/app/Locale/fra/LC_MESSAGES/fiche.po b/app/Locale/fra/LC_MESSAGES/fiche.po
index 8e5d46dd..05e9df16 100755
--- a/app/Locale/fra/LC_MESSAGES/fiche.po
+++ b/app/Locale/fra/LC_MESSAGES/fiche.po
@@ -640,6 +640,9 @@ msgstr "Dupliquer le traitement"
 msgid "fiche.champOrganisationcible"
 msgstr "Entité cible pour la duplication du traitement"
 
+msgid "fiche.champDuplicationOrganisationcible"
+msgstr "Entité cible pour la duplication du traitement"
+
 msgid "fiche.champUsercible"
 msgstr "Utilisateur rédacteur pour la duplication du traitement"
 
diff --git a/app/View/Elements/Fiches/modal/modalDupliquerTraitement.ctp b/app/View/Elements/Fiches/modal/modalDupliquerTraitement.ctp
index cfa641c0..b6a1f15a 100644
--- a/app/View/Elements/Fiches/modal/modalDupliquerTraitement.ctp
+++ b/app/View/Elements/Fiches/modal/modalDupliquerTraitement.ctp
@@ -4,9 +4,10 @@ $body = $this->WebcilForm->inputs([
         'id' => "FicheId",
         'value' => null
     ],
-    'Fiche.organisationcible' => [
-        'id' => 'organisationcible',
+    'Fiche.duplicationOrganisationcible' => [
+        'id' => 'duplicationOrganisationcible',
         'options' => $mesOrganisations,
+        'class' => 'usersDeroulant transformSelect form-control',
         'required' => true,
         'empty' => true,
         'placeholder' => false,
@@ -15,6 +16,7 @@ $body = $this->WebcilForm->inputs([
     'Fiche.usercible' => [
         'id' => 'usercible',
         'options' => [],
+        'class' => 'usersDeroulant transformSelect form-control',
         'required' => true,
         'empty' => true,
         'placeholder' => false,
@@ -23,6 +25,7 @@ $body = $this->WebcilForm->inputs([
     'Fiche.userservicecible' => [
         'id' => 'userservicecible',
         'options' => [],
+        'class' => 'usersDeroulant transformSelect form-control',
         'required' => true,
         'empty' => true,
         'placeholder' => false,
@@ -70,36 +73,37 @@ echo $this->element('modal', [
             $('#FicheId').val($(this).attr('value'));
         });
 
-        // Lors d'action sur une menu déroulant : organisationcible
-        $("#organisationcible").change(function () {
-            let organisationcible = $(this).val();
+        // Lors d'action sur une menu déroulant : duplicationOrganisationcible
+        $("#duplicationOrganisationcible").on('change.select2', function () {
+            let duplicationOrganisationcible = $(this).val();
 
             hideAndRemoveField();
 
-            if (organisationcible) {
-                updateListingUser(organisationcible);
+            if (duplicationOrganisationcible) {
+                updateListingUser(duplicationOrganisationcible);
             } else {
                 hideBtnSave();
             }
         });
 
-        $("#usercible").change(function () {
+        // $("#usercible").change(function () {
+        $("#usercible").on('change.select2', function () {
             let usercible = $(this).val();
-            let organisationcible = $('#organisationcible').val();
+            let duplicationOrganisationcible = $('#duplicationOrganisationcible').val();
 
             $('#userservicecible option').remove();
 
-            if (usercible && organisationcible) {
+            if (usercible && duplicationOrganisationcible) {
                 updateListingServices(
                     usercible,
-                    organisationcible
+                    duplicationOrganisationcible
                 );
             } else {
                 hideBtnSave();
             }
         });
 
-        $("#userservicecible").change(function () {
+        $("#userservicecible").on('change.select2', function () {
             if ($(this).val()) {
                 $('#btnSave').removeAttr('disabled');
             } else {
@@ -107,6 +111,11 @@ echo $this->element('modal', [
             }
         });
 
+        // $('#modalDupliquerTraitement').on('hidden.bs.modal', function () {
+        //     $('#organisationcible').val();
+        //     hideAndRemoveField();
+        //     hideBtnSave();
+        // })
     });
 
     function hideAndRemoveField()
@@ -123,12 +132,12 @@ echo $this->element('modal', [
         $('#btnSave').attr('disabled', true);
     }
 
-    function updateListingUser(organisationcible)
+    function updateListingUser(duplicationOrganisationcible)
     {
         $.ajax({
             url: '<?php echo Router::url(['controller' => 'pannel', 'action' => 'ajax_listing_users_organisation']);?>',
             method: 'POST',
-            data: {'organisation_id': organisationcible},
+            data: {'organisation_id': duplicationOrganisationcible},
             success: function(dataResponse) {
                 try {
                     let organisations = JSON.parse(dataResponse);
@@ -153,14 +162,14 @@ echo $this->element('modal', [
         });
     }
 
-    function updateListingServices(usercible, organisationcible)
+    function updateListingServices(usercible, duplicationOrganisationcible)
     {
         $.ajax({
             url: '<?php echo Router::url(['controller' => 'pannel', 'action' => 'ajax_listing_services_user']);?>',
             method: 'POST',
             data: {
                 'user_id': usercible,
-                'organisation_id': organisationcible,
+                'organisation_id': duplicationOrganisationcible,
             },
             success: function(dataResponse) {
                 try {
@@ -189,4 +198,4 @@ echo $this->element('modal', [
         });
     }
 
-</script>
+</script>
\ No newline at end of file
diff --git a/app/View/Users/edit.ctp b/app/View/Users/edit.ctp
index 22ce60d7..bf1b8140 100755
--- a/app/View/Users/edit.ctp
+++ b/app/View/Users/edit.ctp
@@ -277,27 +277,30 @@ echo $this->element('modalpassword');
 
         <?php $selected = (array)Hash::get($this->request->data, 'User.organisation_id');?>
         <?php foreach(array_keys($options['organisation_id']) as $organisation_id): ?>
-        $("#<?php echo 'service_id'.$organisation_id;?>").select2({
-            language: "fr",
-            placeholder: "Sélectionnez un ou plusieurs service",
-            allowClear: true
-        });
+            $("#<?php echo 'service_id'.$organisation_id;?>").select2({
+                language: "fr",
+                placeholder: "Sélectionnez un ou plusieurs service",
+                allowClear: true
+            });
 
-        <?php if(false === in_array($organisation_id, $selected)):?>
-        $("#organisation-block-<?php echo $organisation_id;?>").hide();
-        <?php endif;?>
+            <?php if(false === in_array($organisation_id, $selected)):?>
+                $("#organisation-block-<?php echo $organisation_id;?>").hide();
+                $("#organisation-block-<?php echo $organisation_id;?>").attr('disabled', true);
+            <?php endif;?>
         <?php endforeach;?>
 
         $('#deroulant').change(function(event) {
-            var select = $(this),
+            let select = $(this),
                 values = $.map($(select).children('option'),function(option){return option.value;}),
                 selected = $(select).val();
 
             $.each(values, function(index, value){
                 if(-1 !== $.inArray(value, selected)) {
                     $("#organisation-block-"+value).show();
+                    $("#organisation-block-"+value).attr('disabled', false);
                 } else {
                     $("#organisation-block-"+value).hide();
+                    $("#organisation-block-"+value).attr('disabled', true);
                 }
             });
         });
diff --git a/docker-compose.yml b/docker-compose.yml
index 4b8ca5e5..98fe7f43 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -51,6 +51,7 @@ services:
             - ./VERSION.txt:/var/www/html/web-dpo/VERSION.txt
             - tmp-volume:/var/www/html/web-dpo/app/tmp
             - ./app/tmp/out:/var/www/html/web-dpo/app/tmp/out
+            - ./vendors:/var/www/html/web-dpo/vendors
 
     web-dpo-cloudooo:
         container_name: web-dpo-cloudooo
-- 
GitLab