diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index 00ab97ed3611a2ef8e9d16e8fca622da9872977f..088d8562ef1cee589145b0728c03594a56140d7d 100644 --- a/src/scripts/coopstarter.js +++ b/src/scripts/coopstarter.js @@ -101,13 +101,38 @@ async function refreshList(formId, listId) { let list = document.getElementById(listId); if (list) { - let listProxy = await list.component.resource + let listProxy = await list.component.resource; + + // Refresh du cache sur la liste listProxy.clearCache(); list.dataset.src = list.dataset.src; } }); } +/** + * Refresh user and account information after a form submission + * @param {String} formId - Id of the sumitted form + * @param {String} listId - Id of the user object to refresh + */ +async function refreshUser(formId, listId) { + let form = document.getElementById(formId); + form.addEventListener("save", async function() { + let list = document.getElementById(listId); + + if (list) { + let listProxy = await list.component.resource; + let account = await listProxy['account']; + + // Refresh du cache sur le User + listProxy.clearCache(); + account.clearCache(); + + list.dataset.src = list.dataset.src; + } + }); +} + /** * Remove pagination when there is no resource in a step group. */ @@ -553,7 +578,6 @@ function addProperFilterToSearchComponents(targetId) { let language_field_search = more_criterias_form.querySelector( `select[name="language"]` ); - let language_hidden_field = baseElement.querySelectorAll( 'hidden-widget[name="more_criterias_hidden"] select[name="language"]' ); @@ -785,25 +809,20 @@ jQuery(document).ready(function($) { refreshList("validation_form", "pending_resources"); refreshList("refusal_dialog_form", "pending_resources"); refreshList("improvement_dialog_form", "pending_resources"); - initFileUpload("entrepreneur_profile_creation", "account.picture"); - refreshList("entrepreneur_profile_creation", "entrepreneur_info"); - refreshList("entrepreneur_profile_creation", "entrepreneur_contact"); - refreshList("entrepreneur_profile_creation", "entrepreneur_account_picture"); - initFileUpload("mentor_profile_creation", "account.picture"); - refreshList("mentor_profile_creation", "mentor_info"); - refreshList("mentor_profile_creation", "mentor_complementary"); - refreshList("mentor_profile_creation", "mentor_contact"); - refreshList("mentor_profile_creation", "mentor_account_picture"); - initFileUpload("entrepreneur_profile_edition", "account.picture"); - refreshList("entrepreneur_profile_edition", "entrepreneur_info"); - refreshList("entrepreneur_profile_edition", "entrepreneur_contact"); - refreshList("entrepreneur_profile_edition", "entrepreneur_account_picture"); - initFileUpload("mentor_profile_edition", "account.picture"); - refreshList("mentor_profile_edition", "mentor_info"); - refreshList("mentor_profile_edition", "mentor_complementary"); - refreshList("mentor_profile_edition", "mentor_contact"); - refreshList("mentor_profile_edition", "mentor_account_picture"); - refreshRequestList("change_status_request", "request_list"); + refreshUser("entrepreneur_profile_creation", "entrepreneur_info"); + refreshUser("entrepreneur_profile_creation", "entrepreneur_contact"); + refreshUser("entrepreneur_profile_creation", "entrepreneur_account_picture"); + refreshUser("mentor_profile_creation", "mentor_info"); + refreshUser("mentor_profile_creation", "mentor_complementary"); + refreshUser("mentor_profile_creation", "mentor_contact"); + refreshUser("mentor_profile_creation", "mentor_account_picture"); + refreshUser("entrepreneur_profile_edition", "entrepreneur_info"); + refreshUser("entrepreneur_profile_edition", "entrepreneur_contact"); + refreshUser("entrepreneur_profile_edition", "entrepreneur_account_picture"); + refreshUser("mentor_profile_edition", "mentor_info"); + refreshUser("mentor_profile_edition", "mentor_complementary"); + refreshUser("mentor_profile_edition", "mentor_contact"); + refreshUser("mentor_profile_edition", "mentor_account_picture"); addProperFilterToSearchComponents("entrepreneur-resource-list"); addProperFilterToSearchComponents("mentor-database"); @@ -879,7 +898,10 @@ jQuery(document).ready(function($) { //Init the form file behaviour initFileUpload("resource_creation_form", "preview_image"); initFileUpload("resource_edition_form", "preview_image"); + + initFileUpload("mentor_profile_creation", "account.picture"); initFileUpload("mentor_profile_edition", "account.picture"); + refreshRequestList("change_status_request", "request_list"); //Manage the accordion in request mentor dashboard. manageAccordionForRequest(); @@ -931,9 +953,8 @@ jQuery(document).ready(function($) { //manage accordion for "More criteria" manageAccordionMoreCriteria(); - //Init the form file behaviour - // initFileUpload(); initFileUpload("entrepreneur_profile_edition", "account.picture"); + initFileUpload("entrepreneur_profile_creation", "account.picture"); //Correct the native default of pagination refreshPagination();