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-tabulator-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-tabulator-remote/src')
-rw-r--r-- | kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt index e61ced55..21bfc5d4 100644 --- a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt +++ b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt @@ -24,6 +24,8 @@ package pl.treksoft.kvision.tabulator import kotlinx.serialization.ImplicitReflectionSerializer 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 @@ -69,6 +71,10 @@ open class TabulatorRemote<T : Any, E : Any>( ?: throw IllegalStateException("Function not specified!") val callAgent = CallAgent() + + @Suppress("UnsafeCastFromDynamic") + val beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = options.ajaxConfig.beforeSend + options.ajaxConfig.beforeSend = undefined options.ajaxURL = urlPrefix + url.drop(1) options.ajaxRequestFunc = { _, _, params -> val page = params.page @@ -91,15 +97,16 @@ open class TabulatorRemote<T : Any, E : Any>( @Suppress("UnsafeCastFromDynamic") val data = JSON.plain.stringify(JsonRpcRequest(0, url, listOf(page, size, filters, sorters, state))) - callAgent.remoteCall(url, data, method = HttpMethod.valueOf(method.name)).then { r: dynamic -> - val result = kotlin.js.JSON.parse<dynamic>(r.result as String) - @Suppress("UnsafeCastFromDynamic") - if (page != null) { - result - } else { - result.data + callAgent.remoteCall(url, data, method = HttpMethod.valueOf(method.name), beforeSend = beforeSend) + .then { r: dynamic -> + val result = kotlin.js.JSON.parse<dynamic>(r.result as String) + @Suppress("UnsafeCastFromDynamic") + if (page != null) { + result + } else { + result.data + } } - } } } } |