This commit is contained in:
Lars Westermann 2019-06-12 23:01:08 +02:00
parent 36bdad8036
commit 8cdebf7f3b
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
7 changed files with 109 additions and 10 deletions

View file

@ -1,14 +1,13 @@
package de.kif.frontend.views
import de.kif.common.formatDate
import de.westermann.kwebview.View
import de.westermann.kwebview.components.InputType
import de.westermann.kwebview.components.InputView
import de.westermann.kwebview.components.TextView
import de.westermann.kwebview.createHtmlView
import de.westermann.kwebview.iterator
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
import org.w3c.dom.get
import org.w3c.dom.*
import kotlin.browser.document
fun initRoomConstraints() {
@ -19,6 +18,14 @@ fun initRoomConstraints() {
val addButton =
View.wrap(document.getElementsByClassName("room-constraints-add")[0] as HTMLElement)
val referenceDate = constraints.dataset["reference"]?.toLongOrNull() ?: 0L
fun updateDateView(inputGroup: HTMLElement, day: Int) {
val date = referenceDate + (day * 1000 * 60 * 60 * 24)
val dateName = formatDate(date)
inputGroup.dataset["hint"] = dateName
}
addButton.onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {
classList += "input-group"
@ -26,10 +33,18 @@ fun initRoomConstraints() {
classList += "form-btn"
onClick { this@wrap.html.remove() }
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
html.appendChild(InputView(InputType.NUMBER).apply {
classList += "form-control"
html.name = "constraint-room-day-${index}"
placeholder = "Tag"
min = -1337.0
max = 1337.0
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -52,6 +67,17 @@ fun initRoomConstraints() {
println("click")
child.remove()
})
for (e in child.children.iterator()) {
if (e.classList.contains("-day-")) {
val input = InputView.wrap(e as HTMLInputElement)
updateDateView(child, input.value.toIntOrNull() ?: 0)
input.valueProperty.onChange {
updateDateView(child, input.value.toIntOrNull() ?: 0)
}
}
}
}
}
}

View file

@ -1,5 +1,6 @@
package de.kif.frontend.views
import de.kif.common.formatDate
import de.kif.frontend.launch
import de.kif.frontend.repository.RoomRepository
import de.kif.frontend.repository.WorkGroupRepository
@ -17,12 +18,14 @@ fun initWorkGroupConstraints() {
var index = 10000
val constraints =
document.getElementsByClassName("work-group-constraints")[0] as HTMLElement
document.getElementsByClassName("work-group-constraints")[0] as HTMLElement
val addButton =
View.wrap(document.getElementsByClassName("work-group-constraints-add")[0] as HTMLElement)
val addList =
ListView.wrap<View>(document.getElementsByClassName("work-group-constraints-add-list")[0] as HTMLElement)
val referenceDate = constraints.dataset["reference"]?.toLongOrNull() ?: 0L
addButton.onClick {
addList.classList += "active"
@ -36,6 +39,12 @@ fun initWorkGroupConstraints() {
}
}
fun updateDateView(inputGroup: HTMLElement, day: Int) {
val date = referenceDate + (day * 1000 * 60 * 60 * 24)
val dateName = formatDate(date)
inputGroup.dataset["hint"] = dateName
}
addList.textView("Nur an Tag x") {
onClick {
constraints.appendChild(View.wrap(createHtmlView<HTMLDivElement>()) {
@ -50,6 +59,11 @@ fun initWorkGroupConstraints() {
min = -1337.0
max = 1337.0
placeholder = "Tag"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
}.html)
}
@ -68,6 +82,11 @@ fun initWorkGroupConstraints() {
min = -1337.0
max = 1337.0
placeholder = "Tag"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
}.html)
}
@ -84,6 +103,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-only-before-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -105,6 +129,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-only-after-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -126,6 +155,11 @@ fun initWorkGroupConstraints() {
classList += "form-control"
html.name = "constraint-exact-time-day-${index}"
placeholder = "Tag (optional)"
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
valueProperty.onChange {
updateDateView(this@wrap.html, value.toIntOrNull() ?: 0)
}
}.html)
html.appendChild(InputView(InputType.TEXT).apply {
classList += "form-control"
@ -243,6 +277,17 @@ fun initWorkGroupConstraints() {
span.addEventListener("click", org.w3c.dom.events.EventListener {
child.remove()
})
for (e in child.children.iterator()) {
if (e.classList.contains("-day-")) {
val input = InputView.wrap(e as HTMLInputElement)
updateDateView(child, input.value.toIntOrNull() ?: 0)
input.valueProperty.onChange {
updateDateView(child, input.value.toIntOrNull() ?: 0)
}
}
}
}
}
}

View file

@ -206,4 +206,15 @@ form {
border-bottom-right-radius: 0;
}
}
&:after {
content: attr(data-hint);
position: absolute;
left: 100%;
color: var(--text-secondary-color);
line-height: 2.5rem;
margin-left: 1rem;
width: 100%;
top: 2.3rem;
}
}