From b57e30bb8115e1ab109db52aa44ad772d9889ad2 Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Tue, 7 Apr 2020 21:36:18 +0200
Subject: [PATCH] Adding check on fields content before proposing submission

---
 src/includes/mentor/profile/create.pug | 14 +++++++-------
 src/includes/mentor/profile/edit.pug   |  2 +-
 src/scripts/coopstarter.js             | 22 ++++++++++++++++++++++
 src/styles/index.scss                  |  5 +++++
 4 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/includes/mentor/profile/create.pug b/src/includes/mentor/profile/create.pug
index 0cd81b9c..c8ee6818 100644
--- a/src/includes/mentor/profile/create.pug
+++ b/src/includes/mentor/profile/create.pug
@@ -28,17 +28,17 @@ sib-form#mentor_profile_creation.block_log.block_creat_count(
     widget-header_social_media="cs-section_header"
     widget-header_about_you="cs-section_introduction"
     
-    label-first_name=`${data.Surname}`
-    label-last_name=`${data.Name}`
-    label-mentorProfile.organisation=`${data.Organisation}`
+    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}`
+    label-mentorProfile.languages=`${data.Language} *`
+    label-mentorProfile.fields=`${data.Field} *`
     label-account.picture=`${data.Photo}`
     label-mentorProfile.headline=`${data.Headline}`
     class-mentorProfile.headline="w_75"
-    label-mentorProfile.city=`${data.City}`
-    label-mentorProfile.country=`${data.Country}`
+    label-mentorProfile.city=`${data.City} *`
+    label-mentorProfile.country=`${data.Country} *`
     label-mentorProfile.biography=`${data.ActivitiesMore}`
     label-mentorProfile.skills=`${data.SkillForSearcher}`
     label-mentorProfile.linkedin="Linkedin"
diff --git a/src/includes/mentor/profile/edit.pug b/src/includes/mentor/profile/edit.pug
index 7be96a99..f0c7efba 100644
--- a/src/includes/mentor/profile/edit.pug
+++ b/src/includes/mentor/profile/edit.pug
@@ -26,7 +26,6 @@ sib-form#mentor_profile_edition.block_log.block_creat_count(
     label-mentorProfile.phone=`${data.PhoneNumber}`
     label-mentorProfile.languages=`${data.Language}`
     label-mentorProfile.fields=`${data.Field}`
-    label-account.picture=`${data.Photo}`
     label-mentorProfile.headline=`${data.Headline}`
     class-mentorProfile.headline="w_75"
     label-mentorProfile.city=`${data.City}`
@@ -57,6 +56,7 @@ sib-form#mentor_profile_edition.block_log.block_creat_count(
     upload-url-account.picture=`${sdn}upload/`
     widget-account.picture='cs-form-profile-picture'
     class-account.picture='input_photo w_25'
+    label-account.picture=`${data.Photo}`
     class-headline='w_75'
 
     submit-button=`${data.SaveModification}`
diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js
index 86d98f49..1f7f039e 100644
--- a/src/scripts/coopstarter.js
+++ b/src/scripts/coopstarter.js
@@ -590,6 +590,28 @@ jQuery(document).ready(function($) {
     }, 2000);
   });
 
+  const mentorCreationForm = document.getElementById('mentor_profile_creation');
+  mentorCreationForm.addEventListener("populate", e => {
+    let submitInput = mentorCreationForm.querySelectorAll('input[type=submit]')[0];
+    submitInput.disabled = true;
+    submitInput.classList.add('disabled');
+    const textInputs = mentorCreationForm.querySelectorAll('input[type="text"]');
+    textInputs.forEach(function(text_input) {
+      text_input.addEventListener('focusout', (() => {
+        if (mentorCreationForm.querySelectorAll('input[name="first_name"]')[0].value != "" &&
+            mentorCreationForm.querySelectorAll('input[name="last_name"]')[0].value != "" &&
+            mentorCreationForm.querySelectorAll('input[name="mentorProfile.city"]')[0].value != "" &&
+            mentorCreationForm.querySelectorAll('select[name="mentorProfile.languages"]')[0].value != "" &&
+            mentorCreationForm.querySelectorAll('select[name="mentorProfile.fields"]')[0].value != "" &&
+            mentorCreationForm.querySelectorAll('select[name="mentorProfile.country"]')[0].value != "") {
+          let submitInput = mentorCreationForm.querySelectorAll('input[type=submit]')[0];
+          submitInput.disabled = false;
+          submitInput.classList.remove('disabled');
+        }
+      }));
+    });
+  });
+
   //Set the share links
   $(".twitter-link").on("populate", function (e) {
     var regexContributor = /mentor/g
diff --git a/src/styles/index.scss b/src/styles/index.scss
index 7314d640..bba7c755 100644
--- a/src/styles/index.scss
+++ b/src/styles/index.scss
@@ -227,6 +227,11 @@ body{
     box-shadow: none;
 }
 
+input[type="submit"].disabled {
+    pointer-events: none;
+    opacity: .35;
+}
+
 .button_base, input[type="submit"], #mentor-resource-detail a, #entrepreneur-resource-detail a,
 #mentor-resource-validate a, .sib-conversation form input[type="submit"],
 #public-resource-detail a,  #mentor-database-resource-detail a{
-- 
GitLab