aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Css.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt5
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Widget.kt7
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt67
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt13
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt15
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt9
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/Password.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/Radio.kt18
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/Text.kt7
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/TextArea.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/TextAreaInput.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt7
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Button.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt24
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt14
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt9
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/CheckInputSpec.kt12
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt9
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/RadioSpec.kt10
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaInputSpec.kt9
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaSpec.kt8
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt9
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt8
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt6
25 files changed, 147 insertions, 153 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt b/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
index eba7782a..a645ac83 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
@@ -1,6 +1,6 @@
package pl.treksoft.kvision.core
-import pl.treksoft.kvision.utils.Utils
+import pl.treksoft.kvision.utils.toHexString
@Suppress("EnumNaming", "EnumEntryName")
enum class UNIT(val unit: String) {
@@ -215,7 +215,7 @@ class Border private constructor(private val width: CssSize? = null, private val
private val color: String? = null) {
constructor(width: CssSize? = null, style: BORDERSTYLE? = null) : this(width, style, null)
constructor(width: CssSize? = null, style: BORDERSTYLE? = null, color: Int) : this(width, style,
- "#" + Utils.intToHexString(color))
+ "#" + color.toHexString())
constructor(width: CssSize? = null, style: BORDERSTYLE? = null, color: COLOR) : this(width, style, color.color)
@@ -228,7 +228,7 @@ class Border private constructor(private val width: CssSize? = null, private val
}
class Color private constructor(private val color: String? = null) {
- constructor(color: Int) : this("#" + Utils.intToHexString(color))
+ constructor(color: Int) : this("#" + color.toHexString())
constructor(color: COLOR) : this(color.color)
fun asString(): String {
@@ -253,7 +253,7 @@ class Background private constructor(private val color: String? = null, private
sizeX: CssSize? = null, sizeY: CssSize? = null, size: BGSIZE? = null,
repeat: BGREPEAT? = null, origin: BGORIGIN? = null, clip: BGCLIP? = null,
attachment: BGATTACH? = null) : this("#" +
- Utils.intToHexString(color), image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip,
+ color.toHexString(), image, positionX, positionY, sizeX, sizeY, size, repeat, origin, clip,
attachment)
constructor(color: COLOR, image: ResString? = null, positionX: CssSize? = null,
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt b/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt
index e394db73..f603d944 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/KVManager.kt
@@ -8,7 +8,6 @@ import com.github.snabbdom.datasetModule
import com.github.snabbdom.eventListenersModule
import com.github.snabbdom.propsModule
import com.github.snabbdom.styleModule
-import pl.treksoft.jquery.jQuery
import pl.treksoft.kvision.require
import pl.treksoft.kvision.routing.routing
import kotlin.browser.document
@@ -19,6 +18,9 @@ object KVManager {
private val fontAwesomeWebpack = require("font-awesome-webpack")
private val resizable = require("jquery-resizable-dom")
private val awesomeBootstrapCheckbox = require("awesome-bootstrap-checkbox")
+ private val bootstrapSelectCss = require("bootstrap-select/dist/css/bootstrap-select.min.css")
+ private val bootstrapSelect = require("bootstrap-select")
+ private val bootstrapSelectI18n = require("./js/bootstrap-select-i18n.min.js")
private val sdPatch = Snabbdom.init(arrayOf(classModule, attributesModule, propsModule, styleModule,
eventListenersModule, datasetModule))
@@ -41,7 +43,6 @@ object KVManager {
}
fun init() {
- jQuery(document).off(".data-api")
}
fun shutdown() {
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
index 6ce1eade..123ffc4c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
@@ -215,6 +215,13 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() {
return hooks
}
+ @Suppress("UNCHECKED_CAST")
+ protected fun <T : Widget> setInternalEventListener(block: SnOn<T>.() -> Unit): Widget {
+ internalListeners.add(block as SnOn<Widget>.() -> Unit)
+ refresh()
+ return this
+ }
+
protected fun setInternalEventListener(block: SnOn<Widget>.() -> Unit): Widget {
internalListeners.add(block)
refresh()
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
index 1ba20211..eabed092 100644
--- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
@@ -1,8 +1,6 @@
package pl.treksoft.kvision.dropdown
import com.github.snabbdom.VNode
-import pl.treksoft.kvision.panel.SimplePanel
-import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.html.BUTTONSTYLE
import pl.treksoft.kvision.html.Button
@@ -11,9 +9,11 @@ import pl.treksoft.kvision.html.Link
import pl.treksoft.kvision.html.ListTag
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
+import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
import pl.treksoft.kvision.snabbdom.obj
+import kotlin.browser.window
enum class DD(val type: String) {
HEADER("DD#HEADER"),
@@ -22,8 +22,8 @@ enum class DD(val type: String) {
}
open class DropDown(text: String, elements: List<StringPair>? = null, icon: String? = null,
- style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT, disabled: Boolean = false, image: ResString? = null,
- dropup: Boolean = false, classes: Set<String> = setOf()) : SimplePanel(classes) {
+ style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT, disabled: Boolean = false,
+ classes: Set<String> = setOf()) : SimplePanel(classes) {
var text
get() = button.text
set(value) {
@@ -31,7 +31,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
}
private var elements = elements
set(value) {
- field = elements
+ field = value
setChildrenFromElements()
}
var icon
@@ -64,7 +64,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
set(value) {
button.image = value
}
- private var dropup = dropup
+ var dropup = false
set(value) {
field = value
refresh()
@@ -72,16 +72,10 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
private val idc = "kv_dropdown_" + counter
internal val button: DropDownButton = DropDownButton(idc, text, icon, style,
- disabled, image, setOf("dropdown"))
+ disabled, setOf("dropdown"))
internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu"))
init {
- button.setEventListener {
- click = {
- if (!button.disabled) toggle()
- }
- }
-
list.hide()
setChildrenFromElements()
this.addInternal(button)
@@ -104,8 +98,8 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
}
private fun setChildrenFromElements() {
- val elems = elements
- if (elems != null) {
+ list.removeAll()
+ elements?.let { elems ->
val c = elems.map {
when (it.second) {
DD.HEADER.type -> Tag(TAG.LI, it.first, classes = setOf("dropdown-header"))
@@ -123,14 +117,13 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
}
}
list.addAll(c)
- } else {
- list.removeAll()
}
}
@Suppress("UnsafeCastFromDynamic")
override fun afterInsert(node: VNode) {
this.getElementJQuery()?.on("show.bs.dropdown", { e, _ ->
+ if (!list.visible) list.visible = true
this.dispatchEvent("showBsDropdown", obj({ detail = e }))
})
this.getElementJQuery()?.on("shown.bs.dropdown", { e, _ ->
@@ -140,7 +133,7 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
this.dispatchEvent("hideBsDropdown", obj({ detail = e }))
})
this.getElementJQuery()?.on("hidden.bs.dropdown", { e, _ ->
- list.visible = false
+ if (list.visible) list.visible = false
this.dispatchEvent("hiddenBsDropdown", obj({ detail = e }))
})
}
@@ -155,17 +148,18 @@ open class DropDown(text: String, elements: List<StringPair>? = null, icon: Stri
}
open fun toggle() {
- if (list.visible)
- list.hideInternal()
- else
- list.show()
+ if (this.list.visible) {
+ this.list.getElementJQueryD()?.dropdown("toggle")
+ } else {
+ this.list.visible = true
+ window.setTimeout({ this.list.getElementJQueryD()?.dropdown("toggle") }, 0)
+ }
}
}
open class DropDownButton(id: String, text: String, icon: String? = null, style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT,
- disabled: Boolean = false,
- image: ResString? = null, classes: Set<String> = setOf()) :
- Button(text, icon, style, disabled, image, classes) {
+ disabled: Boolean = false, classes: Set<String> = setOf()) :
+ Button(text, icon, style, disabled, classes) {
init {
this.id = id
@@ -183,27 +177,4 @@ open class DropDownListTag(private val ariaId: String, classes: Set<String> = se
override fun getSnAttrs(): List<StringPair> {
return super.getSnAttrs() + listOf("aria-labelledby" to ariaId)
}
-
- override fun hide(): Widget {
- if (visible) hideInternal()
- return super.hide()
- }
-
- override fun afterInsert(node: VNode) {
- if (visible) showInternal()
- }
-
- @Suppress("UnsafeCastFromDynamic")
- private fun showInternal() {
- if (getElementJQueryD()?.`is`(":hidden")) {
- getElementJQueryD()?.dropdown("toggle")
- }
- }
-
- @Suppress("UnsafeCastFromDynamic")
- internal fun hideInternal() {
- if (!getElementJQueryD()?.`is`(":hidden")) {
- getElementJQueryD()?.dropdown("toggle")
- }
- }
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
index 82846012..84ad5661 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
@@ -4,12 +4,9 @@ import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
-abstract class AbstractTextInput(placeholder: String? = null,
- override var value: String? = null, name: String? = null, maxlength: Int? = null,
- disabled: Boolean = false, id: String? = null,
+abstract class AbstractTextInput(override var value: String? = null,
classes: Set<String> = setOf()) : Widget(classes + "form-control"), StringFormField {
init {
- this.id = id
this.setInternalEventListener {
input = {
val v = getElementJQuery()?.`val`() as String?
@@ -29,22 +26,22 @@ abstract class AbstractTextInput(placeholder: String? = null,
this.value = value
refresh()
}
- var placeholder: String? = placeholder
+ var placeholder: String? = null
set(value) {
field = value
refresh()
}
- var name: String? = name
+ var name: String? = null
set(value) {
field = value
refresh()
}
- var maxlength: Int? = maxlength
+ var maxlength: Int? = null
set(value) {
field = value
refresh()
}
- override var disabled: Boolean = disabled
+ override var disabled: Boolean = false
set(value) {
field = value
refresh()
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt
index 65941495..f4598d4d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckBox.kt
@@ -1,7 +1,7 @@
package pl.treksoft.kvision.form
-import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.SnOn
import pl.treksoft.kvision.snabbdom.StringBoolPair
@@ -14,9 +14,8 @@ enum class CHECKBOXSTYLE(val className: String) {
DANGER("checkbox-danger"),
}
-open class CheckBox(value: Boolean = false, name: String? = null, style: CHECKBOXSTYLE? = null,
- circled: Boolean = false, inline: Boolean = false, disabled: Boolean = false,
- label: String? = null, rich: Boolean = false) : SimplePanel(setOf("checkbox")), BoolFormField {
+open class CheckBox(value: Boolean = false, label: String? = null,
+ rich: Boolean = false) : SimplePanel(setOf("checkbox")), BoolFormField {
override var value
get() = input.value
@@ -48,17 +47,17 @@ open class CheckBox(value: Boolean = false, name: String? = null, style: CHECKBO
set(value) {
flabel.rich = value
}
- var style = style
+ var style: CHECKBOXSTYLE? = null
set(value) {
field = value
refresh()
}
- var circled = circled
+ var circled: Boolean = false
set(value) {
field = value
refresh()
}
- var inline = inline
+ var inline: Boolean = false
set(value) {
field = value
refresh()
@@ -70,7 +69,7 @@ open class CheckBox(value: Boolean = false, name: String? = null, style: CHECKBO
}
private val idc = "kv_form_checkbox_" + counter
- val input: CheckInput = CheckInput(CHECKINPUTTYPE.CHECKBOX, value, name, disabled, idc, null, setOf("styled"))
+ val input: CheckInput = CheckInput(CHECKINPUTTYPE.CHECKBOX, value, setOf("styled")).apply { id = idc }
val flabel: FieldLabel = FieldLabel(idc, label, rich)
init {
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
index 07008ddd..36e59e87 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
@@ -11,12 +11,9 @@ enum class CHECKINPUTTYPE(val type: String) {
}
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<String> = setOf()) : Widget(classes), BoolFormField {
init {
- this.id = id
this.setInternalEventListener {
click = {
val v = getElementJQuery()?.prop("checked") as Boolean?
@@ -41,17 +38,17 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, override v
field = value
refresh()
}
- var name: String? = name
+ var name: String? = null
set(value) {
field = value
refresh()
}
- override var disabled: Boolean = disabled
+ override var disabled: Boolean = false
set(value) {
field = value
refresh()
}
- var extraValue: String? = extraValue
+ var extraValue: String? = null
set(value) {
field = value
refresh()
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Password.kt b/src/main/kotlin/pl/treksoft/kvision/form/Password.kt
index 86a862cd..9b505e8b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/Password.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/Password.kt
@@ -1,6 +1,4 @@
package pl.treksoft.kvision.form
-open class Password(placeholder: String? = null, value: String? = null,
- name: String? = null, maxlength: Int? = null, label: String? = null, rich: Boolean = false,
- disabled: Boolean = false) : Text(TEXTINPUTTYPE.PASSWORD, placeholder, value, name, maxlength,
- label, rich, disabled)
+open class Password(value: String? = null, label: String? = null, rich: Boolean = false) : Text(TEXTINPUTTYPE.PASSWORD,
+ value, label, rich)
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt
index 66c2d75c..3ee6edff 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/Radio.kt
@@ -1,7 +1,7 @@
package pl.treksoft.kvision.form
-import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.SnOn
import pl.treksoft.kvision.snabbdom.StringBoolPair
@@ -14,9 +14,8 @@ enum class RADIOSTYLE(val className: String) {
DANGER("radio-danger"),
}
-open class Radio(value: Boolean = false, extraValue: String? = null, name: String? = null, style: RADIOSTYLE? = null,
- squared: Boolean = false, inline: Boolean = false, disabled: Boolean = false,
- label: String? = null, rich: Boolean = false) : SimplePanel(), BoolFormField {
+open class Radio(value: Boolean = false, extraValue: String? = null, label: String? = null,
+ rich: Boolean = false) : SimplePanel(), BoolFormField {
override var value
get() = input.value
@@ -53,17 +52,17 @@ open class Radio(value: Boolean = false, extraValue: String? = null, name: Strin
set(value) {
flabel.rich = value
}
- var style = style
+ var style: RADIOSTYLE? = null
set(value) {
field = value
refresh()
}
- var squared = squared
+ var squared: Boolean = false
set(value) {
field = value
refresh()
}
- var inline = inline
+ var inline: Boolean = false
set(value) {
field = value
refresh()
@@ -75,7 +74,10 @@ open class Radio(value: Boolean = false, extraValue: String? = null, name: Strin
}
private val idc = "kv_form_radio_" + counter
- val input: CheckInput = CheckInput(CHECKINPUTTYPE.RADIO, value, name, disabled, idc, extraValue)
+ val input: CheckInput = CheckInput(CHECKINPUTTYPE.RADIO, value).apply {
+ this.id = idc
+ this.extraValue = extraValue
+ }
val flabel: FieldLabel = FieldLabel(idc, label, rich)
init {
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Text.kt b/src/main/kotlin/pl/treksoft/kvision/form/Text.kt
index 44cbf0c9..01816195 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/Text.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/Text.kt
@@ -1,9 +1,8 @@
package pl.treksoft.kvision.form
-open class Text(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? = null, value: String? = null,
- name: String? = null, maxlength: Int? = null, label: String? = null, rich: Boolean = false,
- disabled: Boolean = false) : AbstractText(label, rich) {
+open class Text(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null,
+ label: String? = null, rich: Boolean = false) : AbstractText(label, rich) {
var type
get() = input.type
@@ -16,7 +15,7 @@ open class Text(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? =
input.autocomplete = value
}
- final override val input: TextInput = TextInput(type, placeholder, value, name, maxlength, disabled, idc)
+ final override val input: TextInput = TextInput(type, value).apply { id = idc }
init {
this.addInternal(input)
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/TextArea.kt b/src/main/kotlin/pl/treksoft/kvision/form/TextArea.kt
index 7cc45971..9b65a306 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/TextArea.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/TextArea.kt
@@ -1,8 +1,7 @@
package pl.treksoft.kvision.form
-open class TextArea(cols: Int? = null, rows: Int? = null, placeholder: String? = null, value: String? = null,
- name: String? = null, maxlength: Int? = null, label: String? = null, rich: Boolean = false,
- disabled: Boolean = false) : AbstractText(label, rich) {
+open class TextArea(cols: Int? = null, rows: Int? = null, value: String? = null,
+ label: String? = null, rich: Boolean = false) : AbstractText(label, rich) {
var cols
get() = input.cols
@@ -20,8 +19,7 @@ open class TextArea(cols: Int? = null, rows: Int? = null, placeholder: String? =
input.wrapHard = value
}
- final override val input: TextAreaInput = TextAreaInput(cols, rows, placeholder, value, name, maxlength,
- disabled, idc)
+ final override val input: TextAreaInput = TextAreaInput(cols, rows, value).apply { id = idc }
init {
this.addInternal(input)
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/TextAreaInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/TextAreaInput.kt
index 0b2c69fd..5b8dd5b5 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/TextAreaInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/TextAreaInput.kt
@@ -3,10 +3,8 @@ package pl.treksoft.kvision.form
import com.github.snabbdom.VNode
import pl.treksoft.kvision.snabbdom.StringPair
-class TextAreaInput(cols: Int? = null, rows: Int? = null, placeholder: String? = null,
- value: String? = null, name: String? = null, maxlength: Int? = null,
- disabled: Boolean = false, id: String? = null, classes: Set<String> = setOf()) :
- AbstractTextInput(placeholder, value, name, maxlength, disabled, id, classes) {
+class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = null, classes: Set<String> = setOf()) :
+ AbstractTextInput(value, classes) {
var cols: Int? = cols
set(value) {
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
index 6cf0f239..7b3510ac 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
@@ -8,10 +8,8 @@ enum class TEXTINPUTTYPE(val type: String) {
PASSWORD("password")
}
-class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? = null,
- value: String? = null, name: String? = null, maxlength: Int? = null,
- disabled: Boolean = false, id: String? = null, classes: Set<String> = setOf()) :
- AbstractTextInput(placeholder, value, name, maxlength, disabled, id, classes) {
+class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null, classes: Set<String> = setOf()) :
+ AbstractTextInput(value, classes) {
var type: TEXTINPUTTYPE = type
set(value) {
@@ -28,7 +26,6 @@ class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? =
return kvh("input")
}
- @Suppress("ComplexMethod")
override fun getSnAttrs(): List<StringPair> {
val sn = super.getSnAttrs().toMutableList()
sn.add("type" to type.type)
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
index f0cb91f7..d14ce66e 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
@@ -23,8 +23,7 @@ enum class BUTTONSIZE(val className: String) {
}
open class Button(text: String, icon: String? = null, style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT,
- disabled: Boolean = false, image: ResString? = null,
- classes: Set<String> = setOf()) : Widget(classes) {
+ disabled: Boolean = false, classes: Set<String> = setOf()) : Widget(classes) {
var text = text
set(value) {
field = value
@@ -45,12 +44,11 @@ open class Button(text: String, icon: String? = null, style: BUTTONSTYLE = BUTTO
field = value
refresh()
}
- var image = image
+ var image: ResString? = null
set(value) {
field = value
refresh()
}
-
var size: BUTTONSIZE? = null
set(value) {
field = value
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
index 9c88326b..e2396868 100644
--- a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
@@ -1,4 +1,5 @@
@file:Suppress("TooManyFunctions")
+
package pl.treksoft.kvision.utils
import pl.treksoft.kvision.core.CssSize
@@ -14,25 +15,22 @@ fun Int.cm(): CssSize = Pair(this, UNIT.cm)
fun Int.mm(): CssSize = Pair(this, UNIT.mm)
@Suppress("FunctionNaming")
fun Int.`in`(): CssSize = Pair(this, UNIT.`in`)
+
fun Int.pc(): CssSize = Pair(this, UNIT.pc)
fun Int.vh(): CssSize = Pair(this, UNIT.vh)
fun Int.vw(): CssSize = Pair(this, UNIT.vw)
fun Int.vmin(): CssSize = Pair(this, UNIT.vmin)
fun Int.vmax(): CssSize = Pair(this, UNIT.vmax)
-object Utils {
+private val hex = arrayOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")
- private val hex = arrayOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")
-
- @Suppress("MagicNumber")
- fun intToHexString(n: Int): String {
- var result = ""
- var num = n
- for (i in 0 until 6) {
- result = hex[num and 0xF] + result
- num = num shr 4
- }
- return result
+@Suppress("MagicNumber")
+fun Int.toHexString(): String {
+ var result = ""
+ var num = this
+ for (i in 0 until 6) {
+ result = hex[num and 0xF] + result
+ num = num shr 4
}
-
+ return result
}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt
index 4e42fbe2..6cfd948a 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/dropdown/DropDownSpec.kt
@@ -20,7 +20,7 @@ class DropDownSpec : DomSpec {
dd.toggle()
val element = document.getElementById("test")
val id = dd.button.id
- assertEquals("<div class=\"dropdown open\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\" aria-expanded=\"true\"><li><a href=\"#!/x\">abc</a></li><li><a href=\"#!/y\">def</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ assertEquals("<div class=\"dropdown\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\"><li><a href=\"#!/x\">abc</a></li><li><a href=\"#!/y\">def</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
}
}
@@ -28,12 +28,12 @@ class DropDownSpec : DomSpec {
fun renderDropUp() {
run {
val root = Root("test")
- val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag", dropup = true)
+ val dd = DropDown("Dropdown", listOf("abc" to "#!/x", "def" to "#!/y"), "flag").apply { dropup = true }
root.add(dd)
dd.toggle()
val element = document.getElementById("test")
val id = dd.button.id
- assertEquals("<div class=\"dropup open\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\" aria-expanded=\"true\"><li><a href=\"#!/x\">abc</a></li><li><a href=\"#!/y\">def</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ assertEquals("<div class=\"dropup\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\"><li><a href=\"#!/x\">abc</a></li><li><a href=\"#!/y\">def</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
}
}
@@ -46,7 +46,7 @@ class DropDownSpec : DomSpec {
dd.toggle()
val element = document.getElementById("test")
val id = dd.button.id
- assertEquals("<div class=\"dropdown open\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\" aria-expanded=\"true\"><li class=\"dropdown-header\">abc</li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ assertEquals("<div class=\"dropdown\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\"><li class=\"dropdown-header\">abc</li></ul></div>", element?.innerHTML, "Should render correct drop down")
}
}
@@ -59,7 +59,7 @@ class DropDownSpec : DomSpec {
dd.toggle()
val element = document.getElementById("test")
val id = dd.button.id
- assertEquals("<div class=\"dropdown open\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\" aria-expanded=\"true\"><li class=\"divider\" role=\"separator\">abc</li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ assertEquals("<div class=\"dropdown\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\"><li class=\"divider\" role=\"separator\">abc</li></ul></div>", element?.innerHTML, "Should render correct drop down")
}
}
@@ -72,7 +72,7 @@ class DropDownSpec : DomSpec {
dd.toggle()
val element = document.getElementById("test")
val id = dd.button.id
- assertEquals("<div class=\"dropdown open\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\" aria-expanded=\"true\"><li class=\"disabled\"><a href=\"#\">abc</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
+ assertEquals("<div class=\"dropdown\"><button class=\"dropdown btn btn-default\" id=\"$id\" type=\"button\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"><span class=\"glyphicon glyphicon-flag\"></span> Dropdown</button><ul class=\"dropdown-menu\" aria-labelledby=\"$id\"><li class=\"disabled\"><a href=\"#\">abc</a></li></ul></div>", element?.innerHTML, "Should render correct drop down")
}
}
@@ -85,8 +85,6 @@ class DropDownSpec : DomSpec {
val menu = dd.list.getElementJQuery()
assertTrue("Dropdown menu is not rendered before toggle") { menu == null }
dd.toggle()
- val classes = dd.getElementJQuery()?.attr("class")
- assertTrue("Dropdown is visible after toggle") { classes?.contains("open") == true }
val menu2 = dd.list.getElementJQuery()
assertTrue("Dropdown menu is rendered after toggle") { menu2 != null }
}
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt
index 3da204b3..dd46d747 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckBoxSpec.kt
@@ -14,8 +14,13 @@ class CheckBoxSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ci = CheckBox(value = true, name = "name", style = CHECKBOXSTYLE.DANGER, disabled = true, circled = true,
- inline = true, label = "Label")
+ val ci = CheckBox(value = true, label = "Label").apply {
+ name = "name"
+ style = CHECKBOXSTYLE.DANGER
+ disabled = true
+ circled = true
+ inline = true
+ }
root.add(ci)
val element = document.getElementById("test")
val id = ci.input.id
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckInputSpec.kt
index 8991b710..fb1b0fbf 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/CheckInputSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/CheckInputSpec.kt
@@ -14,7 +14,11 @@ class CheckInputSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ci = CheckInput(value = true, name = "name", id = "idti", disabled = true)
+ val ci = CheckInput(value = true).apply {
+ name = "name"
+ id = "idti"
+ disabled = true
+ }
root.add(ci)
val element = document.getElementById("test")
assertEquals("<input id=\"idti\" type=\"checkbox\" checked=\"\" name=\"name\" disabled=\"\">", element?.innerHTML, "Should render correct checkbox field")
@@ -25,7 +29,11 @@ class CheckInputSpec : DomSpec {
fun renderAsRadio() {
run {
val root = Root("test")
- val ci = CheckInput(type = CHECKINPUTTYPE.RADIO, value = true, name = "name", id = "idti", extraValue = "abc")
+ val ci = CheckInput(type = CHECKINPUTTYPE.RADIO, value = true).apply {
+ name = "name"
+ id = "idti"
+ extraValue = "abc"
+ }
root.add(ci)
val element = document.getElementById("test")
assertEquals("<input id=\"idti\" type=\"radio\" checked=\"\" name=\"name\" value=\"abc\">", element?.innerHTML, "Should render correct radio button field")
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt
index b03112a7..789d13fa 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/PasswordSpec.kt
@@ -2,7 +2,6 @@ package test.pl.treksoft.kvision.form
import pl.treksoft.kvision.core.Root
import pl.treksoft.kvision.form.Password
-import pl.treksoft.kvision.form.Text
import test.pl.treksoft.kvision.DomSpec
import kotlin.browser.document
import kotlin.test.Test
@@ -14,8 +13,12 @@ class PasswordSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ti = Password(placeholder = "place", value = "abc", name = "name",
- maxlength = 15, disabled = true, label = "Label")
+ val ti = Password(value = "abc", label = "Label").apply {
+ placeholder = "place"
+ name = "name"
+ maxlength = 15
+ disabled = true
+ }
root.add(ti)
val element = document.getElementById("test")
val id = ti.input.id
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/RadioSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/RadioSpec.kt
index 5b827a56..a0e4b853 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/RadioSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/RadioSpec.kt
@@ -1,8 +1,6 @@
package test.pl.treksoft.kvision.form
import pl.treksoft.kvision.core.Root
-import pl.treksoft.kvision.form.CHECKBOXSTYLE
-import pl.treksoft.kvision.form.CheckBox
import pl.treksoft.kvision.form.RADIOSTYLE
import pl.treksoft.kvision.form.Radio
import test.pl.treksoft.kvision.DomSpec
@@ -16,8 +14,12 @@ class RadioSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ci = Radio(value = true, name = "name", style = RADIOSTYLE.DANGER, disabled = true,
- inline = true, label = "Label", extraValue = "abc")
+ val ci = Radio(value = true, label = "Label", extraValue = "abc").apply {
+ name = "name"
+ style = RADIOSTYLE.DANGER
+ disabled = true
+ inline = true
+ }
root.add(ci)
val element = document.getElementById("test")
val id = ci.input.id
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaInputSpec.kt
index 630a0eed..ff73b35c 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaInputSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaInputSpec.kt
@@ -13,8 +13,13 @@ class TextAreaInputSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ti = TextAreaInput(cols = 5, rows = 2, placeholder = "place", value = "abc", name = "name",
- maxlength = 15, id = "idti", disabled = true)
+ val ti = TextAreaInput(cols = 5, rows = 2, value = "abc").apply {
+ placeholder = "place"
+ name = "name"
+ maxlength = 15
+ id = "idti"
+ disabled = true
+ }
root.add(ti)
val element = document.getElementById("test")
assertEquals("<textarea class=\"form-control\" id=\"idti\" placeholder=\"place\" name=\"name\" maxlength=\"15\" disabled=\"\" cols=\"5\" rows=\"2\">abc</textarea>", element?.innerHTML, "Should render correct input field")
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaSpec.kt
index e422ac2b..3be42379 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextAreaSpec.kt
@@ -13,8 +13,12 @@ class TextAreaSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ti = TextArea(cols = 5, rows = 2, placeholder = "place", value = "abc", name = "name",
- maxlength = 15, disabled = true, label = "Label")
+ val ti = TextArea(cols = 5, rows = 2, value = "abc", label = "Label").apply {
+ placeholder = "place"
+ name = "name"
+ maxlength = 15
+ disabled = true
+ }
root.add(ti)
val element = document.getElementById("test")
val id = ti.input.id
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt
index 9e5ed64d..0bce8656 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextInputSpec.kt
@@ -14,8 +14,13 @@ class TextInputSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ti = TextInput(type = TEXTINPUTTYPE.PASSWORD, placeholder = "place", value = "abc", name = "name",
- maxlength = 15, id = "idti", disabled = true)
+ val ti = TextInput(type = TEXTINPUTTYPE.PASSWORD, value = "abc").apply {
+ placeholder = "place"
+ name = "name"
+ maxlength = 15
+ id = "idti"
+ disabled = true
+ }
root.add(ti)
val element = document.getElementById("test")
assertEquals("<input class=\"form-control\" id=\"idti\" placeholder=\"place\" name=\"name\" maxlength=\"15\" disabled=\"\" type=\"password\" value=\"abc\">", element?.innerHTML, "Should render correct input field")
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt
index 675d9db8..8b460e3c 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/form/TextSpec.kt
@@ -13,8 +13,12 @@ class TextSpec : DomSpec {
fun render() {
run {
val root = Root("test")
- val ti = Text(placeholder = "place", value = "abc", name = "name",
- maxlength = 15, disabled = true, label = "Label")
+ val ti = Text(value = "abc", label = "Label").apply {
+ placeholder = "place"
+ name = "name"
+ maxlength = 15
+ disabled = true
+ }
root.add(ti)
val element = document.getElementById("test")
val id = ti.input.id
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
index 5ea10c7a..1190bc1a 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
@@ -1,6 +1,6 @@
package test.pl.treksoft.kvision.utils
-import pl.treksoft.kvision.utils.Utils
+import pl.treksoft.kvision.utils.toHexString
import test.pl.treksoft.kvision.SimpleSpec
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -10,9 +10,9 @@ class UtilsSpec : SimpleSpec {
@Test
fun intToHexString() {
run {
- val res = Utils.intToHexString(0xabcdef)
+ val res = 0xabcdef.toHexString()
assertEquals("abcdef", res, "Should convert int value to hex string")
- val res2 = Utils.intToHexString(0x123456)
+ val res2 = 0x123456.toHexString()
assertEquals("123456", res2, "Should convert int value to hex string")
}
}