cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r409528 - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF: flow/forms_flow_example.js forms/calculatedfields.xml forms/calculatedfields_template.xml welcome.xml
Date Fri, 26 May 2006 00:53:38 GMT
Author: simoneg
Date: Thu May 25 17:53:38 2006
New Revision: 409528

URL: http://svn.apache.org/viewvc?rev=409528&view=rev
Log:
Calculated fields samples

Added:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml
Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/flow/forms_flow_example.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/flow/forms_flow_example.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/flow/forms_flow_example.js?rev=409528&r1=409527&r2=409528&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/flow/forms_flow_example.js
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/flow/forms_flow_example.js
Thu May 25 17:53:38 2006
@@ -211,3 +211,11 @@
             "\noccupation: " + form.getChild("occupation").value +
             "\ncomments: " + form.getChild("comments") });
 }
+
+function do_calculatedfields(form) {
+    var form = new Form("forms/calculatedfields.xml");
+    form.showForm("calculatedfields-display-pipeline.jx");
+    cocoon.sendPage("textresult-display-pipeline.jx",
+        {title: "Calculated results", text: "Grand total of your order: " + form.getChild("grandtotal").value});
+}
+

Added: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields.xml?rev=409528&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields.xml
(added)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields.xml
Thu May 25 17:53:38 2006
@@ -0,0 +1,151 @@
+<?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 calculated fields. -->
+<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
+  
+  <fd:widgets>
+    <fd:repeater id="articles" orderable="true" initial-size="1">
+      <fd:widgets>
+        <fd:field id="description">
+          <fd:label>Description</fd:label>
+          <fd:datatype base="string"/>
+        </fd:field>
+        <fd:field id="items" required="true">
+          <fd:label>Items</fd:label>
+          <fd:datatype base="integer"/>
+        </fd:field>
+        <fd:field id="price" required="true">
+          <fd:label>Price</fd:label>
+          <fd:datatype base="double"/>
+        </fd:field>
+        <fd:calculatedfield id="subtotal" required="true" state="output">
+          <fd:label>Sub total</fd:label>
+          <fd:datatype base="double">
+            <fd:convertor type="formatting" variant="currency"/>
+          </fd:datatype>
+          <fd:value eval="items * price"/>
+        </fd:calculatedfield>
+        <fd:calculatedfield id="vat" required="true" state="output">
+          <fd:label>VAT</fd:label>
+          <fd:datatype base="double">
+            <fd:convertor type="formatting" variant="currency"/>
+          </fd:datatype>
+          <fd:value eval="Round((subtotal / 100.000000) * 20,2)"/>
+        </fd:calculatedfield>
+        <fd:calculatedfield id="total" required="true" state="output">
+          <fd:label>Total</fd:label>
+          <fd:datatype base="double">
+            <fd:convertor type="formatting" variant="currency"/>
+          </fd:datatype>
+          <fd:value eval="subtotal + vat"/>
+        </fd:calculatedfield>
+        <fd:booleanfield id="select">
+          <fd:label>Select</fd:label>
+        </fd:booleanfield>
+      </fd:widgets>
+    </fd:repeater>
+    
+    <fd:repeater-action id="addarticle" command="add-row" repeater="articles">
+      <fd:label>Add article</fd:label>
+    </fd:repeater-action>
+    
+    <fd:repeater-action id="removearticles" command="delete-rows" repeater="articles"
select="select">
+      <fd:label>Remove selected articles</fd:label>
+    </fd:repeater-action>
+    
+    <fd:calculatedfield id="totalitems" state="output" required="true">
+      <fd:label>Total items</fd:label>
+      <fd:datatype base="integer"/>
+      <fd:value eval="Sum({/articles/./items})"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="totalitemscost" state="output" required="true">
+      <fd:label>Total cost</fd:label>
+      <fd:datatype base="double">
+        <fd:convertor type="formatting" variant="currency"/>
+      </fd:datatype>
+      <fd:value eval="Sum({/articles/./subtotal})"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="totalvat" state="output" required="true">
+      <fd:label>Total VAT</fd:label>
+      <fd:datatype base="double">
+        <fd:convertor type="formatting" variant="currency"/>
+      </fd:datatype>
+      <fd:value eval="Sum({/articles/./vat})"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="totalcost" state="output" required="true">
+      <fd:label>Total Cost</fd:label>
+      <fd:datatype base="double">
+        <fd:convertor type="formatting" variant="currency"/>
+      </fd:datatype>
+      <fd:value eval="Sum({/articles/./total})"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="boxes" state="output" required="true">
+      <fd:label>Boxes</fd:label>
+      <fd:datatype base="integer"/>
+      <fd:value type="repeatedformula" repeat-on="/articles/./items" eval="formulaResult
+ Ceiling(Round(formulaCurrent,4) / 10)" initial-result="0"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="freeboxes" state="output">
+      <fd:label>Free boxes</fd:label>
+      <fd:datatype base="integer"/>
+      <fd:value type="javascript" triggers="boxes"> 
+        var acboxes = form.lookupWidget('boxes').getValue(); 
+        var freeboxes = 0; 
+        if (acboxes > 100) { 
+        	freeboxes = 30; 
+        } else if (acboxes > 50) { 
+        	freeboxes = 15; 
+       	} else if (acboxes > 10) { 
+        	freeboxes = 2; 
+        } 
+        return freeboxes;
+      </fd:value>
+    </fd:calculatedfield>
+    
+    <fd:field id="courier" required="true">
+      <fd:label>Courier</fd:label>
+      <fd:datatype base="double"/>
+      <fd:selection-list>
+        <fd:item value="5"><fd:label>Normal mail - 5 per box</fd:label></fd:item>
+        <fd:item value="10"><fd:label>Express/air mail - 10 per box</fd:label></fd:item>
+        <fd:item value="15"><fd:label>12 hours delivery - 15 per box</fd:label></fd:item>
+        <fd:item value="25"><fd:label>12 hours delivery with refund - 25 per
box</fd:label></fd:item>
+      </fd:selection-list>
+    </fd:field>
+    
+    <fd:calculatedfield id="couriercost" state="output">
+      <fd:label>Courier cost</fd:label>
+      <fd:datatype base="double">
+        <fd:convertor type="formatting" variant="currency"/>
+      </fd:datatype>
+      <fd:value eval="(boxes - freeboxes) * courier"/>
+    </fd:calculatedfield>
+    
+    <fd:calculatedfield id="grandtotal" state="output">
+      <fd:label>Grand total</fd:label>
+      <fd:datatype base="double">
+        <fd:convertor type="formatting" variant="currency"/>
+      </fd:datatype>
+      <fd:value eval="totalcost + couriercost"/>
+    </fd:calculatedfield>
+    
+  </fd:widgets>
+</fd:form>
\ No newline at end of file

