startit/Codealong/view.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-10-31 09:07:48 +01:00
updateView();
function updateView() {
2024-11-01 14:45:13 +01:00
header.innerHTML = '<h1 class="header">Lån en sykkel</h1>';
main.innerHTML = /*html*/ `
2024-10-31 09:07:48 +01:00
<div>Alle sykkler:</div>
2024-11-01 14:45:13 +01:00
${bikeList()}`;
input.innerHTML = /*html*/ `
<h1> Legg til en sykkel:</h1>
${addBikeview()}
2024-10-31 09:07:48 +01:00
`;
}
2024-11-01 14:45:13 +01:00
2024-10-31 09:07:48 +01:00
function bikeList() {
let bikeHtml = '';
2024-11-01 14:45:13 +01:00
let bikes = model.data.bikes
for (i = 0; i < model.data.bikes.length; i++) {
2024-10-31 09:07:48 +01:00
bikeHtml += /*html*/ `
2024-11-01 14:45:13 +01:00
<div class="list">
2024-10-31 09:07:48 +01:00
<ul>
2024-11-01 14:45:13 +01:00
<li>Merke: ${bikes[i].brand}</li>
<li>Gir: ${bikes[i].gears}</li>
<li>Beskrivelse: ${bikes[i].description}</li>
<li>Tilgjengelig: ${bikes[i].isAvilable}</li>
<li>Tilstand: ${bikes[i].state}</li>
</ul>
</div>`;
2024-10-31 09:07:48 +01:00
}
return bikeHtml;
}
2024-11-01 14:45:13 +01:00
function addBikeview() {
2024-10-31 09:07:48 +01:00
let addBikeHtml = /*html*/ `
2024-11-01 14:45:13 +01:00
<div>
<label class="labels">Merke:</label>
<input type="text" onchange="model.input.newBike.brand = this.value">
</div>
<div>
<label class="labels">Gir:</label>
<input type="number" onchange="model.input.newBike.gears = this.value">
</div>
<div>
2024-11-12 18:58:11 +01:00
Er sykkelen tigjengelig<input type="checkbox" checked="" onclick="model.input.newBike.isAvailable = this.value">Ja</button>
2024-11-01 14:45:13 +01:00
<input type="checkbox" checked="" onclick="model.input.newBike.isAvailable = this.value">Nei</button>
</div>
<div>
<label class="labels">Beskrivelse:</label>
<textarea onchange="model.input.newBike.comment = this.value"></textarea>
</div>
<button onclick="addBike()">Legg til sykkel</button>
2024-10-31 09:07:48 +01:00
`;
2024-11-01 14:45:13 +01:00
return addBikeHtml
2024-10-31 09:07:48 +01:00
}