/** * Dashboard Modal & Multi-step Form Handlers */ jQuery(document).ready(function($) { // Modal elements const $fabButton = $('.mf-floating-action-button'); const $modalOverlay = $('.mf-modal-overlay'); const $modalContainer = $('.mf-modal-container'); const $modalClose = $('.mf-modal-close'); const $backBtn = $('.mf-back-btn'); const $nextBtn = $('.mf-next-btn'); // Step indicators const $stepDots = $('.mf-step-dot'); let $steps = $('.mf-step'); // Selection buttons const $selectionButtons = $('.mf-selection-button'); // Current step and selected type let currentStep = 0; let selectedType = ''; let domainData = { domain: '', isValid: false, usesCloudFlare: false, cloudflareZoneId: '', cloudflareEmail: '', cloudflareKey: '', hasMX: false, configureMailferno: false, emailAccounts: [] }; // Open Modal $fabButton.on('click', function() { resetForm(); $modalOverlay.addClass('active'); }); // Close Modal $modalClose.on('click', closeModal); $modalOverlay.on('click', function(e) { if (e.target === this) { closeModal(); } }); function closeModal() { $modalOverlay.removeClass('active'); resetForm(); } // Reset Form function resetForm() { currentStep = 0; selectedType = ''; domainData = { domain: '', isValid: false, usesCloudFlare: false, cloudflareZoneId: '', cloudflareEmail: '', cloudflareKey: '', hasMX: false, configureMailferno: false, emailAccounts: [] }; $selectionButtons.removeClass('selected'); updateStepIndicators(); showCurrentStep(); $('.mf-validation-error').hide(); $('.mf-success-message, .mf-error-message').remove(); $('.mf-loading').hide(); $('#mf-domain-input').val(''); $('#mf-cloudflare-email').val(''); $('#mf-cloudflare-key').val(''); $('.mf-mx-option').removeClass('selected'); $('.mf-email-row:not(:first)').remove(); $('.mf-email-row input').val(''); } // Selection buttons $selectionButtons.on('click', function() { $selectionButtons.removeClass('selected'); $(this).addClass('selected'); selectedType = $(this).data('type'); $nextBtn.removeClass('disabled'); }); // Navigation buttons $backBtn.on('click', function() { if (currentStep > 0) { currentStep--; updateStepIndicators(); showCurrentStep(); } }); $nextBtn.on('click', function() { if ($(this).hasClass('disabled')) return; // Handle first step (selection) if (currentStep === 0) { if (!selectedType) { alert('Please select an option to continue'); return; } // Set up next steps based on selection setupStepsByType(selectedType); currentStep++; updateStepIndicators(); showCurrentStep(); return; } // Domain specific step handling if (selectedType === 'domain') { const result = handleDomainStep(currentStep); if (!result) return; // If step validation fails, don't proceed } // If we reach here, move to next step currentStep++; updateStepIndicators(); showCurrentStep(); }); // Update step indicators function updateStepIndicators() { $stepDots.removeClass('active completed'); // Update for current setup $stepDots.each(function(index) { if (index < currentStep) { $(this).addClass('completed'); } else if (index === currentStep) { $(this).addClass('active'); } }); // Update back button visibility if (currentStep === 0) { $backBtn.hide(); } else { $backBtn.show(); } // Update next button text const isLastStep = (currentStep === $steps.length - 1); $nextBtn.text(isLastStep ? 'Next' : 'Next'); // When on selection step, disable next until selection made if (currentStep === 0) { $nextBtn.toggleClass('disabled', !selectedType); } else { $nextBtn.removeClass('disabled'); } } // Show current step function showCurrentStep() { $steps.removeClass('active'); $steps.eq(currentStep).addClass('active'); } // Setup steps by selected type function setupStepsByType(type) { // Hide all steps except the first one $steps.not(':first').remove(); // Clear step indicators $('.mf-steps-indicator').empty(); let stepCount = 1; // Selection step if (type === 'domain') { // Step 1: Input domain $('
How would you like to configure email for this domain?
') .append('') .append('Would you like to create email accounts for this domain now?
') .append('You can now continue to manage your domain, email accounts, and campaigns from the dashboard.
') .appendTo($modalContainer.find('.mf-modal-body')); stepCount++; } else if (type === 'campaign') { // Add campaign specific steps $('Campaign creation functionality will be implemented here.
') .appendTo($modalContainer.find('.mf-modal-body')); stepCount++; // Final step $('Email account creation functionality will be implemented here.
') .appendTo($modalContainer.find('.mf-modal-body')); stepCount++; // Final step $('