diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index c4819ea4119654d1c5e8ed96ebd437b3944f6818..9b87630995f4a1d9aa72e33c5b4885d37c2f568b 100644 --- a/src/scripts/coopstarter.js +++ b/src/scripts/coopstarter.js @@ -1,3 +1,8 @@ +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ + function openTab(pageName, elmnt) { // Hide all elements with class="tabcontent" by default */ var i, tabcontent, tablinks; @@ -14,6 +19,7 @@ function openTab(pageName, elmnt) { elmnt.classList.add("active"); } + //Manage the visual of the fake tabs in entrepreneur dashboard. function openFakeTab(elmnt) { // Hide all elements with class="tabcontent" by default */ @@ -26,6 +32,7 @@ function openFakeTab(elmnt) { elmnt.classList.add("active"); } + function loadFile(event) { var elt = document.createElement("img"); elt.src = URL.createObjectURL(event.target.files[0]); @@ -41,6 +48,7 @@ function loadFile(event) { labeltag.insertAdjacentElement("afterbegin", elt); } + function linkDatasetToField(detail, targetFormName, inputName) { let targetForm = document.getElementById(targetFormName); targetForm.addEventListener("populate", event => { @@ -55,6 +63,7 @@ function linkDatasetToField(detail, targetFormName, inputName) { }); } + //Refresh information after a form submission function refreshList(formId, listId) { let form = document.getElementById(formId); @@ -64,6 +73,7 @@ function refreshList(formId, listId) { }); } + //Remove pagination when there is no resource in a step group function refreshPagination() { var resources_containers = document.querySelectorAll( @@ -78,8 +88,8 @@ function refreshPagination() { .textContent == 1) ) { resources_container.nextSibling.setAttribute("style", "display:none"); - } else if (resources_container.nextSibling) { - resources_container.nextSibling.setAttribute("style", "display:block"); + } else if (resources_container.nextSibling && resources_container.closest(".step").querySelector('.accordion:not(.active)')) { + resources_container.nextSibling.setAttribute("hidden", "hidden"); } } } @@ -143,6 +153,76 @@ function selectHiddenManagementForType(tab, form) { } } +//Manage the accordion for step in entrepreneur dashboard +function manageAccordionByStep(){ + var acc = document.getElementsByClassName("accordion"); + var i; + + for (i = 0; i < acc.length; i++) { + acc[i].addEventListener("click", function() { + if (this.classList.contains("active") == true){ + this.classList.remove("active") + this.nextElementSibling.querySelector("sib-form + div").style.maxHeight = "0px"; + }else{ + this.classList.add("active") + } + + this.closest(".step").querySelector('nav').removeAttribute("hidden"); + refreshPagination() + + var panel = this.nextElementSibling.querySelector("sib-form + div"); + + if (panel.style.maxHeight) { + panel.style.maxHeight = null; + } else { + panel.style.maxHeight = panel.scrollHeight + "px"; + } + + }); + } +} + +//Manage the accordion for requested resources in the mentor dashboard +function manageAccordionForRequest(){ + var accRequest = document.querySelectorAll( + "#requests accordion-request-resource" + ); + + for (let i = 0; i < accRequest.length; i++) { + accRequest[i].addEventListener("click", function() { + /* Toggle between adding and removing the "active" class, + to highlight the button that controls the panel */ + this.classList.toggle("active"); + + /* Toggle between hiding and showing the active panel */ + var panelRequest = this.nextElementSibling; + if (panelRequest.style.maxHeight) { + panelRequest.style.maxHeight = null; + } else { + panelRequest.style.maxHeight = panelRequest.scrollHeight + "px"; + } + }); + } +} + +//Manage the action of the logout button +function manageLogoutButton(){ + const logoutButtons = document.getElementsByClassName("logout-button"); + for (var i = 0; i < logoutButtons.length; i++) { + logoutButtons[i].addEventListener("click", function() { + window.dispatchEvent( + new CustomEvent("requestNavigation", { + detail: { route: "splash-index" } + }) + ); + document.querySelector("sib-auth").logout(); + setTimeout(function() { + location.reload(); + }, 1000); + }); + } +} + function addProperFilterToSearchComponents(targetId) { var baseElement = document.getElementById(targetId); var forms = baseElement.querySelectorAll(".resource_by_step"); @@ -309,7 +389,10 @@ function addProperFilterToSearchComponents(targetId) { }); }); } - +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXX ON LOAD XXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ jQuery(document).ready(function($) { //Refresh pagination refreshPagination(); @@ -357,22 +440,12 @@ jQuery(document).ready(function($) { } //Manage the logout action - const logoutButtons = document.getElementsByClassName("logout-button"); - for (var i = 0; i < logoutButtons.length; i++) { - logoutButtons[i].addEventListener("click", function() { - window.dispatchEvent( - new CustomEvent("requestNavigation", { - detail: { route: "splash-index" } - }) - ); - document.querySelector("sib-auth").logout(); - setTimeout(function() { - location.reload(); - }, 1000); - }); - } + manageLogoutButton() - //MENTOR DASHBOARD************************************************************* +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXX MENTOR DASHBOARD XXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ window.setTimeout(() => { var forms = document.querySelectorAll("sib-form"); forms.forEach(form => { @@ -393,25 +466,7 @@ jQuery(document).ready(function($) { }); //Manage the accordion in request mentor dashboard. - var accRequest = document.querySelectorAll( - "#requests accordion-request-resource" - ); - - for (let i = 0; i < accRequest.length; i++) { - accRequest[i].addEventListener("click", function() { - /* Toggle between adding and removing the "active" class, - to highlight the button that controls the panel */ - this.classList.toggle("active"); - - /* Toggle between hiding and showing the active panel */ - var panelRequest = this.nextElementSibling; - if (panelRequest.style.maxHeight) { - panelRequest.style.maxHeight = null; - } else { - panelRequest.style.maxHeight = panelRequest.scrollHeight + "px"; - } - }); - } + manageAccordionForRequest() //Refresh data list on delete resources const deleteButton = document.querySelectorAll("sib-delete"); @@ -439,26 +494,16 @@ jQuery(document).ready(function($) { }); }, 2000); - //ENTREPRENEUR DASHBOARD************************************************************* +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXX ENTREPRENEUR DASHBOARD XXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ window.setTimeout(() => { - //Accordion by step - var acc = document.getElementsByClassName("accordion"); - var i; - - for (i = 0; i < acc.length; i++) { - acc[i].addEventListener("click", function() { - this.classList.toggle("active"); - - var panel = this.nextElementSibling.querySelector("sib-form + div"); + //Manage accordion by step + manageAccordionByStep() + refreshPagination() - if (panel.style.maxHeight) { - panel.style.maxHeight = null; - } else { - panel.style.maxHeight = panel.scrollHeight + "px"; - } - }); - } }, 2000); //In the entrepreneur dashboard, we set data from the display form to the hidden ones.