// //Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:17:38 // $(document).ready(function() { }); // Initialize multiselect with existing text values // Initialize multiselect based on text input values function initMultiselect(multiselectId, textInputId) { const multiselect = document.getElementById(multiselectId); const textInput = document.getElementById(textInputId); if (!multiselect || !textInput) { console.error('Could not find elements with provided IDs'); return; } textInput.value.split(',').forEach(value => { const option = Array.from(multiselect.options) .find(opt => opt.value === value.trim()); if (option) option.selected = true; }); } // Update text input when multiselect changes function updateTextInput(multiselectId, textInputId) { const multiselect = document.getElementById(multiselectId); const textInput = document.getElementById(textInputId); if (!multiselect || !textInput) { console.error('Could not find elements with provided IDs'); return; } const selectedValues = Array.from(multiselect.selectedOptions) .map(option => option.value); const currentValues = textInput.value.split(',') .map(code => code.trim()) .filter(code => code !== ''); const updatedValuesSet = new Set(currentValues); selectedValues.forEach(value => updatedValuesSet.add(value)); currentValues.forEach(code => { if (!selectedValues.includes(code) && multiselect.querySelector(`option[value="${code}"]`)) { updatedValuesSet.delete(code); } }); textInput.value = Array.from(updatedValuesSet).join(','); } // Initialize on page load document.addEventListener('DOMContentLoaded', () => { initMultiselect('CountrySelect_select','AccumCountryCodes_text'); initMultiselect('RBLList_select','RBLList_text'); initMultiselect('SBLList_select','SBLList_text'); initMultiselect('URIBLList_select','URIBLList_text'); // Add change listener to multiselect document.getElementById('CountrySelect_select') .addEventListener('click', () => updateTextInput('CountrySelect_select','AccumCountryCodes_text')); document.getElementById('RBLList_select') .addEventListener('click', () => updateTextInput('RBLList_select','RBLList_text')); document.getElementById('SBLList_select') .addEventListener('click', () => updateTextInput('SBLList_select','SBLList_text')); document.getElementById('URIBLList_select') .addEventListener('click', () => updateTextInput('URIBLList_select','URIBLList_text')); }); /** * Date Select Manager * * This script manages an HTML select element with dates and updates an HTML object * based on the selected date. It sets the initial value to yesterday's date (or the latest date available), * updates the object's data parameter, and refreshes the display. */ // Wait for DOM to be fully loaded before executing document.addEventListener('DOMContentLoaded', function() { // Initialize all date selects and their corresponding objects initializeSelects(); }); function initializeSelects() { // Find all select elements with IDs starting with "StatsDate_select" const selects = document.querySelectorAll('select[id^="StatsDate_select"]'); selects.forEach(function(dateSelect) { const selectId = dateSelect.id; // Find the corresponding object element // If the select has a numeric suffix, look for object with same suffix const objectId = selectId === 'StatsDate_select' ? 'mailstats_object' : 'mailstats_object' + selectId.replace('StatsDate_select', ''); const mailstatsObject = document.getElementById(objectId); const mailstatsfull = document.getElementById('mailstats-full-window'); // Check if elements exist before proceeding if (!dateSelect) { console.error(`Select element with ID "${selectId}" not found.`); return; // Skip this pair if select doesn't exist } if (!mailstatsObject) { console.error(`Object element with ID "${objectId}" not found.`); // Continue anyway, as we can still set the select to the right date } // Function to update the object's data parameter and refresh it function updateMailstatsObject(date) { if (date && mailstatsObject) { try { // Create the full URL including the selected date const currentDomain = window.location.origin; const fullUrl = `${currentDomain}/mailstats/mailstats_for_${date}.html`; // Update the data attribute with the full URL mailstatsObject.setAttribute('data', fullUrl); mailstatsfull.setAttribute('href', fullUrl); // Force a refresh of the object // [refresh code here] console.log(`Updated object to show data from: ${fullUrl}`); } catch (error) { console.error(`Error updating object:`, error); } } } // Set the initial value of the select const yesterdayDate = getYesterdayDate(); let dateFound = false; // Find and select the option with yesterday's date for (let i = 0; i < dateSelect.options.length; i++) { if (dateSelect.options[i].value === yesterdayDate) { dateSelect.selectedIndex = i; dateFound = true; break; } } // If yesterday's date is not found, select the latest date (last option) if (!dateFound && dateSelect.options.length > 0) { dateSelect.selectedIndex = dateSelect.options.length - 1; console.log(`Yesterday's date (${yesterdayDate}) not found in options for ${selectId}. Selected the latest date instead: ${dateSelect.value}`); } // Update the object with the initial date if (dateSelect.value) { updateMailstatsObject(dateSelect.value); } // Add event listener for changes to the select element dateSelect.addEventListener('change', function() { const selectedDate = this.value; updateMailstatsObject(selectedDate); }); }); } // Function to get yesterday's date in YYYY-MM-DD format function getYesterdayDate() { const today = new Date(); const yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); const year = yesterday.getFullYear(); const month = String(yesterday.getMonth() + 1).padStart(2, '0'); const day = String(yesterday.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; } // // disable enable RBL/SBL/URIBL list selection // // Example html formatting to use it. //