aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/upload
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-04-25 08:12:25 +0200
committerRobert Jaros <rjaros@finn.pl>2018-04-25 08:12:25 +0200
commit5b9535e9964816eb228d3797f4c8a3e7676d1f53 (patch)
tree00889e3c489288d6386367e8ac26973868e11f8f /src/main/kotlin/pl/treksoft/kvision/form/upload
parent76c436567b87672609879a11762202599ed27af4 (diff)
downloadkvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.gz
kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.tar.bz2
kvision-5b9535e9964816eb228d3797f4c8a3e7676d1f53.zip
Multiplatform kvision-common and kvision-server modules.
Support for automatic remote bindings (work in progress).
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/upload')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt15
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt25
2 files changed, 34 insertions, 6 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt b/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt
index e6b397eb..5e3ac0df 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt
@@ -3,13 +3,15 @@
*/
package pl.treksoft.kvision.form.upload
+import org.w3c.files.File
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.form.FieldLabel
-import pl.treksoft.kvision.form.FilesFormControl
import pl.treksoft.kvision.form.HelpBlock
+import pl.treksoft.kvision.form.KFilesFormControl
import pl.treksoft.kvision.panel.SimplePanel
+import pl.treksoft.kvision.types.KFile
import pl.treksoft.kvision.utils.SnOn
/**
@@ -25,7 +27,7 @@ import pl.treksoft.kvision.utils.SnOn
open class Upload(
uploadUrl: String? = null, multiple: Boolean = false, label: String? = null,
rich: Boolean = false
-) : SimplePanel(setOf("form-group")), FilesFormControl {
+) : SimplePanel(setOf("form-group")), KFilesFormControl {
/**
* File input value.
@@ -228,6 +230,15 @@ open class Upload(
}
/**
+ * Returns the native JavaScript File object.
+ * @param kFile KFile object
+ * @return File object
+ */
+ fun getNativeFile(kFile: KFile): File? {
+ return input.getNativeFile(kFile)
+ }
+
+ /**
* Resets the file input control.
*/
open fun resetInput() {
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt
index d77a9b9b..645cc69b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt
@@ -11,6 +11,7 @@ import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.form.FormInput
import pl.treksoft.kvision.form.InputSize
+import pl.treksoft.kvision.types.KFile
import pl.treksoft.kvision.utils.obj
/**
@@ -28,7 +29,7 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla
/**
* File input value.
*/
- var value: List<File>?
+ var value: List<KFile>?
get() = getValue()
set(value) {
if (value == null) resetInput()
@@ -112,6 +113,8 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla
*/
override var size: InputSize? by refreshOnUpdate()
+ private val nativeFiles: MutableMap<KFile, File> = mutableMapOf()
+
override fun render(): VNode {
return render("input")
}
@@ -139,7 +142,7 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla
return sn
}
- private fun getValue(): List<File>? {
+ private fun getValue(): List<KFile>? {
val v = getFiles()
return if (v.isNotEmpty()) v else null
}
@@ -217,8 +220,22 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla
getElementJQueryD()?.fileinput("unlock")
}
- private fun getFiles(): List<File> {
- return (getElementJQueryD()?.fileinput("getFileStack") as Array<File>).toList()
+ /**
+ * Returns the native JavaScript File object.
+ * @param kFile KFile object
+ * @return File object
+ */
+ fun getNativeFile(kFile: KFile): File? {
+ return nativeFiles[kFile]
+ }
+
+ private fun getFiles(): List<KFile> {
+ nativeFiles.clear()
+ return (getElementJQueryD()?.fileinput("getFileStack") as Array<File>).toList().map {
+ val kFile = KFile(it.name, it.size, null)
+ nativeFiles[kFile] = it
+ kFile
+ }
}
/**