From 6caae545b7961f9ba5f136d38730ecf026ab7fbb Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 19 Oct 2017 13:51:01 +0200 Subject: Refactoring - CheckBoxInput -> CheckInput --- .../kotlin/pl/treksoft/kvision/form/CheckBox.kt | 2 +- .../pl/treksoft/kvision/form/CheckBoxInput.kt | 97 ---------------------- .../kotlin/pl/treksoft/kvision/form/CheckInput.kt | 97 ++++++++++++++++++++++ src/main/kotlin/pl/treksoft/kvision/form/Radio.kt | 2 +- 4 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt create mode 100644 src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt index 13551f67..87963922 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt @@ -70,7 +70,7 @@ open class CheckBox(value: Boolean = false, name: String? = null, style: CHECKBO } private val idc = "kv_form_checkbox_" + counter - val input: CheckBoxInput = CheckBoxInput(CHECKINPUTTYPE.CHECKBOX, value, name, disabled, idc, null, setOf("styled")) + val input: CheckInput = CheckInput(CHECKINPUTTYPE.CHECKBOX, value, name, disabled, idc, null, setOf("styled")) val flabel: FieldLabel = FieldLabel(idc, label, rich) init { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt deleted file mode 100644 index 5fa220e9..00000000 --- a/src/main/kotlin/pl/treksoft/kvision/form/CheckBoxInput.kt +++ /dev/null @@ -1,97 +0,0 @@ -package pl.treksoft.kvision.form - -import com.github.snabbdom.VNode -import pl.treksoft.kvision.core.Widget -import pl.treksoft.kvision.snabbdom.StringBoolPair -import pl.treksoft.kvision.snabbdom.StringPair - -enum class CHECKINPUTTYPE(val type: String) { - CHECKBOX("checkbox"), - RADIO("radio") -} - -open class CheckBoxInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, override var value: Boolean = false, - name: String? = null, disabled: Boolean = false, id: String? = null, - extraValue: String? = null, - classes: Set = setOf()) : Widget(classes), BoolFormField { - - init { - this.id = id - } - - @Suppress("LeakingThis") - var startValue: Boolean = value - set(value) { - field = value - this.value = value - refresh() - } - var type: CHECKINPUTTYPE = type - set(value) { - field = value - refresh() - } - var name: String? = name - set(value) { - field = value - refresh() - } - override var disabled: Boolean = disabled - set(value) { - field = value - refresh() - } - var extraValue: String? = extraValue - set(value) { - field = value - refresh() - } - override var size: INPUTSIZE? = null - set(value) { - field = value - refresh() - } - - override fun render(): VNode { - return kvh("input") - } - - override fun getSnClass(): List { - val cl = super.getSnClass().toMutableList() - size?.let { - cl.add(it.className to true) - } - return cl - } - - override fun getSnAttrs(): List { - val sn = super.getSnAttrs().toMutableList() - sn.add("type" to type.type) - if (startValue) { - sn.add("checked" to "true") - } - name?.let { - sn.add("name" to it) - } - if (disabled) { - sn.add("disabled" to "true") - } - extraValue?.let { - sn.add("value" to it) - } - return sn - } - - override fun afterInsert(node: VNode) { - this.getElementJQuery()?.on("change", { _, _ -> - val v = getElementJQuery()?.prop("checked") as Boolean? - value = (v == true) - true - }) - this.getElementJQuery()?.on("click", { _, _ -> - val v = getElementJQuery()?.prop("checked") as Boolean? - value = (v == true) - true - }) - } -} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt new file mode 100644 index 00000000..131793b8 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt @@ -0,0 +1,97 @@ +package pl.treksoft.kvision.form + +import com.github.snabbdom.VNode +import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.snabbdom.StringBoolPair +import pl.treksoft.kvision.snabbdom.StringPair + +enum class CHECKINPUTTYPE(val type: String) { + CHECKBOX("checkbox"), + RADIO("radio") +} + +open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, override var value: Boolean = false, + name: String? = null, disabled: Boolean = false, id: String? = null, + extraValue: String? = null, + classes: Set = setOf()) : Widget(classes), BoolFormField { + + init { + this.id = id + } + + @Suppress("LeakingThis") + var startValue: Boolean = value + set(value) { + field = value + this.value = value + refresh() + } + var type: CHECKINPUTTYPE = type + set(value) { + field = value + refresh() + } + var name: String? = name + set(value) { + field = value + refresh() + } + override var disabled: Boolean = disabled + set(value) { + field = value + refresh() + } + var extraValue: String? = extraValue + set(value) { + field = value + refresh() + } + override var size: INPUTSIZE? = null + set(value) { + field = value + refresh() + } + + override fun render(): VNode { + return kvh("input") + } + + override fun getSnClass(): List { + val cl = super.getSnClass().toMutableList() + size?.let { + cl.add(it.className to true) + } + return cl + } + + override fun getSnAttrs(): List { + val sn = super.getSnAttrs().toMutableList() + sn.add("type" to type.type) + if (startValue) { + sn.add("checked" to "true") + } + name?.let { + sn.add("name" to it) + } + if (disabled) { + sn.add("disabled" to "true") + } + extraValue?.let { + sn.add("value" to it) + } + return sn + } + + override fun afterInsert(node: VNode) { + this.getElementJQuery()?.on("change", { _, _ -> + val v = getElementJQuery()?.prop("checked") as Boolean? + value = (v == true) + true + }) + this.getElementJQuery()?.on("click", { _, _ -> + val v = getElementJQuery()?.prop("checked") as Boolean? + value = (v == true) + true + }) + } +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt index f3f72a3d..f8db5162 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt @@ -75,7 +75,7 @@ open class Radio(value: Boolean = false, extraValue: String? = null, name: Strin } private val idc = "kv_form_radio_" + counter - val input: CheckBoxInput = CheckBoxInput(CHECKINPUTTYPE.RADIO, value, name, disabled, idc, extraValue) + val input: CheckInput = CheckInput(CHECKINPUTTYPE.RADIO, value, name, disabled, idc, extraValue) val flabel: FieldLabel = FieldLabel(idc, label, rich) init { -- cgit