From 3702c2fb92661d0c69ccc7361d86f26caf0dc52f Mon Sep 17 00:00:00 2001
From: senza <maximesenzamici@gmail.com>
Date: Wed, 9 Mar 2022 10:35:35 +0100
Subject: [PATCH] Action Step Visibility - dedicated controler

---
 united4earth/static/js/main.js | 41 +++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/united4earth/static/js/main.js b/united4earth/static/js/main.js
index 6e0311b6e..ae7b3e314 100644
--- a/united4earth/static/js/main.js
+++ b/united4earth/static/js/main.js
@@ -911,6 +911,7 @@ function visibilityControler(solidDisplay,parentSection) {
   setTimeout(() => {
     let section = parentSection;
     let isRepresentativeSection = false ;
+    let isActionStep = false;
 
     //console.log("section classes",section.classList,solidDisplay);
     sectionClasses = section.classList;
@@ -918,11 +919,18 @@ function visibilityControler(solidDisplay,parentSection) {
       if(sectionClass.includes('contact-representative')){
         isRepresentativeSection = true;
       }
+      else if (sectionClass.includes('action-step')) {
+        isActionStep = true; 
+      }
     });
     //Handle representative section seperately
     if (isRepresentativeSection == true){
       visibilityControlerRepresentative(section);
     }
+    //handle steps seperately
+    else if(isActionStep == true){
+      visibilityControlerActionStep(section);
+    }
     else{
       //get content of the display
       let content = solidDisplay.querySelector("div").innerText;
@@ -954,6 +962,21 @@ function visibilityControlerRepresentative(section){
   }, 2000);
 }
 
+//handle action step section
+function visibilityControlerActionStep(section) {
+  setTimeout(() => {
+      stepContent = section.querySelector('u4e-multiple-action-steps > solid-display > div').innerText;
+      stepContent= stepContent.replace(/\s/g,"");
+      stepContent= stepContent.replace(/\n/g,"");
+      // console.log('step content is',stepContent);
+      if (stepContent == '') {
+        section.style.display = "none";
+      }
+      else{
+        section.style.display = "block";
+      }    
+    }, 500);
+}
 
 /***********************
         IF SPECIFIC REPRESENTATIVES ARE TARGETTED
@@ -1014,30 +1037,22 @@ function hideRepresentativeSearch(solidDisplay){
 function styleActiveActionStep(solidDisplay){
   //get all "active" fields in display
   activeFields = solidDisplay.querySelectorAll("*[name=active]");
-  console.log("step fields",activeFields);
+  // console.log("step fields",activeFields);
   //if none, hide section
-  if (activeFields.length == 0) {
-    solidDisplay.closest('section').style.display='none';
-  }
-  else{
+  if (!activeFields.length == 0) {
     activeFields.forEach(activeField => {
       activeFieldValue = activeField.innerText;
       //if Active is true, set "active" class to parent display
       if (activeFieldValue.toLowerCase() == 'true' ){
         activeField.closest('solid-display').classList.add('active');
-        console.log(activeField.closest('solid-display').classList);
+        // console.log(activeField.closest('solid-display').classList);
       }
-    });
+    }); 
   }
 }
-
-
-
 /***********************
-        LANGUAGE SWITCH
-          
+    LANGUAGE SWITCH         
 ***********************/
-
 async function manageSelectLanguage() {
   let languageSelects = document.querySelectorAll(".languageChoice")
   //console.log("languages",languageSelects);
-- 
GitLab