keep selected plan when changing service level
This commit is contained in:
parent
7f7ffd625b
commit
a4ff21cc35
2 changed files with 81 additions and 16 deletions
|
|
@ -88,6 +88,9 @@ class PriceCalculator {
|
|||
|
||||
// Initialize instances slider
|
||||
this.uiManager.updateInstancesSlider(this.domManager, this.pricingDataManager);
|
||||
|
||||
// Setup service level event listeners after UI is created
|
||||
this.setupServiceLevelEventListeners();
|
||||
}
|
||||
|
||||
// Setup event listeners for calculator controls
|
||||
|
|
@ -166,20 +169,81 @@ class PriceCalculator {
|
|||
window.addEventListener('addon-changed', () => {
|
||||
this.updatePricing();
|
||||
});
|
||||
}
|
||||
|
||||
// Setup service level event listeners (called after UI setup)
|
||||
setupServiceLevelEventListeners() {
|
||||
// Service level change listener
|
||||
const serviceLevelInputs = this.domManager.get('serviceLevelInputs');
|
||||
|
||||
if (serviceLevelInputs) {
|
||||
serviceLevelInputs.forEach(input => {
|
||||
serviceLevelInputs.forEach((input, index) => {
|
||||
input.addEventListener('change', () => {
|
||||
try {
|
||||
// Check if a plan is currently selected before updating
|
||||
const planSelect = this.domManager.get('planSelect');
|
||||
const currentlySelectedPlan = planSelect?.value ? JSON.parse(planSelect.value) : null;
|
||||
|
||||
// Update instances slider for the new service level (functionality from UIManager)
|
||||
this.uiManager.updateInstancesSlider(this.domManager, this.pricingDataManager);
|
||||
|
||||
// Update plan dropdown for new service level
|
||||
this.planManager.populatePlanDropdown(this.domManager);
|
||||
|
||||
// Update addons for new service level
|
||||
// Update addons for new service level first
|
||||
this.addonManager.updateAddons(this.domManager);
|
||||
|
||||
// Update pricing
|
||||
// If a plan was previously selected, try to maintain selection
|
||||
if (currentlySelectedPlan && planSelect) {
|
||||
// Find the same plan in the new dropdown options
|
||||
const options = planSelect.querySelectorAll('option');
|
||||
let planFound = false;
|
||||
let matchingPlan = null;
|
||||
|
||||
for (const option of options) {
|
||||
if (option.value) {
|
||||
try {
|
||||
const optionPlan = JSON.parse(option.value);
|
||||
|
||||
// First, try to match by exact plan name
|
||||
if (optionPlan.compute_plan === currentlySelectedPlan.compute_plan) {
|
||||
matchingPlan = optionPlan;
|
||||
planFound = true;
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Error parsing plan option:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (planFound && matchingPlan) {
|
||||
// Set the plan selection
|
||||
planSelect.value = JSON.stringify(matchingPlan);
|
||||
|
||||
// Maintain the UI state for manually selected plan
|
||||
this.planManager.updateSlidersForPlan(matchingPlan, this.domManager);
|
||||
this.uiManager.fadeOutSliders(this.domManager, ['cpu', 'memory']);
|
||||
|
||||
// Update pricing with the selected plan
|
||||
this.updatePricingWithPlan(matchingPlan);
|
||||
} else {
|
||||
planSelect.value = '';
|
||||
// Reset sliders to smart defaults and fade them back in
|
||||
this.domManager.setSmartDefaults(this.pricingDataManager);
|
||||
this.uiManager.fadeInSliders(this.domManager, ['cpu', 'memory']);
|
||||
// Update pricing in auto-select mode
|
||||
this.updatePricing();
|
||||
}
|
||||
} else {
|
||||
// No plan was previously selected, just update pricing
|
||||
this.updatePricing();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in service level change handler:', error);
|
||||
// Fallback to basic functionality if there's an error
|
||||
this.updatePricing();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,8 +215,9 @@ class UIManager {
|
|||
// Update the serviceLevelInputs reference
|
||||
domManager.elements.serviceLevelInputs = document.querySelectorAll('input[name="serviceLevel"]');
|
||||
|
||||
// Set up event listeners for the dynamically created service level inputs
|
||||
this.setupServiceLevelEventListeners(domManager, pricingDataManager);
|
||||
// Note: Event listeners are now handled in price-calculator.js setupEventListeners method
|
||||
// to properly preserve plan selection when service level changes
|
||||
// this.setupServiceLevelEventListeners(domManager, pricingDataManager);
|
||||
}
|
||||
|
||||
// Setup event listeners for service level inputs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue