]> _ Git - ccv-wordpress.git/commitdiff
wait #7041 @7:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 27 Aug 2024 16:10:50 +0000 (18:10 +0200)
committersoufiane <soufiane@cubedesigners.com>
Tue, 27 Aug 2024 16:10:50 +0000 (18:10 +0200)
wp-content/mu-plugins/cube/src/Forms/Base.php
wp-content/mu-plugins/cube/src/Forms/Builder/Fields/Text.php
wp-content/mu-plugins/cube/src/Forms/Consultation.php
wp-content/themes/CCV/resources/assets/scripts/forms/forms.js
wp-content/themes/CCV/resources/assets/scripts/forms/parsley-setup.js
wp-content/themes/CCV/resources/views/partials/content-form.blade.php

index f88a137861ab97ac351dac6216ff1e203e0bfc6b..164c02895ba4186fb357d971491d4ec7811e2558 100644 (file)
@@ -246,39 +246,60 @@ class Base
         $charset      = get_bloginfo('charset');
         $headers[]    = sprintf('Content-Type: %s; charset=%s', $content_type, $charset);
         $headers[]    = sprintf('From: %s', $from);
+        $first_data_names = [
+            'date-first-symptoms',
+            'imagery-condition',
+            'chirurgical-solutions'
+        ];
 
         // Gather filled fields into label/value pairs
