templates/planning/edit.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Rendez-vous{% endblock %}
  3. {% block body %}
  4.     {% include 'breadcrumb.html.twig' with {level1: 'Planning', level2: 'Edition'} %}
  5.     <div class="page-header">
  6.         <h1>{% if rdv.client %}
  7.                 {{ rdv.client.civilite }}  {{ rdv.client.lastname|capitalize }} {{ rdv.client.roomNumber }}
  8.                {% endif %}
  9.             {% for product in rdv.rdvProducts %}
  10.            {{ product.product.ui }},
  11.             {% endfor %}
  12.         </h1>
  13.     <div>
  14.         Référence contrat : {{ rdv.contract ? rdv.contract.id : '' }}
  15.     </div>
  16.         <div>
  17.             Batiment / Étage / Numéro de chambre : {{ rdv.client.roomNumber }}
  18.         </div>
  19.     </div>
  20.     {% if rdv.status == 'validated' and canBill %}
  21.         <div style="padding: 20px">
  22.             <a class="btn btn-success " href="{{ path('billing_new_rdv', {id : rdv.id}) }}">Facturer</a>
  23.         </div>
  24.     {% endif %}
  25.     <input type="hidden" id="minuteIncrement" value="{{ minuteIncrement }}" />
  26.     {{ include('planning/_form.html.twig', {'button_label': 'Update'}) }}
  27.     <a class="btn btn-outline-info back-button" href="{{ path('app_planning_site') }}">Revenir au planning</a>
  28.     {% if not is_granted('ROLE_COIFFEUR') %}
  29.             {{ include('planning/_delete_form.html.twig') }}
  30.     {% endif %}
  31.     <style>
  32.         #rdv_products {
  33.             height: 200px;
  34.         }
  35.         {% if rdv.status == 'validated' %}
  36.         select.form-control{
  37.             background-color: green;
  38.             color:white;
  39.         }
  40.         {% endif %}
  41.         {% if rdv.status == 'cancel' %}
  42.         select.form-control{
  43.             background-color: red;
  44.             color:white;
  45.         }
  46.         {% endif %}
  47.     </style>
  48. {% endblock %}
  49. {% block javascripts %}
  50.     {{ parent() }}
  51.     <script type="text/javascript">
  52.         // Pass the role information to JavaScript
  53.         var isCoiffeur = {{ is_granted('ROLE_COIFFEUR') ? 'true' : 'false' }};
  54.     </script>
  55.     <script type="text/javascript">
  56.         jQuery.fn.preventDoubleSubmission = function() {
  57.             $(this).on('submit',function(e){
  58.                 var $form = $(this);
  59.                 if ($form.data('submitted') === true) {
  60.                     // Previously submitted - don't submit again
  61.                     e.preventDefault();
  62.                 } else {
  63.                     // Mark it so that the next submit can be ignored
  64.                     $form.data('submitted', true);
  65.                 }
  66.             });
  67.             // Keep chainability
  68.             return this;
  69.         };
  70.         $('#edit_form_rdv').preventDoubleSubmission();
  71.         $('#save-edit').on('click', (e) => {
  72.             e.preventDefault();
  73.             notie.confirm({
  74.                 text: 'Etes vous sur de vouloir enregister?',
  75.                 submitText: 'Confirmer', // optional, default = 'Yes'
  76.                 cancelText: 'Annuler', // optional, default = 'Cancel'
  77.                 submitCallback: function () {
  78.                     if($('#rdv_cancelReason').val() == '1' || $('#rdv_cancelReason').val() == '8') {
  79.                         const text = $('#rdv_cancelReason').val() == '1' ? 'Cette action entrainera la suppression de tous les RDV à venir et l’envoi d’une lettre de condoléance' : 'Cette action entrainera la suppression de tous les RDV à venir.';
  80.                         notie.confirm({
  81.                             text: text,
  82.                             submitText: 'Confirmer', // optional, default = 'Yes'
  83.                             cancelText: 'Annuler', // optional, default = 'Cancel'
  84.                             submitCallback: function () {
  85.                                 $('#edit_form_rdv').unbind();
  86.                                 $('#edit_form_rdv').submit();
  87.                             },
  88.                             cancelCallback: function () {
  89.                                 return false;
  90.                             }
  91.                         });
  92.                     }
  93.                     else {
  94.                         $('#edit_form_rdv').unbind();
  95.                         $('#edit_form_rdv').submit();
  96.                     }
  97.                 }, // optional
  98.                 cancelCallback: function () {
  99.                     return false;
  100.                 } // optional
  101.             });
  102.         })
  103.         $('#rdv_products').select2({ width: '100%' });
  104.         var flatpickrConfig = {
  105.             'dateFormat' : 'Y-m-d H:i',
  106.             'altFormat' : 'd-m-Y H:i',
  107.             'altInput': true,
  108.             'enableTime': true,
  109.             "locale": "fr",
  110.             minuteIncrement: jQuery('#minuteIncrement').val(),
  111.         };
  112.         function restrictFutureDates(selectedDates, dateStr, instance) {
  113.             console.log(selectedDates[0]);
  114.             var selectedDate = selectedDates[0];
  115.             if(selectedDate){
  116.                 selectedDate.setHours(0, 0, 0, 0);
  117.             }
  118.             var today = new Date();
  119.             today.setHours(0, 0, 0, 0);
  120.             if (selectedDate && selectedDate > today) {
  121.                 // Prevent selecting future dates
  122.                 instance.clear(); // Clear the selected date
  123.                 alert("Vous ne pouvez pas sélectionner une date dans le futur.");
  124.             }
  125.         }
  126.         if (isCoiffeur) {
  127.             var today = new Date();
  128.             var tomorrow = new Date(today);
  129.             flatpickrConfig['onChange'] = restrictFutureDates;
  130.         }
  131.         $('#rdv_start').flatpickr(flatpickrConfig);
  132.         $('#rdv_end').flatpickr(flatpickrConfig);
  133.         if($('#rdv_status').val() !== 'cancel') {
  134.             $('#rdv_cancelReason').parent('.form-group').hide();
  135.         }
  136.         $('#rdv_status').on('change', function () {
  137.             if($('#rdv_status').val() !== 'cancel') {
  138.                 $('#rdv_cancelReason').parent('.form-group').hide();
  139.             } else {
  140.                 $('#rdv_cancelReason').parent('.form-group').show();
  141.             }
  142.         })
  143.         $('#rdv_cancelReason').on('change',function (){
  144.             if($('#rdv_cancelReason').val() == '12') {
  145.                 alert('Attention le RDV ne sera pas replanifié');
  146.             }
  147.         });
  148.         document.addEventListener('DOMContentLoaded', function() {
  149.             // Prevent changing the select field
  150.             document.querySelector('select[name="rdv[client]"]').addEventListener('mousedown', function(event) {
  151.                 event.preventDefault(); // Prevent any interaction
  152.             });
  153.             document.querySelector('select[name="rdv[salon]"]').addEventListener('mousedown', function(event) {
  154.                 event.preventDefault(); // Prevent any interaction
  155.             });
  156.         });
  157.         document.addEventListener('DOMContentLoaded', function() {
  158.             const chequeReceptionField = document.getElementById('rdv_chequeReception');
  159.             const infoChequeField = document.getElementById('rdv_infoCheque');
  160.             // Function to send AJAX request to save the field
  161.             function autoSaveField(field, value) {
  162.                 fetch('{{ path('rdv_auto_save') }}', {
  163.                     method: 'POST',
  164.                     headers: {
  165.                         'Content-Type': 'application/json',
  166.                         'X-Requested-With': 'XMLHttpRequest',
  167.                         'X-CSRF-Token': '{{ csrf_token('rdv_auto_save') }}' // Ensure CSRF token is valid
  168.                     },
  169.                     body: JSON.stringify({
  170.                         field: field,
  171.                         value: value,
  172.                         rdvId: '{{ rdv.id }}' // Pass the RDV ID if needed
  173.                     })
  174.                 })
  175.                         .then(response => response.json())
  176.                         .then(data => {
  177.                             if (data.success) {
  178.                                 console.log(`${field} auto-saved.`);
  179.                             } else {
  180.                                 console.error(`Failed to auto-save ${field}.`);
  181.                             }
  182.                         })
  183.                         .catch(error => console.error('Error:', error));
  184.             }
  185.             // Event listeners for changes on the fields
  186.             function addAutoSaveEventListener(field, fieldName) {
  187.                 // Handle checkboxes separately
  188.                 if (field.type === 'checkbox') {
  189.                     field.addEventListener('change', (event) => {
  190.                         autoSaveField(fieldName, event.target.checked ? 1 : 0); // Save as 1 for checked, 0 for unchecked
  191.                     });
  192.                 } else {
  193.                     field.addEventListener('input', (event) => {
  194.                         autoSaveField(fieldName, event.target.value);
  195.                     });
  196.                 }
  197.             }
  198.             addAutoSaveEventListener(chequeReceptionField, 'chequeReception');
  199.             addAutoSaveEventListener(infoChequeField, 'infoCheque');
  200.         });
  201.     </script>
  202. {% endblock %}