blob: 5eacc699055fa377ec575e5c2db97a47dfe47f8a [file] [log] [blame]
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<!--
@version $Id: dynamicrepeater.xml 385334 2006-03-12 18:27:44Z sylvain $
-->
<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="contacts1" orderable="true">
<fd:widgets>
<!-- The ID is here to keep track of row creation order, which can
have no relation with row index when the users used move up/down -->
<fd:output id="ID">
<fd:label>ID</fd:label>
<fd:datatype base="integer"/>
</fd:output>
<fd:field id="firstname">
<fd:label>Firstname</fd:label>
<fd:hint>First name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:field id="lastname">
<fd:label>Lastname</fd:label>
<fd:hint>Last name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:row-action id="up" command="move-up"/>
<fd:row-action id="down" command="move-down"/>
<fd:booleanfield id="select">
<fd:label>Select</fd:label>
</fd:booleanfield>
</fd:widgets>
</fd:repeater>
<fd:repeater-action id="removecontacts1" command="delete-rows" repeater="contacts1" select="select">
<fd:label>Remove selected contacts</fd:label>
</fd:repeater-action>
<fd:repeater-action id="addcontact1" command="add-row" repeater="contacts1">
<fd:label>Add contact</fd:label>
<fd:on-action>
<fd:javascript>
// Increment the row creation ID counter (it has been initialized in
// the flowscript when the form was created).
// This shows how attributes can be used as a communication means between
// application logic and widget event handlers.
var form = event.source.form;
var count = new java.lang.Integer(form.getAttribute("counter1").intValue() + 1);
form.setAttribute("counter1", count);
var repeater = form.getChild("contacts1");
repeater.getRow(repeater.getSize() - 1).getChild("ID").setValue(count);
</fd:javascript>
</fd:on-action>
</fd:repeater-action>
<!-- Second repeater -->
<fd:repeater id="contacts2" orderable="true">
<fd:widgets>
<!-- The ID is here to keep track of row creation order, which can
have no relation with row index when the users used move up/down -->
<fd:output id="ID">
<fd:label>ID</fd:label>
<fd:datatype base="integer"/>
</fd:output>
<fd:field id="firstname">
<fd:label>Firstname</fd:label>
<fd:hint>First name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:field id="lastname">
<fd:label>Lastname</fd:label>
<fd:hint>Last name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:row-action id="up" command="move-up"/>
<fd:row-action id="down" command="move-down"/>
<fd:booleanfield id="select">
<fd:label>Select</fd:label>
</fd:booleanfield>
</fd:widgets>
</fd:repeater>
<fd:repeater-action id="removecontacts2" command="delete-rows" repeater="contacts2" select="select">
<fd:label>Remove selected contacts</fd:label>
</fd:repeater-action>
<fd:repeater-action id="addcontact2" command="add-row" repeater="contacts2">
<fd:label>Add contact</fd:label>
<fd:on-action>
<fd:javascript>
// Increment the row creation ID counter (it has been initialized in
// the flowscript when the form was created).
// This shows how attributes can be used as a communication means between
// application logic and widget event handlers.
var form = event.source.form;
var count = new java.lang.Integer(form.getAttribute("counter2").intValue() + 1);
form.setAttribute("counter2", count);
var repeater = form.getChild("contacts2");
repeater.getRow(repeater.getSize() - 1).getChild("ID").setValue(count);
</fd:javascript>
</fd:on-action>
</fd:repeater-action>
<!-- 3rd repeater -->
<fd:repeater id="contacts3" orderable="true">
<fd:widgets>
<!-- The ID is here to keep track of row creation order, which can
have no relation with row index when the users used move up/down -->
<fd:output id="ID">
<fd:label>ID</fd:label>
<fd:datatype base="integer"/>
</fd:output>
<fd:field id="firstname">
<fd:label>Firstname</fd:label>
<fd:hint>First name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:field id="lastname">
<fd:label>Lastname</fd:label>
<fd:hint>Last name</fd:hint>
<fd:datatype base="string"/>
</fd:field>
<fd:row-action id="up" command="move-up"/>
<fd:row-action id="down" command="move-down"/>
<fd:booleanfield id="select">
<fd:label>Select</fd:label>
</fd:booleanfield>
</fd:widgets>
</fd:repeater>
<fd:repeater-action id="removecontacts3" command="delete-rows" repeater="contacts3" select="select">
<fd:label>Remove selected contacts</fd:label>
</fd:repeater-action>
<fd:repeater-action id="addcontact3" command="add-row" repeater="contacts3">
<fd:label>Add contact</fd:label>
<fd:on-action>
<fd:javascript>
// Increment the row creation ID counter (it has been initialized in
// the flowscript when the form was created).
// This shows how attributes can be used as a communication means between
// application logic and widget event handlers.
var form = event.source.form;
var count = new java.lang.Integer(form.getAttribute("counter3").intValue() + 1);
form.setAttribute("counter3", count);
var repeater = form.getChild("contacts3");
repeater.getRow(repeater.getSize() - 1).getChild("ID").setValue(count);
</fd:javascript>
</fd:on-action>
</fd:repeater-action>
<fd:action id="dnd" status="invisible">
<fd:on-action>
<fd:javascript>
// Retrieve special action parameters
var targetRepeaterId = cocoon.request.getParameter("dndTarget.id");
var sourceRepeaterId = cocoon.request.getParameter(targetRepeaterId + ".sourceRepeaterId");
var sourceRowIndex = cocoon.request.getParameter(targetRepeaterId + ".sourceRowIndex");
var targetRowIndex = cocoon.request.getParameter(targetRepeaterId + ".before");
// Processing: Copy the row from the source repeater to target
var form = event.source.form;
var sourceRepeater = form.getChild(sourceRepeaterId);
var sourceRow = sourceRepeater.getRow(sourceRowIndex);
var targetRepeater = form.getChild(targetRepeaterId);
var targetRow = targetRepeater.addRow(targetRowIndex);
targetRow.getChild("firstname").setValue(sourceRow.getChild("firstname").getValue());
targetRow.getChild("lastname").setValue(sourceRow.getChild("lastname").getValue());
targetRow.getChild("ID").setValue(sourceRow.getChild("ID").getValue());
</fd:javascript>
</fd:on-action>
</fd:action>
<fd:submit id="ok">
<fd:label>Submit</fd:label>
</fd:submit>
</fd:widgets>
</fd:form>