diff --git a/src/jsMain/kotlin/de/kif/frontend/views/RoomConstraints.kt b/src/jsMain/kotlin/de/kif/frontend/views/RoomConstraints.kt index f0df9f4..c550865 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/RoomConstraints.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/RoomConstraints.kt @@ -71,7 +71,7 @@ fun initRoomConstraints() { for (e in child.children.iterator()) { if (e is HTMLInputElement && e.name.contains("-day-")) { - val input = InputView.wrap(e) + val input = InputView.wrap(InputType.NUMBER, e) updateDateView(child, input.value.toIntOrNull() ?: 0) input.valueProperty.onChange { diff --git a/src/jsMain/kotlin/de/kif/frontend/views/WorkGroupConstraints.kt b/src/jsMain/kotlin/de/kif/frontend/views/WorkGroupConstraints.kt index c871795..166a35b 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/WorkGroupConstraints.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/WorkGroupConstraints.kt @@ -100,11 +100,14 @@ fun initWorkGroupConstraints() { 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-only-before-time-day-${index}" placeholder = "Tag (optional)" + min = -1337.0 + max = 1337.0 + updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) valueProperty.onChange { updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) @@ -126,11 +129,14 @@ fun initWorkGroupConstraints() { 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-only-after-time-day-${index}" placeholder = "Tag (optional)" + min = -1337.0 + max = 1337.0 + updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) valueProperty.onChange { updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) @@ -152,11 +158,14 @@ fun initWorkGroupConstraints() { 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-exact-time-day-${index}" placeholder = "Tag (optional)" + min = -1337.0 + max = 1337.0 + updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) valueProperty.onChange { updateDateView(this@wrap.html, value.toIntOrNull() ?: 0) @@ -281,7 +290,7 @@ fun initWorkGroupConstraints() { for (e in child.children.iterator()) { if (e is HTMLInputElement && e.name.contains("-day-")) { - val input = InputView.wrap(e) + val input = InputView.wrap(InputType.NUMBER, e) updateDateView(child, input.value.toIntOrNull() ?: 0) input.valueProperty.onChange { diff --git a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt index f429106..025ec3a 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarEdit.kt @@ -8,6 +8,7 @@ import de.westermann.kobserve.list.observableListOf import de.westermann.kobserve.list.sortObservable import de.westermann.kwebview.View import de.westermann.kwebview.components.Button +import de.westermann.kwebview.components.InputType import de.westermann.kwebview.components.InputView import de.westermann.kwebview.components.ListView import de.westermann.kwebview.extra.listFactory @@ -24,7 +25,7 @@ class CalendarEdit( Button.wrap(document.getElementById("calendar-edit-button") as HTMLButtonElement) val search = - InputView.wrap(view.querySelector(".calendar-edit-search input") as HTMLInputElement) + InputView.wrap(InputType.SEARCH, view.querySelector(".calendar-edit-search input") as HTMLInputElement) val listView = ListView.wrap( view.querySelector(".calendar-edit-list") as HTMLElement diff --git a/src/jsMain/kotlin/de/kif/frontend/views/table/TableLayout.kt b/src/jsMain/kotlin/de/kif/frontend/views/table/TableLayout.kt index 2b7f57f..56011de 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/table/TableLayout.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/table/TableLayout.kt @@ -2,6 +2,7 @@ package de.kif.frontend.views.table import de.kif.frontend.launch import de.kif.frontend.repository.TrackRepository +import de.westermann.kwebview.components.InputType import de.westermann.kwebview.components.InputView import de.westermann.kwebview.iterator import org.w3c.dom.HTMLFormElement @@ -30,7 +31,7 @@ fun initTableLayout() { }.toList() val input = form.getElementsByTagName("input")[0] as HTMLInputElement - val search = InputView.wrap(input) + val search = InputView.wrap(InputType.SEARCH, input) search.valueProperty.onChange { for (row in list) { row.search(search.value) diff --git a/src/jsMain/kotlin/de/westermann/kwebview/components/InputView.kt b/src/jsMain/kotlin/de/westermann/kwebview/components/InputView.kt index a99203a..e29f7de 100644 --- a/src/jsMain/kotlin/de/westermann/kwebview/components/InputView.kt +++ b/src/jsMain/kotlin/de/westermann/kwebview/components/InputView.kt @@ -111,7 +111,7 @@ class InputView( } companion object { - fun wrap(view: HTMLInputElement) = InputView(InputType.SEARCH, view.value, view) + fun wrap(type: InputType, view: HTMLInputElement) = InputView(type, view.value, view) } } diff --git a/src/jsMain/resources/style/components/_form.scss b/src/jsMain/resources/style/components/_form.scss index 534c90f..529ff93 100644 --- a/src/jsMain/resources/style/components/_form.scss +++ b/src/jsMain/resources/style/components/_form.scss @@ -176,6 +176,7 @@ form { .input-group { display: flex; + position: relative; .form-btn { height: 2.5rem; @@ -215,6 +216,6 @@ form { line-height: 2.5rem; margin-left: 1rem; width: 100%; - top: 2.3rem; + top: 0; } } diff --git a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt index ac61a56..6025e8b 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/Account.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/Account.kt @@ -51,7 +51,7 @@ fun Route.account() { +"Sicherung" } - if (user.checkPermission(Permission.ADMIN)) { + if (user.checkPermission(Permission.SCHEDULE)) { a(href = "$prefix/account/import", classes = "form-btn") { +"Aus Wiki importieren" } @@ -185,16 +185,11 @@ fun Route.account() { +"Arbeitskreise löschen" } } - if ( - user.checkPermission(Permission.WORK_GROUP) && - user.checkPermission(Permission.ROOM) && - user.checkPermission(Permission.SCHEDULE) - ) { + if (user.checkPermission(Permission.SCHEDULE)) { a("$prefix/account/backup/delete/schedules", classes = "form-btn btn-danger") { +"Zeitplan löschen" } } - if (user.checkPermission(Permission.ADMIN)) { a("$prefix/account/backup/delete/all", classes = "form-btn btn-danger") { +"Alles löschen" @@ -207,7 +202,7 @@ fun Route.account() { } get("/account/import") { - authenticateOrRedirect(Permission.ADMIN) { user -> + authenticateOrRedirect(Permission.SCHEDULE) { user -> val tracks = TrackRepository.all() val wikiSections = WikiImporter.loadSections() @@ -215,80 +210,78 @@ fun Route.account() { content { h1 { +"Aus Wiki importieren" } - if (user.checkPermission(Permission.ADMIN)) { - div("account-import-wiki") { - span { +"Arbeitskreise aus dem KIF-Wiki importieren" } + div("account-import-wiki") { + span { +"Arbeitskreise aus dem KIF-Wiki importieren" } - form(action = "$prefix/account/import", method = FormMethod.post) { - for ((index, section) in wikiSections.withIndex()) { - div("form-group") { - label { - htmlFor = "section-$index-track" - +section + form(action = "$prefix/account/import", method = FormMethod.post) { + for ((index, section) in wikiSections.withIndex()) { + div("form-group") { + label { + htmlFor = "section-$index-track" + +section + } + select( + classes = "form-control" + ) { + name = "section-$index-track" + + option { + selected = false + value = "-1" + +"Nicht importieren" } - select( - classes = "form-control" - ) { - name = "section-$index-track" - + option { + selected = true + value = "null" + +"Importieren" + } + for (track in tracks) { option { selected = false - value = "-1" - +"Nicht importieren" + value = track.id.toString() + +track.name } - option { - selected = true - value = "null" - +"Importieren" - } - for (track in tracks) { - option { - selected = false - value = track.id.toString() - +track.name - } - } - } - input(type = InputType.hidden, name = "section-$index-name") { - value = section } } + input(type = InputType.hidden, name = "section-$index-name") { + value = section + } } + } - div("form-switch-group") { - div("form-group form-switch") { - input( - name = "skip-existing", - classes = "form-control", - type = InputType.checkBox - ) { - id = "skip-existing" - checked = false - } - label { - htmlFor = "skip-existing" - +"Existierende Arbeitskreise überspringen" - } + div("form-switch-group") { + div("form-group form-switch") { + input( + name = "skip-existing", + classes = "form-control", + type = InputType.checkBox + ) { + id = "skip-existing" + checked = false } - div("form-group form-switch") { - input( - name = "delete-existing", - classes = "form-control", - type = InputType.checkBox - ) { - id = "delete-existing" - checked = false - } - label { - htmlFor = "delete-existing" - +"Existierende Arbeitskreise löschen" - } + label { + htmlFor = "skip-existing" + +"Existierende Arbeitskreise überspringen" } } + div("form-group form-switch") { + input( + name = "delete-existing", + classes = "form-control", + type = InputType.checkBox + ) { + id = "delete-existing" + checked = false + } + label { + htmlFor = "delete-existing" + +"Existierende Arbeitskreise löschen" + } + } + } - button(type = ButtonType.submit, classes = "form-btn btn-primary") { - +"Importieren" - } + button(type = ButtonType.submit, classes = "form-btn btn-primary") { + +"Importieren" } } } @@ -377,7 +370,7 @@ fun Route.account() { } post("/account/import") { - authenticate(Permission.ADMIN) { + authenticate(Permission.SCHEDULE) { val params = call.receiveParameters().toMap().mapValues { (_, list) -> list.firstOrNull() } @@ -488,7 +481,7 @@ fun Route.account() { } get("/account/backup/delete/schedules") { - authenticate(Permission.ROOM, Permission.WORK_GROUP, Permission.SCHEDULE) { + authenticate(Permission.SCHEDULE) { ScheduleRepository.all().forEach { if (it.id != null) ScheduleRepository.delete(it.id) } diff --git a/src/jvmMain/kotlin/de/kif/backend/route/WorkGroup.kt b/src/jvmMain/kotlin/de/kif/backend/route/WorkGroup.kt index 2167d72..26fc78a 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/WorkGroup.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/WorkGroup.kt @@ -418,10 +418,14 @@ fun Route.workGroup() { } input( name = "constraint-only-before-time-day-$index", - classes = "form-control" + classes = "form-control", + type = InputType.number ) { value = constraint.day?.toString() ?: "" + min = "-1337" + max = "1337" + placeholder = "Tag (optional)" } input( @@ -447,10 +451,14 @@ fun Route.workGroup() { } input( name = "constraint-only-after-time-day-$index", - classes = "form-control" + classes = "form-control", + type = InputType.number ) { value = constraint.day?.toString() ?: "" + min = "-1337" + max = "1337" + placeholder = "Tag (optional)" } input( @@ -476,10 +484,14 @@ fun Route.workGroup() { } input( name = "constraint-exact-time-day-$index", - classes = "form-control" + classes = "form-control", + type = InputType.number ) { value = constraint.day?.toString() ?: "" + min = "-1337" + max = "1337" + placeholder = "Tag (optional)" } input(