From 89475c0aa389249255c193252547eb8f8b9af155 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Thu, 10 Apr 2025 09:02:57 +0100 Subject: [PATCH] Enable/disable rbl,sbl,uribl setting according to db property --- .../themes/default/public/js/mailstats.js | 102 ++++++++++++++---- .../templates/partials/_mst_CONFIG.html.ep | 80 +++++++++----- 2 files changed, 137 insertions(+), 45 deletions(-) diff --git a/root/usr/share/smanager/themes/default/public/js/mailstats.js b/root/usr/share/smanager/themes/default/public/js/mailstats.js index 98076d7..da5b573 100644 --- a/root/usr/share/smanager/themes/default/public/js/mailstats.js +++ b/root/usr/share/smanager/themes/default/public/js/mailstats.js @@ -5,53 +5,71 @@ $(document).ready(function() { }); // Initialize multiselect with existing text values -function initMultiselect() { - const multiselect = document.getElementById('CountrySelect_select'); - const textInput = document.getElementById('AccumCountryCodes_text'); +// Initialize multiselect based on text input values +function initMultiselect(multiselectId, textInputId) { + const multiselect = document.getElementById(multiselectId); + const textInput = document.getElementById(textInputId); - // Split text input values and select corresponding options + 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()); + 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() { - const multiselect = document.getElementById('CountrySelect_select'); - const textInput = document.getElementById('AccumCountryCodes_text'); +function updateTextInput(multiselectId, textInputId) { + const multiselect = document.getElementById(multiselectId); + const textInput = document.getElementById(textInputId); - // Get selected values from the multiselect as an array - const selectedValues = Array.from(multiselect.selectedOptions).map(option => option.value); + if (!multiselect || !textInput) { + console.error('Could not find elements with provided IDs'); + return; + } + + const selectedValues = Array.from(multiselect.selectedOptions) + .map(option => option.value); - // Split the current value of the text input into an array of codes - const currentValues = textInput.value.split(',').map(code => code.trim()).filter(code => code !== ''); + const currentValues = textInput.value.split(',') + .map(code => code.trim()) + .filter(code => code !== ''); - // Create a new set to manage the codes const updatedValuesSet = new Set(currentValues); - // Add selected values to the set selectedValues.forEach(value => updatedValuesSet.add(value)); - // Remove values from the set that are no longer selected but were added via the multiselect currentValues.forEach(code => { - if (!selectedValues.includes(code) && multiselect.querySelector(`option[value="${code}"]`)) { + if (!selectedValues.includes(code) && + multiselect.querySelector(`option[value="${code}"]`)) { updatedValuesSet.delete(code); } }); - // Update the text input with the updated values, preserving manually added codes textInput.value = Array.from(updatedValuesSet).join(','); } // Initialize on page load document.addEventListener('DOMContentLoaded', () => { - initMultiselect(); + 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); + .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')); }); /** @@ -159,4 +177,48 @@ function getYesterdayDate() { 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. +//
+ // + + //
+ // + //
+//
+// or , 'data-mailstats-control' => undef, 'data-mailstats-target' => "RBL_group" for mojo html helper +// +document.addEventListener('DOMContentLoaded', () => { + // Initialize all control pairs + document.querySelectorAll('[data-mailstats-group]').forEach(group => { + const select = group.querySelector('select[data-mailstats-control]'); + const target = document.getElementById(select.dataset.mailstatsTarget); + + if (!select || !target) { + console.error('Control group misconfigured', group); + return; + } + + // Initial state + updateState(target, select.value === 'enabled'); + + // Change listener + select.addEventListener('change', () => + updateState(target, select.value === 'enabled') + ); + }); +}); + +function updateState(target, enabled) { + target.style.opacity = enabled ? '1' : '0.5'; + target.style.pointerEvents = enabled ? 'auto' : 'none'; + target.style.filter = enabled ? 'none' : 'grayscale(50%)'; + target.setAttribute('aria-disabled', !enabled); } \ No newline at end of file diff --git a/root/usr/share/smanager/themes/default/templates/partials/_mst_CONFIG.html.ep b/root/usr/share/smanager/themes/default/templates/partials/_mst_CONFIG.html.ep index 4d91510..19c2cdd 100644 --- a/root/usr/share/smanager/themes/default/templates/partials/_mst_CONFIG.html.ep +++ b/root/usr/share/smanager/themes/default/templates/partials/_mst_CONFIG.html.ep @@ -2,11 +2,6 @@ %# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:17:38 %#
- % if (config->{debug} == 1) {
 			%= dumper $mst_data
@@ -134,51 +129,86 @@
 			% param 'AccumCountryCodes' => $mst_data->{AccumCountryCodes} unless param 'AccumCountryCodes';
 			%= text_field 'AccumCountryCodes', size => '50', class => 'textinput AccumCountryCodes' , pattern=>'.*' , placeholder=>'AccumCountryCodes', title =>'Pattern regex mismatch', id => 'AccumCountryCodes_text'
 		

- + +

%=l('mst_Enable_RHSBL_checking') % my @EnableRHSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % param 'EnableRHSBL' => $mst_data->{EnableRHSBL} unless param 'EnableRHSBL'; - %= select_field 'EnableRHSBL' => @EnableRHSBL_options, class => 'input', id => 'EnableRHSBL_select' + %= select_field 'EnableRHSBL' => @EnableRHSBL_options, class => 'input', id => 'EnableRHSBL_select', 'data-mailstats-control' => undef, 'data-mailstats-target' => "RBL_group"

+
+

+ %=l('mst_Select_the_RBL_Lists') + + % my @RBLSelect_options = $c->get_RBL_lists(); + % param 'RBLSelect' => $mst_data->{RBLSelect} unless param 'RBLSelect'; + %= select_field 'RBLSelect' => @RBLSelect_options, class => 'input', id => 'RBLList_select', multiple => 'multiple' +

+ +

+ %=l('mst_RBL_Servers_to_use') + + % param 'RBLList' => $mst_data->{RBLList} unless param 'RBLList'; + %= text_field 'RBLList', size => '50', class => 'textinput RBLList' , pattern=>'.*' , placeholder=>'RBLList', title =>'Pattern regex mismatch', id => 'RBLList_text' +

+
+
+

%=l('mst_Enable_DNSBL_checking') % my @EnableDNSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % param 'EnableDNSBL' => $mst_data->{EnableDNSBL} unless param 'EnableDNSBL'; - %= select_field 'EnableDNSBL' => @EnableDNSBL_options, class => 'input', id => 'EnableDNSBL_select' + %= select_field 'EnableDNSBL' => @EnableDNSBL_options, class => 'input', id => 'EnableDNSBL_select' , 'data-mailstats-control' => undef, 'data-mailstats-target' => "SBL_group"

+ +
+

+ %=l('mst_Select_the_SBL_Lists') + + % my @SBLSelect_options = $c->get_SBL_lists(); + % param 'SBLSelect' => $mst_data->{SBLSelect} unless param 'SBLSelect'; + %= select_field 'SBLSelect' => @SBLSelect_options, class => 'input', id => 'SBLList_select', multiple => 'multiple' +

+ +

+ %=l('mst_SBL_Servers_to_use') + + % param 'SBLList' => $mst_data->{SBLList} unless param 'SBLList'; + %= text_field 'SBLList', size => '50', class => 'textinput SBLList' , pattern=>'.*' , placeholder=>'SBLList', title =>'Pattern regex mismatch', id => "SBLList_text" +

+
+
+

%=l('mst_Enable_URIBL_checking') % my @EnableURIBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % param 'EnableURIBL' => $mst_data->{EnableURIBL} unless param 'EnableURIBL'; - %= select_field 'EnableURIBL' => @EnableURIBL_options, class => 'input', id => 'EnableURIBL_select' + %= select_field 'EnableURIBL' => @EnableURIBL_options, class => 'input', id => 'EnableURIBL_select' , 'data-mailstats-control' => undef, 'data-mailstats-target' => "URIBL_group"

- + +

- %=l('mst_RBL_Servers_to_use') + %=l('mst_Select_the_URIBL_Lists') - % param 'RBLList' => $mst_data->{RBLList} unless param 'RBLList'; - %= text_field 'RBLList', size => '50', class => 'textinput RBLList' , pattern=>'.*' , placeholder=>'RBLList', title =>'Pattern regex mismatch' -

- + % my @URIBLSelect_options = $c->get_URIBL_lists(); + % param 'URIBLSelect' => $mst_data->{URIBLSelect} unless param 'URIBLSelect'; + %= select_field 'URIBLSelect' => @URIBLSelect_options, class => 'input', id => 'URIBLList_select', multiple => 'multiple' +

+

- %=l('mst_SBL_Servers_to_use') + %=l('mst_URIBL_Servers_to_use') - % param 'SBLList' => $mst_data->{SBLList} unless param 'SBLList'; - %= text_field 'SBLList', size => '50', class => 'textinput SBLList' , pattern=>'.*' , placeholder=>'SBLList', title =>'Pattern regex mismatch' -

- -

- %=l('mst_UBL_Servers_to_use') - - % param 'UBLList' => $mst_data->{UBLList} unless param 'UBLList'; - %= text_field 'UBLList', size => '50', class => 'textinput UBLList' , pattern=>'.*' , placeholder=>'UBLList', title =>'Pattern regex mismatch' + % param 'URIBLList' => $mst_data->{URIBLList} unless param 'URIBLList'; + %= text_field 'URIBLList', size => '50', class => 'textinput URIBLList' , pattern=>'.*' , placeholder=>'URIBLList', title =>'Pattern regex mismatch', id => 'URIBLList_text'

+
+

<%=l('mst_Spamassassin_scores_-_tag_and')%>