wip: booking process

This commit is contained in:
Björn Fromme
2025-07-16 11:55:49 +02:00
parent bef18971c3
commit 47faa6b08e
26 changed files with 1123 additions and 271 deletions
@@ -0,0 +1,46 @@
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static targets = [ 'fields', 'field', 'addButton', 'index' ]
static values = {
prototype: String,
maxItems: Number,
itemsCount: Number,
}
connect () {
this.index = this.itemsCountValue = this.fieldTargets.length
}
addItem() {
let prototype = JSON.parse(this.prototypeValue)
const newField = prototype.replace(/__name__/g, this.index)
this.fieldsTarget.insertAdjacentHTML('beforeend', newField)
this.index++
this.itemsCountValue++
}
removeItem(event) {
this.fieldTargets.forEach(element => {
if (element.contains(event.target)) {
element.remove()
this.itemsCountValue--
}
})
}
itemsCountValueChanged(itemsCount) {
if (this.hasIndexTarget) {
this.indexTargets.forEach((target, index) => {
target.innerText = index + 1
})
}
if (false === this.hasAddButtonTarget || 0 === this.maxItemsValue) {
return
}
const maxItemsReached = itemsCount >= this.maxItemsValue
this.addButtonTarget.classList.toggle('hidden', maxItemsReached)
}
}