From d925aec8029b63bdb8457ce70dcc3b91c2e3cb58 Mon Sep 17 00:00:00 2001 From: Alice <alice.poggioli@hotmail.fr> Date: Mon, 14 Oct 2019 15:43:45 +0200 Subject: [PATCH] Improve file form custom init. --- src/scripts/coopstarter.js | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index 2f43bc72..f0c921e4 100644 --- a/src/scripts/coopstarter.js +++ b/src/scripts/coopstarter.js @@ -288,6 +288,24 @@ function manageLogoutButton() { } } +/** + * Initi the custom form file behaviour + * Todo : we can improve the performance adding param to reduce the loop + */ +function initFileUpload(){ + 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 entrepreneur dashboard only : * As we cannot have multiple imbricated filtering with the native sib-display, we manage it manually. @@ -540,17 +558,8 @@ jQuery(document).ready(function($) { fillReportBrokenLinkForm(event, userWhoSubmitReport, formBrokenLink); }); - 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); - } + //Init the form file behaviour + initFileUpload() //Manage the accordion in request mentor dashboard. manageAccordionForRequest() @@ -596,8 +605,14 @@ jQuery(document).ready(function($) { window.setTimeout(() => { //Manage accordion by step manageAccordionByStep(); + + //Init the form file behaviour + initFileUpload() + + //Correct the native default of pagination refreshPagination(); - }, 2000); + }, 3000); + //In the entrepreneur dashboard, we set data from the display form to the hidden ones. addProperFilterToSearchComponents("entrepreneur-resource-list"); -- GitLab