- initial commit

This commit is contained in:
Enrico Bühler 2022-08-02 12:13:30 +02:00
parent 99f469990f
commit 13229d1123
2 changed files with 148 additions and 0 deletions

64
index.html Normal file
View File

@ -0,0 +1,64 @@
<html>
<body>
<div>
<h1>
FeBaFix Rechner
</h1>
<form id="windowsill-calculator" class="count-calculator">
<label data-field class="field">
Stärke der Fensterbank
<select name="" id="windowsill-type-input">
<option value="16">
15-17mm
</option>
<option value="18">
18-21mm
</option>
<option value="custom">
Sondegröße (bitte angeben)
</option>
</select>
</label>
<label data-field id="windowsill-strength-input-container" style="display: none;" class="field">
Sondergröße der Fensterbank
<input name="windowsill-strength" type="number" id="windowsill-strength-input" max="1000" />
</label>
<label data-field class="field">
Summe zu montierender Fensterbänke in Meter
<input name="length" type="number" id="length-input" min="0" />
</label>
<h3>Ergebnis</h3>
<label data-field class="field">
Stückzahl:
<output id="count-output">Erwarte Eingabe...</output>
</label>
<label data-field class="field">
Art:
<output id="windowsill-type-output">Erwarte Eingabe...</output>
</label>
</form>
</div>
<style>
html {
font-family: Arial, Helvetica, sans-serif;
}
.count-calculator {
max-width: 500px;
display: flex;
gap: 2rem;
flex-direction: column;
}
.count-calculator .field {
display: flex;
gap: 0.5rem;
flex-direction: column;
}
</style>
<script src="./main.js" defer async>
</script>
</body>
</html>

84
main.js Normal file
View File

@ -0,0 +1,84 @@
class CountCalculator {
constructor() {
// count of the item
this.count = 0;
this.windowsillType;
this.windowsillStrength;
// collect form inputs/outputs
this.lengthInput = document.getElementById("length-input");
this.countOutput = document.getElementById("count-output");
this.windowsillTypeInput = document.getElementById("windowsill-type-input");
this.windowsillStrengthInput = document.getElementById(
"windowsill-strength-input"
);
this.windowsillTypeOutput = document.getElementById(
"windowsill-type-output"
);
this.windowsillStrengthInputContainer = document.getElementById(
"windowsill-strength-input-container"
);
// listen for input changes
this.lengthInput.addEventListener("change", (e) => {
this.handleCountChange(e.target.value);
});
this.windowsillTypeInput.addEventListener("change", (e) => {
this.handleWindowsillTypeChange(e.target.value);
});
this.windowsillStrengthInput.addEventListener("change", (e) => {
this.handleWindowsillStrengthChange(e.target.value);
});
this.init();
}
init() {
this.handleCountChange(this.lengthInput.value);
this.handleWindowsillStrengthChange(this.windowsillStrengthInput.value);
this.handleWindowsillTypeChange(this.windowsillTypeInput.value);
this.updateOutput();
}
updateOutput() {
this.countOutput.innerHTML = this.count;
console.log(this.windowsillStrength, this.windowsillType);
if (this.windowsillType === "custom") {
this.windowsillTypeOutput.innerHTML = `Sondergröße: ${
(this.windowsillStrength !== "" &&
this.windowsillStrength + "er Lehre") ||
""
}`;
} else {
this.windowsillTypeOutput.innerHTML = `${this.windowsillType}er Lehre`;
}
}
handleCountChange(value) {
this.count = this.calculateCount(value);
this.updateOutput();
}
handleWindowsillTypeChange(value) {
if (value === "custom") {
this.windowsillStrengthInputContainer.style.display = "flex";
} else {
this.windowsillStrengthInputContainer.style.display = "none";
}
this.windowsillType = value;
this.updateOutput();
}
handleWindowsillStrengthChange(value) {
this.windowsillStrength = value;
this.updateOutput();
}
calculateCount(length) {
let count = length * 3;
count = Math.ceil(count / 10) * 10;
return count;
}
}
new CountCalculator();