From 1a7374b9d24bfcf1ea942d19d099f2c6c7edb81f Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 30 Mar 2018 13:50:01 +0200 Subject: Support for some events of file upload control. --- .../pl/treksoft/kvision/form/upload/UploadInput.kt | 19 +++++++++++++++++++ src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'src/main/kotlin') 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 b0c07c3e..d77a9b9b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt @@ -144,8 +144,27 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla return if (v.isNotEmpty()) v else null } + @Suppress("UnsafeCastFromDynamic") override fun afterInsert(node: VNode) { getElementJQueryD()?.fileinput(getSettingsObj()) + this.getElementJQuery()?.on("fileselect", { e, _ -> + this.dispatchEvent("fileSelectUpload", obj { detail = e }) + }) + this.getElementJQuery()?.on("fileclear", { e, _ -> + this.dispatchEvent("fileClearUpload", obj { detail = e }) + }) + this.getElementJQuery()?.on("filereset", { e, _ -> + this.dispatchEvent("fileResetUpload", obj { detail = e }) + }) + this.getElementJQuery()?.on("filebrowse", { e, _ -> + this.dispatchEvent("fileBrowseUpload", obj { detail = e }) + }) + this.getElementJQueryD()?.on("filepreupload", lambda@{ _, data, previewId, index -> + data["previewId"] = previewId + data["index"] = index + this.dispatchEvent("filePreUpload", obj { detail = data }) + return@lambda null + }) } override fun afterDestroy() { diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt index e719d133..ccb11ff9 100644 --- a/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt +++ b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt @@ -95,6 +95,11 @@ interface BtOn : On { var onMinBsSpinner: ((KvEvent) -> kotlin.Unit)? var onMaxBsSpinner: ((KvEvent) -> kotlin.Unit)? var updateModel: ((KvEvent) -> kotlin.Unit)? + var fileSelectUpload: ((KvEvent) -> kotlin.Unit)? + var fileClearUpload: ((KvEvent) -> kotlin.Unit)? + var fileResetUpload: ((KvEvent) -> kotlin.Unit)? + var fileBrowseUpload: ((KvEvent) -> kotlin.Unit)? + var filePreUpload: ((KvEvent) -> kotlin.Unit)? } /** -- cgit