Skip to content

Commit

Permalink
Merge pull request #1139 from UdashFramework/sjsdom-2.7.0
Browse files Browse the repository at this point in the history
scalajs-dom 2.7.0
  • Loading branch information
ddworak authored Sep 25, 2023
2 parents 981091c + e8cab0a commit 426f958
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions core/.js/src/main/scala/io/udash/utils/FileUploader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.udash._
import io.udash.properties.{Blank, HasModelPropertyCreator, PropertyCreator}
import org.scalajs.dom._

import scala.scalajs.js
import scala.scalajs.js.|

class FileUploader(url: Url) {

Expand All @@ -20,20 +20,26 @@ class FileUploader(url: Url) {

/** Uploads provided `file` in a field named `fieldName` with optional additional request headers. */
def uploadFile(
fieldName: String, file: File, extraData: Map[js.Any, js.Any] = Map.empty, additionalRequestHeaders: Map[RequestName, RequestValue] = Map.empty
fieldName: String, file: File, extraData: Map[String, String | Blob] = Map.empty, additionalRequestHeaders: Map[RequestName, RequestValue] = Map.empty
): ReadableModelProperty[FileUploadModel] =
upload(fieldName, Seq(file), extraData = extraData, additionalRequestHeaders = additionalRequestHeaders)

/** Uploads provided `files` in a field named `fieldName` with optional additional request headers. */
def upload(
fieldName: String, files: Seq[File], extraData: Map[js.Any, js.Any] = Map.empty, additionalRequestHeaders: Map[RequestName, RequestValue] = Map.empty
fieldName: String, files: Seq[File], extraData: Map[String, String | Blob] = Map.empty, additionalRequestHeaders: Map[RequestName, RequestValue] = Map.empty
): ReadableModelProperty[FileUploadModel] = {
val p = ModelProperty[FileUploadModel](
new FileUploadModel(Seq.empty, FileUploadState.InProgress, 0, 0, None)
)
val data = new FormData()

extraData.foreach { case (key, value) => data.append(key, value) }
extraData.foreach {
case (key, value) =>
(value: Any) match {
case string: String => data.append(key, string)
case blob: Blob => data.append(key, blob)
}
}
files.foreach(file => {
data.append(fieldName, file)
p.subSeq(_.files).append(file)
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Dependencies {

val jqueryWrapperVersion = "3.2.0"

val scalaJsDomVersion = "2.6.0"
val scalaJsDomVersion = "2.7.0"
val scalaTagsVersion = "0.12.0"
val scalaCssVersion = "1.0.0"

Expand Down

0 comments on commit 426f958

Please sign in to comment.