/** * Order Manager - Handles order form functionality */ class OrderManager { constructor() { this.selectedConfiguration = null; } // Setup order button click handler setupOrderButton(domManager) { const orderButton = domManager.get('orderButton'); if (orderButton) { orderButton.addEventListener('click', (e) => { e.preventDefault(); this.handleOrderClick(); }); } } // Handle order button click handleOrderClick() { if (this.selectedConfiguration) { // Pre-fill the contact form with configuration details this.prefillContactForm(); // Scroll to the contact form const contactForm = document.getElementById('order-form'); if (contactForm) { contactForm.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } } // Pre-fill contact form with selected configuration prefillContactForm() { if (!this.selectedConfiguration) return; const config = this.selectedConfiguration; // Create configuration summary message const configMessage = this.generateConfigurationMessage(config); // Find and fill the message textarea in the contact form const messageField = document.querySelector('#order-form textarea[name="message"]'); if (messageField) { messageField.value = configMessage; } // Store configuration details in hidden field const detailsField = document.querySelector('#order-form input[name="details"]'); if (detailsField) { detailsField.value = JSON.stringify({ plan: config.planName, vcpus: config.vcpus, memory: config.memory, storage: config.storage, instances: config.instances, serviceLevel: config.serviceLevel, totalPrice: config.totalPrice, addons: config.addons || [] }); } } // Generate human-readable configuration message generateConfigurationMessage(config) { let message = `I would like to order the following configuration: Plan: ${config.planName} (${config.planGroup}) vCPUs: ${config.vcpus} Memory: ${config.memory} GB Storage: ${config.storage} GB Instances: ${config.instances} Service Level: ${config.serviceLevel}`; // Add addons to the message if any are selected if (config.addons && config.addons.length > 0) { message += '\n\nSelected Add-ons:'; config.addons.forEach(addon => { message += `\n- ${addon.name}: CHF ${addon.price}`; }); } message += `\n\nTotal Monthly Price: CHF ${config.totalPrice} Please contact me with next steps for ordering this configuration.`; return message; } // Store current configuration for order button storeConfiguration(plan, config, serviceLevel, totalPrice, addons) { this.selectedConfiguration = { planName: plan.compute_plan, planGroup: plan.groupName, vcpus: plan.vcpus, memory: plan.ram, storage: config.storage, instances: config.instances, serviceLevel: serviceLevel, totalPrice: totalPrice, addons: addons }; } // Get stored configuration getStoredConfiguration() { return this.selectedConfiguration; } } // Export for use in other modules window.OrderManager = OrderManager;