From 3b4b0ea1f42dcdcd60ca116a5d0a0da871bdf9c4 Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Tue, 26 May 2020 20:55:53 +0200
Subject: [PATCH] Manage organisation edition in its own fiedl

---
 src/includes/components/widgets.pug           | 11 +++--
 .../entrepreneur/components/header.pug        |  5 ++-
 src/includes/entrepreneur/profile/edit.pug    | 41 ++++++++++++++-----
 src/includes/mentor/components/header.pug     |  6 ++-
 src/includes/mentor/profile/detail.pug        |  3 +-
 src/includes/mentor/profile/edit.pug          | 22 +++++++---
 src/scripts/coopstarter.js                    | 11 ++++-
 7 files changed, 73 insertions(+), 26 deletions(-)

diff --git a/src/includes/components/widgets.pug b/src/includes/components/widgets.pug
index ff31811f..272832c1 100644
--- a/src/includes/components/widgets.pug
+++ b/src/includes/components/widgets.pug
@@ -196,15 +196,15 @@ sib-widget(name='cs-about-field')
 sib-widget(name='cs-account-picture')
   template
     figure.avatar
-        img(src="\${value || '/images/alien.jpg'}", alt="Profile picture")
+        img(src="\${await value || '/images/alien.jpg'}", alt="Profile picture")
 
 sib-widget(name='cs-profile-picture')
   template
-      img(src="\${value || '/images/alien.jpg'}", alt="Profile picture")
+      img(src="\${await value || '/images/alien.jpg'}", alt="Profile picture")
 
 sib-widget(name='cs-preview-picture')
   template
-      img(src="\${value || '/images/alien.jpg'}", alt="Preview of the resource")
+      img(src="\${await value || '/images/alien.jpg'}", alt="Preview of the resource")
 
 sib-widget(name="hidden-widget")
     template
@@ -232,6 +232,11 @@ sib-widget(name="cs-form-file-custom")
       label(for="preview_image")
         sib-form-file(upload-url=`${sdn}upload/` name="preview_image" )
 
+sib-widget(name="cs-ent-profile-picture")
+    template
+      label(for="picture")
+        sib-form-file(upload-url=`${sdn}upload/` name="picture")
+
 sib-widget(name="cs-form-profile-picture")
     template
       label(for="account.picture")
diff --git a/src/includes/entrepreneur/components/header.pug b/src/includes/entrepreneur/components/header.pug
index 728a3821..7748c9c2 100644
--- a/src/includes/entrepreneur/components/header.pug
+++ b/src/includes/entrepreneur/components/header.pug
@@ -19,8 +19,9 @@
             .dropdownWrapper
                 sib-display#entrepreneur_account_picture.dropdownLabel(
                     bind-user
-                    fields='account.picture',
-                    widget-account.picture='cs-account-picture'
+                    nested-field="account"
+                    fields="foaf:depiction"
+                    widget-foaf:depiction='cs-account-picture'
                 )
 
                 div.dropdownPanel
diff --git a/src/includes/entrepreneur/profile/edit.pug b/src/includes/entrepreneur/profile/edit.pug
index 924a1794..c878deab 100644
--- a/src/includes/entrepreneur/profile/edit.pug
+++ b/src/includes/entrepreneur/profile/edit.pug
@@ -3,29 +3,50 @@ h2.title_create= data.EditYourAccount
 sib-form#entrepreneur_profile_edition.block_log.block_creat_count(
     partial
     bind-user
-    fields="info(last_name, first_name, username, email, entrepreneurProfile.organisation, account.picture)"     
-    range-entrepreneurProfile.organisation=`${endpoints.organisations}`
+    fields="info(last_name, first_name, username, email)"
     
     label-first_name=`${data.Surname}`
     label-last_name=`${data.Name}`
-    label-entrepreneurProfile.organisation=`${data.Organisation}`
     label-account.picture=`${data.Photo}`
     widget-username="sib-form-hidden"
 
     class-last_name='form-label is-dark input_big'
     class-first_name='form-label is-dark input_big'
     class-email='form-label is-dark input_big'
