{"version":3,"file":"medvigie.min.js","sources":["medvigie.min.js"],"sourcesContent":["(function (factory) {\n typeof define === 'function' && define.amd ? define(factory) :\n factory();\n}((function () { 'use strict';\n\n var utils = {\n /**\n * Get parent element matching selector\n * \n * @param {Element} $el \n * @param {string} selector\n */\n getParent: function getParent($el, selector) {\n for ( ; $el && $el !== document; $el = $el.parentNode) {\n if ($el.matches(selector)) {\n return $el;\n }\n }\n\n return null;\n },\n\n /**\n * Add leading zero to number\n * \n * @param {int|string} number \n * @param {int} length \n */\n pad: function pad(number, length) {\n var str = '' + number;\n while (str.length < length) {\n str = '0' + str;\n }\n\n return str;\n },\n\n /**\n * Replace line break by HTML break\n * \n * @param {string} str \n */\n nl2br: function nl2br(str) {\n return (str + '').replace(/([^>\\r\\n]?)(\\r\\n|\\n\\r|\\r|\\n)/g, '$1
');\n },\n\n /**\n * Get the transition duration of element\n * \n * @param {Element} $el \n * @param {boolean} inMS default: true\n */\n getElementTransitionDurationEnd: function getElementTransitionDurationEnd($el, inMS) {\n if (typeof inMS === 'undefined') {\n inMS = true;\n }\n\n var computedStyles = window.getComputedStyle($el);\n\n var duration = computedStyles.transitionDuration.split(',').map(function (n) { return parseFloat(n); }).filter(function (a, b) { return b > a; }).shift();\n\n return duration * (inMS ? 1000 : 1);\n },\n\n /**\n * Execute function at transition end\n * \n * @param {Element} $el \n * @param {CallableFunction} fn \n */\n onTransitionEnd: function onTransitionEnd($el, fn) {\n var computedStyles = window.getComputedStyle($el);\n\n var duration = 0;\n\n if (computedStyles.transitionDuration !== '0s') {\n duration = computedStyles.transitionDuration.split(',').map(function (n) { return parseFloat(n); });\n duration = Math.max.apply(Math, duration);\n }\n\n if (duration) {\n setTimeout(function () {\n fn($el);\n }, (duration * 1000) + 1);\n } else {\n fn($el);\n }\n },\n\n /**\n * Convert string to Element\n * \n * @param {String} html HTML representing a single element\n * \n * @return {Element}\n */\n htmlToElement: function htmlToElement(html) {\n var template = document.createElement('template');\n html = html.trim();\n template.innerHTML = html;\n return template.content.firstChild;\n },\n\n /**\n * Get dimensions of non-existent element in the DOM\n * \n * @param {Element} $el Non-existent element in the DOM\n * @param {Element} $ref The reference after which $el will be added\n * \n * @return {DOMRect}\n */\n getDimensionsOfFutureElement: function getDimensionsOfFutureElement($el, $ref) {\n var boundingClientRect = $ref.getBoundingClientRect();\n \n $el.setAttribute('aria-hidden', false);\n $el.style.position = 'fixed';\n $el.style.zIndex = '-1';\n $el.style.width = boundingClientRect.width + 'px';\n $el.style.opacity = '0';\n $el.style.visibility = 'hidden';\n\n $el = $ref.parentNode.insertBefore($el, $ref.nextElementSibling);\n\n var elementBoudingClientRect = $el.getBoundingClientRect();\n $el.remove();\n\n return elementBoudingClientRect;\n },\n\n /**\n * Fetch url\n * \n * @param {string} url \n * @param {string} method POST or GET\n * @param {Object} params \n * \n * @return {Object} Object with promise and xhr\n */\n sendHTTPRequest: function sendHTTPRequest(obj) {\n var this$1 = this;\n\n var xhr = new XMLHttpRequest();\n\n var promise = new Promise(function (resolve, reject) {\n xhr.open(obj.method || 'GET', obj.url);\n if (obj.headers) {\n Object.keys(obj.headers).forEach(function (key) {\n xhr.setRequestHeader(key, obj.headers[key]);\n });\n }\n xhr.onload = function () {\n if (xhr.status >= 200 && xhr.status < 300) {\n resolve(JSON.parse(xhr.response));\n } else {\n reject(xhr.statusText);\n }\n };\n xhr.onerror = function () { return reject(xhr.statusText); };\n\n var params = obj.body || {};\n var formData = new FormData();\n\n this$1.buildFormData(formData, params);\n\n xhr.send(formData);\n });\n\n return {\n promise: promise,\n xhr: xhr,\n };\n },\n\n /**\n * Convert Object to FormData\n * \n * @param {FormData} formData \n * @param {Object} data \n * @param {string} parentKey \n */\n buildFormData: function buildFormData(formData, data, parentKey) {\n var this$1 = this;\n\n if (data && typeof data === 'object' && !(data instanceof Date) && !(data instanceof File)) {\n Object.keys(data).forEach(function (key) {\n this$1.buildFormData(formData, data[key], parentKey ? (parentKey + \"[\" + key + \"]\") : key);\n });\n } else {\n var value = data === null ? '' : data;\n \n formData.append(parentKey, value);\n }\n },\n\n /**\n * Add CSS classes to hide and show element with animation\n * CSS classes: animation-hide, animation-show, hide\n * Options:\n * hide {boolean} Enable/disable the hidding class (default: false)\n * show {boolean} Enable/disable the showing class (default: false)\n * attr {Object} Attribute to pass to callbacks\n * afterHide {CallableFunction} Function fired after element disappear\n * afterShow {CallableFunction} Function fired after element appear\n * \n * @param {Element} $el Element to change\n * @param {Object} options Object of options\n */\n changeWithCSSAnimation: function changeWithCSSAnimation($el, options) {\n options.hide = typeof options.hide === 'undefined' || (typeof options.hide === 'boolean' && options.hide === true);\n options.show = typeof options.show === 'undefined' || (typeof options.show === 'boolean' && options.show === true);\n options.attr = typeof options.attr === 'object' ? options.attr : {};\n\n if (options.hide) {\n $el.classList.add('animation-hide');\n }\n\n utils.onTransitionEnd($el, function ($el) {\n if (options.hide) {\n $el.classList.add('hide');\n $el.classList.remove('animation-hide');\n\n if (typeof options.afterHide === 'function') {\n options.afterHide($el, options.attr);\n }\n }\n\n if (options.show) {\n $el.classList.add('animation-show');\n\n utils.onTransitionEnd($el, function () {\n $el.classList.remove('hide', 'animation-show');\n\n if (typeof options.afterShow === 'function') {\n options.afterShow($el, options.attr);\n }\n });\n }\n });\n }\n };\n\n var Registration = {\n els: {\n form: {\n $wrapper: null,\n rpps_error: null,\n rpps: null,\n first_name: null,\n last_name: null,\n postal_code: null,\n department: null,\n phone_label: null,\n password: null,\n show_button: null\n },\n },\n view_password_str: 'Voir le mot de passe',\n hide_password_str: 'Masquer le mot de passe',\n init: function init() {\n this.els.form.$wrapper = document.querySelector('#registration_form');\n if (this.els.form.$wrapper) {\n\n // Add HTML to form\n var target = document.querySelector('.elementor-field-group-password');\n\n target.insertAdjacentHTML('afterend', this.getPasswordVerificationHtmlContent());\n target.insertAdjacentHTML('afterend', this.getShowPasswordButtonHtmlContent());\n\n this.els.form.rpps = document.getElementById('form-field-rpps');\n this.els.form.rpps_error = document.getElementById('rpps-error-message').querySelector('p');\n this.els.form.rpps_error.style.display = 'none';\n this.els.form.first_name = document.getElementById('form-field-firstname');\n this.els.form.last_name = document.getElementById('form-field-lastname');\n\n this.els.form.password = document.getElementById('form-field-password');\n this.els.form.show_button = document.getElementById('togglePW');\n\n this.els.form.postal_code = document.getElementById('form-field-postal_code');\n this.els.form.department = document.getElementById('form-field-department');\n\n this.els.form.phone_label = document.querySelector('.elementor-field-group-phone label');\n\n this.initEvents();\n }\n },\n initEvents: function initEvents() {\n var this$1 = this;\n\n this.els.form.password.addEventListener(\"keyup\", function (e) {\n this$1.getPassword();\n });\n this.els.form.show_button.addEventListener(\"click\", function (e) {\n this$1.togglePassword();\n });\n\n // Auto-select department based on postal code input\n this.els.form.postal_code.addEventListener('keyup', function (e) {\n this$1.autoSelectDepartment(e.target.value);\n });\n\n // Add tooltip on phone label\n var phoneDescription = 'Il peut être nécessaire pour vous envoyer un code de sécurité ou vous contacter personnellement afin de vérifier votre identité à l\\'issue de votre inscription';\n var labelPhone = this.els.form.phone_label.innerHTML;\n this.els.form.phone_label.innerHTML = labelPhone + '
Erreur de chargement des données pour \" + key + \".
\";\n }\n });\n },\n\n getChartTitle: function getChartTitle(key) {\n var ref = key.split('-');\n var type = ref[0];\n var typeLabel = \"\";\n switch (type) {\n case 'ira':\n typeLabel = \"Infection respiratoire aiguë (IRA)\";\n break;\n case 'gastro':\n typeLabel = \"Gastro\";\n break;\n case 'varicelle':\n typeLabel = \"Varicelle\";\n break;\n case 'bronchio':\n typeLabel = \"Bronchiolite, chez les enfants de moins de 2 ans\";\n break;\n default:\n typeLabel = \"Taux d'incidence\";\n }\n\n return typeLabel;\n },\n\n getChartSubtitle: function getChartSubtitle(key) {\n var ref = key.split('-');\n var type = ref[0];\n var subtitleLabel = \"\";\n switch (type) {\n case 'ira':\n subtitleLabel = 'Source : Sentinelles et IQVIA (EMR)';\n break;\n case 'gastro':\n subtitleLabel = 'Source : Sentinelles et IQVIA (EMR)';\n break;\n case 'varicelle':\n subtitleLabel = 'Source : Sentinelles et IQVIA (EMR)';\n break;\n case 'bronchio':\n subtitleLabel = \"Source : IQVIA (EMR)\";\n break;\n default:\n subtitleLabel = \"\";\n }\n\n return subtitleLabel;\n },\n\n createHighcharts: function createHighcharts(containerId, titleText, subtitleText, data) {\n Highcharts.chart(containerId, {\n exporting: {\n buttons: {\n contextButton: {\n symbolStroke: '#343434',\n menuItems: [\n 'downloadPNG',\n 'downloadJPEG',\n 'downloadPDF',\n 'downloadSVG',\n 'separator',\n 'printChart'\n ],\n symbol: 'menu',\n theme: {\n fill: 'transparent',\n }\n }\n },\n },\n title: {\n text: titleText,\n align: 'left',\n style: {color: '#343434', fontWeight: '600', fontSize: '21px'},\n margin: 20\n },\n subtitle: {\n text: subtitleText,\n style: {color: 'red st', fontWeight: '300', fontSize: '12px'},\n align: 'left',\n margin: 40\n },\n chart: {\n backgroundColor: 'transparent',\n height: 400\n },\n xAxis: {\n title: {\n text: \"Semaine de l'année\",\n style: {color: '#343434'},\n },\n crosshair: true,\n type: 'category',\n labels: {\n style: {color: '#343434'},\n }\n },\n yAxis: {\n title: {\n text: \"Cas pour 100 000 habitants\",\n style: {color: '#343434'},\n },\n labels: {\n style: {color: '#343434'},\n }\n },\n tooltip: {\n crosshairs: true,\n shared: true,\n },\n data: {\n rows: data,\n seriesMapping: [\n {x: 0, low: 2, high: 3},\n {x: 0, low: 4, high: 5},\n {x: 0, y: 1}\n ],\n complete: function (options) {\n options.series[0].name = 'Min/MAX';\n options.series[1].name = 'Q1/Q3';\n options.series[2].name = 'Saison en cours';\n }\n },\n plotOptions: {\n series: {\n label: {\n connectorAllowed: false\n },\n marker: {\n enabled: false\n }\n }\n },\n series: [\n {\n type: 'arearange',\n color: '#FF0000',\n fillOpacity: 0.3\n },\n {\n type: 'arearange',\n color: '#FFA500',\n fillOpacity: 0.3\n },\n {\n type: 'spline',\n lineWidth: 3,\n color: 'steelblue'\n }\n ],\n responsive: {\n rules: [{\n condition: {\n maxWidth: 800\n },\n chartOptions: {\n legend: {\n enabled: true\n }\n }\n }]\n }\n });\n },\n\n initChartIndicators: function initChartIndicators() {\n var this$1 = this;\n\n fetch(ajaxurl, {\n method: \"POST\",\n body: new URLSearchParams({action: \"get_indicators_graph\"})\n })\n .then(function (response) { return response.json(); })\n .then(function (jsonData) {\n\n Highcharts.chart(this$1.els.$container_indicators.id, {\n exporting: {\n buttons: {\n contextButton: {\n symbolStroke: '#FFFFFF',\n menuItems: [\n 'downloadPNG',\n 'downloadJPEG',\n 'downloadPDF',\n 'downloadSVG',\n 'separator',\n 'printChart'\n ],\n symbol: 'menu',\n theme: {\n fill: 'transparent',\n }\n }\n },\n },\n chart: {\n height: 350,\n type: 'areaspline',\n backgroundColor: 'transparent'\n },\n title: {\n text: 'Suivi des contributions médecins vigies à la surveillance épidémiologique',\n align: 'left',\n style: {color: '#FFFFFF', fontWeight: '600', fontSize: '21px'},\n margin: 50\n },\n subtitle: {\n text: ''\n },\n xAxis: {\n title: {\n text: \"Semaines\",\n style: {color: '#FFFFFF'},\n },\n categories: jsonData.weeks,\n labels: {\n style: {color: '#FFFFFF'},\n },\n crosshair: true\n },\n yAxis: {\n title: {\n text: 'Pourcentage (%)',\n style: {color: '#FFFFFF'},\n },\n labels: {\n format: '{value} %',\n style: {color: '#FFFFFF'},\n },\n max: 100\n },\n tooltip: {\n shared: true,\n valueSuffix: ' %'\n },\n series: jsonData.series,\n colors: ['#e65f10', '#1167a8', '#16b8be', '#F24F13'],\n legend: {\n itemStyle: {\n color: '#FFFFFF',\n fontSize: '12px',\n fontWeight: '300',\n }\n },\n });\n\n })\n .catch(function (error) {\n console.error('Erreur AJAX get_indicators_graph:', error);\n });\n }\n };\n\n var Login = {\n els: {\n $wrapper: null,\n login_container: null,\n password_container: null,\n cms_container: null,\n login_form: {\n $wrapper: null,\n rpps: null,\n rpps_error: null,\n },\n password_form: {\n $wrapper: null,\n password: null,\n password_error: null,\n },\n user_email: null\n },\n init: function init() {\n this.els.$wrapper = document.querySelector('.js-login');\n if (this.els.$wrapper) {\n this.els.login_container = this.els.$wrapper.querySelector('.container-login');\n this.els.password_container = this.els.$wrapper.querySelector('.container-password');\n this.els.cms_container = this.els.$wrapper.querySelector('.container-cms');\n this.els.previous_step = this.els.$wrapper.querySelector('.previous-step');\n this.els.login_form.$wrapper = this.els.$wrapper.querySelector('#loginForm');\n this.els.login_form.rpps = this.els.login_form.$wrapper.querySelector('[name=\"login\"]');\n this.els.login_form.rpps_error = document.getElementById('rpps-error-message').querySelector('p');\n this.els.login_form.rpps_error.style.display = 'none';\n\n this.els.password_form.$wrapper = this.els.$wrapper.querySelector('#passwordForm');\n this.els.password_form.password = this.els.password_form.$wrapper.querySelector('[name=\"password\"]');\n this.els.password_form.password_error = document.getElementById('password-error-message').querySelector('p');\n this.els.password_form.password_error.style.display = 'none';\n\n this.initEvents();\n }\n },\n initEvents: function initEvents() {\n var this$1 = this;\n\n this.els.login_form.$wrapper.addEventListener('submit', function (e) {\n e.preventDefault();\n this$1.loginRPPS();\n });\n\n this.els.previous_step.addEventListener('click', function (e) {\n this$1.els.login_container.classList.remove('hidden');\n this$1.els.cms_container.classList.remove('hidden');\n this$1.els.password_container.classList.add('hidden');\n this$1.els.previous_step.classList.add('hidden');\n });\n\n this.els.password_form.$wrapper.addEventListener('submit', function (e) {\n e.preventDefault();\n this$1.loginPassword();\n });\n\n document.getElementById('toggle-password').addEventListener('click', function () {\n var passwordField = document.getElementById('password');\n var passwordToggleIcon = this.querySelector('img');\n\n var openEyeIcon = passwordToggleIcon.getAttribute('data-open');\n var closeEyeIcon = passwordToggleIcon.getAttribute('data-close');\n\n if (passwordField.type === 'password') {\n passwordField.type = 'text';\n passwordToggleIcon.src = closeEyeIcon;\n passwordToggleIcon.alt = \"Hide Password\";\n } else {\n passwordField.type = 'password';\n passwordToggleIcon.src = openEyeIcon;\n passwordToggleIcon.alt = \"Show Password\";\n }\n });\n\n this.els.password_form.password.addEventListener('input', function () {\n var password = this$1.els.password_form.password.value;\n var strength = this$1.getPasswordStrength(password);\n this$1.updatePasswordFeedback(strength);\n });\n },\n\n /**\n * Increment or decrement loading\n *\n * @param {boolean} increment\n */\n setLoading: function setLoading(increment) {\n this.loading = increment ? this.loading + 1 : this.loading - 1;\n\n if (this.loading > 0 && !this.els.$wrapper.classList.contains('loading')) {\n this.els.$wrapper.classList.add('loading');\n } else if (this.loading === 0) {\n this.els.$wrapper.classList.remove('loading');\n }\n },\n\n loginRPPS: function loginRPPS() {\n var this$1 = this;\n\n this.setLoading(true);\n\n var rppsValue = this.els.login_form.rpps.value;\n var hasError = false;\n var errorMessage = \"\";\n if (!rppsValue) {\n hasError = true;\n errorMessage = \"Veuillez saisir votre identifiant RPPS\";\n } else if (!Number.isInteger(parseInt(rppsValue))) {\n hasError = true;\n errorMessage = \"Identifiant RPPS invalide\";\n }\n if (hasError) {\n this.displayLoginError(errorMessage);\n } else {\n // Try login\n this.els.login_form.rpps_error.style.display = 'none';\n this.els.login_form.rpps_error.innerHTML = \"\";\n this.els.login_form.rpps.classList.remove('error');\n\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: 'POST',\n body: {\n action: 'login_with_rpps',\n params: JSON.stringify({\n rpps: rppsValue\n }),\n },\n });\n\n this.saveRequest.promise.then(function (data) {\n if (!data.response.success) {\n this$1.displayLoginError(data.response.errorMessage);\n } else {\n // Get use case\n var useCase = data.response.use_case;\n if (useCase === 'password') {\n this$1.els.login_container.classList.add('hidden');\n this$1.els.cms_container.classList.add('hidden');\n this$1.els.password_container.classList.remove('hidden');\n this$1.els.previous_step.classList.remove('hidden');\n this$1.els.user_email = data.response.user_email;\n } else if (useCase === 'inscription') {\n window.localStorage.setItem(\"userData\", JSON.stringify(data.response.user_data));\n window.location.href = \"/inscription/\";\n }\n }\n this$1.setLoading(false);\n this$1.saveRequest = null;\n }).catch(function (error) {\n this$1.displayLoginError(error);\n this$1.setLoading(false);\n this$1.saveRequest = null;\n });\n }\n },\n\n loginPassword: function loginPassword() {\n var this$1 = this;\n\n this.setLoading(true);\n\n var passwordValue = this.els.password_form.password.value;\n if (!passwordValue) {\n this.displayPasswordError(\"Veuillez saisir votre mot de pasee\");\n } else {\n // Try login with RPPS and password\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: 'POST',\n body: {\n action: 'login_with_email_and_password',\n params: JSON.stringify({\n email: this.els.user_email,\n password: passwordValue,\n }),\n },\n });\n\n this.saveRequest.promise.then(function (response) {\n if (!response.success) {\n this$1.displayPasswordError(response.errorMessage);\n } else {\n window.location.href = \"/dashboard\";\n }\n this$1.setLoading(false);\n this$1.saveRequest = null;\n }).catch(function (error) {\n this$1.displayPasswordError(error);\n this$1.setLoading(false);\n this$1.saveRequest = null;\n });\n }\n },\n\n displayLoginError: function displayLoginError(message) {\n this.els.login_form.rpps_error.innerHTML = message;\n this.els.login_form.rpps_error.style.display = 'block';\n this.els.login_form.rpps.classList.add('error');\n this.setLoading(false);\n },\n\n displayPasswordError: function displayPasswordError(message) {\n this.els.password_form.password_error.innerHTML = message;\n this.els.password_form.password_error.style.display = 'block';\n this.els.password_form.password.classList.add('error');\n this.setLoading(false);\n },\n\n getPasswordStrength: function getPasswordStrength(password) {\n var strength = 0;\n\n if (password.length < 8) {\n return strength;\n }\n\n if (/[A-Z]/.test(password)) { strength++; }\n if (/\\d/.test(password)) { strength++; }\n if (/[@$!%*?]/.test(password)) { strength++; }\n\n return strength;\n },\n updatePasswordFeedback: function updatePasswordFeedback(strength) {\n // Réinitialisation du message et des classes\n this.els.password_form.password_error.classList.remove('error', 'success');\n this.els.password_form.password_error.textContent = '';\n this.els.password_form.password.classList.remove('input-error', 'input-success'); // Réinitialisation des bordures\n this.els.passwordStrengthBar.className = 'password-strength-bar'; // Réinitialiser la barre de progression\n this.els.passwordStrengthBar.style.width = '0%'; // Réinitialiser la largeur de la barre\n\n // Sélection des icônes d'erreur et de succès\n var errorIcon = this.els.passwordValidationIcon.querySelector('img[alt=\"Error\"]');\n var successIcon = this.els.passwordValidationIcon.querySelector('img[alt=\"Success\"]');\n\n // Cache les icônes par défaut\n errorIcon.style.display = 'none';\n successIcon.style.display = 'none';\n\n // Mot de passe trop court ou Aucun critère validé\n if (this.els.password_form.password.value.length < 8 || strength === 0) {\n this.els.password_form.password_error.textContent = \"Le mot de passe doit comporter au moins 8 caractères, une majuscule, un chiffre, et un caractère spécial.\";\n this.els.password_form.password_error.classList.add('error');\n this.els.passwordStrengthBar.style.width = '0%'; // Barre vide\n this.els.password_form.password.classList.add('input-error'); // Ajouter la bordure rouge\n errorIcon.style.display = 'block'; // Afficher l'icône rouge\n }\n\n // Mot de passe valide mais niveau faible\n if (strength === 1) {\n this.els.password_form.password_error.innerHTML = \"Niveau de sécurité : FAIBLE\";\n this.els.password_form.password_error.classList.add('error');\n this.els.passwordStrengthBar.classList.add('low'); // Ajouter la classe \"low\"\n this.els.passwordStrengthBar.style.width = '33%'; // Remplir la barre à 33%\n this.els.password_form.password.classList.add('input-error'); // Ajouter la bordure rouge\n errorIcon.style.display = 'block'; // Afficher l'icône rouge\n } else if (strength === 2) {\n // Niveau moyen\n this.els.password_form.password_error.innerHTML = \"Niveau de sécurité : BIEN\";\n this.els.password_form.password_error.classList.add('success');\n this.els.passwordStrengthBar.classList.add('medium'); // Ajouter la classe \"medium\"\n this.els.passwordStrengthBar.style.width = '66%'; // Remplir la barre à 66%\n this.els.password_form.password.classList.add('input-success'); // Ajouter la bordure verte\n successIcon.style.display = 'block'; // Afficher l'icône verte\n } else if (strength >= 3) {\n // Niveau fort\n this.els.password_form.password_error.innerHTML = \"Niveau de sécurité : TRÈS BIEN\";\n this.els.password_form.password_error.classList.add('success');\n this.els.passwordStrengthBar.classList.add('high'); // Ajouter la classe \"high\"\n this.els.passwordStrengthBar.style.width = '100%'; // Remplir la barre à 100%\n this.els.password_form.password.classList.add('input-success'); // Ajouter la bordure verte\n successIcon.style.display = 'block'; // Afficher l'icône verte\n }\n }\n };\n\n var modal = {\n modalTitle: '',\n modalText: '',\n modalConfirmText: '',\n modalCancelText: '',\n modalType: '',\n onConfirm: null,\n onCancel: null,\n\n showModal: function (modalText, modalConfirmText, modalCancelText, onConfirm, onCancel) {\n this.modalText = modalText;\n this.modalConfirmText = modalConfirmText;\n this.modalCancelText = modalCancelText;\n this.onConfirm = onConfirm;\n this.onCancel = onCancel;\n this.renderModal();\n },\n renderModal: function () {\n var this$1 = this;\n\n var modal = document.createElement('div');\n modal.classList.add('modale');\n modal.innerHTML = \"\\n\" + (this.modalText) + \"
\\n \\n\" + (this.modalTitle) + \"
\\n\" + (this.modalText) + \"
\\n \\nVous devez choisir une fréquence
\\nIl n'existe aucun indicateur de renseigné.
\";\n } else {\n activeIndicators.forEach(function (indicator) {\n var isSelected = this$1.userIndicators.some(\n function (userIndicator) { return userIndicator.id &&\n parseInt(userIndicator.id) ===\n parseInt(indicator.id); }\n );\n var selectedClass = isSelected ? \"selected\" : \"\";\n indicatorButtons += \"\";\n\n if (isSelected) {\n this$1.selectedDiseases.push(parseInt(indicator.id));\n }\n });\n }\n\n var isAllSelected =\n this$1.selectedDiseases.length === activeIndicators.length;\n\n var modalHtml = \"\\n\" + (data.message) + \"
\"));\n resolve(false);\n return;\n }\n\n var categories = {};\n data.data.forEach(function (disease) {\n if (!categories[disease.category_index]) {\n categories[disease.category_index] = {\n name: disease.category,\n items: []\n };\n }\n categories[disease.category_index].items.push(disease);\n });\n\n var sortedCategories = Object.values(categories).sort(function (a, b) { return a.category_index - b.category_index; });\n var categoryTitleContainer = document.getElementById('categoryTitleContainer');\n if (categoryTitleContainer && sortedCategories.length > 0) {\n var firstCategory = sortedCategories[0];\n categoryTitleContainer.innerHTML = \"\" + (firstCategory.name);\n }\n\n sortedCategories.forEach(function (category, index) {\n if (index !== 0) {\n var header = \"\" + (category.name) + \"
\";\n this$1.els.tableItems.insertAdjacentHTML('beforeend', header);\n }\n category.items.forEach(function (disease) {\n var itemHTML = this$1.createItem(disease, category.name);\n this$1.els.tableItems.insertAdjacentHTML('beforeend', itemHTML);\n });\n });\n\n this$1.setupLateElements();\n this$1.bindLateEvents();\n\n EntryModeModal.loadUserEntryMode(function () {\n if (!EntryModeModal.entryMode || EntryModeModal.entryMode === 'no_subscription') {\n var modalTitle = \"Mode de saisie\";\n var modalText = \"Vous n'avez pas sélectionné de mode de saisie (journalier / hebdomadaire). Veuillez choisir le mode de saisie depuis la page Mon compte.\";\n var modalConfirmText = \"OK\";\n var modalType = \"error\";\n modal.showInformationModal(modalTitle, modalText, modalConfirmText, modalType, function () {\n modal.closeModal();\n });\n resolve(false);\n this$1.updateDateDisplay(EntryModeModal.entryMode);\n } else {\n this$1.updateDateDisplay(EntryModeModal.entryMode);\n this$1.getUserData();\n resolve(true);\n }\n });\n }).catch(function (error) {\n console.error('Error updating diseases list:', error);\n var modalTitle = \"Aucun indicateur\";\n var modalText = \"Vous n'êtes abonné à aucun indicateur. Vous pouvez vous abonner depuis la page Mon compte.\";\n var modalConfirmText = \"OK\";\n var modalType = \"error\";\n modal.showInformationModal(modalTitle, modalText, modalConfirmText, modalType, function () {\n modal.closeModal();\n });\n resolve(false);\n });\n });\n },\n createItem: function createItem(disease, categoryName) {\n return (\"\\n\" + (disease.title) + (disease.description ? (\"?\") : '') + \"
\\n\" + (data.message) + \"
\"));\n return;\n }\n data.surveys.forEach(function (survey, index) {\n if (index < 3) {\n this$1.els.surveyList.insertAdjacentHTML('beforeend', this$1.createSurveyItem(survey, index));\n }\n this$1.els.surveysBtn.style.display = 'flex';\n });\n }).catch(function (error) {\n console.error(\"error\", error);\n });\n },\n\n createSurveyItem: function createSurveyItem(survey) {\n var date = new Date(survey.date_published);\n var formattedMonth = (\"\" + (date.getMonth() + 1)).padStart(2, '0');\n var formattedDay = (\"\" + (date.getDate())).padStart(2, '0');\n var formattedDate = formattedDay + \".\" + formattedMonth;\n\n return (\"\\n \\n\" + formattedDate + \"
\\n\" + (survey.title) + \"
\\n \\n \");\n },\n\n updateAlertsList: function updateAlertsList() {\n var this$1 = this;\n\n this.request = utils.sendHTTPRequest({\n url: ajaxurl,\n method: 'POST',\n body: {\n action: 'fetch_alerts',\n }\n });\n\n this.request.promise.then(function (data) {\n this$1.els.alertsList.innerHTML = '';\n if (data.message) {\n this$1.els.alertsList.insertAdjacentHTML('beforeend', (\"\" + (data.message) + \"
\"));\n return;\n }\n data.alerts.forEach(function (alert, index) {\n if (index < 3) {\n this$1.els.alertsList.insertAdjacentHTML('beforeend', this$1.createAlertItem(alert, index));\n }\n this$1.els.alertsBtn.style.display = 'flex';\n });\n }).catch(function (error) {\n console.error(\"error\", error);\n });\n },\n\n createAlertItem: function createAlertItem(alert) {\n var date = new Date(alert.date_published);\n var formattedMonth = (\"\" + (date.getMonth() + 1)).padStart(2, '0');\n var formattedDay = (\"\" + (date.getDate())).padStart(2, '0');\n var formattedDate = formattedDay + \".\" + formattedMonth;\n\n var categoryColor = alert.category && alert.category.color ? alert.category.color : '#1267a8';\n var categoryName = alert.category ? alert.category.name : 'General';\n\n return (\"\\n \\n \" + categoryName + \"\\n\" + formattedDate + \"
\\n\" + (alert.title) + \"
\\n\" + (data.message) + \"
\"));\n this$1.els.alertTableHeader.style.display = 'none';\n return;\n }\n\n data.alerts.forEach(function (alert, index) {\n this$1.els.alertsTable.insertAdjacentHTML('beforeend', this$1.createAlertItem(alert, index));\n });\n\n this$1.els.totalPages = data.total_pages;\n this$1.renderPagination();\n\n }).catch(function (error) {\n console.error(\"error\", error);\n });\n },\n renderPagination: function renderPagination() {\n var this$1 = this;\n\n this.els.paginationContainer.innerHTML = '';\n\n if (this.els.totalPages <= 1) {\n return;\n }\n\n var paginationHTML = '';\n\n if (this.els.currentPage > 1) {\n paginationHTML +=\n \"\";\n }\n\n for (var i = 1; i <= this.els.totalPages; i++) {\n if (i === this.els.currentPage) {\n paginationHTML += \"\" + i + \"\";\n } else {\n paginationHTML += \"\";\n }\n }\n\n if (this.els.currentPage < this.els.totalPages) {\n paginationHTML +=\n \"\";\n }\n\n this.els.paginationContainer.innerHTML = paginationHTML;\n\n var paginationButtons = this.els.paginationContainer.querySelectorAll('.pagination-btn');\n paginationButtons.forEach(function (button) {\n button.addEventListener('click', function (event) {\n var page = parseInt(event.currentTarget.getAttribute('data-page'), 10);\n if (page !== this$1.els.currentPage) {\n this$1.updateAlertsList(page);\n }\n });\n });\n },\n createAlertItem: function createAlertItem(alert) {\n var date = new Date(alert.date_published);\n var formattedMonth = (\"\" + (date.getMonth() + 1)).padStart(2, '0');\n var formattedDay = (\"\" + (date.getDate())).padStart(2, '0');\n var formattedYear = \"\" + (date.getFullYear());\n var formattedDate = formattedDay + \"/\" + formattedMonth + \"/\" + formattedYear;\n\n var formattedcriticality = '';\n if (alert.criticality) {\n formattedcriticality = alert.criticality.slug\n .toLowerCase()\n .normalize('NFD')\n .replace(/[\\u0300-\\u036f]/g, '');\n }\n\n function getImageElement(formattedcriticality) {\n return formattedcriticality ? (\"\" + (alert.title) + \"
\\n\" + formattedDate + \"
\\n\" + highestTerritory + (hasMoreLevels ? '...' : '') + \"
\\n\\n \" + (getImageElement(formattedcriticality)) + \" \\n \" + (alert.criticality.name) + \"\\n
\\n\" + categoryName + \"
\\n \\n \");\n },\n };\n\n var Surveys = {\n els: {\n surveysTable: null,\n paginationContainer: null,\n currentPage: 1,\n totalPages: 1,\n surveyTableHeader: null,\n singleSurvey: null,\n surveyCompleted: null,\n surveyLink: null,\n },\n init: function init() {\n this.els.$wrapper = document.querySelector('.surveys');\n if (this.els.$wrapper) {\n this.setupElements();\n this.updateSurveysList();\n }\n this.els.$singleWrapper = document.querySelector('.single-survey');\n if (this.els.$singleWrapper) {\n this.checkIfCompleted();\n this.setupSingleElements();\n }\n },\n setupElements: function setupElements() {\n this.els.surveysTable = document.querySelector('.surveys__table__items');\n this.els.paginationContainer = document.querySelector('.surveys__pagination');\n this.els.surveyTableHeader = document.querySelector('.surveys__table__header');\n },\n setupSingleElements: function setupSingleElements() {\n this.els.surveyLink = document.getElementById('surveyLink');\n this.els.surveyCompleted = document.querySelector('.survey-completed');\n },\n updateSurveysList: function updateSurveysList(page, itemsPerPage) {\n var this$1 = this;\n if ( page === void 0 ) page = 1;\n if ( itemsPerPage === void 0 ) itemsPerPage = 6;\n\n this.els.currentPage = page;\n\n this.request = utils.sendHTTPRequest({\n url: ajaxurl,\n method: 'POST',\n body: {\n action: 'fetch_surveys',\n page: page,\n items_per_page: itemsPerPage,\n }\n });\n\n this.request.promise.then(function (response) {\n var data = response;\n\n this$1.els.surveysTable.innerHTML = '';\n\n if (data.message) {\n this$1.els.surveysTable.insertAdjacentHTML('beforeend', (\"\" + (data.message) + \"
\"));\n this$1.els.surveyTableHeader.style.display = 'none';\n return;\n }\n\n data.surveys.forEach(function (survey, index) {\n this$1.els.surveysTable.insertAdjacentHTML('beforeend', this$1.createSurveyItem(survey, index));\n });\n\n this$1.els.totalPages = data.total_pages;\n this$1.renderPagination();\n\n }).catch(function (error) {\n console.error(\"error\", error);\n });\n },\n renderPagination: function renderPagination() {\n var this$1 = this;\n\n this.els.paginationContainer.innerHTML = '';\n\n if (this.els.totalPages <= 1) {\n return;\n }\n\n var paginationHTML = '';\n\n // Bouton \"Précédent\"\n\n if (this.els.currentPage > 1) {\n paginationHTML +=\n \"\";\n }\n\n for (var i = 1; i <= this.els.totalPages; i++) {\n if (i === this.els.currentPage) {\n paginationHTML += \"\" + i + \"\";\n } else {\n paginationHTML += \"\";\n }\n }\n\n if (this.els.currentPage < this.els.totalPages) {\n paginationHTML +=\n \"\";\n }\n\n this.els.paginationContainer.innerHTML = paginationHTML;\n\n var paginationButtons = this.els.paginationContainer.querySelectorAll('.pagination-btn');\n paginationButtons.forEach(function (button) {\n button.addEventListener('click', function (event) {\n var page = parseInt(event.currentTarget.getAttribute('data-page'), 10);\n if (page !== this$1.els.currentPage) {\n this$1.updateSurveysList(page); // Naviguer vers la page choisie\n }\n });\n });\n },\n createSurveyItem: function createSurveyItem(survey, index) {\n var date = new Date(survey.date_published);\n var formattedMonth = (\"\" + (date.getMonth() + 1)).padStart(2, '0');\n var formattedDay = (\"\" + (date.getDate())).padStart(2, '0');\n var formattedYear = \"\" + (date.getFullYear());\n var formattedDate = formattedDay + \"/\" + formattedMonth + \"/\" + formattedYear;\n\n var state = '';\n var formattedState = '';\n\n fetch(ajaxurl, {\n method: 'POST',\n credentials: 'same-origin',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: new URLSearchParams({\n 'action': 'gw_check_survey_status',\n 'form_id': survey.form_id,\n })\n })\n .then(function (response) { return response.json(); })\n .then(function (data) {\n if (data.success) {\n state = data.data.status;\n formattedState = state.replace(/\\s+/g, '').toLowerCase();\n } else {\n console.error('Failed to check completion status', data);\n }\n document.querySelector((\"#survey-item-\" + index + \" .survey__item__state\")).textContent = state;\n document.querySelector((\"#survey-item-\" + index)).classList.add((\"survey__item__state--\" + formattedState));\n })\n .catch(function (error) {\n console.error(\"Error\", error);\n });\n return (\"\\n\" + (survey.title) + \"
\\n\" + formattedDate + \"
\\n\" + indicatorText + \"
\";\n this$1.els.$accountFormFrequency = this$1.els.$wrapper.querySelector(\".account__form__frequency\");\n if (this$1.selectedDiseases.length === 0) {\n this$1.els.$accountFormFrequency.style.display = \"none\";\n } else {\n this$1.els.$accountFormFrequency.style.display = \"block\";\n }\n\n this$1.updateIndicatorButtons();\n\n })\n .catch(function (error) {\n console.error(\"Erreur lors de la récupération des indicateurs :\", error);\n this$1.els.$userEpidemyHtml.innerHTML = \"Erreur lors du chargement des épidémies.
\";\n });\n },\n selectAllDiseases: function selectAllDiseases() {\n if (this.selectedDiseases.length === this.allEpidemy.length) {\n this.selectedDiseases = [];\n this.els.$wrapper.querySelector(\".select-all\").checked = false;\n } else {\n this.selectedDiseases = this.allEpidemy.map(function (indicator) { return indicator.id; });\n this.els.$wrapper.querySelector(\".select-all\").checked = true;\n }\n this.updateIndicatorButtons();\n },\n deselectAllDiseases: function deselectAllDiseases() {\n this.selectedDiseases = [];\n this.els.$wrapper.querySelector(\".select-custom\").checked = true;\n this.updateIndicatorButtons();\n },\n updateIndicatorButtons: function updateIndicatorButtons() {\n var this$1 = this;\n\n var indicatorListDiv = this.els.$wrapper.querySelector(\".indicator-list\");\n\n indicatorListDiv.innerHTML = \"\";\n\n if (this.allEpidemy.length === 0) {\n this.updateSelectionState();\n }\n\n this.allEpidemy.forEach(function (indicator) {\n var isSelected = this$1.selectedDiseases.includes(indicator.id);\n var button = document.createElement(\"button\");\n button.className = \"indicator-btn \" + (isSelected ? \"selected\" : \"\");\n button.textContent = indicator.title;\n button.dataset.indicatorId = indicator.id;\n\n button.addEventListener(\"click\", function (e) {\n var id = parseInt(e.target.dataset.indicatorId);\n var index = this$1.selectedDiseases.indexOf(id);\n if (index > -1) {\n this$1.selectedDiseases.splice(index, 1);\n e.target.classList.remove(\"selected\");\n } else {\n this$1.selectedDiseases.push(id);\n e.target.classList.add(\"selected\");\n }\n this$1.updateSelectionState();\n });\n\n indicatorListDiv.appendChild(button);\n });\n this.updateSelectionState();\n },\n updateSelectionState: function updateSelectionState() {\n var allSelectedRadio = this.els.$wrapper.querySelector(\".select-all\");\n var allSelectedBtn = this.els.$wrapper.querySelector(\".all-selected\");\n var customSelectedBtn = this.els.$wrapper.querySelector(\".custom-selected\");\n var customSelectedRadio = this.els.$wrapper.querySelector(\".select-custom\");\n\n if (this.selectedDiseases.length === this.allEpidemy.length) {\n allSelectedRadio.checked = true;\n allSelectedBtn.classList.add(\"selected\");\n customSelectedBtn.classList.remove(\"selected\");\n } else {\n allSelectedRadio.checked = false;\n allSelectedBtn.classList.remove(\"selected\");\n customSelectedBtn.classList.add(\"selected\");\n customSelectedRadio.checked = true;\n }\n },\n saveEpidemySelection: function saveEpidemySelection() {\n var this$1 = this;\n\n var formData = new FormData();\n formData.append(\"action\", \"save_user_indicator_selection\");\n var tabOfIndicators = [];\n this.selectedDiseases.forEach(function (indicatorId) {\n formData.append(\"indicator_subscription_0_indicator[]\", indicatorId);\n tabOfIndicators.push(indicatorId);\n });\n\n if (this.selectedDiseases.length === 0) {\n var confirmationMessage = \"Vous n’avez sélectionné aucun indicateur, êtes-vous sûr de ne pas vouloir contribuer ?\";\n var confirmText = \"Oui\";\n var cancelText = \"Non\";\n modal.showModal(confirmationMessage, confirmText, cancelText, function () {\n fetch(ajaxurl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: 'action=set_user_indicator_empty',\n credentials: 'same-origin',\n })\n .then(function (response) { return response.json(); })\n .catch(function (error) {\n console.error('Erreur réseau ou de serveur :', error);\n });\n\n location.reload();\n }, function () {\n modal.closeModal();\n });\n }\n\n fetch(ajaxurl, {\n method: \"POST\",\n body: formData,\n })\n .then(function (response) { return response.json(); })\n .then(function (data) {\n if (data.success) {\n this$1.getUserEpidemy();\n //find id into allEpidemy and add selected\n this$1.els.$userEpidemy = \"\";\n this$1.allEpidemy.forEach(function (indicator) {\n tabOfIndicators.forEach(function (userIndicator) {\n if (indicator.id === userIndicator) {\n if (this$1.els.$userEpidemy.length > 0) {\n this$1.els.$userEpidemy += \", \";\n }\n this$1.els.$userEpidemy += indicator.title;\n }\n });\n });\n //For no reload with ajax request\n this$1.els.$userEpidemyAfterSave = true;\n this$1.els.$userEpidemyHtml.innerHTML = this$1.els.$userEpidemy;\n if (this$1.els.$userEpidemyHtml.innerHTML === \"\") {\n this$1.els.$userEpidemyHtml.innerHTML =\n \"Aucun abonnement aux indicateurs\";\n }\n\n this$1.calculatePercentage();\n } else {\n console.error(\n \"Erreur lors de la sauvegarde des indicateurs:\",\n data.data\n );\n }\n })\n .catch(function (error) {\n console.error(\"Erreur AJAX lors de la sauvegarde:\", error);\n });\n\n //Close part\n this.els.$wrapper.querySelector(\"#update_epidemy .skip__button\").click();\n this.loadData();\n },\n updatePassword: function updatePassword(newPassword) {\n if (newPassword) {\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: \"POST\",\n body: {\n action: \"update_password\",\n params: JSON.stringify({\n newPassword: newPassword,\n }),\n },\n });\n }\n },\n updateName: function updateName(newFirstname, newLastName) {\n var this$1 = this;\n\n if (newFirstname && newLastName) {\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: \"POST\",\n body: {\n action: \"update_name\",\n params: JSON.stringify({\n newFirstname: newFirstname,\n newLastname: newLastName,\n }),\n },\n });\n\n this.saveRequest.promise.then(function (response) {\n if (response.success) {\n this$1.els.$userNameHtml.innerHTML = newFirstname + \" \" + newLastName;\n this$1.els.$userFirstName = newFirstname;\n this$1.els.$userLastName = newLastName;\n } else {\n console.error(\"error\", response.data);\n }\n });\n }\n },\n updateEmail: function updateEmail(newEmail) {\n var this$1 = this;\n\n if (newEmail) {\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: \"POST\",\n body: {\n action: \"update_email\",\n params: JSON.stringify({\n newEmail: newEmail,\n }),\n },\n });\n this.saveRequest.promise.then(function (response) {\n if (response.success) {\n this$1.els.$userEmailHtml.innerHTML = newEmail;\n this$1.els.$userEmail = newEmail;\n } else {\n console.error(\"error when update mail\");\n }\n });\n }\n },\n updatePhone: function updatePhone(newPhone) {\n var this$1 = this;\n\n if (newPhone) {\n this.saveRequest = utils.sendHTTPRequest({\n url: ajaxurl,\n method: \"POST\",\n body: {\n action: \"update_cellphone\",\n params: JSON.stringify({\n newCellphone: newPhone,\n }),\n },\n });\n this.saveRequest.promise.then(function (response) {\n if (response.success) {\n this$1.els.$userPhoneHtml.innerHTML = newPhone;\n this$1.els.$userPhone = newPhone;\n } else {\n console.error(\"error when update phone\");\n }\n });\n }\n },\n loadUserEntryMode: function loadUserEntryMode() {\n var this$1 = this;\n\n fetch(ajaxurl, {\n method: \"POST\",\n credentials: \"same-origin\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: new URLSearchParams({\n action: \"get_entry_mode\",\n }),\n })\n .then(function (response) { return response.json(); })\n .then(function (data) {\n this$1.entryMode = data.data.entryMode;\n\n if (this$1.entryMode) {\n if (this$1.entryMode.toLowerCase() === \"weekly\") {\n this$1.els.$wrapper.querySelector(\"#frequency .form__data\").innerHTML = \"Une fois par semaine\";\n } else if (this$1.entryMode.toLowerCase() === \"daily\") {\n this$1.els.$wrapper.querySelector(\"#frequency .form__data\").innerHTML = \"Une fois par jour\";\n } else {\n this$1.els.$wrapper.querySelector(\"#frequency .form__data\").innerHTML = \"Aucun mode de saisie défini\";\n }\n }\n\n if (this$1.els.$wrapper.querySelector(\"#frequency .indicator-options\")) {\n this$1.els.$wrapper.querySelector(\"#frequency .indicator-options\").remove();\n }\n if (this$1.els.$wrapper.querySelector(\"#update_frequency .title__data\")) {\n this$1.els.$wrapper.querySelector(\"#update_frequency .title__data\").remove();\n }\n\n var frequencyHtml = \"\\nFréquence de saisie des indicateurs
\\n