From 1670a34517fd18bfe226ab53476c2fcb0f24dec5 Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Sat, 25 Apr 2020 23:52:20 +0200
Subject: [PATCH] Fix accordion after refresh

---
 src/scripts/coopstarter.js | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js
index 364cef05..93d392a4 100644
--- a/src/scripts/coopstarter.js
+++ b/src/scripts/coopstarter.js
@@ -403,6 +403,24 @@ function fillSenderLike(userWhoSubmitLike, formSenderLike, currentResource) {
   receiver_object_id
 }
 
+/**
+ * Specific treatments for the request lists refresh
+ * @param {String} formId - Id of the sumitted form
+ * @param {String} listId  - Id of the list to refresh
+ */
+async function refreshRequestList(formId, listId) {
+  let form = document.getElementById(formId);
+  form.addEventListener("save", async function() {
+    let list = document.getElementById(listId);
+    let listProxy = await list.component.resource
+    listProxy.clearCache();
+    list.dataset.src = list.dataset.src;
+    setTimeout(() => {
+      manageAccordionForRequest();
+    }, 1000);
+  });
+}
+
 /**
  * For entrepreneur dashboard only :
  * As we cannot have multiple imbricated filtering with the native sib-display, we manage it manually.
@@ -750,7 +768,7 @@ jQuery(document).ready(function($) {
   refreshList("mentor_profile_edition", "mentor_contact");
   refreshList("mentor_profile_edition", "user_account_picture");
   initFileUpload("mentor_profile_edition", "account.picture");
-  refreshList("change_status_request", "request_list");
+  refreshRequestList("change_status_request", "request_list");
 
   addProperFilterToSearchComponents("entrepreneur-resource-list");
   addProperFilterToSearchComponents("mentor-database");
-- 
GitLab