Added: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml?rev=409528&view=auto
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml
(added)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml
Thu May 25 17:53:38 2006
@@ -0,0 +1,107 @@
+<?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"
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"/>
+  <fi:init>
+    <script type="text/javascript"> // Uncomment this to see Dojo debug // var djConfig
= { isDebug: true };
+    </script>
+  </fi:init>
+  <h4 class="samplesGroup">Calculated widgets sample</h4>
+  <title>Sample form</title>
+  <content>
+    <p>This is an example of how calculated fields can be used for an invoice form.
The invoice business rules are :
+    </p>
+    <ul>
+      <li>VAT is always 20% of total price.</li>
+      <li>Boxes contain 10 items each, and we cannot mix different articles in the
same box.</li>
+      <li>As a bonus you receive 2 shipment-free boxes if you buy more than 10 boxes,
15 if you buy more than 50, 30 if you buy more than 100.</li>
+      <li>You can choose different couriers with different costs.</li>
+    </ul>
+    <ft:form-template action="#{$cocoon/continuation/id}.continue" method="POST" ajax="true">
+      <!-- manual layout of fields, without use of a fi:group -->
+      <ft:widget-label id="articles"/><br/>
+      <ft:repeater id="articles">
+        <div dojoType="CFormsRepeater" orderable="true">
+          <table border="1">
+            <thead>
+              <tr>
+                <th><ft:repeater-widget-label id="articles" widget-id="description"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="items"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="price"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="subtotal"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="vat"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="total"/></th>
+                <th><ft:repeater-widget-label id="articles" widget-id="select"/></th>
+              </tr>
+            </thead>
+            <tbody>
+              <jx:choose>
+                <jx:when test="${widget.getChild('articles').getSize() == 0}">
+                  <tr><td colspan="7" align="center"><em>There are no articles
to display</em></td></tr>
+                </jx:when>
+                <jx:otherwise>
+                  <ft:repeater-rows>
+                    <tr>
+                      <td><ft:widget id="description"/></td>
+                      <td><ft:widget id="items"/></td>
+                      <td><ft:widget id="price"/></td>
+                      <td><ft:widget id="subtotal"/></td>
+                      <td><ft:widget id="vat"/></td>
+                      <td><ft:widget id="total"/></td>
+                      <td><ft:widget id="select"/></td>
+                    </tr>
+                  </ft:repeater-rows>
+                </jx:otherwise>
+              </jx:choose>
+            </tbody>
+          </table>
+          <p>
+            <ft:widget id="../addarticle"/>
+            <ft:widget id="../removearticles"/>
+          </p>
+        </div>
+      </ft:repeater>
+      <fi:group>
+        <fi:styling layout="row"/>
+        <fi:items>
+          <ft:widget id="totalitems"/>
+          <ft:widget id="totalitemscost"/>
+          <ft:widget id="totalvat"/>
+          <ft:widget id="totalcost"/>
+        </fi:items>
+      </fi:group>
+      <fi:group>
+        <fi:styling layout="columns"/>
+        <fi:items>
+          <ft:widget id="boxes"/>
+          <ft:widget id="freeboxes"/>
+          <ft:widget id="courier"/>
+          <ft:widget id="couriercost"/>
+        </fi:items>
+      </fi:group>
+      <fi:group>
+        <fi:styling layout="columns"/>
+        <fi:items>
+          <ft:widget id="grandtotal"/>
+        </fi:items>
+      </fi:group>
+      <input type="submit"/>
+      
+    </ft:form-template>
+  </content>
+</page>
\ No newline at end of file

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml?rev=409528&r1=409527&r2=409528&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml
Thu May 25 17:53:38 2006
@@ -47,6 +47,7 @@
   <sample name="Multipage wizard" href="do-multipage.flow">(Ajax) A multipage wizard,
using widget states and actions to move between pages.</sample>
   <sample name="CAPTCHA validation" href="captcha/">CAPTCHA validation (requires <a
href="/samples/blocks/batik/">Batik block</a>)</sample>
   <sample name="ImageMap" href="imagemap">A simple form using the Image Map widget</sample>
+  <sample name="Calculated fields" href="do-calculatedfields.flow">Calculated fields
: values are calculated automatically</sample>
  </group>
 
  <group name="Binding Samples">



Mime
View raw message