From 06f297d68887c7934e66d2c757abc8bf619df66a Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 28 Oct 2017 23:45:26 +0200 Subject: Databinding components Event handlers refactoring --- src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 81 +++++++++++++++++++--- .../kotlin/pl/treksoft/kvision/core/Container.kt | 61 +++------------- src/main/kotlin/pl/treksoft/kvision/core/Root.kt | 9 ++- src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 79 +++++++++++++++++++-- .../pl/treksoft/kvision/data/DataComponent.kt | 15 ++++ .../pl/treksoft/kvision/data/DataContainer.kt | 60 ++++++++++++++++ .../pl/treksoft/kvision/data/DataUpdatable.kt | 5 ++ .../pl/treksoft/kvision/dropdown/DropDown.kt | 8 +-- .../pl/treksoft/kvision/form/AbstractText.kt | 4 +- .../pl/treksoft/kvision/form/AbstractTextInput.kt | 28 ++++---- .../kotlin/pl/treksoft/kvision/form/CheckBox.kt | 4 +- .../kotlin/pl/treksoft/kvision/form/CheckInput.kt | 32 ++++++--- src/main/kotlin/pl/treksoft/kvision/form/Radio.kt | 4 +- src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 4 +- src/main/kotlin/pl/treksoft/kvision/html/List.kt | 4 +- src/main/kotlin/pl/treksoft/kvision/html/Tag.kt | 4 +- src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt | 18 ++--- .../kotlin/pl/treksoft/kvision/panel/DockPanel.kt | 13 ++-- .../kotlin/pl/treksoft/kvision/panel/FlexPanel.kt | 16 ++--- .../kotlin/pl/treksoft/kvision/panel/GridPanel.kt | 17 +++-- .../treksoft/kvision/panel/ResponsiveGridPanel.kt | 63 ++++++++--------- .../pl/treksoft/kvision/panel/SimplePanel.kt | 59 ++++++++++++++++ .../kotlin/pl/treksoft/kvision/panel/SplitPanel.kt | 3 +- .../kotlin/pl/treksoft/kvision/panel/StackPanel.kt | 11 ++- .../kotlin/pl/treksoft/kvision/panel/TabPanel.kt | 33 +++++++-- .../test/pl/treksoft/kvision/core/ContainerSpec.kt | 18 ++--- .../test/pl/treksoft/kvision/core/KVManagerSpec.kt | 16 ++--- .../test/pl/treksoft/kvision/core/RootSpec.kt | 4 +- 28 files changed, 465 insertions(+), 208 deletions(-) create mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataComponent.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/data/DataUpdatable.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index f1406505..282ea510 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -1,10 +1,27 @@ package pl.treksoft.kvision +import com.lightningkite.kotlin.observable.list.observableListOf import pl.treksoft.kvision.basic.Label -import pl.treksoft.kvision.core.* +import pl.treksoft.kvision.core.BGATTACH +import pl.treksoft.kvision.core.BGREPEAT +import pl.treksoft.kvision.core.BGSIZE +import pl.treksoft.kvision.core.BORDERSTYLE +import pl.treksoft.kvision.core.Background +import pl.treksoft.kvision.core.Border +import pl.treksoft.kvision.core.COLOR +import pl.treksoft.kvision.core.Img +import pl.treksoft.kvision.core.Root +import pl.treksoft.kvision.data.DataComponent +import pl.treksoft.kvision.data.DataContainer import pl.treksoft.kvision.dropdown.DD.* import pl.treksoft.kvision.dropdown.DropDown -import pl.treksoft.kvision.form.* +import pl.treksoft.kvision.form.CheckBox +import pl.treksoft.kvision.form.INPUTSIZE +import pl.treksoft.kvision.form.TEXTINPUTTYPE +import pl.treksoft.kvision.form.Text +import pl.treksoft.kvision.form.TextArea +import pl.treksoft.kvision.form.TextAreaInput +import pl.treksoft.kvision.form.TextInput import pl.treksoft.kvision.html.* import pl.treksoft.kvision.html.TAG.DIV import pl.treksoft.kvision.html.TAG.H1 @@ -21,7 +38,51 @@ class Showcase : ApplicationBase() { override fun start(state: Map) { val root = Root("showcase") - val container = Container(setOf("abc", "def")) + class Model(p: Boolean, t: String) : DataComponent() { + var p: Boolean by obs(p) + var t: String by obs(t) + } + + val model = observableListOf(Model(true, "Pierwszy"), Model(false, "Drugi"), Model(false, "Trzeci")) + val datac = DataContainer(model, { element, index -> + CheckBox(value = element.p, + label = if (element.p) "" + (index + 1) + " " + element.t + "" else element.t, + rich = true).setEventListener({ + click = { + element.p = self.value + } + }) + }) + root.add(datac) + + val mbutton = Button("Pokaż wartości").setEventListener