/*
 *  SPL - The SPL Programming Language
 *  Copyright (C) 2004, 2005  Clifford Wolf <clifford@clifford.at>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  wsfaction.webspl: An example for the WsfAction module
 */

load "wsf";
load "wsf_action";
load "wsf_debug";

var counter = 100;

var page = new WsfDocument();
page.root = new WsfAction(function() { return #file-as-template *demotpl; }, undef);
page.main();

#embedded-file demotpl EOT
<div id="$id">

<h1>The counter has the value $counter.</h1>

<form id="$id" ${add_action(cgi.url)}>
<input type="hidden" name="sid" value="${sid}" />

	<spl:inline>
		var button_id = 0;
		function add_counter_button(offset) {
			action("count_${button_id}", function() { counter += offset; });
			return '<input type="submit" name="count_${button_id++}" value="Count $offset" />';
		}
	</spl:inline>

	<spl:if code="counter >= 60">
		${ add_counter_button("-10") }
	</spl:if>

	<spl:if code="counter > 50">
		${ add_counter_button("-1") }
	</spl:if>

	<spl:if code="counter < 150">
		${ add_counter_button("+1") }
	</spl:if>

	<spl:if code="counter <= 140">
		${ add_counter_button("+10") }
	</spl:if>

</form>

<hr/>

<spl:code>
	if ( not declared children.["debugger"] )
		child_set("debugger", new WsfDebug());
	return children.["debugger"].get_html_cached();
</spl:code>

</div>
EOT

