r9756 - in helma-ng/trunk: apps/demo apps/demo/skins modules/helma/webapp
[email protected] Thu, 14 May 2009 15:45:22 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090514134522.2211E3D0D6@mia> |
Author: hannes
Date: 2009-05-14 15:45:22 +0200 (Thu, 14 May 2009)
New Revision: 9756
Modified:
helma-ng/trunk/apps/demo/actions.js
helma-ng/trunk/apps/demo/skins/continuation.txt
helma-ng/trunk/modules/helma/webapp/continuation.js
Log:
Add page accessor functions first(), current(), last(), rename back()/forward() to previous()/next() and add isActive()
Details at http://dev.helma.org/trac/helma/changeset/9756
Modified: helma-ng/trunk/apps/demo/actions.js
===================================================================
--- helma-ng/trunk/apps/demo/actions.js 2009-05-14 13:18:44 UTC (rev 9755)
+++ helma-ng/trunk/apps/demo/actions.js 2009-05-14 13:45:22 UTC (rev 9756)
@@ -49,17 +49,19 @@
}
// demo for continuation support
-function continuation(req, run) {
+function continuation(req) {
- if (!run) {
+ var session = new ContinuationSession(req);
+
+ if (!session.isActive()) {
+ // render welcome page
return SkinnedResponse('skins/continuation.txt', {
+ session: session,
page: "welcome",
title: "Continuations"
});
}
- var session = new ContinuationSession(req);
-
session.addPage("ask_name", function(req) {
return SkinnedResponse('skins/continuation.txt', {
session: session,
Modified: helma-ng/trunk/apps/demo/skins/continuation.txt
===================================================================
--- helma-ng/trunk/apps/demo/skins/continuation.txt 2009-05-14 13:18:44 UTC (rev 9755)
+++ helma-ng/trunk/apps/demo/skins/continuation.txt 2009-05-14 13:45:22 UTC (rev 9756)
@@ -8,7 +8,7 @@
This is a little game to show off continuations support in Helma NG.
All you'll have to do is answer a few easy questions.</p>
- [Click here to start](/continuation/run)
+ [Click here to start](<% session.first %>)
What's special about this demo is that all pages are generated by
[one single JavaScript function][1] providing multiple action callbacks.
@@ -20,36 +20,36 @@
<% subskin 'ask_name' | markdown %>
What is your name?
- <form method="post" action="<% session.forward %>">
+ <form method="post" action="<% session.next %>">
<input name="name" value="<% session.data.name %>">
<input type="submit">
</form>
- [forward](<% session.forward %>)
+ [forward](<% session.next %>)
<% render 'list' %>
<% subskin 'ask_food' | markdown %>
What is your favorite food?
- <form method="post" action="<% session.forward %>">
+ <form method="post" action="<% session.next %>">
<input name="food" value="<% session.data.food %>">
<input type="submit">
</form>
- [back](<% session.back %>) [forward](<% session.forward %>)
+ [back](<% session.previous %>) [forward](<% session.next %>)
<% render 'list' %>
<% subskin 'ask_animal' | markdown %>
What is your favorite animal?
- <form method="post" action="<% session.forward %>">
+ <form method="post" action="<% session.next %>">
<input name="animal" value="<% session.data.animal %>">
<input type="submit">
</form>
- [back](<% session.back %>) [forward](<% session.forward %>)
+ [back](<% session.previous %>) [forward](<% session.next %>)
<% render 'list' %>
@@ -59,7 +59,7 @@
you love to eat <b><% session.data.food %></b> and your favorite animal
is <b><% session.data.animal %></b>.
- [back](<% session.back %>)
+ [back](<% session.previous %>)
<% render 'list' %>
Modified: helma-ng/trunk/modules/helma/webapp/continuation.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp/continuation.js 2009-05-14 13:18:44 UTC (rev 9755)
+++ helma-ng/trunk/modules/helma/webapp/continuation.js 2009-05-14 13:45:22 UTC (rev 9756)
@@ -11,11 +11,6 @@
function ContinuationSession(req) {
var id = req.params._cid;
-
- if (!id) {
- throw {redirect: getContinuationUrl(0)};
- }
-
var data = getData(req) || new HashMap();
var pages = [];
var callbacks = [];
@@ -29,6 +24,9 @@
}
this.run = function() {
+ if (!this.isActive()) {
+ throw {redirect: this.first()};
+ }
var callback = callbacks[step];
if (!(typeof callback === "function")) {
throw new Error("invalid continuation step: " + step);
@@ -38,6 +36,10 @@
return result;
};
+ this.isActive = function() {
+ return id != null;
+ }
+
Object.defineProperty(this, "data", {
value: new ScriptableMap(data)
});
@@ -51,11 +53,23 @@
set: function(s) { step = s; }
})
- this.back = function() {
+ this.first = function() {
+ return getContinuationUrl(0);
+ }
+
+ this.last = function() {
+ return getContinuationUrl(length - 1);
+ }
+
+ this.current = function() {
+ return getContinuationUrl(step);
+ }
+
+ this.previous = function() {
return step > 0 ? getContinuationUrl(step - 1) : null;
};
- this.forward = function() {
+ this.next = function() {
return step < length ? getContinuationUrl(step + 1) : null;
};