diff --git a/src/includes/mentor/profile/edit.pug b/src/includes/mentor/profile/edit.pug index c758091c3d4aa339cf511426c51cd48146c4c379..198a850a3b35ce05fb54806682eb33c30e7e4f1a 100644 --- a/src/includes/mentor/profile/edit.pug +++ b/src/includes/mentor/profile/edit.pug @@ -7,7 +7,7 @@ sib-form#mentor_profile_edition.block_log.block_creat_count( fields="account_information(last_name, first_name, mentor_profile.organisation,\ mentor_profile.phone, mentor_profile.languages, mentor_profile.fields),\ about_you(header_about_you, account.picture, mentor_profile.headline, mentor_profile.city, mentor_profile.country,\ - mentor_profile.biography, mentor_profile.skills),\ + mentor_profile.biography, mentor_profile.skills, resources),\ social_media(header_social_media, mentor_profile.linkedin, mentor_profile.twitter), username" range-mentor_profile.fields=`${endpoints.fields}` @@ -39,6 +39,7 @@ sib-form#mentor_profile_edition.block_log.block_creat_count( widget-mentor_profile.skills="sib-form-textarea" widget-mentor_profile.biography="sib-form-textarea" widget-username="sib-form-hidden" + widget-resources="hidden-widget" class-mentor_profile.organisation='form-label is-dark' widget-mentor_profile.organisation='sib-form-auto-completion' diff --git a/src/index.pug b/src/index.pug index 97b326b592cdd829cecca836c67c617cc06b0c98..20604cd66059d2a1260247cafb7a3a7d153d64af 100644 --- a/src/index.pug +++ b/src/index.pug @@ -51,7 +51,9 @@ script(type='module'). let idToken = await sibAuth.getUserIdToken(); if ( !user ) { - return; + window.dispatchEvent( + new CustomEvent('requestNavigation', { detail: { route: 'splash' } }) + ); } user = await store.get(user); diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index 047fcbc0889f7c13816233624c2102c07611f13f..8925fd1ebb536a0915f829f3f526928aeb49d7cc 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"); @@ -307,7 +387,10 @@ function addProperFilterToSearchComponents(targetId) { }); }); } - +/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXX ON LOAD XXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ jQuery(document).ready(function($) { //Refresh pagination refreshPagination(); @@ -357,110 +440,63 @@ 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 => { - // form.addEventListener("populate", e => { - var previewImage = document.querySelectorAll( - "sib-form-file input[name='preview_image']+input" - ); - var previewlabel = document.querySelectorAll("sib-form-file div"); - for (let item of previewlabel) { - item.innerHTML = "Upload a file"; - } + var previewImage = document.querySelectorAll( + "sib-form-file input[name='preview_image']+input" + ); + var previewlabel = document.querySelectorAll("sib-form-file div"); + for (let item of previewlabel) { + item.innerHTML = "Upload a file"; + } - for (let item of previewImage) { - item.addEventListener("change", loadFile); - } - // }); + for (let item of previewImage) { + item.addEventListener("change", loadFile); + } - //Manage the accordion in request mentor dashboard. - var accRequest = document.querySelectorAll( - "#requests accordion-request-resource" - ); + //Manage the accordion in request mentor dashboard. + manageAccordionForRequest() - for (let i = 0; i < accRequest.length; i++) { - accRequest[i].addEventListener("click", function() { - if (this.classList.contains("active") == true) { - this.classList.remove("active"); - } else { - this.classList.add("active"); - } + //Refresh data list on delete resources + const deleteButton = document.querySelectorAll("sib-delete"); + for (var i = 0; i < deleteButton.length; i++) { + deleteButton[i].addEventListener("resourceDeleted", e => { + const historyList = document.getElementById("resources-history"); + historyList.dataset.src = historyList.dataset.src; - /* Toggle between hiding and showing the active panel */ - var panelRequest = this.nextElementSibling; - if (!this.classList.contains("active")) { - panelRequest.style.maxHeight = null; - - refreshPagination(); - } else { - panelRequest.style.maxHeight = panelRequest.scrollHeight + "px"; - } - }); - } + let confirm_suppress = document.getElementById("confirm_suppress"); + confirm_suppress.setAttribute("hidden", "hidden"); - //Refresh data list on delete resources - const deleteButton = document.querySelectorAll("sib-delete"); - for (var i = 0; i < deleteButton.length; i++) { - deleteButton[i].addEventListener("resourceDeleted", e => { - const historyList = document.getElementById("resources-history"); - historyList.dataset.src = historyList.dataset.src; - - let confirm_suppress = document.getElementById("confirm_suppress"); - confirm_suppress.setAttribute("hidden", "hidden"); - - //If we supress from the detail resource view, we close this view. - let mentor_resource_detail = document.getElementById( - "mentor-resource-detail" - ); - mentor_resource_detail.setAttribute("hidden", "hidden"); - this.dispatchEvent( - new CustomEvent("requestNavigation", { - bubbles: true, - detail: { route: "actions" } - }) - ); - }); - // } + //If we supress from the detail resource view, we close this view. + let mentor_resource_detail = document.getElementById( + "mentor-resource-detail" + ); + mentor_resource_detail.setAttribute("hidden", "hidden"); + this.dispatchEvent( + new CustomEvent("requestNavigation", { + bubbles: true, + detail: { route: "actions" } + }) + ); + }); }; }, 3000); - //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"); + //Manage accordion by step + manageAccordionByStep() + refreshPagination() - var panel = this.nextElementSibling.querySelector("sib-form + div"); - - 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.