Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

WIP revamping Ajax calls

  • Loading branch information...
commit 769bef00225b9c5cd57a4603f012ed38cc9b9b24 1 parent 0e17bce
@dpp dpp authored
View
7 web/webkit/src/main/scala/net/liftweb/http/LiftMerge.scala
@@ -230,6 +230,13 @@ private[http] trait LiftMerge {
bodyChildren += JsCmds.Script((if (!cometList.isEmpty || hasFuncsForOwner(RenderVersion.get)) OnLoad(JsRaw("liftAjax.lift_successRegisterGC()")) else Noop) &
JsCrVar("lift_page", RenderVersion.get))
+ } else if (stateful_?) {
+ import js._
+ import JsCmds._
+ import JE._
+
+ // always include the lift_page
+ bodyChildren += JsCrVar("lift_page", RenderVersion.get))
}
htmlKids += nl
View
123 web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
@@ -399,74 +399,85 @@ class LiftServlet extends Loggable {
toReturn
}
- private def extractVersion(path: List[String]) {
+ private def extractVersion[T](liftSession: LiftSession,
+ path: List[String])(f: => T): T = {
path match {
- case first :: second :: _ => RenderVersion.set(second)
- case _ =>
+ case _ :: second :: guid :: _ if second != "na" &&
+ guid != "index" && guid.length > 0 =>
+ // recover page, lock page, set up requestvars
+ // de-dup GUID
+ RenderVersion.doWith(second)(f)
+
+ case _ :: _ :: guid :: _ if guid.length > 0 && guid != "index" =>
+ // dedup GUID
+ f
+
+ case _ => f
}
}
private def handleAjax(liftSession: LiftSession,
requestState: Req): Box[LiftResponse] =
{
- extractVersion(requestState.path.partPath)
-
- LiftRules.cometLogger.debug("AJAX Request: " + liftSession.uniqueId + " " + requestState.params)
- tryo {LiftSession.onBeginServicing.foreach(_(liftSession, requestState))}
-
- val ret = try {
- requestState.param("__lift__GC") match {
- case Full(_) =>
- liftSession.updateFuncByOwner(RenderVersion.get, millis)
- Full(JavaScriptResponse(js.JsCmds.Noop))
-
- case _ =>
- try {
- val what = flatten(try {
- liftSession.runParams(requestState)
- } catch {
- case ResponseShortcutException(_, Full(to), _) =>
- import js.JsCmds._
- List(RedirectTo(to))
- })
-
- val what2 = what.flatMap {
- case js: JsCmd => List(js)
- case n: NodeSeq => List(n)
- case js: JsCommands => List(js)
- case r: LiftResponse => List(r)
- case s => Nil
+ extractVersion(liftSession, requestState.path.partPath){
+ LiftRules.cometLogger.debug("AJAX Request: " + liftSession.uniqueId + " " + requestState.params)
+ tryo {LiftSession.onBeginServicing.foreach(_(liftSession, requestState))}
+
+ val ret = try {
+ requestState.param("__lift__GC") match {
+ case Full(_) => {
+ liftSession.updateFuncByOwner(RenderVersion.get, millis)
+ Full(JavaScriptResponse(js.JsCmds.Noop))
}
-
- val ret: LiftResponse = what2 match {
- case (json: JsObj) :: Nil => JsonResponse(json)
- case (js: JsCmd) :: xs => {
- (JsCommands(S.noticesToJsCmd :: Nil) &
- ((js :: xs).flatMap
- {case js: JsCmd => List(js)
- case _ => Nil}.reverse) &
- S.jsToAppend).toResponse
- }
+
+ case _ =>
+ try {
+ val what = flatten(try {
+ liftSession.runParams(requestState)
+ } catch {
+ case ResponseShortcutException(_, Full(to), _) =>
+ import js.JsCmds._
+ List(RedirectTo(to))
+ })
- case (n: Node) :: _ => XmlResponse(n)
- case (ns: NodeSeq) :: _ => XmlResponse(Group(ns))
- case (r: LiftResponse) :: _ => r
- case _ => JsCommands(S.noticesToJsCmd :: JsCmds.Noop :: S.jsToAppend).toResponse
- }
-
- LiftRules.cometLogger.debug("AJAX Response: " + liftSession.uniqueId + " " + ret)
-
- Full(ret)
- } finally {
- liftSession.updateFunctionMap(S.functionMap, RenderVersion.get, millis)
+ val what2 = what.flatMap {
+ case js: JsCmd => List(js)
+ case n: NodeSeq => List(n)
+ case js: JsCommands => List(js)
+ case r: LiftResponse => List(r)
+ case s => Nil
+ }
+
+ val ret: LiftResponse = what2 match {
+ case (json: JsObj) :: Nil => JsonResponse(json)
+ case (js: JsCmd) :: xs => {
+ (JsCommands(S.noticesToJsCmd :: Nil) &
+ ((js :: xs).flatMap
+ {case js: JsCmd => List(js)
+ case _ => Nil}.reverse) &
+ S.jsToAppend).toResponse
+ }
+
+ case (n: Node) :: _ => XmlResponse(n)
+ case (ns: NodeSeq) :: _ => XmlResponse(Group(ns))
+ case (r: LiftResponse) :: _ => r
+ case _ => JsCommands(S.noticesToJsCmd :: JsCmds.Noop :: S.jsToAppend).toResponse
+ }
+
+ LiftRules.cometLogger.debug("AJAX Response: " + liftSession.uniqueId + " " + ret)
+
+ Full(ret)
+ } finally {
+ liftSession.updateFunctionMap(S.functionMap, RenderVersion.get, millis)
+ }
}
+ } catch {
+ case foc: LiftFlowOfControlException => throw foc
+ case e => NamedPF.applyBox((Props.mode, requestState, e), LiftRules.exceptionHandler.toList);
}
- } catch {
- case foc: LiftFlowOfControlException => throw foc
- case e => NamedPF.applyBox((Props.mode, requestState, e), LiftRules.exceptionHandler.toList);
+ tryo {LiftSession.onEndServicing.foreach(_(liftSession, requestState, ret))}
+ ret
}
- tryo {LiftSession.onEndServicing.foreach(_(liftSession, requestState, ret))}
- ret
}
/**
View
10 web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala
@@ -467,6 +467,13 @@ private final case class PostPageFunctions(renderVersion: String,
}
+private final case class PageInfo(lastSeen: Long,
+ restore: Function1[Function0[_], _],
+ guid: String,
+ sync: Object,
+ respMap: Map[String, Box[LiftResponse]])
+
+
/**
* The LiftSession class containg the session state information
*/
@@ -496,6 +503,9 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
def ? = this.box openOr false
}
+ private var pages: Map[String, PageInfo] = Map()
+ private val pagesSyncObj = new Object()
+
/**
* ****IMPORTANT**** when you access messageCallback, it *MUST*
* be in a block that's synchronized on the owner LiftSession
View
24 web/webkit/src/main/scala/net/liftweb/http/js/ScriptRenderer.scala
@@ -44,6 +44,7 @@ object ScriptRenderer {
toSend.onSuccess = theSuccess;
toSend.onFailure = theFailure;
toSend.responseType = responseType;
+ toSend.guid = Math.floor(Math.random()*10000000).toString()+Math.floor(Math.random()*10000000).toString()+Math.floor(Math.random()*10000000).toString();
liftAjax.lift_ajaxQueue.push(toSend);
liftAjax.lift_ajaxQueueSort();
@@ -144,6 +145,9 @@ object ScriptRenderer {
liftAjax.lift_doAjaxCycle();
};
+ var oldGUID = currentGUID;
+ try {
+ currentGUID = aboutToSend.guid;
if (aboutToSend.responseType != undefined &&
aboutToSend.responseType != null &&
aboutToSend.responseType.toLowerCase() === "json") {
@@ -156,6 +160,9 @@ object ScriptRenderer {
}
liftAjax.lift_actualAjaxCall(theData, successFunc, failureFunc);
}
+ } finally {
+ liftAjax.currentGUID = oldGUID;
+ }
}
}
@@ -163,14 +170,17 @@ object ScriptRenderer {
setTimeout("liftAjax.lift_doAjaxCycle();", 200);
},
+ currentGUID: "",
+
+ calcGUID: function() {
+ if (liftAjax.currentGUID == "") return "na";
+ return liftAjax.currentGUID;
+ }
+
addPageName: function(url) {
- return """ + {
- if (LiftRules.enableLiftGC) {
- "url.replace('" + LiftRules.ajaxPath + "', '" + LiftRules.ajaxPath + "/'+lift_page);"
- } else {
- "url;"
- }
- } + """
+ return url + '/' + """+
+ (if (LiftRules.enableLiftGC) "lift_page" else "'na'")+
+ """ + '/' + liftAjax.calcGUID();
},
lift_actualAjaxCall: function(data, onSuccess, onFailure) {
Please sign in to comment.
Something went wrong with that request. Please try again.