summaryrefslogtreecommitdiffstats
path: root/test/uscxml/test-xhtml-invoker.scxml
blob: 3a868a9b76524e4d81ddc20305754f3d6d84a6c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<scxml datamodel="ecmascript" name="comet-test"
	xmlns:html="http://www.w3.org/1999/xhtml" 
	xmlns="http://www.w3.org/2005/07/scxml">

	<script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" />

	<script>
		var entered = {};
	</script>

	<state id="noBackChannelInlineDOM">
		<invoke type="xhtml" id="xhtml4">
			<!-- provide initial content as a inline DOM -->
			<content>
				<html:p>We can never get this data into SCXML, just wait 3s!</html:p>
				<html:form id="form1">
					First name1: <html:input type="text" name="firstname" /><html:br />
					Last name1: <html:input type="text" name="lastname" />
					<html:input type="submit" value="Submit" />
				</html:form>
			</content>
			<finalize>
				<script>dump(_event);</script>
			</finalize>
		</invoke>

		<onentry>
			<send event="continue" delay="3s" />
		</onentry>
		
		<transition event="continue" target="backChannelDomOPContent" />
	</state>

	<state id="backChannelDomOPContent">
		<invoke type="xhtml" id="xhtml3">
			<!-- provide initial content as a DOM operation, this will load the template for backchanneling via _parent -->
			<content type="replacechildren" xpath="/html/body">
				<html:p>Enter some details to continue!</html:p>
				<html:form id="form1" onsubmit="_parent.send('form.submitted', [ document.forms['form1'].elements[0].value, document.forms['form1'].elements[1].value ]); return false;">
					First name1: <html:input type="text" name="firstname" /><html:br />
					Last name1: <html:input type="text" name="lastname" />
					<html:input type="submit" value="Submit" />
				</html:form>
			</content>
			<finalize>
				<script>dump(_event);</script>
			</finalize>
		</invoke>

		<transition event="form.submitted">
			<script>
				entered.first = _event.data[0];
				entered.second = _event.data[1];
			</script>
			<send target="#_xhtml3">
				<!-- replace children in body by a form and register onclick on submit button -->
				<content type="replacechildren" xpath="/html/body">
					<html:p>Thank you!</html:p>
				</content>
			</send>
			<send event="continue" delay="1000ms" />
		</transition>
		
		<transition event="continue" target="backChannelNoContent" />
		
	</state>

	<state id="backChannelNoContent">
		<!-- without a src and no content, we invoke with a back channel via template/xhtml-invoker.xhtml for later sends -->
		<invoke type="xhtml" id="xhtml2">
			<finalize>
				<script>dump(_event);</script>
			</finalize>
		</invoke>
		
		<state id="waitForStabilize">
			<onentry>
				<send event="continue" delay="10ms" />
			</onentry>
			<transition event="continue" target="backChannelNoContentInitContent" />
		</state>
		
		<state id="backChannelNoContentInitContent">
			<onentry>
				<!-- template initialized empty body and the scxml session -->
				<send target="#_xhtml2">
					<!-- replace children in body by a form and register onclick on submit button -->
					<content type="replacechildren" xpath="/html/body">
						<html:p>Enter some more details to continue!</html:p>
						<html:form id="form1" onsubmit="_parent.send('form.submitted', [ document.forms['form1'].elements[0].value, document.forms['form1'].elements[1].value ]); return false;">
							First name1 (${entered.first}): <html:input type="text" name="firstname" /><html:br />
							Last name1 (${entered.second}): <html:input type="text" name="lastname" />
							<html:input type="submit" value="Submit" />
						</html:form>
					</content>
				</send>
			</onentry>
			
			<transition event="form.submitted">
				<send target="#_xhtml2">
					<!-- replace children in body by a form and register onclick on submit button -->
					<content type="replacechildren" xpath="/html/body">
						<html:p>Thank you!</html:p>
					</content>
				</send>
				<send event="continue" delay="1000ms" />
			</transition>
			
			<transition event="continue" target="arbitraryURL" />
			
		</state>
	</state>

	<state id="arbitraryURL">
		<!-- simply open some arbitrary URL, we cannot communicate with these -->
		<invoke src="http://www.heise.de" type="xhtml" id="xhtml1">
			<finalize>
				<script>dump(_event);</script>
			</finalize>
		</invoke>
		<onentry>
			<!-- we need a delayed send for this to be a stable configuration for the invoker -->
			<send event="continue" delay="10ms" />
		</onentry>
		<transition event="continue" target="quit" />
	</state>
	
		
		
		<!-- <invoke type="xhtml" id="xhtml1">
		</invoke> -->
		
		<!-- state id="idle">
			<transition target="idle" event="onmouseover">
				<log expr="dump(_event)" />
			</transition>
			<transition target="idle" event="onclick" cond="_event.origin=='xhtml1'">
				<send target="#_xhtml1">
					<content type="lastchild" xpath="/html/body">
						<html:p>Thank you!</html:p>
					</content>
				</send>
			</transition>
		</state -->
		
	<final id="quit" />
</scxml>