diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-20 22:38:08 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-20 22:38:08 +0200 |
commit | 3f2925996743bb3dba8464f863efe124aba85a51 (patch) | |
tree | 368af569a8f6d58e0ca13f75b4bbfa090a1a65ee /kvision-modules/kvision-bootstrap-select-remote/src | |
parent | 18af38d4ac7bbc33a43115c99ed47a586acf6020 (diff) | |
download | kvision-3f2925996743bb3dba8464f863efe124aba85a51.tar.gz kvision-3f2925996743bb3dba8464f863efe124aba85a51.tar.bz2 kvision-3f2925996743bb3dba8464f863efe124aba85a51.zip |
Support for request configuration when using remote interfaces.
Diffstat (limited to 'kvision-modules/kvision-bootstrap-select-remote/src')
-rw-r--r-- | kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt index b2dad8fe..5d60e4fe 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt @@ -28,6 +28,8 @@ import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.builtins.list import kotlinx.serialization.stringify import org.w3c.dom.get +import pl.treksoft.jquery.JQueryAjaxSettings +import pl.treksoft.jquery.JQueryXHR import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.remote.CallAgent import pl.treksoft.kvision.remote.HttpMethod @@ -72,12 +74,14 @@ open class SelectRemoteInput<T : Any>( private val url: String private val labelsCache = mutableMapOf<String, String>() private var initRun = false + private var beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> dynamic)? init { val (_url, method) = serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] ?: throw IllegalStateException("Function not specified!") this.url = _url + this.beforeSend = ajaxOptions?.beforeSend if (!preload) { val data = obj { q = "{{{q}}}" @@ -103,9 +107,10 @@ open class SelectRemoteInput<T : Any>( }.toTypedArray() }, data = data, - beforeSend = { _, b -> + beforeSend = { xhr, b -> + beforeSend?.invoke(xhr, b) @Suppress("UnsafeCastFromDynamic") - val q = decodeURIComponent(b.data.substring(2)) + val q = decodeURIComponent(b.asDynamic().data.substring(2)) val state = stateFunction?.invoke() b.data = JSON.plain.stringify(JsonRpcRequest(0, url, listOf(q, this.value, state))) true @@ -131,7 +136,8 @@ open class SelectRemoteInput<T : Any>( val values = callAgent.remoteCall( url, JSON.plain.stringify(JsonRpcRequest(0, url, listOf(null, null, state))), - HttpMethod.POST + HttpMethod.POST, + beforeSend = beforeSend ).await() JSON.plain.parse(RemoteOption.serializer().list, values.result as String).forEach { add( @@ -168,7 +174,8 @@ open class SelectRemoteInput<T : Any>( val initials = callAgent.remoteCall( url, JSON.plain.stringify(JsonRpcRequest(0, url, listOf(null, it, state))), - HttpMethod.POST + HttpMethod.POST, + beforeSend = beforeSend ).await() JSON.plain.parse(RemoteOption.serializer().list, initials.result as String).mapNotNull { it.text |