Author: sylvain Date: Fri Nov 12 10:33:30 2004 New Revision: 57536 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_binding.xml (contents, props changed) cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_model.xml (contents, props changed) cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_template.xml (contents, props changed) Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/flow/forms_flow_example.js cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-lib.js cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml Log: adding multipage wizard sample
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/flow/forms_flow_example.js ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/flow/forms_flow_example.js (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/flow/forms_flow_example.js Fri Nov 12 10:33:30 2004 @@ -121,3 +121,22 @@ ); } +// import WidgetState for direct access in event handlers. +// FIXME(SW) would be better to import it implicitely within Forms.js +importClass(org.apache.cocoon.forms.formmodel.WidgetState); + +function do_multipage() { + var form = new Form("forms/multipage_model.xml"); + form.showForm("multipage-display-pipeline.jx"); + + var doc = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + doc.appendChild(doc.createElement("result")); + form.createBinding("forms/multipage_binding.xml"); + form.save(doc); + + cocoon.sendPage("xmlresult-display-pipeline.jx", + {title: "Here's the resulting document", document: doc} + ); +} + + Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_binding.xml ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_binding.xml Fri Nov 12 10:33:30 2004 @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!--+ + | CVS $Id$ + +--> + +<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" + xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" + path="result"> + + <fb:struct id="page1" path="."> + <fb:value id="email" path="email"/> + <fb:value id="fourchars" path="fourchars"/> + <fb:value id="birthdate" path="birthdate"> + <fd:convertor datatype="date" type="formatting" style="short"/> + </fb:value> + </fb:struct> + + <fb:struct id="page2" path="."> + <fb:value id="number1" path="number1"/> + <fb:value id="number2" path="number2"/> + <fb:value id="account" path="account"/> + <fb:value id="cowheight" path="cowheight"/> + </fb:struct> + + <fb:struct id="page3" path="."> + <fb:value id="somebool" path="somebool"/> + <fb:multi-value id="drinks" parent-path="drinks" row-path="drink"/> + </fb:struct> + +</fb:context> Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_model.xml ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_model.xml Fri Nov 12 10:33:30 2004 @@ -0,0 +1,221 @@ +<?xml version="1.0"?> +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!--+ + | CVS $Id$ + +--> + +<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" + xmlns:i18n="http://apache.org/cocoon/i18n/2.1"> + + <fd:widgets> + + <fd:struct id="page1"> + <fd:widgets> + <fd:field id="email" required="true"> + <fd:datatype base="string"/> + <!-- new-style validation, outside of the datatype --> + <fd:validation> + <fd:email/> + </fd:validation> + <fd:label>Enter an <b>email</b> address:</fd:label> + <fd:help> + An email address must be in <i>[EMAIL PROTECTED]</i> format. + <br/> + And if you do not know what <b>email</b> address is, then well, chances are + that you do not have it. However, if you have access to the Internet, + you can easily get yourself one! + <br/> + Choose one of the following options: + <ul> + <li><a href='http://mail.yahoo.com/'>Yahoo! Mail</a></li> + <li><a href='http://www.hotmail.com/'>Hotmail</a></li> + </ul> + <small>Anyway, the point of all this was to show a popup help with mixed html content.</small> + </fd:help> + </fd:field> + + <fd:field id="fourchars" required="true"> + <fd:label>Select something that's 4 characters long:</fd:label> + <fd:datatype base="string"/> + <fd:validation> + <fd:length exact='2*2'/> + </fd:validation> + <fd:selection-list src="forms/a-choices.xml"/> + </fd:field> + + <fd:field id="birthdate" required="true"> + <fd:label>Your birthdate (dd/MM/yyyy):</fd:label> + <fd:datatype base="date"> + <fd:convertor> + <fd:patterns> + <fd:pattern>dd/MM/yyyy</fd:pattern> + <!-- The above pattern is a non-locale-specific pattern. You can + also add locale-specific patterns by adding more fd:pattern elements + here, with a locale attribute on them. --> + </fd:patterns> + </fd:convertor> + </fd:datatype> + <fd:validation> + <fd:range min="Date(1850, 1, 1)" max="Date(2150, 1, 1)"> + <fd:failmessage>Dead and not born yet should not bother filling this form</fd:failmessage> + </fd:range> + </fd:validation> + </fd:field> + + <fd:action id="next" action-command="foo"> + <fd:label>Next</fd:label> + <fd:on-action> + <fd:javascript> + var parent = event.source.parent; + if (parent.validate()) { + parent.setState(WidgetState.INVISIBLE); + parent.lookupWidget("../page2").setState(WidgetState.ACTIVE); + } + </fd:javascript> + </fd:on-action> + </fd:action> + </fd:widgets> + </fd:struct> + + <fd:struct id="page2" state="invisible"> + <fd:widgets> + <fd:field id="number1" required="true"> + <fd:label>Please enter a number<br/> + <small>(will automatically set a correct value below if needed)</small>:</fd:label> + <fd:datatype base="long"/> + <fd:on-value-changed> + <javascript> + java.lang.System.err.println("Was here!"); + var newValue = event.source.value; + if (newValue != null) { + var number2 = event.source.parent.lookupWidget("number2"); + if (number2.value == null) { + number2.setValue(new java.lang.Long(newValue.intValue() + 1)); + } + } + </javascript> + </fd:on-value-changed> + </fd:field> + + <fd:field id="number2" required="true"> + <fd:label>Enter another number, larger than the other number:</fd:label> + <fd:datatype base="long"/> + <fd:validation> + <fd:range min="number1 + 1"> + <fd:failmessage>This number should be larger than the first number.</fd:failmessage> + </fd:range> + </fd:validation> + </fd:field> + + <fd:field id="account" required="true"> + <fd:label>Indicate the size of your bank account (in m<sup>3</sup>):</fd:label> + <fd:datatype base="long"/> + <fd:selection-list> + <fd:item value="1"/> + <fd:item value="2"/> + <fd:item value="3"> + <fd:label>three</fd:label> + </fd:item> + <fd:item value="4"/> + <fd:item value="5"/> + </fd:selection-list> + </fd:field> + + <fd:field id="cowheight" required="true"> + <fd:label>Indicate your height (in cows):</fd:label> + <fd:datatype base="long"/> + <fd:selection-list> + <fd:item value="1"/> + <fd:item value="2"/> + <fd:item value="3"> + <fd:label>three</fd:label> + </fd:item> + <fd:item value="4"/> + <fd:item value="5"/> + </fd:selection-list> + </fd:field> + + <fd:action id="prev" action-command="foo"> + <fd:label>Previous</fd:label> + <fd:on-action> + <fd:javascript> + // switch back to previous back with no validation + var parent = event.source.parent; + parent.setState(WidgetState.INVISIBLE); + parent.lookupWidget("../page1").setState(WidgetState.ACTIVE); + </fd:javascript> + </fd:on-action> + </fd:action> + <fd:action id="next" action-command="foo"> + <fd:label>Next</fd:label> + <fd:on-action> + <fd:javascript> + var parent = event.source.parent; + if (parent.validate()) { + parent.setState(WidgetState.INVISIBLE); + parent.lookupWidget("../page3").setState(WidgetState.ACTIVE); + } + </fd:javascript> + </fd:on-action> + </fd:action> + </fd:widgets> + </fd:struct> + + <fd:struct id="page3" state="invisible"> + <fd:widgets> + <fd:booleanfield id="somebool"> + <fd:label>Put me <em>on</em> or <em>off</em>.</fd:label> + </fd:booleanfield> + + + <fd:multivaluefield id="drinks" required="true"> + <fd:label>Indicate which 2 of the following drinks you'd like to receive:</fd:label> + <fd:datatype base="string"/> + <fd:validation> + <fd:value-count exact="2"/> + </fd:validation> + <fd:selection-list> + <fd:item value="Maes"/> + <fd:item value="Jupiler"/> + <fd:item value="Leffe"/> + <fd:item value="Hoegaarden"/> + <fd:item value="Coca Cola"/> + </fd:selection-list> + </fd:multivaluefield> + + <fd:action id="prev" action-command="foo"> + <fd:label>Previous</fd:label> + <fd:on-action> + <fd:javascript> + // switch back to previous back with no validation + var parent = event.source.parent; + parent.setState(WidgetState.INVISIBLE); + parent.lookupWidget("../page2").setState(WidgetState.ACTIVE); + </fd:javascript> + </fd:on-action> + </fd:action> + + <fd:submit id="ok" action-command="foo"> + <fd:label>Finish</fd:label> + </fd:submit> + </fd:widgets> + </fd:struct> + + </fd:widgets> + +</fd:form> Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_template.xml ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/multipage_template.xml Fri Nov 12 10:33:30 2004 @@ -0,0 +1,95 @@ +<?xml version="1.0"?> +<!-- + Copyright 1999-2004 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<!-- This file is similar to form1_template_action.xml. They differ in group layout, + form's action attribute (to use continuations) and, this one is a dynamic form + template that changes the 'contacts' repeater layout depending on its size --> +<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template" + xmlns:fi="http://apache.org/cocoon/forms/1.0#instance" + xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"> + + <!-- Import the macros that define CForms template elements --> + <jx:import uri="resource://org/apache/cocoon/forms/generation/jx-macros.xml"/> + + <title>Sample multipage form</title> + <content> + <ft:form-template action="#{$continuation/id}.continue" method="POST"> + <div style="width: 70%; margin: 10px 50px 50px 50px;"> + + <ft:struct id="page1"> + <!-- group with automatic two-column layout --> + <fi:group> + <fi:label>String fields</fi:label> + <fi:styling type="fieldset" layout="columns"/> + <fi:items> + <ft:widget id="email"/> + <ft:widget id="birthdate"/> + <ft:widget id="fourchars"> + <!-- particular styling for the enumeration --> + <fi:styling list-type="listbox" listbox-size="4"/> + </ft:widget> + </fi:items> + </fi:group> + + <br/> + <ft:widget id="next"/> + + </ft:struct> + + <ft:struct id="page2"> + <fi:group> + <fi:label>Number fields</fi:label> + <fi:styling type="fieldset" layout="columns"/> + <fi:items> + <ft:widget id="number1"> + <fi:styling submit-on-change="true"/> + </ft:widget> + <ft:widget id="number2"/> + <ft:widget id="account"/> + <ft:widget id="cowheight"> + <fi:styling list-type="radio"/> + </ft:widget> + </fi:items> + </fi:group> + + <br/> + <ft:widget id="prev"/> + <ft:widget id="next"/> + </ft:struct> + + <ft:struct id="page3"> + <fi:group> + <fi:styling type="fieldset" layout="columns"/> + <fi:label>Boolean fields</fi:label> + <fi:items> + <ft:widget id="somebool"/> + <ft:widget id="drinks"> + <fi:styling list-type="listbox" listbox-size="4"/> + </ft:widget> + </fi:items> + </fi:group> + + <br/> + <ft:widget id="prev"/> + <ft:widget id="ok"/> + </ft:struct> + + </div> + </ft:form-template> + + <a href="do-multipage.flow">Restart this sample</a> - <a href="./">Back to form samples</a> + </content> +</page> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-lib.js ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-lib.js (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-lib.js Fri Nov 12 10:33:30 2004 @@ -182,7 +182,9 @@ if (tabitems != null) { tabitems.style.display = (i == idx) ? '' : 'none'; // execute event handler if any - if (i == idx && window.onTabShownHandlers != null) { + if (i == idx && + window.onTabShownHandlers != null && + window.onTabShownHandlers[tabgroup] != null) { var onShowHandler = window.onTabShownHandlers[tabgroup][tabgroup + "_items_" + i]; if (onShowHandler != null) { eval(onShowHandler); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/welcome.xml Fri Nov 12 10:33:30 2004 @@ -40,6 +40,7 @@ <sample name="Form Model GUI" href="form_model_gui.flow">Illustrates the use of Class, New, Struct, and Union.</sample> <sample name="HTMLArea" href="htmlarea">A simple form using the HTML editor widget.</sample> <sample name="Aggregate" href="aggregate/example">Aggregate field examples</sample> + <sample name="Multipage wizard" href="do-multipage.flow">A multipage wizard, using widget states and actions to go throgh pages.</sample> </group> <group name="Binding Samples">