aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-datetime/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
committerRobert Jaros <rjaros@finn.pl>2018-10-13 03:37:40 +0200
commitebce2c4b839c0b2f8be78bc31c1ce12c45a0164c (patch)
tree7cac3c5449eb8aa398b279d62d9a67ed34fa4115 /kvision-modules/kvision-datetime/src
parent470953c78c2509224bb452c16f8bbea54e53b3d7 (diff)
downloadkvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.gz
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.tar.bz2
kvision-ebce2c4b839c0b2f8be78bc31c1ce12c45a0164c.zip
Major refactoring of the multi-platform components.
Dependencies upgrade. A lot of code style fixes.
Diffstat (limited to 'kvision-modules/kvision-datetime/src')
-rw-r--r--kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/KVManagerDatetime.kt2
-rw-r--r--kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt10
-rw-r--r--kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt43
-rw-r--r--kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt4
-rw-r--r--kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt4
5 files changed, 31 insertions, 32 deletions
diff --git a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/KVManagerDatetime.kt b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/KVManagerDatetime.kt
index cde55b1e..4cc71c8b 100644
--- a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/KVManagerDatetime.kt
+++ b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/KVManagerDatetime.kt
@@ -21,7 +21,7 @@
*/
package pl.treksoft.kvision
-internal val KVManagerDatetimeInit = KVManagerDatetime.init()
+internal val kVManagerDatetimeInit = KVManagerDatetime.init()
/**
* Internal singleton object which initializes and configures KVision datetime module.
diff --git a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
index 9cdd0369..3d32fd8c 100644
--- a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
+++ b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt
@@ -24,12 +24,12 @@ package pl.treksoft.kvision.form.time
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.form.DateFormControl
import pl.treksoft.kvision.form.FieldLabel
import pl.treksoft.kvision.form.HelpBlock
-import pl.treksoft.kvision.form.KDateFormControl
import pl.treksoft.kvision.panel.SimplePanel
-import pl.treksoft.kvision.types.KDate
import pl.treksoft.kvision.utils.SnOn
+import kotlin.js.Date
/**
* Form field date/time chooser component.
@@ -42,9 +42,9 @@ import pl.treksoft.kvision.utils.SnOn
* @param rich determines if [label] can contain HTML code
*/
open class DateTime(
- value: KDate? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
+ value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
rich: Boolean = false
-) : SimplePanel(setOf("form-group")), KDateFormControl {
+) : SimplePanel(setOf("form-group")), DateFormControl {
/**
* Date/time input value.
@@ -235,7 +235,7 @@ open class DateTime(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.dateTime(
- value: KDate? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
+ value: Date? = null, name: String? = null, format: String = "YYYY-MM-DD HH:mm", label: String? = null,
rich: Boolean = false, init: (DateTime.() -> Unit)? = null
): DateTime {
val dateTime = DateTime(value, name, format, label, rich).apply { init?.invoke(this) }
diff --git a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
index 1df8a082..69b84c87 100644
--- a/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
+++ b/kvision-modules/kvision-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt
@@ -29,11 +29,10 @@ import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.form.FormInput
import pl.treksoft.kvision.form.InputSize
import pl.treksoft.kvision.i18n.I18n
-import pl.treksoft.kvision.types.KDate
-import pl.treksoft.kvision.types.toJS
-import pl.treksoft.kvision.types.toKDateF
+import pl.treksoft.kvision.types.toDateF
import pl.treksoft.kvision.types.toStringF
import pl.treksoft.kvision.utils.obj
+import kotlin.js.Date
internal const val DEFAULT_MINUTE_STEP = 5
internal const val MAX_VIEW = 4
@@ -48,7 +47,7 @@ internal const val MAX_VIEW = 4
*/
@Suppress("TooManyFunctions")
open class DateTimeInput(
- value: KDate? = null, format: String = "YYYY-MM-DD HH:mm",
+ value: Date? = null, format: String = "YYYY-MM-DD HH:mm",
classes: Set<String> = setOf()
) : Widget(classes + "form-control"), FormInput {
@@ -63,11 +62,11 @@ open class DateTimeInput(
/**
* Date/time input value.
*/
- var value by refreshOnUpdate(value, { refreshState() })
+ var value by refreshOnUpdate(value) { refreshState() }
/**
* Date/time format.
*/
- var format by refreshOnUpdate(format, { refreshDatePicker() })
+ var format by refreshOnUpdate(format) { refreshDatePicker() }
/**
* The placeholder for the date/time input.
*/
@@ -95,31 +94,31 @@ open class DateTimeInput(
/**
* Day of the week start. 0 (Sunday) to 6 (Saturday).
*/
- var weekStart by refreshOnUpdate(0, { refreshDatePicker() })
+ var weekStart by refreshOnUpdate(0) { refreshDatePicker() }
/**
* Days of the week that should be disabled. Multiple values should be comma separated.
*/
- var daysOfWeekDisabled by refreshOnUpdate(arrayOf<Int>(), { refreshDatePicker() })
+ var daysOfWeekDisabled by refreshOnUpdate(arrayOf<Int>()) { refreshDatePicker() }
/**
* Determines if *Clear* button should be visible.
*/
- var clearBtn by refreshOnUpdate(true, { refreshDatePicker() })
+ var clearBtn by refreshOnUpdate(true) { refreshDatePicker() }
/**
* Determines if *Today* button should be visible.
*/
- var todayBtn by refreshOnUpdate(false, { refreshDatePicker() })
+ var todayBtn by refreshOnUpdate(false) { refreshDatePicker() }
/**
* Determines if the current day should be highlighted.
*/
- var todayHighlight by refreshOnUpdate(false, { refreshDatePicker() })
+ var todayHighlight by refreshOnUpdate(false) { refreshDatePicker() }
/**
* The increment used to build the hour view.
*/
- var minuteStep by refreshOnUpdate(DEFAULT_MINUTE_STEP, { refreshDatePicker() })
+ var minuteStep by refreshOnUpdate(DEFAULT_MINUTE_STEP) { refreshDatePicker() }
/**
* Determines if meridian views are visible in day and hour views.
*/
- var showMeridian by refreshOnUpdate(false, { refreshDatePicker() })
+ var showMeridian by refreshOnUpdate(false) { refreshDatePicker() }
override fun render(): VNode {
return render("input")
@@ -164,7 +163,7 @@ open class DateTimeInput(
@Suppress("UnsafeCastFromDynamic")
protected open fun refreshState() {
value?.let {
- getElementJQueryD()?.datetimepicker("update", it.toJS())
+ getElementJQueryD()?.datetimepicker("update", it)
} ?: run {
getElementJQueryD()?.`val`(null)
getElementJQueryD()?.datetimepicker("update", null)
@@ -181,7 +180,7 @@ open class DateTimeInput(
protected open fun changeValue() {
val v = getElementJQuery()?.`val`() as String?
if (v != null && v.isNotEmpty()) {
- this.value = v.toKDateF(format)
+ this.value = v.toDateF(format)
} else {
this.value = null
}
@@ -205,15 +204,15 @@ open class DateTimeInput(
override fun afterInsert(node: VNode) {
if (!this.disabled) {
this.initDateTimePicker()
- this.getElementJQuery()?.on("changeDate", { e, _ ->
+ this.getElementJQuery()?.on("changeDate") { e, _ ->
this.dispatchEvent("change", obj { detail = e })
- })
- this.getElementJQuery()?.on("show", { e, _ ->
+ }
+ this.getElementJQuery()?.on("show") { e, _ ->
this.dispatchEvent("showBsDateTime", obj { detail = e })
- })
- this.getElementJQuery()?.on("hide", { e, _ ->
+ }
+ this.getElementJQuery()?.on("hide") { e, _ ->
this.dispatchEvent("hideBsDateTime", obj { detail = e })
- })
+ }
refreshState()
}
}
@@ -280,7 +279,7 @@ open class DateTimeInput(
* It takes the same parameters as the constructor of the built component.
*/
fun Container.dateTimeInput(
- value: KDate? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set<String> = setOf(),
+ value: Date? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set<String> = setOf(),
init: (DateTimeInput.() -> Unit)? = null
): DateTimeInput {
val dateTimeInput = DateTimeInput(value, format, classes).apply { init?.invoke(this) }
diff --git a/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt b/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt
index d824125b..69ab46ec 100644
--- a/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt
+++ b/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeInputSpec.kt
@@ -23,9 +23,9 @@ package test.pl.treksoft.kvision.form.time
import pl.treksoft.kvision.form.time.DateTimeInput
import pl.treksoft.kvision.panel.Root
-import pl.treksoft.kvision.types.KDate
import pl.treksoft.kvision.types.toStringF
import test.pl.treksoft.kvision.DomSpec
+import kotlin.js.Date
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -35,7 +35,7 @@ class DateTimeInputSpec : DomSpec {
fun render() {
run {
val root = Root("test", true)
- val data = KDate()
+ val data = Date()
val dti = DateTimeInput(value = data).apply {
placeholder = "place"
id = "idti"
diff --git a/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt b/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt
index 482a7b7a..19cefd86 100644
--- a/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt
+++ b/kvision-modules/kvision-datetime/src/test/kotlin/test/pl/treksoft/kvision/form/time/DateTimeSpec.kt
@@ -23,10 +23,10 @@ package test.pl.treksoft.kvision.form.time
import pl.treksoft.kvision.form.time.DateTime
import pl.treksoft.kvision.panel.Root
-import pl.treksoft.kvision.types.KDate
import pl.treksoft.kvision.types.toStringF
import test.pl.treksoft.kvision.DomSpec
import kotlin.browser.document
+import kotlin.js.Date
import kotlin.test.Test
class DateTimeSpec : DomSpec {
@@ -35,7 +35,7 @@ class DateTimeSpec : DomSpec {
fun render() {
run {
val root = Root("test", true)
- val data = KDate()
+ val data = Date()
val ti = DateTime(value = data, label = "Label").apply {
placeholder = "place"
name = "name"