diff options
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision')
-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 */ |