From 10f169670db695cfb36ad08c6c6adf58304034cf Mon Sep 17 00:00:00 2001 From: Alice <alice.poggioli@hotmail.fr> Date: Fri, 11 Oct 2019 07:53:13 +0200 Subject: [PATCH] Add jsDoc on the coopstarter.js file. --- src/scripts/coopstarter.js | 164 +++++++++++++++++++++++++------------ 1 file changed, 112 insertions(+), 52 deletions(-) diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index 9b876309..50d88c65 100644 --- a/src/scripts/coopstarter.js +++ b/src/scripts/coopstarter.js @@ -3,6 +3,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ +/** + * Manage classic tabs. + * @param {string} pageName - Id of the tab content + * @param {HTMLElement} elmnt - Accordion element + */ function openTab(pageName, elmnt) { // Hide all elements with class="tabcontent" by default */ var i, tabcontent, tablinks; @@ -19,8 +24,10 @@ function openTab(pageName, elmnt) { elmnt.classList.add("active"); } - -//Manage the visual of the fake tabs in entrepreneur dashboard. +/** + * Manage the visual of the fake tabs in entrepreneur dashboard. + * @param {HTMLElement} elmnt - Active fake tab. + */ function openFakeTab(elmnt) { // Hide all elements with class="tabcontent" by default */ var i, tablinks; @@ -29,26 +36,40 @@ function openFakeTab(elmnt) { for (i = 0; i < tablinks.length; i++) { tablinks[i].classList.remove("active"); } + + // Show the specific tab content elmnt.classList.add("active"); } - +/** + * Set a preview image on load. + * @param {event} event - On file loading. + */ function loadFile(event) { + //Création of the preview var elt = document.createElement("img"); elt.src = URL.createObjectURL(event.target.files[0]); + //Remove the default useless image. var labeltag = event.target.closest("label"); labeltag.querySelector("input[name='preview_image']").style.display = "none"; + //If there is already a image previewed, remove it. if (labeltag.querySelector("img")) { var oldImage = labeltag.querySelector("img"); labeltag.removeChild(oldImage); } + //Add the previewimage labeltag.insertAdjacentElement("afterbegin", elt); } - +/** + * Fill datas to a form. + * @param {HTMLElment} detail - Element with the datas to retrieve. + * @param {string} targetFormName - Id of the form to fill. + * @param {string} inputName - Name of the input to fill. + */ function linkDatasetToField(detail, targetFormName, inputName) { let targetForm = document.getElementById(targetFormName); targetForm.addEventListener("populate", event => { @@ -63,8 +84,11 @@ function linkDatasetToField(detail, targetFormName, inputName) { }); } - -//Refresh information after a form submission +/** + * Refresh information after a form submission + * @param {String} formId - Id of the sumitted form + * @param {String} listId - Id of the list to refresh + */ function refreshList(formId, listId) { let form = document.getElementById(formId); form.addEventListener("save", event => { @@ -73,8 +97,9 @@ function refreshList(formId, listId) { }); } - -//Remove pagination when there is no resource in a step group +/** + * Remove pagination when there is no resource in a step group. + */ function refreshPagination() { var resources_containers = document.querySelectorAll( ".resource_by_step sib-form+div" @@ -88,13 +113,22 @@ function refreshPagination() { .textContent == 1) ) { resources_container.nextSibling.setAttribute("style", "display:none"); - } else if (resources_container.nextSibling && resources_container.closest(".step").querySelector('.accordion:not(.active)')) { + } else if ( + resources_container.nextSibling && + resources_container + .closest(".step") + .querySelector(".accordion:not(.active)") + ) { resources_container.nextSibling.setAttribute("hidden", "hidden"); } } } -//Manage select hidden to fullfill them with more "more criterias" selection +/** + * Manage select hidden to fullfill them with more "more criterias" selection + * @param {HTMLElement} select_hidden - Hidden select to fullfill. + * @param {HTMLElement} option_selected - Option selcted to set in hidden select. + */ function selectHiddenManagement(select_hidden, option_selected) { options_hidden = select_hidden.getElementsByTagName("option"); for (let option_hidden of options_hidden) { @@ -114,7 +148,11 @@ function selectHiddenManagement(select_hidden, option_selected) { refreshPagination(); } -//Manage input hidden field to fullfill them with more "more criterias" selection +/** + * Manage input hidden field to fullfill them with more "more criterias" selection + * @param {HTMLElement} field - Hidden field to fullfill. + * @param {HTMLElement} field_search - Field with the value wanted by the user. + */ function inputHiddenManagement(field, field_search) { field.setAttribute("value", field_search.value); let parent_form = field.closest("sib-form"); @@ -122,7 +160,11 @@ function inputHiddenManagement(field, field_search) { refreshPagination(); } -//Manage select hidden for type to fullfill them with more "more criterias" selection +/** + * Manage select hidden for type to fullfill them with more "more criterias" selection + * @param {HTMLElement} tab - Selected type tabs. + * @param {HTMLElement} form - Hidden form to fullfill. + */ function selectHiddenManagementForType(tab, form) { let type_hidden_field = form.querySelectorAll( 'hidden-widget[name="more_criterias_hidden"] select[name="type"]' @@ -153,22 +195,28 @@ function selectHiddenManagementForType(tab, form) { } } -//Manage the accordion for step in entrepreneur dashboard -function manageAccordionByStep(){ +/** + * 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") + 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() + this.closest(".step") + .querySelector("nav") + .removeAttribute("hidden"); + refreshPagination(); var panel = this.nextElementSibling.querySelector("sib-form + div"); @@ -177,13 +225,14 @@ function manageAccordionByStep(){ } else { panel.style.maxHeight = panel.scrollHeight + "px"; } - }); } } -//Manage the accordion for requested resources in the mentor dashboard -function manageAccordionForRequest(){ +/** + * Manage the accordion for requested resources in the mentor dashboard + */ +function manageAccordionForRequest() { var accRequest = document.querySelectorAll( "#requests accordion-request-resource" ); @@ -205,8 +254,10 @@ function manageAccordionForRequest(){ } } -//Manage the action of the logout button -function manageLogoutButton(){ +/** + * 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() { @@ -223,19 +274,23 @@ function manageLogoutButton(){ } } +/** + * For entrepreneur dashboard only : + * As we cannot have multiple imbricated filtering with the native sib-display, we manage it manually. + * @param {String} targetId - Id of the element to update + */ function addProperFilterToSearchComponents(targetId) { var baseElement = document.getElementById(targetId); var forms = baseElement.querySelectorAll(".resource_by_step"); forms.forEach(form => { form.addEventListener("populate", e => { - //Manage fake tabs let tabs = baseElement.getElementsByClassName("filter_by_type"); for (let tab of tabs) { selectHiddenManagementForType(tab, form); } - //On load in dashbord Entrepreneur + //Manage the pagination refreshPagination(); //SEARCH BY KEYWORD @@ -243,7 +298,9 @@ function addProperFilterToSearchComponents(targetId) { //https://git.happy-dev.fr/startinblox/framework/sib-core/issues/379 //TODO: Wait for a solution to filter with multiple value with "OR" instead of "AND". let keyword_form = baseElement.querySelectorAll(".search-by-keyword")[0]; - let keyword_field = keyword_form.querySelector(`input[name="name_keyword"]`); + let keyword_field = keyword_form.querySelector( + `input[name="name_keyword"]` + ); let keyword_submit = baseElement.querySelectorAll(" .keyword_submit")[0]; let keyword_hidden_fields = baseElement.querySelectorAll( @@ -283,12 +340,9 @@ function addProperFilterToSearchComponents(targetId) { //Manage fake tabs for type let tabs = baseElement.getElementsByClassName("filter_by_type"); for (let tab of tabs) { - tab.addEventListener( - "click", - function() { - selectHiddenManagementForType(tab, form) - } - ); + tab.addEventListener("click", function() { + selectHiddenManagementForType(tab, form); + }); } //To retrieve format @@ -389,10 +443,12 @@ function addProperFilterToSearchComponents(targetId) { }); }); } + /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX ON LOAD XXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ + jQuery(document).ready(function($) { //Refresh pagination refreshPagination(); @@ -400,11 +456,15 @@ jQuery(document).ready(function($) { // Get the element with id="defaultOpen" and click on it document.getElementById("defaultOpen").click(); + //Retrieve the current user let userAccountDataSrc = document.getElementById("user-account-picture"); + + //Add the current user as reviewer. linkDatasetToField(userAccountDataSrc, "validation-form", "reviewer"); linkDatasetToField(userAccountDataSrc, "improvement-dialog-form", "reviewer"); linkDatasetToField(userAccountDataSrc, "refusal-dialog-form", "reviewer"); + //On form submission, we sometime have to refresh a list. refreshList("resource-creation-form", "resources-history"); refreshList("validation-form", "pending-resources"); refreshList("refusal-dialog-form", "pending-resources"); @@ -440,24 +500,25 @@ jQuery(document).ready(function($) { } //Manage the logout action - manageLogoutButton() + manageLogoutButton(); -/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXX MENTOR DASHBOARD XXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ + /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXXXXXXXX MENTOR DASHBOARD XXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ window.setTimeout(() => { + //TODO : We can be more precise. var forms = document.querySelectorAll("sib-form"); forms.forEach(form => { form.addEventListener("populate", e => { + + //Manage the upload file. var previewImage = document.querySelectorAll( "sib-form-file input[name='preview_image']+input" ); - var previewlabel = document.querySelectorAll( - "sib-form-file div" - ); + var previewlabel = document.querySelectorAll("sib-form-file div"); for (let item of previewlabel) { - item.innerHTML="Upload a file" + item.innerHTML = "Upload a file"; } for (let item of previewImage) { @@ -466,7 +527,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ }); //Manage the accordion in request mentor dashboard. - manageAccordionForRequest() + manageAccordionForRequest(); //Refresh data list on delete resources const deleteButton = document.querySelectorAll("sib-delete"); @@ -494,16 +555,15 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ }); }, 2000); -/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXX ENTREPRENEUR DASHBOARD XXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ + /* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXX ENTREPRENEUR DASHBOARD XXXXXXXXXXXXXXXXXXXX + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ window.setTimeout(() => { //Manage accordion by step - manageAccordionByStep() - refreshPagination() - + manageAccordionByStep(); + refreshPagination(); }, 2000); //In the entrepreneur dashboard, we set data from the display form to the hidden ones. -- GitLab