first pass on repeats.

- refactoring of schemaformbuilder to remove unnecessary methods/cleanup and modifications to get it to emit triggers that i need for insert at the top and insert after
- implementation of ajax server side method for setting the repeat index and support for capturing and sending back event responses for all server requests.
- implementation of client side repeat support: dom manipulation of repeat elements, identifying and relating widgets with model data, creating prototype clones, and support for some XFormsEvent (chiba-index-changed, chiba-item-inserted, chiba-prototype-cloned, chiba-id-generated)
- changing background-colour to background-color in the dashlet.  funny.
- handling a null pointer exception in the errorbean when an error is thrown from the ajax stuff.
- minor debugging enhancements in TemplatingService



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3814 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-09-18 04:04:43 +00:00
parent be0bc389cc
commit 913aa6a830
14 changed files with 1712 additions and 1391 deletions

View File

@@ -123,6 +123,7 @@ public class ErrorBean
{ {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter); PrintWriter writer = new PrintWriter(stringWriter);
if (this.lastError != null)
this.lastError.printStackTrace(writer); this.lastError.printStackTrace(writer);
// format the message for HTML display // format the message for HTML display

View File

@@ -20,6 +20,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter; import javax.faces.context.ResponseWriter;
@@ -36,7 +37,10 @@ import org.w3c.dom.Node;
import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.app.servlet.FacesHelper;
import org.chiba.xml.xforms.ChibaBean; import org.chiba.xml.xforms.ChibaBean;
import org.chiba.xml.xforms.exception.XFormsException; import org.chiba.xml.xforms.exception.XFormsException;
import org.chiba.xml.xforms.events.XFormsEvent;
import org.chiba.xml.xforms.events.XFormsEventFactory; import org.chiba.xml.xforms.events.XFormsEventFactory;
import org.w3c.dom.*;
import org.w3c.dom.events.Event; import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget; import org.w3c.dom.events.EventTarget;
@@ -47,13 +51,13 @@ import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector;
* Manages the chiba bean lifecycle. * Manages the chiba bean lifecycle.
*/ */
public class XFormsBean public class XFormsBean
implements EventListener
{ {
private static final Log LOGGER = LogFactory.getLog(XFormsBean.class); private static final Log LOGGER = LogFactory.getLog(XFormsBean.class);
private TemplateType tt; private TemplateType tt;
private InstanceData instanceData = null; private InstanceData instanceData = null;
private ChibaBean chibaBean; private ChibaBean chibaBean;
private final LinkedList<XFormsEvent> eventLog = new LinkedList<XFormsEvent>();
/** @return the template type */ /** @return the template type */
public TemplateType getTemplateType() public TemplateType getTemplateType()
@@ -95,12 +99,33 @@ public class XFormsBean
tt.getInputMethods().get(0); tt.getInputMethods().get(0);
final Document form = tim.getXForm(instanceData.getContent(), tt); final Document form = tim.getXForm(instanceData.getContent(), tt);
this.chibaBean.setXMLContainer(form); this.chibaBean.setXMLContainer(form);
this.chibaBean.init();
EventTarget et = (EventTarget) final EventTarget et = (EventTarget)
this.chibaBean.getXMLContainer().getDocumentElement(); this.chibaBean.getXMLContainer().getDocumentElement();
//XXXarielb register more listener for to do validation and do something final EventListener el = new EventListener()
//with the results. {
et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, this, true); public void handleEvent(Event e)
{
XFormsBean.LOGGER.debug("received event " + e);
XFormsBean.this.eventLog.add((XFormsEvent)e);
}
};
// interaction events my occur during init so we have to register before
et.addEventListener(XFormsEventFactory.CHIBA_LOAD_URI, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_RENDER_MESSAGE, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_REPLACE_ALL, el, true);
this.chibaBean.init();
// register for notification events
et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_STATE_CHANGED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_PROTOTYPE_CLONED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ID_GENERATED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_INSERTED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_ITEM_DELETED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_INDEX_CHANGED, el, true);
et.addEventListener(XFormsEventFactory.CHIBA_SWITCH_TOGGLED, el, true);
} }
catch (FormBuilderException fbe) catch (FormBuilderException fbe)
{ {
@@ -143,8 +168,34 @@ public class XFormsBean
LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")"); LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")");
this.chibaBean.updateControlValue(id, value); this.chibaBean.updateControlValue(id, value);
final TemplatingService ts = TemplatingService.getInstance();
final ResponseWriter out = context.getResponseWriter(); final ResponseWriter out = context.getResponseWriter();
out.write("<todo/>"); ts.writeXML(this.getEventLog(), out);
out.close();
}
/**
* sets the value of a control in the processor.
*
* @param id the id of the control in the host document
* @param value the new value
* @return the list of events that may result through this action
*/
public void setRepeatIndex()
throws XFormsException, IOException
{
final FacesContext context = FacesContext.getCurrentInstance();
final Map requestParameters = context.getExternalContext().getRequestParameterMap();
final String id = (String)requestParameters.get("id");
final int index = Integer.parseInt((String)requestParameters.get("index"));
LOGGER.debug(this + " setRepeatIndex(" + id + ", " + index + ")");
this.chibaBean.updateRepeatIndex(id, index);
final TemplatingService ts = TemplatingService.getInstance();
final ResponseWriter out = context.getResponseWriter();
ts.writeXML(this.getEventLog(), out);
out.close(); out.close();
} }
@@ -162,8 +213,10 @@ public class XFormsBean
LOGGER.debug(this + " fireAction(" + id + ")"); LOGGER.debug(this + " fireAction(" + id + ")");
this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE); this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE);
final TemplatingService ts = TemplatingService.getInstance();
final ResponseWriter out = context.getResponseWriter(); final ResponseWriter out = context.getResponseWriter();
out.write("<todo/>"); ts.writeXML(this.getEventLog(), out);
out.close(); out.close();
} }
@@ -180,15 +233,38 @@ public class XFormsBean
final TemplatingService ts = TemplatingService.getInstance(); final TemplatingService ts = TemplatingService.getInstance();
final Document result = ts.parseXML(request.getInputStream()); final Document result = ts.parseXML(request.getInputStream());
this.instanceData.setContent(result); this.instanceData.setContent(result);
final ResponseWriter out = context.getResponseWriter(); final ResponseWriter out = context.getResponseWriter();
ts.writeXML(result, out); ts.writeXML(result, out);
out.close(); out.close();
} }
//XXXarielb placeholder for error handling private Node getEventLog()
public void handleEvent(Event e)
{ {
LOGGER.debug("handleEvent " + e); final TemplatingService ts = TemplatingService.getInstance();
final Document result = ts.newDocument();
final Element eventsElement = result.createElement("events");
result.appendChild(eventsElement);
for (XFormsEvent xfe : this.eventLog)
{
final String type = xfe.getType();
final Element target = (Element)xfe.getTarget();
final Element eventElement = result.createElement(type);
eventsElement.appendChild(eventElement);
eventElement.setAttribute("targetId", target.getAttributeNS(null, "id"));
eventElement.setAttribute("targetName", target.getLocalName());
for (Object name : xfe.getPropertyNames())
{
final Element propertyElement = result.createElement((String)name);
eventElement.appendChild(propertyElement);
final String value = xfe.getContextInfo((String)name).toString();
propertyElement.appendChild(result.createTextNode(value));
}
}
this.eventLog.clear();
return result;
} }
/** /**

View File

@@ -308,10 +308,21 @@ public final class TemplatingService
{ {
try try
{ {
System.out.println("writing out a document for " + n.getNodeName() +
" to " + output);
final TransformerFactory tf = TransformerFactory.newInstance(); final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t = tf.newTransformer(); final Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("writing out a document for " +
(n instanceof Document
? ((Document)n).getDocumentElement()
: n).getNodeName() +
" to " + output);
final StringWriter sw = new StringWriter();
t.transform(new DOMSource(n), new StreamResult(sw));
LOGGER.debug(sw.toString());
}
t.transform(new DOMSource(n), new StreamResult(output)); t.transform(new DOMSource(n), new StreamResult(output));
} }
catch (TransformerException te) catch (TransformerException te)

View File

@@ -145,6 +145,8 @@ public class XFormsInputMethod
true); true);
LOGGER.debug("building xform for schema " + tt.getName()); LOGGER.debug("building xform for schema " + tt.getName());
final Document result = builder.buildForm(tt); //schemaFile.getPath()); final Document result = builder.buildForm(tt); //schemaFile.getPath());
LOGGER.debug("generated xform:");
LOGGER.debug(ts.writeXMLToString(result));
// xmlContentFile.delete(); // xmlContentFile.delete();
// schemaFile.delete(); // schemaFile.delete();
return result; return result;

View File

@@ -167,15 +167,17 @@ public class BaseSchemaFormBuilder
public Element createControlForAnyType(Document xForm, public Element createControlForAnyType(Document xForm,
String caption, String caption,
XSTypeDefinition controlType) { XSTypeDefinition controlType) {
Element control = xForm.createElementNS(XFORMS_NS, Element control = xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
getXFormsNSPrefix() + "textarea"); SchemaFormBuilder.XFORMS_NS_PREFIX + "textarea");
this.setXFormsId(control); this.setXFormsId(control);
control.setAttributeNS(CHIBA_NS, getChibaNSPrefix() + "height", "3"); control.setAttributeNS(SchemaFormBuilder.CHIBA_NS,
SchemaFormBuilder.CHIBA_NS_PREFIX + "height",
"3");
//label //label
Element captionElement = (Element) Element captionElement = (Element)
control.appendChild(xForm.createElementNS(XFORMS_NS, control.appendChild(xForm.createElementNS(SchemaFormBuilder.XFORMS_NS,
getXFormsNSPrefix() + "label")); SchemaFormBuilder.XFORMS_NS_PREFIX + "label"));
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
captionElement.appendChild(xForm.createTextNode(caption)); captionElement.appendChild(xForm.createTextNode(caption));
@@ -199,24 +201,24 @@ public class BaseSchemaFormBuilder
if ("boolean".equals(controlType.getName())) if ("boolean".equals(controlType.getName()))
{ {
control = xForm.createElementNS(XFORMS_NS, control = xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "select1"); SchemaFormBuilder.XFORMS_NS_PREFIX + "select1");
control.setAttributeNS(XFORMS_NS, control.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "appearance", SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
"full"); "full");
this.setXFormsId(control); this.setXFormsId(control);
Element item_true = Element item_true =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "item"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item_true); this.setXFormsId(item_true);
Element label_true = Element label_true =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(label_true); this.setXFormsId(label_true);
Text label_true_text = xForm.createTextNode("true"); Text label_true_text = xForm.createTextNode("true");
label_true.appendChild(label_true_text); label_true.appendChild(label_true_text);
item_true.appendChild(label_true); item_true.appendChild(label_true);
Element value_true = Element value_true =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "value"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value_true); this.setXFormsId(value_true);
Text value_true_text = xForm.createTextNode("true"); Text value_true_text = xForm.createTextNode("true");
value_true.appendChild(value_true_text); value_true.appendChild(value_true_text);
@@ -224,17 +226,17 @@ public class BaseSchemaFormBuilder
control.appendChild(item_true); control.appendChild(item_true);
Element item_false = Element item_false =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "item"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item_false); this.setXFormsId(item_false);
Element label_false = Element label_false =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(label_false); this.setXFormsId(label_false);
Text label_false_text = xForm.createTextNode("false"); Text label_false_text = xForm.createTextNode("false");
label_false.appendChild(label_false_text); label_false.appendChild(label_false_text);
item_false.appendChild(label_false); item_false.appendChild(label_false);
Element value_false = Element value_false =
xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "value"); xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value_false); this.setXFormsId(value_false);
Text value_false_text = xForm.createTextNode("false"); Text value_false_text = xForm.createTextNode("false");
value_false.appendChild(value_false_text); value_false.appendChild(value_false_text);
@@ -243,14 +245,14 @@ public class BaseSchemaFormBuilder
} }
else else
{ {
control = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "input"); control = xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "input");
this.setXFormsId(control); this.setXFormsId(control);
} }
//label //label
Element captionElement = (Element) Element captionElement = (Element)
control.appendChild(xForm.createElementNS(XFORMS_NS, control.appendChild(xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "label")); SchemaFormBuilder.XFORMS_NS_PREFIX + "label"));
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
captionElement.appendChild(xForm.createTextNode(caption)); captionElement.appendChild(xForm.createTextNode(caption));
@@ -283,18 +285,18 @@ public class BaseSchemaFormBuilder
Vector enumValues = new Vector(); Vector enumValues = new Vector();
Element control = xForm.createElementNS(XFORMS_NS, Element control = xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "select1"); SchemaFormBuilder.XFORMS_NS_PREFIX + "select1");
this.setXFormsId(control); this.setXFormsId(control);
//label //label
Element captionElement1 = (Element) Element captionElement1 = (Element)
control.appendChild(xForm.createElementNS(XFORMS_NS, control.appendChild(xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "label")); SchemaFormBuilder.XFORMS_NS_PREFIX + "label"));
this.setXFormsId(captionElement1); this.setXFormsId(captionElement1);
captionElement1.appendChild(xForm.createTextNode(caption)); captionElement1.appendChild(xForm.createTextNode(caption));
Element choices = xForm.createElementNS(XFORMS_NS, Element choices = xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "choices"); SchemaFormBuilder.XFORMS_NS_PREFIX + "choices");
this.setXFormsId(choices); this.setXFormsId(choices);
for (int i = 0; i < nbFacets; i++) { for (int i = 0; i < nbFacets; i++) {
@@ -304,11 +306,11 @@ public class BaseSchemaFormBuilder
if (nbFacets < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) { if (nbFacets < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) {
control.setAttributeNS(XFORMS_NS, control.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "appearance", SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)); getProperty(SELECTONE_UI_CONTROL_SHORT_PROP));
} else { } else {
control.setAttributeNS(XFORMS_NS, control.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "appearance", SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTONE_UI_CONTROL_LONG_PROP)); getProperty(SELECTONE_UI_CONTROL_LONG_PROP));
// add the "Please select..." instruction item for the combobox // add the "Please select..." instruction item for the combobox
@@ -318,20 +320,20 @@ public class BaseSchemaFormBuilder
{ {
String pleaseSelect = "[Select1 " + caption + "]"; String pleaseSelect = "[Select1 " + caption + "]";
Element item = xForm.createElementNS(XFORMS_NS, Element item = xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "item"); SchemaFormBuilder.XFORMS_NS_PREFIX + "item");
this.setXFormsId(item); this.setXFormsId(item);
choices.appendChild(item); choices.appendChild(item);
Element captionElement = Element captionElement =
xForm.createElementNS(XFORMS_NS, xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "label"); SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
item.appendChild(captionElement); item.appendChild(captionElement);
captionElement.appendChild(xForm.createTextNode(pleaseSelect)); captionElement.appendChild(xForm.createTextNode(pleaseSelect));
Element value = Element value =
xForm.createElementNS(XFORMS_NS, xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "value"); SchemaFormBuilder.XFORMS_NS_PREFIX + "value");
this.setXFormsId(value); this.setXFormsId(value);
item.appendChild(value); item.appendChild(value);
value.appendChild(xForm.createTextNode(pleaseSelect)); value.appendChild(xForm.createTextNode(pleaseSelect));
@@ -344,12 +346,12 @@ public class BaseSchemaFormBuilder
//check if there was a constraint //check if there was a constraint
String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint"); String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint");
constraint = ((constraint != null && constraint.length() != 0) constraint = (constraint != null && constraint.length() != 0
? constraint + " and " + isValidExpr ? constraint + " and " + isValidExpr
: isValidExpr); : isValidExpr);
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "constraint", SchemaFormBuilder.XFORMS_NS_PREFIX + "constraint",
constraint); constraint);
} }
} }
@@ -381,13 +383,13 @@ public class BaseSchemaFormBuilder
if (nbFacets <= 0) if (nbFacets <= 0)
return null; return null;
Element control = xForm.createElementNS(XFORMS_NS, Element control = xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "select"); SchemaFormBuilder.XFORMS_NS_PREFIX + "select");
this.setXFormsId(control); this.setXFormsId(control);
//label //label
Element captionElement = (Element) Element captionElement = (Element)
control.appendChild(xForm.createElementNS(XFORMS_NS, control.appendChild(xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "label")); SchemaFormBuilder.XFORMS_NS_PREFIX + "label"));
this.setXFormsId(captionElement); this.setXFormsId(captionElement);
captionElement.appendChild(xForm.createTextNode(caption)); captionElement.appendChild(xForm.createTextNode(caption));
@@ -402,24 +404,26 @@ public class BaseSchemaFormBuilder
// //
// For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control // For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control
// //
if (enumValues.size() if (enumValues.size() < Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP)))
< Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP))) { {
control.setAttributeNS(XFORMS_NS, control.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "appearance", SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP)); getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP));
} else { }
else
{
control.setAttributeNS(XFORMS_NS, control.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "appearance", SchemaFormBuilder.XFORMS_NS_PREFIX + "appearance",
getProperty(SELECTMANY_UI_CONTROL_LONG_PROP)); getProperty(SELECTMANY_UI_CONTROL_LONG_PROP));
} }
Element choices = Element choices =
xForm.createElementNS(XFORMS_NS, xForm.createElementNS(XFORMS_NS,
getXFormsNSPrefix() + "choices"); SchemaFormBuilder.XFORMS_NS_PREFIX + "choices");
this.setXFormsId(choices); this.setXFormsId(choices);
control.appendChild(choices); control.appendChild(choices);
addChoicesForSelectControl(xForm, choices, enumValues); this.addChoicesForSelectControl(xForm, choices, enumValues);
return control; return control;
} }
@@ -431,7 +435,8 @@ public class BaseSchemaFormBuilder
* @param node __UNDOCUMENTED__ * @param node __UNDOCUMENTED__
* @return __UNDOCUMENTED__ * @return __UNDOCUMENTED__
*/ */
public Element createHint(Document xForm, XSObject node) { public Element createHint(Document xForm, XSObject node)
{
XSAnnotation annotation = null; XSAnnotation annotation = null;
if (node instanceof XSElementDeclaration) if (node instanceof XSElementDeclaration)
annotation = ((XSElementDeclaration) node).getAnnotation(); annotation = ((XSElementDeclaration) node).getAnnotation();
@@ -441,10 +446,9 @@ public class BaseSchemaFormBuilder
annotation = annotation =
((XSAttributeUse) node).getAttrDeclaration().getAnnotation(); ((XSAttributeUse) node).getAttrDeclaration().getAnnotation();
if (annotation != null) return (annotation != null
return addHintFromDocumentation(xForm, annotation); ? addHintFromDocumentation(xForm, annotation)
else : null);
return null;
} }
/** /**
@@ -452,8 +456,8 @@ public class BaseSchemaFormBuilder
* *
* @param bindElement __UNDOCUMENTED__ * @param bindElement __UNDOCUMENTED__
*/ */
public void endBindElement(Element bindElement) { public void endBindElement(Element bindElement)
return; {
} }
/** /**
@@ -506,12 +510,12 @@ public class BaseSchemaFormBuilder
String typeName = this.getXFormsTypeName(enveloppe, controlType); String typeName = this.getXFormsTypeName(enveloppe, controlType);
if (typeName != null && typeName.length() != 0) if (typeName != null && typeName.length() != 0)
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "type", SchemaFormBuilder.XFORMS_NS_PREFIX + "type",
typeName); typeName);
} }
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "required", SchemaFormBuilder.XFORMS_NS_PREFIX + "required",
o.minimum == 0 ? "false()" : "true()"); o.minimum == 0 ? "false()" : "true()");
@@ -528,19 +532,14 @@ public class BaseSchemaFormBuilder
//if 1 or unbounded -> no constraint //if 1 or unbounded -> no constraint
maxConstraint = "count(.) <= " + o.maximum; maxConstraint = "count(.) <= " + o.maximum;
String constraint = null; final String constraint = (minConstraint != null && maxConstraint != null
? minConstraint + " and " + maxConstraint
if ((minConstraint != null) && (maxConstraint != null)) { : (minConstraint != null
constraint = minConstraint + " and " + maxConstraint; ? minConstraint
} else if (minConstraint != null) { : maxConstraint));
constraint = minConstraint;
} else {
constraint = maxConstraint;
}
if (constraint != null && constraint.length() != 0) if (constraint != null && constraint.length() != 0)
bindElement.setAttributeNS(XFORMS_NS, bindElement.setAttributeNS(XFORMS_NS,
getXFormsNSPrefix() + "constraint", SchemaFormBuilder.XFORMS_NS_PREFIX + "constraint",
constraint); constraint);
return bindElement; return bindElement;
} }
@@ -553,7 +552,8 @@ public class BaseSchemaFormBuilder
* @return __UNDOCUMENTED__ * @return __UNDOCUMENTED__
*/ */
public Element startFormControl(Element controlElement, public Element startFormControl(Element controlElement,
XSTypeDefinition controlType) { XSTypeDefinition controlType)
{
return controlElement; return controlElement;
} }
@@ -565,7 +565,8 @@ public class BaseSchemaFormBuilder
* @return __UNDOCUMENTED__ * @return __UNDOCUMENTED__
*/ */
public Element startFormGroup(Element groupElement, public Element startFormGroup(Element groupElement,
XSElementDeclaration schemaElement) { XSElementDeclaration schemaElement)
{
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-align",getProperty(GROUP_BOX_ALIGN_PROP)); //groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-align",getProperty(GROUP_BOX_ALIGN_PROP));
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-orient",getProperty(GROUP_BOX_ORIENT_PROP)); //groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "box-orient",getProperty(GROUP_BOX_ORIENT_PROP));
//groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "caption-width",getProperty(GROUP_CAPTION_WIDTH_PROP)); //groupElement.setAttributeNS(CHIBA_NS,getChibaNSPrefix() + "caption-width",getProperty(GROUP_CAPTION_WIDTH_PROP));

View File

@@ -1,93 +0,0 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.
*/
package org.alfresco.web.templating.xforms.schemabuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Basic implementation of WrapperElementsBuilder, with no additional design
*
* @author - Sophie Ramel
*/
public class BaseWrapperElementsBuilder implements WrapperElementsBuilder {
/**
* Creates a new instance of BaseWrapperElementsBuilder
*/
public BaseWrapperElementsBuilder() {
}
/**
* create the wrapper element of the different controls
*
* @param controlElement the control element (input, select, repeat, group, ...)
* @return the wrapper element, already containing the control element
*/
public Element createControlsWrapper(Element controlElement) {
return controlElement;
}
/**
* creates the global enveloppe of the resulting document, and puts it in the document
*
* @return the enveloppe
*/
public Element createEnvelope(Document xForm) {
Element envelopeElement = xForm.createElement("envelope");
//Element envelopeElement = xForm.createElementNS(CHIBA_NS, this.getChibaNSPrefix()+"envelope");
xForm.appendChild(envelopeElement);
return envelopeElement;
}
/**
* create the wrapper element of the form
*
* @param enveloppeElement the form element (chiba:form or other)
* @return the wrapper element
*/
public Element createFormWrapper(Element enveloppeElement) {
//add a "body" element without NS
Document doc = enveloppeElement.getOwnerDocument();
Element body = doc.createElement("body");
//body.appendChild(formElement);
enveloppeElement.appendChild(body);
return body;
}
/**
* create the element that will contain the content of the group (or repeat) element
*
* @param groupElement the group or repeat element
* @return the wrapper element, already containing the content of the group element
*/
public Element createGroupContentWrapper(Element groupElement) {
return groupElement;
}
/**
* create the wrapper element of the xforms:model element
*
* @param modelElement the xforms:model element
* @return the wrapper element, already containing the model
*/
public Element createModelWrapper(Element modelElement) {
return modelElement;
}
}

View File

@@ -92,9 +92,14 @@ public interface SchemaFormBuilder
/** /**
* XMLSchema Instance Namespace declaration * XMLSchema Instance Namespace declaration
*/ */
public static final String XMLSCHEMA_INSTANCE_NAMESPACE_URI = public static final String XMLSCHEMA_INSTANCE_NS =
"http://www.w3.org/2001/XMLSchema-instance"; "http://www.w3.org/2001/XMLSchema-instance";
/**
* XMLSchema instance prefix *
*/
public static final String XMLSCHEMA_INSTANCE_NS_PREFIX = "xsi:";
/** /**
* XMLNS Namespace declaration. * XMLNS Namespace declaration.
*/ */
@@ -110,7 +115,13 @@ public interface SchemaFormBuilder
/** /**
* XForms namespace declaration. * XForms namespace declaration.
*/ */
public static final String XFORMS_NS = "http://www.w3.org/2002/xforms"; public static final String XFORMS_NS =
"http://www.w3.org/2002/xforms";
/**
* XForms prefix
*/
public static final String XFORMS_NS_PREFIX = "xforms:";
/** /**
* Chiba namespace declaration. * Chiba namespace declaration.
@@ -118,40 +129,30 @@ public interface SchemaFormBuilder
public static final String CHIBA_NS = public static final String CHIBA_NS =
"http://chiba.sourceforge.net/xforms"; "http://chiba.sourceforge.net/xforms";
/**
* Chiba prefix
*/
public static final String CHIBA_NS_PREFIX = "chiba:";
/** /**
* XLink namespace declaration. * XLink namespace declaration.
*/ */
public static final String XLINK_NS = "http://www.w3.org/1999/xlink"; public static final String XLINK_NS = "http://www.w3.org/1999/xlink";
/**
* Xlink prefix
*/
public static final String XLINK_NS_PREFIX = "xlink:";
/** /**
* XML Events namsepace declaration. * XML Events namsepace declaration.
*/ */
public static final String XMLEVENTS_NS = "http://www.w3.org/2001/xml-events"; public static final String XMLEVENTS_NS = "http://www.w3.org/2001/xml-events";
/**
* Chiba prefix
*/
public static final String chibaNSPrefix = "chiba:";
/**
* XForms prefix
*/
public static final String xformsNSPrefix = "xforms:";
/**
* Xlink prefix
*/
public static final String xlinkNSPrefix = "xlink:";
/**
* XMLSchema instance prefix *
*/
public static final String xmlSchemaInstancePrefix = "xsi:";
/** /**
* XML Events prefix * XML Events prefix
*/ */
public static final String xmleventsNSPrefix = "ev:"; public static final String XMLEVENTS_NS_PREFIX = "ev:";
/** /**
* Prossible values of the "@method" on the "submission" element * Prossible values of the "@method" on the "submission" element

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 B

View File

@@ -24,7 +24,7 @@
<f:verbatim> <f:verbatim>
<% PanelGenerator.generatePanelStart(out, request.getContextPath(), "yellow", "#ffffcc"); %> <% PanelGenerator.generatePanelStart(out, request.getContextPath(), "yellow", "#ffffcc"); %>
</f:verbatim> </f:verbatim>
<h:panelGrid columns="2" cellpadding="2" cellspacing="2" border="0" width="100%" style="background-colour:##ffffcc" rowClasses="alignTop"> <h:panelGrid columns="2" cellpadding="2" cellspacing="2" border="0" width="100%" style="background-color:##ffffcc" rowClasses="alignTop">
<h:panelGrid columns="1" cellpadding="2" cellspacing="2" border="0"> <h:panelGrid columns="1" cellpadding="2" cellspacing="2" border="0">
<h:outputText style="font-size: 11px; font-weight:bold; color:#4272B4" value="#{msg.product_name}" /> <h:outputText style="font-size: 11px; font-weight:bold; color:#4272B4" value="#{msg.product_name}" />

View File

@@ -23,6 +23,14 @@ tinyMCE.init({
theme_advanced_buttons2_add : "separator,forecolor,backcolor" theme_advanced_buttons2_add : "separator,forecolor,backcolor"
}); });
var control_images = [ "plus", "minus", "arrow_up", "arrow_down" ];
for (var i in control_images)
{
var s = control_images[i];
control_images[i] = new Image();
control_images[i].src = s;
}
dojo.declare("alfresco.xforms.Widget", dojo.declare("alfresco.xforms.Widget",
null, null,
{ {
@@ -30,13 +38,26 @@ dojo.declare("alfresco.xforms.Widget",
{ {
this.xform = xform; this.xform = xform;
this.node = node; this.node = node;
this.node.widget = this;
this.id = this.node.getAttribute("id"); this.id = this.node.getAttribute("id");
}, },
parent: null, parent: null,
domContainer: null,
_getBinding: function() _getBinding: function()
{ {
return this.xform.getBinding(this.node); return this.xform.getBinding(this.node);
}, },
getDepth: function()
{
var result = 1;
var p = this.parent;
while (p)
{
result++;
p = p.parent;
}
return result;
},
isRequired: function() isRequired: function()
{ {
var binding = this._getBinding(); var binding = this._getBinding();
@@ -114,16 +135,18 @@ dojo.declare("alfresco.xforms.NumericStepper",
value: initial_value value: initial_value
}, },
nodeRef); nodeRef);
var handler = function(event) w.widget = this;
this.widget = w;
dojo.event.connect(w, "adjustValue", this, this._widget_changeHandler);
dojo.event.connect(w, "onkeyup", this, this._widget_changeHandler);
},
getValue: function()
{ {
dojo.debug("value changed " + w.widgetId + return this.widget.getValue();
" value " + w.getValue() + },
" t " + event.target + _widget_changeHandler: function(event)
" w " + w + " this " + this); {
setXFormsValue(w.widgetId, w.getValue()); this.xform.setXFormsValue(this.id, this.getValue());
}
dojo.event.connect(w, "adjustValue", handler);
dojo.event.connect(w, "onkeyup", handler);
} }
}); });
@@ -164,12 +187,13 @@ dojo.declare("alfresco.xforms.DatePicker",
dateTextBox.picker.hide(); dateTextBox.picker.hide();
dojo.event.connect(dateTextBox.picker, dojo.event.connect(dateTextBox.picker,
"onSetDate", "onSetDate",
this,
function(event) function(event)
{ {
dateTextBox.picker.hide(); dateTextBox.picker.hide();
dateTextBox.show(); dateTextBox.show();
dateTextBox.setValue(dojo.widget.DatePicker.util.toRfcDate(dateTextBox.picker.date)); dateTextBox.setValue(dojo.widget.DatePicker.util.toRfcDate(dateTextBox.picker.date));
setXFormsValue(dateTextBox.widgetId, this.xform.setXFormsValue(dateTextBox.widgetId,
dateTextBox.getValue()); dateTextBox.getValue());
}); });
} }
@@ -195,16 +219,17 @@ dojo.declare("alfresco.xforms.TextField",
value: initial_value value: initial_value
}, },
nodeRef); nodeRef);
dojo.event.connect(w, w.widget = this;
"onkeyup", this.widget = w;
function(event) dojo.event.connect(w, "onkeyup", this, this._widget_keyUpHandler);
},
getValue: function()
{ {
dojo.debug("value changed " + w.widgetId + return this.widget.getValue();
" value " + w.getValue() + },
" t " + event.target + _widget_keyUpHandler: function(event)
" w " + w + " this " + this); {
setXFormsValue(w.widgetId, w.getValue()); this.xform.setXFormsValue(this.id, this.getValue());
});
} }
}); });
@@ -277,7 +302,7 @@ dojo.declare("alfresco.xforms.Select1",
radio.setAttribute("checked", "true"); radio.setAttribute("checked", "true");
radio.onclick = function(event) radio.onclick = function(event)
{ {
setXFormsValue(this.getAttribute("id"), this.xform.setXFormsValue(this.getAttribute("id"),
this.value); this.value);
} }
attach_point.appendChild(radio); attach_point.appendChild(radio);
@@ -300,7 +325,7 @@ dojo.declare("alfresco.xforms.Select1",
} }
combobox.onchange = function(event) combobox.onchange = function(event)
{ {
setXFormsValue(this.getAttribute("id"), this.xform.setXFormsValue(this.getAttribute("id"),
this.options[this.selectedIndex].value); this.options[this.selectedIndex].value);
} }
} }
@@ -329,7 +354,7 @@ dojo.declare("alfresco.xforms.CheckBox",
"onClick", "onClick",
function(event) function(event)
{ {
setXFormsValue(w.widgetId, w.checked); this.xform.setXFormsValue(w.widgetId, w.checked);
}); });
} }
}); });
@@ -340,45 +365,289 @@ dojo.declare("alfresco.xforms.Group",
initializer: function(xform, node) initializer: function(xform, node)
{ {
this.inherited("initializer", [ xform, node ]); this.inherited("initializer", [ xform, node ]);
this.children = [];
},
children: null,
getChildAt: function(index)
{
return index < this.children.length ? this.children[index] : null;
},
getChildIndex: function(child)
{
for (var i = 0; i < this.children.length; i++)
{
dojo.debug(this.id + "[" + i + "]: " +
" is " + this.children[i].id + " the same as " + child.id + "?");
if (this.children[i] == child)
return i;
}
return -1;
}, },
children: [],
domNode: null, domNode: null,
addChild: function(child) addChild: function(child)
{ {
this.children.push(child); return this.insertChildAt(child, this.children.length);
},
insertChildAt: function(child, position)
{
dojo.debug(this.id + ".insertChildAt(" + child.id + ", " + position + ")");
child.parent = this; child.parent = this;
var d = document.createElement("div"); var d = document.createElement("div");
d.setAttribute("style", "border: 2px solid green; width: 100%;"); child.domContainer = d;
d.setAttribute("style", "position: relative; border: 0px solid green; margin-top: 2px; margin-bottom: 2px;");
if (this.parent && this.parent.domNode)
d.style.top = this.parent.domNode.style.bottom;
if (position == this.children.length)
{
this.domNode.appendChild(d); this.domNode.appendChild(d);
if (child.isRequired() && child.node.nodeName != "xforms:repeat") this.children.push(child);
}
else
{
this.domNode.insertBefore(d, this.getChildAt(position).domContainer);
this.children.splice(position, 0, child);
}
if (child.isRequired() && !(child instanceof alfresco.xforms.Group))
{ {
var requiredImage = document.createElement("img"); var requiredImage = document.createElement("img");
requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif"); requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
requiredImage.setAttribute("style", "margin:5px"); requiredImage.setAttribute("style", "margin:5px;");
requiredImage.setAttribute("alt", "node Name " + child.node.nodeName);
d.appendChild(requiredImage); d.appendChild(requiredImage);
requiredImage.style.position = "relative";
requiredImage.style.top = "0px";
requiredImage.style.left = "0px";
requiredImage.style.lineHeight = d.style.height;
} }
var label = child._getLabelNode(); var label = child._getLabelNode();
if (label) if (label && !(child instanceof alfresco.xforms.Group))
d.appendChild(document.createTextNode(dojo.dom.textContent(label))); {
var s = document.createElement("span"); var labelDiv = document.createElement("div");
d.appendChild(s); labelDiv.appendChild(document.createTextNode(dojo.dom.textContent(label)));
child.render(s); d.appendChild(labelDiv);
labelDiv.style.position = "relative";
labelDiv.style.top = "-" + labelDiv.offsetTop + "px";
labelDiv.style.left = "5%";
}
var contentDiv = document.createElement("div");
d.appendChild(contentDiv);
child.render(contentDiv);
contentDiv.style.position = "relative";
contentDiv.style.top = "-" + contentDiv.offsetTop + "px";
contentDiv.style.left = (child instanceof alfresco.xforms.Group
? "0px"
: "40%");
d.style.borderColor = "pink";
d.style.borderWidth = "0px";
if (!(child instanceof alfresco.xforms.Group))
d.style.height = contentDiv.offsetHeight;
return d;
},
isIndented: function()
{
return false && this.parent != null;
}, },
render: function(attach_point) render: function(attach_point)
{ {
this.domNode = document.createElement("div"); this.domNode = document.createElement("div");
this.domNode.setAttribute("style", "width:100%; border: 0px solid blue;"); this.domNode.setAttribute("id", this.id + "-domNode");
if (parent) this.domNode.widget = this;
this.domNode.setAttribute("style", "border: 0px solid blue;");
if (this.isIndented())
this.domNode.style.marginLeft = "10px"; this.domNode.style.marginLeft = "10px";
attach_point.appendChild(this.domNode); attach_point.appendChild(this.domNode);
return this.domNode; return this.domNode;
} }
}); });
dojo.declare("alfresco.xforms.Submit", dojo.declare("alfresco.xforms.Repeat",
alfresco.xforms.Group,
{
initializer: function(xform, node)
{
this.inherited("initializer", [ xform, node ]);
},
selectedIndex: null,
insertChildAt: function(child, position)
{
var result = this.inherited("insertChildAt", [ child, position ]);
result.style.borderColor = "green";
result.style.borderWidth = "0px";
child.repeat = this;
dojo.event.browser.addListener(result, "onclick", function(event)
{
child.repeat.setFocusedChild(child);
});
var controls = document.createElement("div");
result.appendChild(controls);
controls.style.position = "absolute";
controls.style.left = "80%";
controls.style.bottom = "0px";
var images = [
{ src: "plus", action: this._insertRepeatItem_handler },
{ src: "arrow_up", action: this._moveRepeatItemUp_handler },
{ src: "arrow_down", action: null },
{ src: "minus", action: null }
];
for (var i in images)
{
var img = document.createElement("img");
img.setAttribute("src",
WEBAPP_CONTEXT + "/images/icons/" + images[i].src + ".gif");
img.style.width = "16px";
img.style.height = "16px";
img.style.marginRight = "4px";
img.repeatItem = child;
img.repeat = this;
controls.appendChild(img);
dojo.event.browser.addListener(img, "onclick", images[i].action);
}
return result;
},
_insertRepeatItem_handler: function(event)
{
alert("insert r=" + event.target.repeat.id +
" item " + event.target.repeatItem.id);
},
_moveRepeatItemUp_handler: function(event)
{
alert("moveUp " + event);
},
setFocusedChild: function(child)
{
if (!child)
this.xform.setRepeatIndex(this.id, 0);
else
{
var index = this.getChildIndex(child);
if (index < 0)
alert("unable to find child " + child.id + " in " + this.id);
// chiba thinks indexes are initialized to 1 so just
// highlight the thing
if (this.selectedIndex == null && index == 0)
this.handleIndexChanged(0);
// xforms repeat indexes are 1-based
this.xform.setRepeatIndex(this.id, index + 1);
}
},
isIndented: function()
{
return false;
},
render: function(attach_point)
{
this.domNode = this.inherited("render", [ attach_point ]);
this.domNode.style.borderColor = "black";
this.domNode.style.borderWidth = "1px";
var d = document.createElement("div");
d.repeat = this;
this.domNode.appendChild(d);
d.setAttribute("style", "position: relative; line-height: 16px; background-color: #cddbe8; font-weight: bold;");
dojo.event.browser.addListener(d, "onclick", function(event)
{
event.currentTarget.repeat.setFocusedChild(null);
});
var labelElement = document.createElement("div");
d.appendChild(labelElement);
labelElement.appendChild(document.createTextNode(this.parent.getLabel()));
labelElement.setAttribute("style", "position: relative; left: 5%; top: 0px;");
var addElement = document.createElement("img");
d.appendChild(addElement);
addElement.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/plus.gif");
addElement.style.width = "16px";
addElement.style.height = "16px";
addElement.style.position = "absolute";
addElement.style.top = "0px";
addElement.style.left = "80%";
dojo.event.browser.addListener(addElement, "onclick", function(event)
{
var repeat = event.currentTarget.parentNode.repeat;
repeat.xform.fireAction("trigger_0");
});
return this.domNode;
},
handleIndexChanged: function(index)
{
dojo.debug(this.id + ".handleIndexChanged(" + index + ")");
if (this.selectedIndex != null && this.selectedIndex >= 0)
{
var child = this.getChildAt(this.selectedIndex);
child.domContainer.style.backgroundColor = "white";
}
if (index >= 0)
{
var child = this.getChildAt(index);
child.domContainer.style.backgroundColor = "orange";
}
this.selectedIndex = index;
},
handlePrototypeCloned: function(prototypeId)
{
dojo.debug(this.id + ".handlePrototypeCloned("+ prototypeId +")");
var chibaData = this.node.getElementsByTagName("data");
dojo.debug("repeat node == " +dojo.dom.innerXML(this.node));
dojo.debug(chibaData + " l = " + chibaData.length);
chibaData = chibaData[chibaData.length - 1];
dojo.debug("chiba:data == " + dojo.dom.innerXML(chibaData));
var prototypeToClone = dojo.dom.firstElement(chibaData);
if (prototypeToClone.getAttribute("id") != prototypeId)
throw new Error("unable to locate " + prototypeId +
" in " + this.id);
return prototypeToClone.cloneNode(true);
},
handleItemInserted: function(clonedPrototype, position)
{
dojo.debug(this.id + ".handleItemInserted(" + clonedPrototype.nodeName +
", " + position + ")");
var w = create_widget(this.xform, clonedPrototype);
this.insertChildAt(w, position);
load_body(this.xform, w.node, w);
}
});
dojo.declare("alfresco.xforms.Trigger",
alfresco.xforms.Widget, alfresco.xforms.Widget,
{ {
initializer: function(xform, node)
{
this.inherited("initializer", [ xform, node ]);
},
render: function(attach_point)
{
var nodeRef = document.createElement("div");
attach_point.appendChild(nodeRef);
var w = dojo.widget.createWidget("Button",
{
widgetId: this.id,
caption: this.getLabel() + " " + this.id
},
nodeRef);
w.onClick = function()
{
fireAction(w.widgetId);
};
this.domContainer.style.display = "none";
}
});
dojo.declare("alfresco.xforms.Submit",
alfresco.xforms.Trigger,
{
initializer: function(xform, node) initializer: function(xform, node)
{ {
this.inherited("initializer", [ xform, node ]); this.inherited("initializer", [ xform, node ]);
@@ -403,36 +672,13 @@ dojo.declare("alfresco.xforms.Submit",
} }
}); });
dojo.declare("alfresco.xforms.Trigger",
alfresco.xforms.Widget,
{
initializer: function(xform, node)
{
this.inherited("initializer", [ xform, node ]);
},
render: function(attach_point)
{
var nodeRef = document.createElement("div");
attach_point.appendChild(nodeRef);
var w = dojo.widget.createWidget("Button",
{
widgetId: this.id,
caption: this.getLabel() + " " + this.id
},
nodeRef);
w.onClick = function()
{
fireAction(w.widgetId);
};
}
});
dojo.declare("alfresco.xforms.XForm", dojo.declare("alfresco.xforms.XForm",
null, null,
{ {
initializer: function(node) initializer: function(document)
{ {
this.node = node; this.document = document;
this.node = document.documentElement;
this._bindings = this._loadBindings(this.getModel()); this._bindings = this._loadBindings(this.getModel());
}, },
getModel: function() getModel: function()
@@ -482,6 +728,164 @@ dojo.declare("alfresco.xforms.XForm",
} }
} }
return result; return result;
},
setRepeatIndex: function(id, index)
{
dojo.debug("setting repeat index " + index + " on " + id);
var req = {
xform: this,
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.setRepeatIndex",
content: { id: id, index: index },
mimetype: "text/xml",
load: function(type, data, evt)
{
this.xform._handleEventLog(data.documentElement);
},
error: function(type, e)
{
alert("error!! " + type + " e = " + e.message);
}
};
dojo.io.bind(req);
},
fireAction: function(id)
{
var req = {
xform: this,
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.fireAction",
content: { id: id },
mimetype: "text/xml",
load: function(type, data, evt)
{
dojo.debug("fireAction." + type);
this.xform._handleEventLog(data.documentElement);
if (document.submitTrigger)
{
document.submitTrigger.done = true;
document.submitTrigger.currentButton.click();
document.submitTrigger.currentButton = null;
}
},
error: function(type, e)
{
alert("error!! " + type + " e = " + e.message);
}
};
dojo.io.bind(req);
},
setXFormsValue: function(id, value)
{
dojo.debug("setting value " + id + " = " + value);
var req = {
xform: this,
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.setXFormsValue",
content: { id: id, value: value },
mimetype: "text/xml",
load: function(type, data, evt)
{
this.xform._handleEventLog(data.documentElement);
},
error: function(type, e)
{
alert("error!! " + type + " e = " + e.message);
}
};
dojo.io.bind(req);
},
_handleEventLog: function(events)
{
var prototypeClones = [];
for (var i = 0; i < events.childNodes.length; i++)
{
if (dojo.dom.isNode(events.childNodes[i]))
{
var targetId = events.childNodes[i].getAttribute("targetId");
var targetName = events.childNodes[i].getAttribute("targetName");
dojo.debug("parsing " + events.childNodes[i].nodeName +
"(" + targetId + ", " + targetName + ")");
switch (events.childNodes[i].nodeName)
{
case "chiba-index-changed":
{
var index = events.childNodes[i].getElementsByTagName("index")[0];
index = Number(dojo.dom.textContent(index)) - 1;
var targetDomNode = document.getElementById(targetId + "-domNode");
if (!targetDomNode)
throw new Error("unable to find node " + targetId + "-domNode");
var target = targetDomNode.widget;
target.handleIndexChanged(index);
break;
}
case "chiba-prototype-cloned":
{
var prototypeId = events.childNodes[i].getElementsByTagName("prototypeId")[0];
prototypeId = dojo.dom.textContent(prototypeId);
var targetDomNode = document.getElementById(targetId + "-domNode");
if (!targetDomNode)
throw new Error("unable to find node " + targetId + "-domNode");
var target = targetDomNode.widget;
var clone = target.handlePrototypeCloned(prototypeId);
prototypeClones.push(clone);
break;
}
case "chiba-id-generated":
{
var originalId = events.childNodes[i].getElementsByTagName("originalId")[0];
originalId = dojo.dom.textContent(originalId);
dojo.debug("handleIdGenerated(" + targetId + ", " + originalId + ")");
function applyId(node, oldId, newId)
{
dojo.debug("looking for " + oldId +
" in " + node.nodeName +
"(" + node.getAttribute("id") + ")");
if (node.getAttribute("id") == oldId)
{
dojo.debug("applying id " + newId +
" to " + node.nodeName + "(" + oldId + ")");
node.setAttribute("id", newId);
return true;
}
for (var i = 0; i < node.childNodes.length; i++)
{
if (dojo.dom.isNode(node.childNodes[i]) &&
applyId(node.childNodes[i], oldId, newId))
return true;
}
return false;
}
var clone = prototypeClones[prototypeClones.length - 1];
if (!applyId(clone, originalId, targetId))
throw new Error("unable to find " + originalId +
" in clone " + dojo.dom.innerXML(clone));
break;
}
case "chiba-item-inserted":
{
var position = events.childNodes[i].getElementsByTagName("position")[0];
position = Number(dojo.dom.textContent(position)) - 1;
var targetDomNode = document.getElementById(targetId + "-domNode");
if (!targetDomNode)
throw new Error("unable to find node " + targetId + "-domNode");
var target = targetDomNode.widget;
var clone = prototypeClones.pop();
target.handleItemInserted(clone, position);
break;
}
default:
{
dojo.debug("unhandled event " + events.childNodes[i].nodeName);
}
}
}
}
} }
}); });
@@ -493,7 +897,7 @@ function xforms_init()
mimetype: "text/xml", mimetype: "text/xml",
load: function(type, data, evt) load: function(type, data, evt)
{ {
var xform = new alfresco.xforms.XForm(data.documentElement); var xform = new alfresco.xforms.XForm(data);
var bindings = xform.getBindings(); var bindings = xform.getBindings();
for (var i in bindings) for (var i in bindings)
{ {
@@ -515,110 +919,66 @@ function xforms_init()
dojo.io.bind(req); dojo.io.bind(req);
} }
function load_body(xform, currentNode, parentWidget) function create_widget(xform, node)
{ {
dojo.lang.forEach(currentNode.childNodes, function(o) switch (node.nodeName.toLowerCase())
{
dojo.debug("loading " + o + " NN " + o.nodeName + " into " + parentWidget);
switch (o.nodeName.toLowerCase())
{ {
case "xforms:group": case "xforms:group":
var w = new alfresco.xforms.Group(xform, o); return new alfresco.xforms.Group(xform, node);
dojo.debug("adding " + w + " to " + parentWidget);
parentWidget.addChild(w);
load_body(xform, o, w);
break;
case "xforms:repeat": case "xforms:repeat":
var w = new alfresco.xforms.Group(xform, o); return new alfresco.xforms.Repeat(xform, node);
parentWidget.addChild(w);
load_body(xform, o, w);
break;
case "xforms:textarea": case "xforms:textarea":
var w = new alfresco.xforms.TextArea(xform, o); return new alfresco.xforms.TextArea(xform, node);
parentWidget.addChild(w);
break;
case "xforms:input": case "xforms:input":
var type = xform.getType(o); var type = xform.getType(node);
switch (type) switch (type)
{ {
case "date": case "date":
var w = new alfresco.xforms.DatePicker(xform, o); return new alfresco.xforms.DatePicker(xform, node);
break;
case "integer": case "integer":
case "positiveInteger": case "positiveInteger":
case "negativeInteger": case "negativeInteger":
case "double": case "double":
var w = new alfresco.xforms.NumericStepper(xform, o, type); return new alfresco.xforms.NumericStepper(xform, node, type);
break;
case "string": case "string":
default: default:
var w = new alfresco.xforms.TextField(xform, o); return new alfresco.xforms.TextField(xform, node);
} }
parentWidget.addChild(w);
break;
case "xforms:select1": case "xforms:select1":
var w = (xform.getType(o) == "boolean" return (xform.getType(node) == "boolean"
? new alfresco.xforms.CheckBox(xform, o) ? new alfresco.xforms.CheckBox(xform, node)
: new alfresco.xforms.Select1(xform, o)); : new alfresco.xforms.Select1(xform, node));
parentWidget.addChild(domNode);
break;
case "xforms:submit": case "xforms:submit":
var w = new alfresco.xforms.Submit(xform, o); return new alfresco.xforms.Submit(xform, node);
parentWidget.addChild(w);
break;
case "xforms:trigger": case "xforms:trigger":
var w = new alfresco.xforms.Trigger(xform, o); return new alfresco.xforms.Trigger(xform, node);
parentWidget.addChild(w);
break;
case "chiba:data": case "chiba:data":
break; case "xforms:label":
case "xforms:alert":
return null;
default: default:
load_body(xform, o, parentWidget); throw new Error("unknown type " + node.nodeName);
break; }
}
function load_body(xform, currentNode, parentWidget)
{
dojo.lang.forEach(currentNode.childNodes, function(o)
{
if (dojo.dom.isNode(o))
{
dojo.debug("loading " + o + " NN " + o.nodeName + " into " + parentWidget);
var w = create_widget(xform, o);
if (w != null)
{
parentWidget.addChild(w);
if (w instanceof alfresco.xforms.Group)
load_body(xform, o, w);
}
} }
}); });
} }
function fireAction(id)
{
var req = {
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.fireAction",
content: { id: id },
mimetype: "text/xml",
load: function(type, data, evt)
{
if (document.submitTrigger)
{
document.submitTrigger.done = true;
document.submitTrigger.currentButton.click();
document.submitTrigger.currentButton = null;
}
},
error: function(type, e)
{
alert("error!! " + type + " e = " + e.message);
}
};
dojo.io.bind(req);
}
function setXFormsValue(id, value)
{
var req = {
url: WEBAPP_CONTEXT + "/ajax/invoke/XFormsBean.setXFormsValue",
content: { id: id, value: value },
mimetype: "text/xml",
load: function(type, data, evt)
{
},
error: function(type, e)
{
alert("error!! " + type + " e = " + e.message);
}
};
dojo.io.bind(req);
}
function addSubmitHandlerToButton(b) function addSubmitHandlerToButton(b)
{ {
var baseOnClick = b.onclick; var baseOnClick = b.onclick;