+        foreach ($first_data_names as $first_data_name) {
+            if($this->fields[$first_data_name]) {
+                $data[$this->fields[$first_data_name]->get_title()] = $this->get_data($first_data_name);
+            }
+        }
         foreach ($this->fields as $field_name => $field) {
-            if ($value = $this->get_data($field_name)) {
-                $data[$field->get_title()] = $value;
+            if(!in_array($field_name,$first_data_names)) {
+                if ($value = $this->get_data($field_name)) {
+                    $data[$field->get_title()] = $value;
+                }
             }
         }
 
         $message = view('forms.common.email', compact('data', 'subject'));
 
-        // Hook directly into WPMailer temporarily so we can add attachments and set their proper filenames
-        add_action('phpmailer_init', [$this, 'attach_files']);
-        $success = wp_mail($to, $subject, $message, $headers);
-        remove_action('phpmailer_init', [$this, 'attach_files']);
-
-        if ($success) {
-            wp_send_json([
-                'message'  => [
-                    'type' => 'success',
-                    'text' => $this->config['success_message'],
-                ],
-                'hide_form' => true,
-            ]);
-        } else {
+        if($this->get_data('social-cover') === __('Accident du travail') && empty($this->get_data('work-accident'))) {
             wp_send_json([
                 'message'  => [
                     'type' => 'error',
-                    'text' => __("Erreur d'envoi du message. Veuillez réessayer.", "ccv"),
+                    'text' => __("Veuillez indiquer une date d'accident de travail.", "ccv"),
                 ]
             ]);
+        } else {
+            // Hook directly into WPMailer temporarily so we can add attachments and set their proper filenames
+            add_action('phpmailer_init', [$this, 'attach_files']);
+            $success = wp_mail($to, $subject, $message, $headers);
+            remove_action('phpmailer_init', [$this, 'attach_files']);
+
+            if ($success) {
+                wp_send_json([
+                    'message' => [
+                        'type' => 'success',
+                        'text' => $this->config['success_message'],
+                    ],
+                    'hide_form' => true,
+                ]);
+            } else {
+                wp_send_json([
+                    'message' => [
+                        'type' => 'error',
+                        'text' => __("Erreur d'envoi du message. Veuillez réessayer.", "ccv"),
+                    ]
+                ]);
+            }
+            $this->post_process();
         }
 
-        $this->post_process();
     }
 
     public function post_process() {}
index 4e27b31b713e6f7dde883b2eb79c42d5f9b44cd9..b2052b5588540da1f21911cabf029ddf7f1845e0 100644 (file)
@@ -9,9 +9,8 @@ class Text extends Field
     public function render($settings) {
         $name = $this->name;
         $type = "text";
-        $attr = "";
+        $attr = "data-parsley-valid-if='[data-parsley-id=170]'";
         if(strstr($name,'link')) {
-            $attr = "data-parsley-type='url'";
             $type = "url";
         }
         return '<input type="'.$type.'" name="'. $this->get_name() .'" placeholder="'. $settings['placeholder'] .'" '. $settings['validation'] . ' '.$attr.'>';
index 643b13d77b997000c25cf468ce2a5499b914ec98..da779ddd56d7d4327c357bec95963268a897c805 100644 (file)
@@ -81,7 +81,7 @@ class Consultation extends Base {
                                        'Dr Caroline HIRSH' => 'dr.hirsch@ccv-montpellier.fr',
                                ]),
 
-            Date::field('work-accident', __('Si accident de travail à quelle date ? ')),
+            Date::field('work-accident', __('Si accident de travail à quelle date ? '))->required(false),
 
                        //=== IMAGERY
                        // This is a special case and will be output manually so only using this for the e-mail label
@@ -144,23 +144,23 @@ class Consultation extends Base {
                        Binary::field('rheumatological', __('Suivi rhumatologique ou médecine spécialisée', 'ccv')),
             Textarea::field('surgeries', __('Indiquez ici vos précédentes chirurgies de la colonne et leurs dates (le cas échéant)', 'ccv'))->required(false),
 
-            Radio::field('imagery-condition', __('', 'ccv'))
+            Radio::field('imagery-condition', __('IRM de moins de 6 mois', 'ccv'))
                 ->options([
                 __('J\'ai bien noté que mon dossier ne pourra être étudié si je fournis pas une IRM de moins de 6 mois', 'ccv'),
             ]),
 
-            Text::field('link-1', __('Lien internet 1', 'ccv')),
-            Text::field('id-1', __('Identifiant', 'ccv')),
-            Password::field('pwd-1', __('Mot de passe', 'ccv')),
-            Text::field('link-2', __('Lien internet 2', 'ccv')),
-            Text::field('id-2', __('Identifiant 2', 'ccv')),
-            Password::field('pwd-2', __('Mot de passe 2', 'ccv')),
-            Text::field('link-3', __('Lien internet 3', 'ccv')),
-            Text::field('id-3', __('Identifiant 3', 'ccv')),
-            Password::field('pwd-3', __('Mot de passe 3', 'ccv')),
-            Text::field('link-4', __('Lien internet 4', 'ccv')),
-            Text::field('id-4', __('Identifiant 4', 'ccv')),
-            Password::field('pwd-4', __('Mot de passe 4', 'ccv')),
+            Text::field('link-1', __('Lien internet 1', 'ccv'))->required(false),
+            Text::field('id-1', __('Identifiant', 'ccv'))->required(false),
+            Password::field('pwd-1', __('Mot de passe', 'ccv'))->required(false),
+            Text::field('link-2', __('Lien internet 2', 'ccv'))->required(false),
+            Text::field('id-2', __('Identifiant 2', 'ccv'))->required(false),
+            Password::field('pwd-2', __('Mot de passe 2', 'ccv'))->required(false),
+            Text::field('link-3', __('Lien internet 3', 'ccv'))->required(false),
+            Text::field('id-3', __('Identifiant 3', 'ccv'))->required(false),
+            Password::field('pwd-3', __('Mot de passe 3', 'ccv'))->required(false),
+            Text::field('link-4', __('Lien internet 4', 'ccv'))->required(false),
+            Text::field('id-4', __('Identifiant 4', 'ccv'))->required(false),
+            Password::field('pwd-4', __('Mot de passe 4', 'ccv'))->required(false),
                ]);
        }
 
@@ -189,5 +189,9 @@ class Consultation extends Base {
                                $this->set_destination($surgeons[$this->get_data('surgeon')]);
                        }
                }
+
+        if($this->form_title === "appointment") {
+            $this->remove_field('surgeon');
+        }
        }
 }
