mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
refacto fonctions
This commit is contained in:
parent
1b0d2d425d
commit
9b09b0d59d
8 changed files with 191 additions and 163 deletions
|
@ -1,23 +1,35 @@
|
|||
|
||||
|
||||
/**
|
||||
* Gestion du formulaire d'horaires d'ouverture
|
||||
*
|
||||
*/
|
||||
const openingHoursFormManager = {
|
||||
defaultOpeningHours: '',
|
||||
init: function () {
|
||||
inputSelector: '',
|
||||
init: function (inputSelector = 'input[name="custom__opening_hours"]') {
|
||||
// Rechercher l'élément par son attribut name plutôt que par son id
|
||||
const openingHoursInput = document.querySelector('input[name="custom__opening_hours"]');
|
||||
this.setInputSelector(inputSelector);
|
||||
const openingHoursInput = document.querySelector(inputSelector);
|
||||
if (!openingHoursInput) {
|
||||
console.warn('Élément input[name="custom__opening_hours"] non trouvé');
|
||||
console.warn('Élément ', inputSelector, ' non trouvé');
|
||||
return;
|
||||
}
|
||||
this.defaultOpeningHours = openingHoursInput.value;
|
||||
|
||||
this.makeForm();
|
||||
this.makeForm(inputSelector);
|
||||
|
||||
if (this.defaultOpeningHours !== '') {
|
||||
this.parseOpeningHoursValue();
|
||||
this.parseOpeningHoursValue(inputSelector);
|
||||
}
|
||||
},
|
||||
parseOpeningHoursValue: function () {
|
||||
setInputSelector: function (inputSelector) {
|
||||
this.inputSelector = inputSelector;
|
||||
},
|
||||
/**
|
||||
* convertir les checkboxes et inputs en horaires OSM dans l'input de référence
|
||||
* @param {string} inputSelector
|
||||
*/
|
||||
parseOpeningHoursValue: function (inputSelector = 'input[name="custom__opening_hours"]') {
|
||||
// Analyser la chaîne d'horaires d'ouverture
|
||||
const parsedOpeningHours = {};
|
||||
|
||||
|
@ -78,8 +90,8 @@ const openingHoursFormManager = {
|
|||
|
||||
console.log(parsedOpeningHours);
|
||||
},
|
||||
makeForm: function () {
|
||||
const customOpeningHours = document.querySelector('input[name="custom__opening_hours"]');
|
||||
makeForm: function (inputSelector = 'input[name="custom__opening_hours"]') {
|
||||
const customOpeningHours = document.querySelector(inputSelector);
|
||||
console.log('makeForm customOpeningHours', customOpeningHours);
|
||||
|
||||
if (customOpeningHours) {
|
||||
|
@ -146,7 +158,7 @@ const openingHoursFormManager = {
|
|||
// Ajouter l'événement pour afficher/masquer les plages horaires
|
||||
input.addEventListener('change', (e) => {
|
||||
horairesContainer.classList.toggle('d-none', !e.target.checked);
|
||||
this.convertToOSMOpeningHours();
|
||||
this.convertToOSMOpeningHours(inputSelector);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -318,7 +330,7 @@ const openingHoursFormManager = {
|
|||
return container;
|
||||
},
|
||||
|
||||
convertToOSMOpeningHours: function () {
|
||||
convertToOSMOpeningHours: function (inputSelector = 'input[name="custom__opening_hours"]') {
|
||||
const jours = {
|
||||
'Lundi': 'Mo',
|
||||
'Mardi': 'Tu',
|
||||
|
@ -363,7 +375,7 @@ const openingHoursFormManager = {
|
|||
}
|
||||
|
||||
// Mettre à jour l'input custom__opening_hours
|
||||
const customOpeningHours = document.querySelector('input[name="custom__opening_hours"]');
|
||||
const customOpeningHours = document.querySelector(inputSelector);
|
||||
if (customOpeningHours) {
|
||||
customOpeningHours.value = osmFormat;
|
||||
}
|
||||
|
@ -386,3 +398,4 @@ const openingHoursFormManager = {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
window.openingHoursFormManager = openingHoursFormManager;
|
Loading…
Add table
Add a link
Reference in a new issue