diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-01-19 00:22:09 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-01-19 00:22:09 +0100 |
commit | d964f6beac4cbde710e684cfaa13667eb8dfeb91 (patch) | |
tree | 389cba3e200994d0f6d96b0db23885d278dc7d0e /src/main | |
parent | 76754fd65d195f418a8643a8e0213fc8b0b6ab31 (diff) | |
download | kvision-d964f6beac4cbde710e684cfaa13667eb8dfeb91.tar.gz kvision-d964f6beac4cbde710e684cfaa13667eb8dfeb91.tar.bz2 kvision-d964f6beac4cbde710e684cfaa13667eb8dfeb91.zip |
New method for easy access to the content of selected files.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 19 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt | 8 |
3 files changed, 35 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index e2f5d730..983b83e5 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -32,6 +32,7 @@ import pl.treksoft.kvision.types.DateSerializer import pl.treksoft.kvision.types.KFile import pl.treksoft.kvision.types.toStringF import pl.treksoft.kvision.utils.JSON +import pl.treksoft.kvision.utils.getContent import kotlin.js.Date import kotlin.js.Json import kotlin.reflect.KProperty1 @@ -279,6 +280,24 @@ class Form<K : Any>(private val panel: FormPanel<K>? = null, private val seriali } /** + * Returns current data model with file content read for all KFiles controls. + * @return data model + */ + suspend fun getDataWithFileContent(): K { + val map = fields.entries.associateBy({ it.key }, { + val value = it.value + if (value is KFilesFormControl) { + value.getValue()?.map { + it.copy(content = value.getNativeFile(it)?.getContent()) + } + } else { + value.getValue() + } + }) + return modelFactory(map.withDefault { null }) + } + + /** * Returns current data model as JSON. * @return data model as JSON */ diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt index 3af41690..57ce88eb 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormControl.kt @@ -21,6 +21,7 @@ */ package pl.treksoft.kvision.form +import org.w3c.files.File import pl.treksoft.kvision.core.Component import pl.treksoft.kvision.types.KFile import kotlin.js.Date @@ -219,4 +220,11 @@ interface KFilesFormControl : FormControl { } override fun getValueAsString(): String? = value?.joinToString(",") { it.name } + + /** + * Returns the native JavaScript File object. + * @param kFile KFile object + * @return File object + */ + fun getNativeFile(kFile: KFile): File? } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt index c9b33572..10b784e0 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt @@ -376,6 +376,14 @@ open class FormPanel<K : Any>( } /** + * Returns current data model with file content read for all KFiles controls. + * @return data model + */ + suspend fun getDataWithFileContent(): K { + return form.getDataWithFileContent() + } + + /** * Returns current data model as JSON. * @return data model as JSON */ |