You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ug...@apache.org on 2004/09/09 17:36:29 UTC
svn commit: rev 43610 - in cocoon/trunk/src/blocks/forms/samples: . flow forms xsl
Author: ugo
Date: Thu Sep 9 08:36:28 2004
New Revision: 43610
Added:
cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_form.xml
cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_template.xml
cocoon/trunk/src/blocks/forms/samples/xsl/xhr_carfilter.xsl
Modified:
cocoon/trunk/src/blocks/forms/samples/flow/forms_flow_example.js
cocoon/trunk/src/blocks/forms/samples/sitemap.xmap
Log:
Carselector with XMLHTTPRequest sample
Modified: cocoon/trunk/src/blocks/forms/samples/flow/forms_flow_example.js
==============================================================================
--- cocoon/trunk/src/blocks/forms/samples/flow/forms_flow_example.js (original)
+++ cocoon/trunk/src/blocks/forms/samples/flow/forms_flow_example.js Thu Sep 9 08:36:28 2004
@@ -52,6 +52,14 @@
cocoon.sendPage("carselector-success-pipeline.xsp");
}
+function xhrSelectCar() {
+ var form = new Form("forms/xhr_carselector_form.xml");
+ // form.lookupWidget("make").setValue(cocoon.parameters.defaultMake);
+ form.showForm("xhr_carselector-display-pipeline");
+ cocoon.request.setAttribute("carselectorform", form.getWidget());
+ cocoon.sendPage("carselector-success-pipeline.xsp");
+}
+
var states = [
{ key: "AL", value: "Alabama" },
{ key: "AK", value: "Alaska" },
Added: cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_form.xml
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_form.xml Thu Sep 9 08:36:28 2004
@@ -0,0 +1,66 @@
+<?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.
+-->
+<!-- form used to illustrate programmatic changing of listbox content. -->
+<fd:form
+ xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
+ xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
+
+ <fd:widgets>
+ <fd:field id="make" required="true">
+ <fd:label>Make:</fd:label>
+ <fd:datatype base="string"/>
+ <fd:selection-list src="cocoon:/cars" dynamic="true"/>
+ </fd:field>
+
+ <fd:field id="type" required="true">
+ <fd:label>Type:</fd:label>
+ <fd:datatype base="string"/>
+ <fd:selection-list>
+ <fd:item value="">
+ <fd:label>Select a maker first</fd:label>
+ </fd:item>
+ </fd:selection-list>
+ </fd:field>
+
+ <fd:field id="model" required="true">
+ <fd:label>Model:</fd:label>
+ <fd:datatype base="string"/>
+ <fd:selection-list>
+ <fd:item value="">
+ <fd:label>Select a type first</fd:label>
+ </fd:item>
+ </fd:selection-list>
+ <fd:on-value-changed>
+ <javascript>
+ var value = event.source.value;
+ if (value != null) {
+ event.source.lookupWidget("../message").setValue("Model " + value + " is a great car!");
+ } else {
+ // Reset value
+ event.source.value = null;
+ }
+ </javascript>
+ </fd:on-value-changed>
+ </fd:field>
+
+ <fd:output id="message">
+ <fd:datatype base="string"/>
+ </fd:output>
+
+ </fd:widgets>
+
+</fd:form>
Added: cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_template.xml
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/samples/forms/xhr_carselector_template.xml Thu Sep 9 08:36:28 2004
@@ -0,0 +1,111 @@
+<?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.
+-->
+<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template" xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">
+ <script language="Javascript">
+<![CDATA[
+var xmlhttp;
+/*@cc_on @*/
+/*@if (@_jscript_version >= 5)
+// JScript gives us Conditional compilation, we can cope with old IE versions.
+// and security blocked creation of the objects.
+ try {
+ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (E) {
+ xmlhttp = false;
+ }
+ }
+@else
+ xmlhttp = false;
+@end @*/
+if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
+ xmlhttp = new XMLHttpRequest();
+} else {
+ xmlhttp = false;
+}
+
+function repopulateSelection(id, xmlhttp) {
+ var select = document.getElementById(id);
+ while (select.length > 0) {
+ select.remove(0);
+ }
+ var xml = xmlhttp.responseXML;
+ var newSelect = xml.documentElement;
+ var options = newSelect.getElementsByTagName("option");
+ for (var i = 0 ; i < options.length ; ++i) {
+ var option = document.createElement("option");
+ option.setAttribute("value", options.item(i).getAttribute("value"));
+ if (options.item(i).firstChild) {
+ var text = document.createTextNode(options.item(i).firstChild.nodeValue);
+ option.appendChild(text);
+ } else {
+ var text = document.createTextNode(option.getAttribute("value"));
+ option.appendChild(text);
+ }
+ select.appendChild(option);
+ }
+}
+
+function changeMake(make, model) {
+ xmlhttp.open("GET", "xhr_cars/" + make.value, true);
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4) {
+ repopulateSelection("type", xmlhttp);
+ while (model.length > 0) {
+ model.remove(0);
+ }
+ }
+ }
+ xmlhttp.send(null)
+}
+
+function changeType(make, type) {
+ xmlhttp.open("GET", "xhr_cars/" + make.value + "/" + type.value, true);
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4) {
+ repopulateSelection("model", xmlhttp);
+ }
+ }
+ xmlhttp.send(null)
+}
+]]>
+ </script>
+ <title>Car selector with XMLHTTPRequest</title>
+ <content>
+ <ft:form-template action="carselector" method="POST">
+ <ft:continuation-id/>
+ <fi:group>
+ <fi:styling layout="columns"/>
+ <fi:items>
+ <ft:widget id="make">
+ <fi:styling submit-on-change="false" onchange="changeMake(this, document.getElementById('model')); return false;"/>
+ </ft:widget>
+ <ft:widget id="type">
+ <fi:styling submit-on-change="false" onchange="changeType(document.getElementById('make'), this); return false;"/>
+ </ft:widget>
+ <ft:widget id="model">
+ <fi:styling submit-on-change="true"/>
+ </ft:widget>
+ <ft:widget id="message"/>
+ <input type="submit" value="Buy it!"/>
+ </fi:items>
+ </fi:group>
+ </ft:form-template>
+ </content>
+</page>
Modified: cocoon/trunk/src/blocks/forms/samples/sitemap.xmap
==============================================================================
--- cocoon/trunk/src/blocks/forms/samples/sitemap.xmap (original)
+++ cocoon/trunk/src/blocks/forms/samples/sitemap.xmap Thu Sep 9 08:36:28 2004
@@ -296,6 +296,50 @@
</map:otherwise>
</map:select>
</map:match>
+
+ <!--
+ | Car selector sample with XMLHTTPRequest
+ -->
+
+ <map:match pattern="xhr_carselector">
+ <map:select type="request-method">
+ <map:when test="POST">
+ <map:call continuation="{request-param:continuation-id}"/>
+ </map:when>
+ <map:otherwise>
+ <map:call function="xhrSelectCar">
+ <map:parameter name="defaultMake" value="Maserati"/>
+ </map:call>
+ </map:otherwise>
+ </map:select>
+ </map:match>
+
+ <map:match pattern="xhr_cars">
+ <map:generate src="forms/car-db.xml"/>
+ <map:transform src="xsl/xhr_carfilter.xsl">
+ <map:parameter name="list" value="makes"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+
+ <map:match pattern="xhr_cars/*">
+ <map:generate src="forms/car-db.xml"/>
+ <map:transform src="xsl/xhr_carfilter.xsl">
+ <map:parameter name="list" value="types"/>
+ <map:parameter name="make" value="{1}"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
+
+ <map:match pattern="xhr_cars/*/*">
+ <map:generate src="forms/car-db.xml"/>
+ <map:transform src="xsl/xhr_carfilter.xsl">
+ <map:parameter name="list" value="models"/>
+ <map:parameter name="make" value="{1}"/>
+ <map:parameter name="type" value="{2}"/>
+ </map:transform>
+ <map:serialize type="xml"/>
+ </map:match>
<!--
| Country selector sample.
Added: cocoon/trunk/src/blocks/forms/samples/xsl/xhr_carfilter.xsl
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/samples/xsl/xhr_carfilter.xsl Thu Sep 9 08:36:28 2004
@@ -0,0 +1,81 @@
+<?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.
+-->
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
+
+ <xsl:param name="list"/>
+ <xsl:param name="make"/>
+ <xsl:param name="type"/>
+
+ <xsl:template match="/">
+ <xsl:choose>
+ <xsl:when test="$list = 'makes'">
+ <xsl:call-template name="makes-list"/>
+ </xsl:when>
+ <xsl:when test="$list = 'models'">
+ <xsl:call-template name="models-list"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="types-list"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="makes-list">
+ <fd:selection-list>
+ <fd:item value="">
+ <fd:label>-- Choose maker --</fd:label>
+ </fd:item>
+ <xsl:for-each select="cars/make">
+ <fd:item value="{@name}"/>
+ </xsl:for-each>
+ </fd:selection-list>
+ </xsl:template>
+
+ <xsl:template name="types-list">
+ <select>
+ <option value="">-- Choose type --</option>
+ <xsl:for-each select="cars/make[@name=$make]/type">
+ <option value="{@name}"/>
+ </xsl:for-each>
+ </select>
+ </xsl:template>
+
+ <xsl:template name="models-list">
+ <select>
+ <option value="">-- Choose model --</option>
+ <xsl:choose>
+ <xsl:when test="cars/make[@name=$make]/type[@name=$type]/model">
+ <xsl:for-each select="cars/make[@name=$make]/type[@name=$type]/model">
+ <option value="{@name}"/>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- dummy list -->
+ <option value="{$type} model 1"/>
+ <option value="{$type} model 2"/>
+ <option value="{$type} model 3"/>
+ <option value="{$type} model 4"/>
+ <option value="{$type} model 5"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </select>
+ </xsl:template>
+
+</xsl:stylesheet>