-    class-entrepreneurProfile.phone='form-label is-dark input_big'
 
-    class-entrepreneurProfile.organisation='form-label is-dark input_big'
-    widget-entrepreneurProfile.organisation='sib-form-auto-completion'
+    submit-button=`${data.SaveModification}`
+    next='entrepreneur-account-edit-confirmation'
+)
+
+sib-form#entrepreneur_profile_organisation.block_log.block_creat_count(
+    partial
+    bind-user
+    nested-field="entrepreneurProfile"
+    fields="organisation"
+
+    range-organisation=`${endpoints.organisations}`
+    label-organisation=`${data.Organisation}`
+    class-organisation='form-label is-dark input_big'
+    widget-organisation='sib-form-auto-completion'
+
+    submit-button=`${data.SaveModification}`
+    next='entrepreneur-account-edit-confirmation'
+)
+
+sib-form#entrepreneur_profile_picture.block_log.block_creat_count(
+    partial
+    bind-user
+    nested-field="account"
+    fields="picture, slug, issuer"
 
-    upload-url-account.picture=`${sdn}upload/`
-    widget-account.picture='cs-form-profile-picture'
-    class-account.picture='input_photo w_25'
+    widget-issuer="sib-form-hidden"
+    widget-slug="sib-form-hidden"
+    upload-url-picture=`${sdn}upload/`
+    widget-picture='cs-ent-profile-picture'
+    class-picture='input_photo w_25'
 
     submit-button=`${data.SaveModification}`
     next='entrepreneur-account-edit-confirmation'
 )
 
-sib-link(class="backlink", next="entrepreneur-resource-list")= data.BackToDashboard
\ No newline at end of file
+sib-link(class="backlink", next="entrepreneur-account")= data.BackToDashboard
\ No newline at end of file
diff --git a/src/includes/mentor/components/header.pug b/src/includes/mentor/components/header.pug
index dc33c055..47dcf1f6 100644
--- a/src/includes/mentor/components/header.pug
+++ b/src/includes/mentor/components/header.pug
@@ -16,11 +16,13 @@
                 label-languages=''
                 naked
             )
+            
             .dropdownWrapper
                 sib-display#mentor_account_picture.dropdownLabel(
                     bind-user
-                    fields='account.picture',
-                    widget-account.picture='cs-account-picture'
+                    nested-field="account"
+                    fields="foaf:depiction"
+                    widget-foaf:depiction='cs-account-picture'
                 )
                 div.dropdownPanel
                     ul
diff --git a/src/includes/mentor/profile/detail.pug b/src/includes/mentor/profile/detail.pug
index 1df3c528..9cc61b3d 100644
--- a/src/includes/mentor/profile/detail.pug
+++ b/src/includes/mentor/profile/detail.pug
@@ -27,9 +27,10 @@ div.block_list.flex
 
         sib-display#mentor_info(
             bind-user
-            fields='account.picture, name, mentorProfile.headline, mentorProfile.city, mentorProfile.country.name, registered_on'
+            fields='account.picture, name, mentorProfile.organisation.name, mentorProfile.headline, mentorProfile.city, mentorProfile.country.name, registered_on'
             widget-account.picture='cs-profile-picture'
             widget-name='cs-display-property'
+            widget-mentorProfile.organisation.name='cs-display-property'
             widget-mentorProfile.headline='cs-display-property'
             widget-mentorProfile.city='cs-display-property'
             widget-mentorProfile.country.name='cs-display-property'
diff --git a/src/includes/mentor/profile/edit.pug b/src/includes/mentor/profile/edit.pug
index 08c42597..2e76aced 100644
--- a/src/includes/mentor/profile/edit.pug
+++ b/src/includes/mentor/profile/edit.pug
@@ -3,14 +3,13 @@ h2.title_create= data.EditYourAccount
 sib-form#mentor_profile_edition.block_log.block_creat_count(
     bind-user
     partial
