From c8c224cfb83495a8100d91c39de66bebff098e93 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 4 Jun 2025 16:58:47 +0200 Subject: [PATCH] order button implementation to send message --- hub/services/static/js/price-calculator.js | 86 +++++++++++++++++++ .../services/embedded_contact_form.html | 19 +++- .../templates/services/offering_detail.html | 14 ++- 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/hub/services/static/js/price-calculator.js b/hub/services/static/js/price-calculator.js index a8dd8ff..e5dde85 100644 --- a/hub/services/static/js/price-calculator.js +++ b/hub/services/static/js/price-calculator.js @@ -8,6 +8,7 @@ class PriceCalculator { this.pricingData = null; this.storagePrice = 0.15; // CHF per GB per month this.currentOffering = null; + this.selectedConfiguration = null; this.init(); } @@ -29,6 +30,9 @@ class PriceCalculator { if (this.currentOffering) { this.loadPricingData(); } + + // Setup order button click handler + this.setupOrderButton(); } // Initialize DOM element references @@ -59,6 +63,77 @@ class PriceCalculator { this.storagePriceEl = document.getElementById('storagePrice'); this.storageAmount = document.getElementById('storageAmount'); this.totalPrice = document.getElementById('totalPrice'); + + // Order button + this.orderButton = document.querySelector('a[href="#order-form"]'); + } + + // Setup order button click handler + setupOrderButton() { + if (this.orderButton) { + this.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, + serviceLevel: config.serviceLevel, + totalPrice: config.totalPrice + }); + } + } + + // Generate human-readable configuration message + generateConfigurationMessage(config) { + return `I would like to order the following configuration: + +Plan: ${config.planName} (${config.planGroup}) +vCPUs: ${config.vcpus} +Memory: ${config.memory} GB +Storage: ${config.storage} GB +Service Level: ${config.serviceLevel} + +Total Monthly Price: CHF ${config.totalPrice} + +Please contact me with next steps for ordering this configuration.`; } // Load pricing data from API endpoint @@ -374,6 +449,17 @@ class PriceCalculator { if (this.storagePriceEl) this.storagePriceEl.textContent = storagePriceValue.toFixed(2); if (this.storageAmount) this.storageAmount.textContent = storage; if (this.totalPrice) this.totalPrice.textContent = totalPriceValue.toFixed(2); + + // Store current configuration for order button + this.selectedConfiguration = { + planName: plan.compute_plan, + planGroup: plan.groupName, + vcpus: plan.vcpus, + memory: plan.ram, + storage: storage, + serviceLevel: serviceLevel, + totalPrice: totalPriceValue.toFixed(2) + }; } // Show no matching plan found diff --git a/hub/services/templates/services/embedded_contact_form.html b/hub/services/templates/services/embedded_contact_form.html index 660be51..46a144f 100644 --- a/hub/services/templates/services/embedded_contact_form.html +++ b/hub/services/templates/services/embedded_contact_form.html @@ -73,14 +73,29 @@ {% endif %}
- + {{ form.message|addclass:"form-control" }} {% if form.message.errors %}
{{ form.message.errors }}
{% endif %} + {% if source == "Configuration Order" %} + Your selected configuration will be automatically filled here when you click "Order This Configuration". + {% endif %}
- + \ No newline at end of file diff --git a/hub/services/templates/services/offering_detail.html b/hub/services/templates/services/offering_detail.html index 4fc2fbd..2962d66 100644 --- a/hub/services/templates/services/offering_detail.html +++ b/hub/services/templates/services/offering_detail.html @@ -306,10 +306,20 @@
- + Order This Configuration
+ + +
+

Order Your Configuration

+
+
+ {% embedded_contact_form source="Configuration Order" service=offering.service offering_id=offering.id %} +
+
+
{% elif offering.plans.all %}

Available Plans

@@ -356,7 +366,7 @@ {% endif %} - {% if offering.plans.exists %} + {% if offering.plans.exists and not pricing_data_by_group_and_service_level %}

I'm interested in a plan