From 76754fd65d195f418a8643a8e0213fc8b0b6ab31 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 19 Jan 2019 00:18:58 +0100 Subject: Upload component upgrade and enhancements. --- .../pl/treksoft/kvision/form/upload/Upload.kt | 2 +- .../pl/treksoft/kvision/form/upload/UploadInput.kt | 40 +++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft') diff --git a/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt b/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt index 314c9904..971ce186 100644 --- a/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt +++ b/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt @@ -252,7 +252,7 @@ open class Upload( * @param kFile KFile object * @return File object */ - fun getNativeFile(kFile: KFile): File? { + override fun getNativeFile(kFile: KFile): File? { return input.getNativeFile(kFile) } diff --git a/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt b/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt index 2af7b3f7..ee17949e 100644 --- a/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt +++ b/kvision-modules/kvision-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/UploadInput.kt @@ -173,23 +173,25 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla @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 + if (uploadUrl != null) { + 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 + } } } @@ -301,6 +303,10 @@ open class UploadInput(uploadUrl: String? = null, multiple: Boolean = false, cla this.allowedFileTypes = allowedFileTypes?.toTypedArray() this.allowedFileExtensions = allowedFileExtensions?.toTypedArray() this.dropZoneEnabled = dropZoneEnabled + this.fileActionSettings = obj { + this.showUpload = showUpload + this.showRemove = showRemove + } this.language = language } } -- cgit