Remve oz, cups, lb

This commit is contained in:
Dayowe 2025-11-12 17:00:45 +01:00
parent d489a87722
commit da9fd20ffb
4 changed files with 54 additions and 196 deletions

View File

@ -206,6 +206,8 @@
display: inline-block;
}
.dog-calculator-results {
background: linear-gradient(135deg, rgba(241, 154, 95, 0.08) 0%, rgba(241, 154, 95, 0.04) 100%);
border: 1px solid rgba(241, 154, 95, 0.2);
@ -1979,6 +1981,8 @@
<div id="ageClampNote" class="dog-calculator-error dog-calculator-hidden">Age adjusted to the supported 212 month range.</div>
</div>
<div class="dog-calculator-form-group">
<label for="kayaEndWeight">Kayas endweight:</label>
<input type="text" id="kayaEndWeight" value="30 kg" readonly>
@ -2035,9 +2039,6 @@
<div class="dog-calculator-unit-buttons" id="unitButtons" style="display: none;">
<button type="button" class="dog-calculator-unit-btn active" data-unit="g">g</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="kg">kg</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="oz">oz</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="lb">lb</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="cups" id="cupsButton" disabled title="Available when using kcal/cup measurement">cups</button>
</div>
<!-- Daily Total Results -->
@ -2052,9 +2053,6 @@
<select id="unit" class="dog-calculator-unit-select-hidden" aria-describedby="unitHelp">
<option value="g">grams (g)</option>
<option value="kg">kilograms (kg)</option>
<option value="oz">ounces (oz)</option>
<option value="lb">pounds (lb)</option>
<option value="cups">cups</option>
</select>
<div class="dog-calculator-food-amounts-section" id="foodAmountsSection" style="display: none;">
@ -2739,32 +2737,15 @@ const CALCULATOR_CONFIG = {
// Auto-select cups when entering energy for kcal/cup
const foodSource = this.foodSources.find(fs => fs.id === id);
if (foodSource && foodSource.energyUnit === 'kcalcup' && parseFloat(energyInput.value) > 0) {
// Cups display removed; default to grams
const unitSelect = document.getElementById('unit');
const cupsButton = document.getElementById('cupsButton');
// First check if cups button will be enabled after update
const willEnableCups = this.foodSources.some(fs =>
fs.energyUnit === 'kcalcup' && fs.energy && parseFloat(fs.energy) > 0
);
if (willEnableCups && unitSelect) {
// Set cups BEFORE updating calculations
unitSelect.value = 'cups';
unitSelect.setAttribute('value', 'cups');
this.setActiveUnitButton('cups');
// Enable the cups button manually since we know it will be valid
if (cupsButton) {
cupsButton.disabled = false;
cupsButton.title = 'Show amounts in cups';
}
if (unitSelect) {
unitSelect.value = 'g';
unitSelect.setAttribute('value', 'g');
this.setActiveUnitButton('g');
}
// Now update calculations with cups already selected
this.updateFoodCalculations();
} else {
this.updateFoodCalculations();
}
this.updateFoodCalculations();
});
energyInput.addEventListener('blur', () => this.validateFoodSourceEnergy(id));
}
@ -2783,21 +2764,9 @@ const CALCULATOR_CONFIG = {
if (unitSelect) {
switch(energyUnitSelect.value) {
case 'kcalcup':
// Check if we have energy value to enable cups
const foodSource = this.foodSources.find(fs => fs.id === id);
if (foodSource && foodSource.energy && parseFloat(foodSource.energy) > 0) {
// Set cups BEFORE updating calculations
unitSelect.value = 'cups';
unitSelect.setAttribute('value', 'cups');
this.setActiveUnitButton('cups');
// Enable the cups button manually
const cupsButton = document.getElementById('cupsButton');
if (cupsButton) {
cupsButton.disabled = false;
cupsButton.title = 'Show amounts in cups';
}
}
// Cups display not available; default to grams
unitSelect.value = 'g';
this.setActiveUnitButton('g');
this.updateFoodCalculations();
break;
case 'kcal100g':
@ -2813,9 +2782,9 @@ const CALCULATOR_CONFIG = {
this.updateFoodCalculations();
break;
case 'kcalcan':
// For kcal/can, use grams as default (or ounces in imperial)
unitSelect.value = this.isImperial ? 'oz' : 'g';
this.setActiveUnitButton(unitSelect.value);
// For kcal/can, use grams as default
unitSelect.value = 'g';
this.setActiveUnitButton('g');
this.updateFoodCalculations();
break;
}
@ -3106,58 +3075,14 @@ const CALCULATOR_CONFIG = {
imperialLabel.classList.toggle('active', this.isImperial);
}
if (this.isImperial) {
if (weightLabel) weightLabel.textContent = "Dog's Weight (lbs):";
if (weightInput) {
weightInput.placeholder = "Enter weight in lbs";
weightInput.min = "0.2";
weightInput.step = "0.1";
// Kaya: restrict to metric g/kg only
if (unitSelect) {
unitSelect.innerHTML = '<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>';
if (!unitSelect.value || (unitSelect.value !== 'g' && unitSelect.value !== 'kg')) {
unitSelect.value = 'g';
this.setActiveUnitButton('g');
}
if (unitSelect) {
unitSelect.innerHTML = '<option value="oz">ounces (oz)</option>' +
'<option value="lb">pounds (lb)</option>' +
'<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>';
unitSelect.value = 'oz'; // Auto-select ounces for imperial
this.setActiveUnitButton('oz'); // Sync unit buttons
}
// Update energy units for all food sources to kcal/cup for imperial
this.foodSources.forEach(fs => {
if (fs.energyUnit === 'kcal100g') {
fs.energyUnit = 'kcalcup';
const energyUnitSelect = document.getElementById(`energy-unit-${fs.id}`);
if (energyUnitSelect) {
energyUnitSelect.value = 'kcalcup';
}
}
});
} else {
if (weightLabel) weightLabel.textContent = "Dog's Weight (kg):";
if (weightInput) {
weightInput.placeholder = "Enter weight in kg";
weightInput.min = "0.1";
weightInput.step = "0.1";
}
if (unitSelect) {
unitSelect.innerHTML = '<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>' +
'<option value="oz">ounces (oz)</option>' +
'<option value="lb">pounds (lb)</option>';
unitSelect.value = 'g'; // Auto-select grams for metric
this.setActiveUnitButton('g'); // Sync unit buttons
}
// Update energy units for all food sources to kcal/100g for metric
this.foodSources.forEach(fs => {
if (fs.energyUnit === 'kcalcup') {
fs.energyUnit = 'kcal100g';
const energyUnitSelect = document.getElementById(`energy-unit-${fs.id}`);
if (energyUnitSelect) {
energyUnitSelect.value = 'kcal100g';
}
}
});
}
}
@ -3340,6 +3265,8 @@ const CALCULATOR_CONFIG = {
if (age < 2) { age = 2; if (ageClampNote) ageClampNote.classList.remove('dog-calculator-hidden'); }
if (age > 12) { age = 12; if (ageClampNote) ageClampNote.classList.remove('dog-calculator-hidden'); }
// Bucket pills removed
// Calculate interpolated kibble grams/day for 30 kg at this age
const kibbleGrams = this.getKayaKibbleGramsForAge(age);
@ -3394,6 +3321,8 @@ const CALCULATOR_CONFIG = {
return lowerVal + (upperVal - lowerVal) * t;
}
updateCupsButtonState() {
const cupsButton = document.getElementById('cupsButton');
if (!cupsButton) return;

View File

@ -196,6 +196,8 @@
display: inline-block;
}
.dog-calculator-results {
background: linear-gradient(135deg, rgba(241, 154, 95, 0.08) 0%, rgba(241, 154, 95, 0.04) 100%);
border: 1px solid rgba(241, 154, 95, 0.2);

View File

@ -10,6 +10,8 @@
<div id="ageClampNote" class="dog-calculator-error dog-calculator-hidden">Age adjusted to the supported 212 month range.</div>
</div>
<div class="dog-calculator-form-group">
<label for="kayaEndWeight">Kayas endweight:</label>
<input type="text" id="kayaEndWeight" value="30 kg" readonly>
@ -66,9 +68,6 @@
<div class="dog-calculator-unit-buttons" id="unitButtons" style="display: none;">
<button type="button" class="dog-calculator-unit-btn active" data-unit="g">g</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="kg">kg</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="oz">oz</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="lb">lb</button>
<button type="button" class="dog-calculator-unit-btn" data-unit="cups" id="cupsButton" disabled title="Available when using kcal/cup measurement">cups</button>
</div>
<!-- Daily Total Results -->
@ -83,9 +82,6 @@
<select id="unit" class="dog-calculator-unit-select-hidden" aria-describedby="unitHelp">
<option value="g">grams (g)</option>
<option value="kg">kilograms (kg)</option>
<option value="oz">ounces (oz)</option>
<option value="lb">pounds (lb)</option>
<option value="cups">cups</option>
</select>
<div class="dog-calculator-food-amounts-section" id="foodAmountsSection" style="display: none;">

View File

@ -641,32 +641,15 @@
// Auto-select cups when entering energy for kcal/cup
const foodSource = this.foodSources.find(fs => fs.id === id);
if (foodSource && foodSource.energyUnit === 'kcalcup' && parseFloat(energyInput.value) > 0) {
// Cups display removed; default to grams
const unitSelect = document.getElementById('unit');
const cupsButton = document.getElementById('cupsButton');
// First check if cups button will be enabled after update
const willEnableCups = this.foodSources.some(fs =>
fs.energyUnit === 'kcalcup' && fs.energy && parseFloat(fs.energy) > 0
);
if (willEnableCups && unitSelect) {
// Set cups BEFORE updating calculations
unitSelect.value = 'cups';
unitSelect.setAttribute('value', 'cups');
this.setActiveUnitButton('cups');
// Enable the cups button manually since we know it will be valid
if (cupsButton) {
cupsButton.disabled = false;
cupsButton.title = 'Show amounts in cups';
}
if (unitSelect) {
unitSelect.value = 'g';
unitSelect.setAttribute('value', 'g');
this.setActiveUnitButton('g');
}
// Now update calculations with cups already selected
this.updateFoodCalculations();
} else {
this.updateFoodCalculations();
}
this.updateFoodCalculations();
});
energyInput.addEventListener('blur', () => this.validateFoodSourceEnergy(id));
}
@ -685,21 +668,9 @@
if (unitSelect) {
switch(energyUnitSelect.value) {
case 'kcalcup':
// Check if we have energy value to enable cups
const foodSource = this.foodSources.find(fs => fs.id === id);
if (foodSource && foodSource.energy && parseFloat(foodSource.energy) > 0) {
// Set cups BEFORE updating calculations
unitSelect.value = 'cups';
unitSelect.setAttribute('value', 'cups');
this.setActiveUnitButton('cups');
// Enable the cups button manually
const cupsButton = document.getElementById('cupsButton');
if (cupsButton) {
cupsButton.disabled = false;
cupsButton.title = 'Show amounts in cups';
}
}
// Cups display not available; default to grams
unitSelect.value = 'g';
this.setActiveUnitButton('g');
this.updateFoodCalculations();
break;
case 'kcal100g':
@ -715,9 +686,9 @@
this.updateFoodCalculations();
break;
case 'kcalcan':
// For kcal/can, use grams as default (or ounces in imperial)
unitSelect.value = this.isImperial ? 'oz' : 'g';
this.setActiveUnitButton(unitSelect.value);
// For kcal/can, use grams as default
unitSelect.value = 'g';
this.setActiveUnitButton('g');
this.updateFoodCalculations();
break;
}
@ -1008,58 +979,14 @@
imperialLabel.classList.toggle('active', this.isImperial);
}
if (this.isImperial) {
if (weightLabel) weightLabel.textContent = "Dog's Weight (lbs):";
if (weightInput) {
weightInput.placeholder = "Enter weight in lbs";
weightInput.min = "0.2";
weightInput.step = "0.1";
// Kaya: restrict to metric g/kg only
if (unitSelect) {
unitSelect.innerHTML = '<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>';
if (!unitSelect.value || (unitSelect.value !== 'g' && unitSelect.value !== 'kg')) {
unitSelect.value = 'g';
this.setActiveUnitButton('g');
}
if (unitSelect) {
unitSelect.innerHTML = '<option value="oz">ounces (oz)</option>' +
'<option value="lb">pounds (lb)</option>' +
'<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>';
unitSelect.value = 'oz'; // Auto-select ounces for imperial
this.setActiveUnitButton('oz'); // Sync unit buttons
}
// Update energy units for all food sources to kcal/cup for imperial
this.foodSources.forEach(fs => {
if (fs.energyUnit === 'kcal100g') {
fs.energyUnit = 'kcalcup';
const energyUnitSelect = document.getElementById(`energy-unit-${fs.id}`);
if (energyUnitSelect) {
energyUnitSelect.value = 'kcalcup';
}
}
});
} else {
if (weightLabel) weightLabel.textContent = "Dog's Weight (kg):";
if (weightInput) {
weightInput.placeholder = "Enter weight in kg";
weightInput.min = "0.1";
weightInput.step = "0.1";
}
if (unitSelect) {
unitSelect.innerHTML = '<option value="g">grams (g)</option>' +
'<option value="kg">kilograms (kg)</option>' +
'<option value="oz">ounces (oz)</option>' +
'<option value="lb">pounds (lb)</option>';
unitSelect.value = 'g'; // Auto-select grams for metric
this.setActiveUnitButton('g'); // Sync unit buttons
}
// Update energy units for all food sources to kcal/100g for metric
this.foodSources.forEach(fs => {
if (fs.energyUnit === 'kcalcup') {
fs.energyUnit = 'kcal100g';
const energyUnitSelect = document.getElementById(`energy-unit-${fs.id}`);
if (energyUnitSelect) {
energyUnitSelect.value = 'kcal100g';
}
}
});
}
}
@ -1242,6 +1169,8 @@
if (age < 2) { age = 2; if (ageClampNote) ageClampNote.classList.remove('dog-calculator-hidden'); }
if (age > 12) { age = 12; if (ageClampNote) ageClampNote.classList.remove('dog-calculator-hidden'); }
// Bucket pills removed
// Calculate interpolated kibble grams/day for 30 kg at this age
const kibbleGrams = this.getKayaKibbleGramsForAge(age);
@ -1296,6 +1225,8 @@
return lowerVal + (upperVal - lowerVal) * t;
}
updateCupsButtonState() {
const cupsButton = document.getElementById('cupsButton');
if (!cupsButton) return;