Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added jsonCall with JValue=>JValue func. Closes #1317

  • Loading branch information...
commit a1fa08b5acb3be43822d64305e0ccf03004b91f8 1 parent 6084c9f
@jeppenejsum jeppenejsum authored
Showing with 18 additions and 3 deletions.
  1. +18 −3 web/webkit/src/main/scala/net/liftweb/http/SHtml.scala
View
21 web/webkit/src/main/scala/net/liftweb/http/SHtml.scala
@@ -199,6 +199,21 @@ trait SHtml {
/**
+ * Build a JavaScript function that will perform a JSON call based on a value calculated in JavaScript.
+ *
+ * The JSON generated by func will be returned to the client and passed as argument to the javascript function specified in
+ * jsonContext.success
+ *
+ * @param jsCalcValue the JavaScript to calculate the value to be sent to the server
+ * @param jsonContext the context instance that defines JavaScript to be executed on call success or failure
+ * @param func the function to call when the JSON data is sent. The returned JSON is sent back to the client
+ *
+ * @return the function ID and JavaScript that makes the call
+ */
+ def jsonCall(jsCalcValue: JsExp, jsonContext: JsonContext, func: JsonAST.JValue => JsonAST.JValue): GUIDJsExp =
+ jsonCall_*(jsCalcValue, jsonContext, S.SFuncHolder(s => parseOpt(s).map(func) getOrElse JsonAST.JNothing))
+
+ /**
* Build a JavaScript function that will perform a JSON call based on a value calculated in JavaScript
*
* @param jsCalcValue the JavaScript to calculate the value to be sent to the server
@@ -254,9 +269,9 @@ trait SHtml {
f(name, js)
}
- def jsonCall(jsCalcValue: JsExp,
- jsonContext: JsonContext,
- func: String => JsObj): GUIDJsExp = ajaxCall_*(jsCalcValue, jsonContext, SFuncHolder(func))
+ @deprecated("Use jsonCall with a function that takes JValue => JValue", "2.5")
+ def jsonCall(jsCalcValue: JsExp, jsonContext: JsonContext, func: String => JsObj)(implicit d: AvoidTypeErasureIssues1): GUIDJsExp =
+ ajaxCall_*(jsCalcValue, jsonContext, SFuncHolder(func))
def fjsonCall[T](jsCalcValue: JsExp, jsonContext: JsonContext, func: String => JsObj)(f: (String, JsExp) => T): T = {
val (name, js) = jsonCall(jsCalcValue, jsonContext, func).product
Please sign in to comment.
Something went wrong with that request. Please try again.