index 784f142276af364ce345175fd897f71e70ed474e..b3d07473b0daf540867f603376eb4b1c9ea304c5 100644 (file)
@@ -95,6 +95,7 @@ function createRequestHandler (formEl) {
         // Should we hide form?
         if (response.hide_form) {
           formEl.querySelector('.cube-form-content').style.display = 'none'
+          formEl.querySelector('.cube-form-message').style.display = 'none'
         }
 
         // Should we redirect?
index dc4043ef95e600cb182282d2c15bbec8e53a6a10..e44cc8e940d07924289d3f433d5c5492a1f38c7a 100644 (file)
 
   $('.cube-form').parsley(parsleyConfig);
 
+  $('[name=social-cover]').on('change', function() {
+    var isChecked = $(this).is(':checked');
+    if (isChecked) {
+      let val = $(this).val()
+      if (val === 'Accident du travail') {
+        $('[name=work-accident]').attr('data-parsley-required', 'true').attr('required');
+      } else {
+        $('[name=work-accident]').attr('data-parsley-required', 'false').removeAttr('required');
+      }
+    }
+
+    // Re-validate the form to apply the changes
+    $('[name=work-accident]').parsley().validate();
+  });
+
+
   // On validation errors, scroll to the first invalid input
   $.listen('parsley:field:error', function() {
 
index 4b38004b7d4f71816db2c8ae21e30d6573942425..f94ae98f0b5b98da6df46b152a0c4db393ace6f1 100644 (file)
 
   <div class="custom-checkbox my-1v">
     <label>
-      <input type="checkbox" name="condition" required>
+      <input type="checkbox" name="imagery-condition" value="Oui" required>
       <span
         class="form-label text-lg font-normal leading-tight">{{ __('J\'ai bien noté que mon dossier ne pourra être étudié si je fournis pas une IRM de moins de 6 mois', 'ccv') }}</span>
       <span class="text-sm font-normal" style="margin-left: 33px;">{{ __('En cas de pathologies de scoliose, envoyez-nous impérativement une radiographie du rachis en totalité, en place de l\'IRM.', 'cvv') }}</span>
       {!! $form->field('message', ['class' => 'mt-6', 'title_class' => 'font-light']) !!}
 
       @if($form_name !== "appointment")
-      <div class="mt-4">
-        <div class="custom-checkbox mb-1">
-          <label>
-            <input type="checkbox" name="send-to-team" value="{{ __('Oui', 'ccv') }}" checked class="ml-2">
-            <span class="form-label-reversed">{{ __("J'envoie ma demande à l'équipe du CCV", 'ccv') }}</span>
-          </label>
+        <div class="mt-4">
+          <div class="custom-checkbox mb-1">
+            <label>
+              <input type="checkbox" name="send-to-team" value="{{ __('Oui', 'ccv') }}" checked class="ml-2">
+              <span class="form-label-reversed">{{ __("J'envoie ma demande à l'équipe du CCV", 'ccv') }}</span>
+            </label>
+          </div>
+          {{ __("ou je souhaite l'envoyer à un chirurgien spécifique :", 'ccv') }}
+
+          @php
+            // The options for this field contains the e-mail address as the value but we don't want to expose that here
+            // so we override options with a new array made up of just their names as both the key and value.
+            // Once the form is processed, this will be used to look up the e-mail address.
+            $surgeons = array_keys($form->get_field('surgeon')->get_options());
+            $surgeons_options = array_combine($surgeons, $surgeons);
+          @endphp
+          {!! $form->field('surgeon', [
+            'class' => 'mt-4',
+            'show_title' => false,
+            'options' => $surgeons_options,
+            'placeholder' => [
+              '' => __('Sélectionner', 'ccv') // First select option
+            ]
+          ]) !!}
         </div>
-        {{ __("ou je souhaite l'envoyer à un chirurgien spécifique :", 'ccv') }}
-
-        @php
-          // The options for this field contains the e-mail address as the value but we don't want to expose that here
-          // so we override options with a new array made up of just their names as both the key and value.
-          // Once the form is processed, this will be used to look up the e-mail address.
-          $surgeons = array_keys($form->get_field('surgeon')->get_options());
-          $surgeons_options = array_combine($surgeons, $surgeons);
-        @endphp
-        {!! $form->field('surgeon', [
-          'class' => 'mt-4',
-          'show_title' => false,
-          'options' => $surgeons_options,
-          'placeholder' => [
-            '' => __('Sélectionner', 'ccv') // First select option
-          ]
-        ]) !!}
-      </div>
       @endif
     </div>
 
   </form>
   <script>
     (function ($) {
+      $('[name=social-cover]').on('change', function() {
+        var isChecked = $(this).is(':checked');
+        if (isChecked) {
+          let val = $(this).val()
+          if (val === 'Accident du travail') {
+            $('[name=work-accident]').attr('data-parsley-required', 'true').attr('required');
+          } else {
+            $('[name=work-accident]').attr('data-parsley-required', 'false').removeAttr('required');
+          }
+        }
+
+        // Re-validate the form to apply the changes
+        $('[name=work-accident]').parsley().validate();
+      });
+
       // Clicking browse triggers the file form. It opens the dialog to capture images or browse files
       $('#phone-image-browse').on('click touchend', function () {
         $('#phone-file-upload-field').click();