-    fields="account_information(last_name, first_name, mentorProfile.organisation,\
+    fields="account_information(last_name, first_name,\
             mentorProfile.phone, mentorProfile.languages, mentorProfile.fields),\
             about_you(header_about_you, account.picture, mentorProfile.headline, mentorProfile.city, mentorProfile.country,\
             mentorProfile.biography, mentorProfile.skills),\
             social_media(header_social_media, mentorProfile.linkedin, mentorProfile.twitter), username"
     
     range-mentorProfile.fields=`${endpoints.fields}`
-    range-mentorProfile.organisation=`${endpoints.organisations}`
     range-mentorProfile.languages=`${endpoints.languages}`
     range-mentorProfile.country=`${endpoints.countries}`
 
@@ -22,7 +21,6 @@ sib-form#mentor_profile_edition.block_log.block_creat_count(
     
     label-first_name=`${data.Surname}`
     label-last_name=`${data.Name}`
-    label-mentorProfile.organisation=`${data.Organisation}`
     label-mentorProfile.phone=`${data.PhoneNumber}`
     label-mentorProfile.languages=`${data.Language}`
     label-mentorProfile.fields=`${data.Field}`
@@ -42,9 +40,6 @@ sib-form#mentor_profile_edition.block_log.block_creat_count(
     class-mentorProfile.country='form-label is-dark'
     widget-mentorProfile.country='sib-form-auto-completion'
 
-    class-mentorProfile.organisation='form-label is-dark'
-    widget-mentorProfile.organisation='sib-form-auto-completion'
-
     class-mentorProfile.languages='form-label is-dark'
     multiple-mentorProfile.languages='sib-multiple-select'
     widget-mentorProfile.languages='sib-form-auto-completion'
@@ -63,5 +58,20 @@ sib-form#mentor_profile_edition.block_log.block_creat_count(
     next="mentor-account-edit-confirmation"
 )
 
+sib-form#mentor_profile_organisation.block_log.block_creat_count(
+    partial
+    bind-user
+    nested-field="mentorProfile"
+    fields="organisation"
+
+    range-organisation=`${endpoints.organisations}`
+    label-organisation=`${data.Organisation}`
+    class-organisation='form-label is-dark input_big'
+    widget-organisation='sib-form-auto-completion'
+
+    submit-button=`${data.SaveModification}`
+    next='mentor-account-edit-confirmation'
+)
+
 sib-link(class="backlink", next="mentor-account")= data.BackToMyAccount
 sib-link(class="backlink", next="mentor-dashboard")= data.BackToDashboard
diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js
index 204c8850..c2efd63f 100644
--- a/src/scripts/coopstarter.js
+++ b/src/scripts/coopstarter.js
@@ -137,7 +137,9 @@ async function refreshUser(formId, listId) {
         profile.clearCache();
       } else {
         profile = await listProxy['mentorProfile'];
-        profile.clearCache();
+        if (profile) {
+          profile.clearCache();
+        }
       }
     }
   });
@@ -748,10 +750,15 @@ document.addEventListener("DOMContentLoaded", event => {
   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("entrepreneur_profile_organisation", "entrepreneur_info");
+  refreshUser("entrepreneur_profile_organisation", "entrepreneur_contact");
+  refreshUser("entrepreneur_profile_picture", "entrepreneur_account_picture");
   refreshUser("mentor_profile_edition", "mentor_info");
   refreshUser("mentor_profile_edition", "mentor_complementary");
   refreshUser("mentor_profile_edition", "mentor_contact");
+  refreshUser("mentor_profile_organisation", "mentor_info");
+  refreshUser("mentor_profile_organisation", "mentor_complementary");
+  refreshUser("mentor_profile_organisation", "mentor_contact");
   refreshUser("mentor_profile_edition", "mentor_account_picture");
 
   addProperFilterToSearchComponents("entrepreneur-resource-list");
-- 
GitLab