diff --git a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java index 5fdfd546c7..45b0ab9a5b 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateWebContentWizard.java @@ -84,6 +84,7 @@ public class CreateWebContentWizard extends BaseContentWizard protected String content = null; protected String formName; protected transient List createMimeTypes; + protected transient List formChoices; protected String createdPath = null; protected List renditions = null; protected FormInstanceData formInstanceData = null; @@ -171,6 +172,8 @@ public class CreateWebContentWizard extends BaseContentWizard this.renditions = null; this.startWorkflow = false; this.formSelectDisabled = false; + this.createMimeTypes = null; + this.formChoices = null; // check for a form ID being passed in as a parameter if (this.parameters.get(UIUserSandboxes.PARAM_FORM_NAME) != null) @@ -523,17 +526,20 @@ public class CreateWebContentWizard extends BaseContentWizard */ public List getFormChoices() { - final List
forms = this.avmBrowseBean.getWebProject().getForms(); - final List items = new ArrayList(forms.size()); - for (final Form f : forms) + if (this.formChoices == null) { - items.add(new SelectItem(f.getName(), f.getTitle())); + final List forms = this.avmBrowseBean.getWebProject().getForms(); + this.formChoices = new ArrayList(forms.size()); + for (final Form f : forms) + { + this.formChoices.add(new SelectItem(f.getName(), f.getTitle())); + } + + final QuickSort sorter = new QuickSort(this.formChoices, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + sorter.sort(); + } - - final QuickSort sorter = new QuickSort(items, "label", true, IDataContainer.SORT_CASEINSENSITIVE); - sorter.sort(); - - return items; + return this.formChoices; } /** @@ -543,21 +549,21 @@ public class CreateWebContentWizard extends BaseContentWizard { if (this.createMimeTypes == null) { - FacesContext context = FacesContext.getCurrentInstance(); + final FacesContext context = FacesContext.getCurrentInstance(); // add the well known object type to start with this.createMimeTypes = new ArrayList(5); // add the configured create mime types to the list - ConfigService svc = Application.getConfigService(context); - Config wizardCfg = svc.getConfig("Content Wizards"); + final ConfigService svc = Application.getConfigService(context); + final Config wizardCfg = svc.getConfig("Content Wizards"); if (wizardCfg == null) { LOGGER.warn("Could not find 'Content Wizards' configuration section"); } else { - ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types"); + final ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types"); if (typesCfg == null) { LOGGER.warn("Could not find 'create-mime-types' configuration element"); @@ -566,16 +572,20 @@ public class CreateWebContentWizard extends BaseContentWizard { for (ConfigElement child : typesCfg.getChildren()) { - String currentMimeType = child.getAttribute("name"); - if (currentMimeType != null) + final String currentMimeType = child.getAttribute("name"); + if (currentMimeType == null || + (MimetypeMap.MIMETYPE_XML.equals(currentMimeType) && + this.getFormChoices().size() == 0)) { - String label = getSummaryMimeType(currentMimeType); - this.createMimeTypes.add(new SelectItem(currentMimeType, label)); + continue; } + + final String label = this.getSummaryMimeType(currentMimeType); + this.createMimeTypes.add(new SelectItem(currentMimeType, label)); } // make sure the list is sorted by the label - QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + final QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); sorter.sort(); } } diff --git a/source/java/org/alfresco/web/forms/XMLUtil.java b/source/java/org/alfresco/web/forms/XMLUtil.java index c7c7c3fce2..eac953ca73 100644 --- a/source/java/org/alfresco/web/forms/XMLUtil.java +++ b/source/java/org/alfresco/web/forms/XMLUtil.java @@ -34,6 +34,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** @@ -175,4 +176,41 @@ public class XMLUtil return null; } } + + /** + * Provides a NodeList of multiple nodelists + */ + public static NodeList combine(final NodeList... nls) + { + + return new NodeList() + { + public Node item(final int index) + { + int offset = 0; + for (int i = 0; i < nls.length; i++) + { + if (index - offset < nls[i].getLength()) + { + return nls[i].item(index - offset); + } + else + { + offset += nls[i].getLength(); + } + } + return null; + } + + public int getLength() + { + int result = 0; + for (int i = 0; i < nls.length; i++) + { + result += nls[i].getLength(); + } + return result; + } + }; + } } \ No newline at end of file diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java index bb91852771..83e419cd4d 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java @@ -73,65 +73,7 @@ public class Schema2XForms private final static Log LOGGER = LogFactory.getLog(Schema2XForms.class); - private static final String PROPERTY_PREFIX = - "http://www.chiba.org/properties/schemaFormBuilder/"; - - /** - * Property to control the selection of UI control for a selectOne control. - * If a selectOne control has >= the number of values specified in this property, - * it is considered a long list, and the UI control specified by - * SELECTONE_UI_CONTROL_LONG_PROP is used. Otherwise, the value of SELECTONE_UI_CONTROL_SHORT_PROP - * is used. - */ - public static final String SELECTONE_LONG_LIST_SIZE_PROP = - PROPERTY_PREFIX + "select1@longListSize"; - - /** - * Property to specify the selectMany UI control to be used when there are releatively few items - * to choose from. - */ - public static final String SELECTONE_UI_CONTROL_SHORT_PROP = - PROPERTY_PREFIX + "select1@appearance/short"; - - /** - * Property to specify the selectMany UI control to be used when there are large numbers of items - * to choose from. - */ - public static final String SELECTONE_UI_CONTROL_LONG_PROP = - PROPERTY_PREFIX + "select1@appearance/long"; - private static final String DEFAULT_SELECTONE_UI_CONTROL_SHORT_PROP = - "full"; - private static final String DEFAULT_SELECTONE_UI_CONTROL_LONG_PROP = - "minimal"; - - /** - * Property to control the selection of UI control for a selectMany control. - * If a selectMany control has >= the number of values specified in this property, - * it is considered a long list, and the UI control specified by - * SELECTMANY_UI_CONTROL_LONG_PROP is used. Otherwise, the value of SELECTMANY_UI_CONTROL_SHORT_PROP - * is used. - */ - public static final String SELECTMANY_LONG_LIST_SIZE_PROP = - PROPERTY_PREFIX + "select@longListSize"; - - /** - * Property to specify the selectMany UI control to be used when there are releatively few items - * to choose from. - */ - public static final String SELECTMANY_UI_CONTROL_SHORT_PROP = - PROPERTY_PREFIX + "select@appearance/short"; - - /** - * Property to specify the selectMany UI control to be used when there are large numbers of items - * to choose from. - */ - public static final String SELECTMANY_UI_CONTROL_LONG_PROP = - PROPERTY_PREFIX + "select@appearance/long"; - private static final String DEFAULT_SELECTMANY_UI_CONTROL_SHORT_PROP = - "full"; - private static final String DEFAULT_SELECTMANY_UI_CONTROL_LONG_PROP = - "compact"; - private static final String DEFAULT_LONG_LIST_MAX_SIZE = "6"; + private final static int LONG_LIST_SIZE = 5; private final String action; private final SubmitMethod submitMethod; @@ -143,7 +85,6 @@ public class Schema2XForms * values: "Long" representing the counter for this element */ private final Map counter = new HashMap(); - private final Properties properties = new Properties(); private String targetNamespace; private final Map namespacePrefixes = new HashMap(); @@ -174,50 +115,6 @@ public class Schema2XForms this.base = base; } - /** - * Get the current set of properties used by implementations of Schema2XForms. - * - * @return The list of properties. - */ - public Properties getProperties() - { - return properties; - } - - /** - * Sets the property to the specified value. If the property exists, its value is overwritten. - * - * @param key The implementation defined property key. - * @param value The value for the property. - */ - public void setProperty(String key, String value) - { - getProperties().setProperty(key, value); - } - - /** - * Gets the value for the specified property. - * - * @param key The implementation defined property key. - * @return The property value if found, or null if the property cannot be located. - */ - public String getProperty(String key) - { - return getProperties().getProperty(key); - } - - /** - * Gets the value for the specified property, with a default if the property cannot be located. - * - * @param key The implementation defined property key. - * @param defaultValue This value will be returned if the property does not exists. - * @return The property value if found, or defaultValue if the property cannot be located. - */ - public String getProperty(String key, String defaultValue) - { - return getProperties().getProperty(key, defaultValue); - } - /** * Generate the XForm based on a user supplied XML Schema. * @@ -373,16 +270,6 @@ public class Schema2XForms public void reset() { this.counter.clear(); - setProperty(SELECTMANY_LONG_LIST_SIZE_PROP, DEFAULT_LONG_LIST_MAX_SIZE); - setProperty(SELECTMANY_UI_CONTROL_SHORT_PROP, - DEFAULT_SELECTMANY_UI_CONTROL_SHORT_PROP); - setProperty(SELECTMANY_UI_CONTROL_LONG_PROP, - DEFAULT_SELECTMANY_UI_CONTROL_LONG_PROP); - setProperty(SELECTONE_LONG_LIST_SIZE_PROP, DEFAULT_LONG_LIST_MAX_SIZE); - setProperty(SELECTONE_UI_CONTROL_SHORT_PROP, - DEFAULT_SELECTONE_UI_CONTROL_SHORT_PROP); - setProperty(SELECTONE_UI_CONTROL_LONG_PROP, - DEFAULT_SELECTONE_UI_CONTROL_LONG_PROP); } private void insertPrototypeNodes(final Element instanceDocumentElement, @@ -580,9 +467,10 @@ public class Schema2XForms /** */ - protected Map addChoicesForSelectSwitchControl(final Document xForm, - final Element choicesElement, - final List choiceValues) + protected Map addChoicesForSelectSwitchControl(final Document xformsDocument, + final Element formSection, + final List choiceValues, + final String typeBindId) { if (LOGGER.isDebugEnabled()) { @@ -613,37 +501,32 @@ public class Schema2XForms } //build the case element - final Element caseElement = xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":case"); + final Element caseElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":case"); + caseElement.appendChild(this.createLabel(xformsDocument, textValue)); final String caseId = this.setXFormsId(caseElement); result.put(textValue, caseElement); - final Element item = this.createXFormsItem(xForm, - this.createCaption(textValue), - textValue); - choicesElement.appendChild(item); - - /// action in the case - final Element action = xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":action"); - this.setXFormsId(action); - item.appendChild(action); - - action.setAttributeNS(NamespaceConstants.XMLEVENTS_NS, - NamespaceConstants.XMLEVENTS_PREFIX + ":event", - "xforms-select"); - - final Element toggle = xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":toggle"); + final Element toggle = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":toggle"); this.setXFormsId(toggle); - toggle.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":case", caseId); - //toggle.setAttributeNS(NamespaceConstants.XFORMS_NS, - //NamespaceConstants.XFORMS_PREFIX + ":case",bindIdPrefix + "_" + textValue +"_case"); - action.appendChild(toggle); + final Element setValue = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":setvalue"); + setValue.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":bind", + typeBindId); + setValue.appendChild(xformsDocument.createTextNode(textValue)); + + formSection.appendChild(this.createTrigger(xformsDocument, + null, + typeBindId, + "toggle to case " + caseId, + toggle, + setValue)); } return result; } @@ -661,11 +544,15 @@ public class Schema2XForms final NodeList d = doc.getElementsByTagNameNS(namespace, elementName); if (d.getLength() == 0) + { return null; + } if (d.getLength() > 1) - LOGGER.warn("expect exactly one value for " + namespace + + { + LOGGER.warn("expected exactly one value for " + namespace + ":" + elementName + ". found " + d.getLength()); + } String result = DOMUtil.getTextNodeAsString(d.item(0)); LOGGER.debug(namespace + ":" + elementName + " = " + result); if (result.startsWith("${") && result.endsWith("}") && resourceBundle != null) @@ -685,7 +572,7 @@ public class Schema2XForms return result; } - private Element addAnyType(final Document xForm, + private Element addAnyType(final Document xformsDocument, final Element modelSection, final Element formSection, final XSModel schema, @@ -694,7 +581,7 @@ public class Schema2XForms final String pathToRoot, final ResourceBundle resourceBundle) { - return this.addSimpleType(xForm, + return this.addSimpleType(xformsDocument, modelSection, formSection, schema, @@ -706,7 +593,7 @@ public class Schema2XForms resourceBundle); } - private void addAttributeSet(final Document xForm, + private void addAttributeSet(final Document xformsDocument, final Element modelSection, final Element defaultInstanceElement, final Element formSection, @@ -819,7 +706,7 @@ public class Schema2XForms throw new FormBuilderException("error retrieving default value for attribute " + attributeName + " at " + newPathToRoot, e); } - this.addSimpleType(xForm, + this.addSimpleType(xformsDocument, modelSection, formSection, schema, @@ -831,7 +718,7 @@ public class Schema2XForms } } - private Element addComplexType(final Document xForm, + private Element addComplexType(final Document xformsDocument, final Element modelSection, final Element defaultInstanceElement, final Element formSection, @@ -861,13 +748,13 @@ public class Schema2XForms } // add a group node and recurse - final Element groupElement = this.createGroup(xForm, + final Element groupElement = this.createGroup(xformsDocument, modelSection, formSection, owner, resourceBundle); final SchemaUtil.Occurance o = SchemaUtil.getOccurance(owner); - final Element repeatSection = this.addRepeatIfNecessary(xForm, + final Element repeatSection = this.addRepeatIfNecessary(xformsDocument, modelSection, groupElement, controlType, @@ -883,7 +770,7 @@ public class Schema2XForms relative = true; } - this.addComplexTypeChildren(xForm, + this.addComplexTypeChildren(xformsDocument, modelSection, defaultInstanceElement, repeatSection, @@ -897,7 +784,7 @@ public class Schema2XForms return groupElement; } - private void addComplexTypeChildren(final Document xForm, + private void addComplexTypeChildren(final Document xformsDocument, Element modelSection, final Element defaultInstanceElement, final Element formSection, @@ -937,7 +824,7 @@ public class Schema2XForms { if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { - this.addSimpleType(xForm, + this.addSimpleType(xformsDocument, modelSection, formSection, schema, @@ -973,7 +860,7 @@ public class Schema2XForms } //attributes - this.addAttributeSet(xForm, + this.addAttributeSet(xformsDocument, modelSection, defaultInstanceElement, formSection, @@ -1001,7 +888,7 @@ public class Schema2XForms if (term instanceof XSModelGroup) { //call addGroup on this group - this.addGroup(xForm, + this.addGroup(xformsDocument, modelSection, defaultInstanceElement, formSection, @@ -1065,7 +952,7 @@ public class Schema2XForms modelSection, formSection, schema, - (XSComplexTypeDefinition) controlType, + (XSComplexTypeDefinition)controlType, elementDecl, pathToRoot, resourceBundle); @@ -1078,13 +965,15 @@ public class Schema2XForms } boolean relative = true; - String typeName = controlType.getName(); + final String typeName = controlType.getName(); + final boolean typeIsAbstract = ((XSComplexTypeDefinition)controlType).getAbstract(); final TreeSet compatibleTypes = - typeName != null ? this.typeTree.get(controlType.getName()) : null; + typeName != null ? this.typeTree.get(typeName) : null; if (compatibleTypes == null && typeName != null && LOGGER.isDebugEnabled()) { LOGGER.debug("No compatible type found for " + typeName); } + if (typeName != null && compatibleTypes != null) { relative = false; @@ -1097,7 +986,7 @@ public class Schema2XForms LOGGER.debug(" compatible type name=" + compType.getName()); } } - final boolean typeIsAbstract = ((XSComplexTypeDefinition)controlType).getAbstract(); + if (!typeIsAbstract && compatibleTypes.size() == 0) { relative = true; @@ -1111,7 +1000,7 @@ public class Schema2XForms } else if (typeIsAbstract && compatibleTypes.size() == 0) { - //name not null but no compatibleType? + // name not null but no compatibleType? relative = false; } else @@ -1147,7 +1036,7 @@ public class Schema2XForms // create the element and add it to the model. final Element bindElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":bind"); + NamespaceConstants.XFORMS_PREFIX + ":bind"); final String bindId = this.setXFormsId(bindElement); bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", @@ -1175,7 +1064,6 @@ public class Schema2XForms true, false, resourceBundle); - } private Element addElementWithMultipleCompatibleTypes(final Document xformsDocument, @@ -1189,12 +1077,16 @@ public class Schema2XForms final ResourceBundle resourceBundle) throws FormBuilderException { - - LOGGER.debug("&&&&&&&&&&&&&&& path to root = " + pathToRoot); // look for compatible types final XSTypeDefinition controlType = elementDecl.getTypeDefinition(); + defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, + NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":type", + controlType.getName()); + defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, + NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", + "true"); - //get possible values + //get possible values final List enumValues = new LinkedList(); //add the type (if not abstract) if (!((XSComplexTypeDefinition) controlType).getAbstract()) @@ -1205,17 +1097,7 @@ public class Schema2XForms //add compatible types enumValues.addAll(compatibleTypes); - final Element control = - xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":select1"); - final String select1Id = this.setXFormsId(control); - - final Element choices = - xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":choices"); - this.setXFormsId(choices, select1Id + "-choices"); final String caption = this.createCaption(elementDecl.getName() + " Type"); - control.appendChild(this.createLabel(xformsDocument, caption)); // multiple compatible types for this element exist // in the schema - allow the user to choose from @@ -1229,109 +1111,47 @@ public class Schema2XForms pathToRoot + "/@xsi:type"); modelSection.appendChild(bindElement); - control.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":bind", - bindId); //add the "element" bind, in addition - Element bindElement2 = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":bind"); - String bindId2 = this.setXFormsId(bindElement2); + final Element bindElement2 = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":bind"); + final String bindId2 = this.setXFormsId(bindElement2); bindElement2.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", pathToRoot); modelSection.appendChild(bindElement2); - control.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":appearance", - (enumValues.size() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)) - ? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP) - : getProperty(SELECTONE_UI_CONTROL_LONG_PROP))); - - if (enumValues.size() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) - { - // add the "Please select..." instruction item for the combobox - // and set the isValid attribute on the bind element to check for the "Please select..." - // item to indicate that is not a valid value - // - final String pleaseSelect = "[Select1 " + caption + "]"; - final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect); - choices.appendChild(item); - - // not(purchaseOrder/state = '[Choose State]') - //String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset") + " = '" + pleaseSelect + "')"; - // ->no, not(. = '[Choose State]') - final String isValidExpr = "not( . = '" + pleaseSelect + "')"; - - //check if there was a constraint - final String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint"); - bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":constraint", - (constraint != null && constraint.length() != 0 - ? constraint + " && " + isValidExpr - : isValidExpr)); - } - - control.appendChild(choices); - formSection.appendChild(control); - // add content to select1 final Map caseTypes = - this.addChoicesForSelectSwitchControl(xformsDocument, choices, enumValues); - - //add a trigger for this control (is there a way to not need it ?) - final Element dispatchTrigger = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":dispatch"); - dispatchTrigger.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":name", - "DOMActivate"); - dispatchTrigger.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":target", - select1Id); - formSection.appendChild(this.createTrigger(xformsDocument, - null, - null, - "validate choice", - dispatchTrigger)); + this.addChoicesForSelectSwitchControl(xformsDocument, formSection, enumValues, bindId); //add switch final Element switchElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":switch"); - this.setXFormsId(switchElement, select1Id + "-" + this.setXFormsId(switchElement)); + final String switchId = this.setXFormsId(switchElement); switchElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":bind", bindId); formSection.appendChild(switchElement); - //formSection.appendChild(switchElement); - /////////////// add this type ////////////// final Element firstCaseElement = caseTypes.get(controlType.getName()); switchElement.appendChild(firstCaseElement); - firstCaseElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":selected", - "true"); - - defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, - NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":type", - controlType.getName()); - defaultInstanceElement.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, - NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", - "true"); - LOGGER.debug("&&&&& die before " + XMLUtil.toString(defaultInstanceElement)); - this.addComplexType(xformsDocument, - modelSection, - defaultInstanceElement, - firstCaseElement, - schema, - (XSComplexTypeDefinition)controlType, - elementDecl, - pathToRoot, - true, - false, - resourceBundle); - LOGGER.debug("&&&&& die after " + XMLUtil.toString(defaultInstanceElement)); + final Element firstGroupElement = this.addComplexType(xformsDocument, + modelSection, + defaultInstanceElement, + firstCaseElement, + schema, + (XSComplexTypeDefinition)controlType, + elementDecl, + pathToRoot, + true, + false, + resourceBundle); + firstGroupElement.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":appearance", + ""); /////////////// add sub types ////////////// // add each compatible type within @@ -1352,27 +1172,23 @@ public class Schema2XForms continue; } - //Element caseElement = (Element) xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":case"); - //caseElement.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":id",bindId + "_" + type.getName() +"_case"); - //String case_id=this.setXFormsId(caseElement); final Element caseElement = caseTypes.get(type.getName()); - caseElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":selected", - "false"); - switchElement.appendChild(caseElement); - this.addComplexType(xformsDocument, - modelSection, - defaultInstanceElement, - caseElement, - schema, - (XSComplexTypeDefinition) type, - elementDecl, - pathToRoot, - true, - true, - resourceBundle); + final Element groupElement = this.addComplexType(xformsDocument, + modelSection, + defaultInstanceElement, + caseElement, + schema, + (XSComplexTypeDefinition) type, + elementDecl, + pathToRoot, + true, + true, + resourceBundle); + groupElement.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":appearance", + ""); // modify bind to add a "relevant" attribute that checks the value of @xsi:type if (LOGGER.isDebugEnabled()) @@ -1383,8 +1199,8 @@ public class Schema2XForms final NodeList binds = bindElement2.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); for (int i = 0; i < binds.getLength(); i++) { - Element subBind = (Element) binds.item(i); - String name = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); + final Element subBind = (Element) binds.item(i); + final String name = subBind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); if (LOGGER.isDebugEnabled()) { @@ -1427,7 +1243,7 @@ public class Schema2XForms newRelevant); } } - return control; + return switchElement; } /** @@ -1629,8 +1445,10 @@ public class Schema2XForms } } else - { //XSWildcard -> ignore ? - //LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); + { + LOGGER.warn("Unhandled term " + term + + " found in group from " + owner.getName() + + " for pathToRoot = " + pathToRoot); } } @@ -1665,7 +1483,7 @@ public class Schema2XForms final Element repeatSection = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":repeat"); + NamespaceConstants.XFORMS_PREFIX + ":repeat"); //bind instead of repeat //repeatSection.setAttributeNS(NamespaceConstants.XFORMS_NS,NamespaceConstants.XFORMS_PREFIX + ":nodeset",pathToRoot); @@ -1713,7 +1531,7 @@ public class Schema2XForms //add a group inside the repeat? final Element group = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":group"); + NamespaceConstants.XFORMS_PREFIX + ":group"); group.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", "repeated"); @@ -1887,6 +1705,7 @@ public class Schema2XForms { formControl = this.createControlForListType(xformsDocument, (XSSimpleTypeDefinition)controlType, + owner, caption, bindElement, resourceBundle); @@ -1896,6 +1715,7 @@ public class Schema2XForms { formControl = this.createControlForEnumerationType(xformsDocument, (XSSimpleTypeDefinition)controlType, + owner, caption, bindElement, resourceBundle); @@ -2040,19 +1860,22 @@ public class Schema2XForms } //model element - Element modelElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":model"); + final Element modelElement = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":model"); this.setXFormsId(modelElement); - Element modelWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":head"); + final Element modelWrapper = + xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, + NamespaceConstants.XHTML_PREFIX + ":head"); modelWrapper.appendChild(modelElement); envelopeElement.appendChild(modelWrapper); //form control wrapper -> created by wrapper //Element formWrapper = xformsDocument.createElement("body"); //envelopeElement.appendChild(formWrapper); - Element formWrapper = xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, - NamespaceConstants.XHTML_PREFIX + ":body"); + final Element formWrapper = + xformsDocument.createElementNS(NamespaceConstants.XHTML_NS, + NamespaceConstants.XHTML_PREFIX + ":body"); envelopeElement.appendChild(formWrapper); return xformsDocument; } @@ -2064,7 +1887,7 @@ public class Schema2XForms final ResourceBundle resourceBundle) { // add a group node and recurse - Element groupElement = + final Element groupElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":group"); this.setXFormsId(groupElement); @@ -2111,18 +1934,26 @@ public class Schema2XForms { // if the word is all upper case, then set to lower case and continue if (text.equals(text.toUpperCase())) + { text = text.toLowerCase(); + } final String[] s = text.split("[-_\\ ]"); final StringBuffer result = new StringBuffer(); for (int i = 0; i < s.length; i++) { if (i != 0) + { result.append(' '); + } if (s[i].length() > 1) + { result.append(Character.toUpperCase(s[i].charAt(0)) + s[i].substring(1, s[i].length())); + } else + { result.append(s[i]); + } } return result.toString(); } @@ -2169,15 +2000,23 @@ public class Schema2XForms final ResourceBundle resourceBundle) { if (element instanceof XSElementDeclaration) + { return this.createCaption((XSElementDeclaration)element, resourceBundle); + } if (element instanceof XSAttributeDeclaration) + { return this.createCaption((XSAttributeDeclaration)element, resourceBundle); + } if (element instanceof XSAttributeUse) + { return this.createCaption((XSAttributeUse)element, resourceBundle); - - LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: " - + element.getClass().getName()); - return null; + } + else + { + LOGGER.warn("WARNING: createCaption: element is not an attribute nor an element: " + + element.getClass().getName()); + return null; + } } /** @@ -2198,15 +2037,14 @@ public class Schema2XForms final String caption, final XSTypeDefinition controlType) { - Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":textarea"); + final Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":textarea"); this.setXFormsId(control); // control.setAttributeNS(Schema2XForms.CHIBA_NS, // Schema2XForms.CHIBA_PREFIX + "height", // "3"); control.appendChild(this.createLabel(xformsDocument, caption)); - return control; } @@ -2310,6 +2148,7 @@ public class Schema2XForms */ public Element createControlForEnumerationType(final Document xformsDocument, final XSSimpleTypeDefinition controlType, + final XSObject owner, final String caption, final Element bindElement, final ResourceBundle resourceBundle) @@ -2326,20 +2165,23 @@ public class Schema2XForms return null; } - Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":select1"); + final Element control = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":select1"); this.setXFormsId(control); //label control.appendChild(this.createLabel(xformsDocument, caption)); - Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":choices"); + final Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":choices"); this.setXFormsId(choices); final XSObjectList mvFacets = controlType.getMultiValueFacets(); if (mvFacets.getLength() != 1) + { throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType); + } final XSObjectList annotations = ((XSMultiValueFacet)mvFacets.item(0)).getAnnotations(); @@ -2354,43 +2196,43 @@ public class Schema2XForms : null)); } + String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI, + "appearance", + this.getAnnotation(owner), + resourceBundle); + if (appearance == null || appearance.length() == 0) + { + appearance = enumFacets.getLength() < Schema2XForms.LONG_LIST_SIZE ? "full" : "compact"; + } control.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", - (enumFacets.getLength() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP)) - ? getProperty(SELECTONE_UI_CONTROL_SHORT_PROP) - : getProperty(SELECTONE_UI_CONTROL_LONG_PROP))); + appearance); - if (enumFacets.getLength() >= Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) - { - // add the "Please select..." instruction item for the combobox - // and set the isValid attribute on the bind element to check for the "Please select..." - // item to indicate that is not a valid value - // - final String pleaseSelect = "[Select1 " + caption + "]"; - final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect); - choices.appendChild(item); - - // not(purchaseOrder/state = '[Choose State]') - //String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')"; - // ->no, not(. = '[Choose State]') - final String isValidExpr = "not( . = '" + pleaseSelect + "')"; - - //check if there was a constraint - String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint"); - - constraint = (constraint != null && constraint.length() != 0 - ? constraint + " and " + isValidExpr - : isValidExpr); - - bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":constraint", - constraint); - } + // add the "Please select..." instruction item for the combobox + // and set the isValid attribute on the bind element to check for the "Please select..." + // item to indicate that is not a valid value + final String pleaseSelect = "[Select1 " + caption + "]"; + final Element item = this.createXFormsItem(xformsDocument, pleaseSelect, pleaseSelect); + choices.appendChild(item); + + // not(purchaseOrder/state = '[Choose State]') + //String isValidExpr = "not(" + bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS,"nodeset") + " = '" + pleaseSelect + "')"; + // ->no, not(. = '[Choose State]') + final String isValidExpr = "not( . = '" + pleaseSelect + "')"; + + //check if there was a constraint + String constraint = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "constraint"); + + constraint = (constraint != null && constraint.length() != 0 + ? constraint + " and " + isValidExpr + : isValidExpr); + + bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":constraint", + constraint); control.appendChild(choices); - this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle); - return control; } @@ -2415,6 +2257,7 @@ public class Schema2XForms */ public Element createControlForListType(final Document xformsDocument, final XSSimpleTypeDefinition listType, + final XSObject owner, final String caption, final Element bindElement, final ResourceBundle resourceBundle) @@ -2423,17 +2266,19 @@ public class Schema2XForms final StringList enumFacets = controlType.getLexicalEnumeration(); if (enumFacets.getLength() <= 0) + { return null; + } Element control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":select"); this.setXFormsId(control); - control.appendChild(this.createLabel(xformsDocument, caption)); - final XSObjectList mvFacets = controlType.getMultiValueFacets(); if (mvFacets.getLength() != 1) + { throw new RuntimeException("expected exactly one MultiValueFacet for " + controlType); + } final XSObjectList annotations = ((XSMultiValueFacet)mvFacets.item(0)).getAnnotations(); @@ -2453,19 +2298,23 @@ public class Schema2XForms // Possibly look for special appInfo section in the schema and if not present default to checkBox... // // For now, use checkbox if there are < DEFAULT_LONG_LIST_MAX_SIZE items, otherwise use long control - // + String appearance = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI, + "appearance", + this.getAnnotation(owner), + resourceBundle); + if (appearance == null || appearance.length() == 0) + { + appearance = enumValues.size() < Schema2XForms.LONG_LIST_SIZE ? "full" : "compact"; + } control.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":appearance", - (enumValues.size() < Long.parseLong(getProperty(SELECTMANY_LONG_LIST_SIZE_PROP)) - ? getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP) - : getProperty(SELECTMANY_UI_CONTROL_LONG_PROP))); - Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":choices"); + appearance); + final Element choices = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":choices"); this.setXFormsId(choices); control.appendChild(choices); - this.addChoicesForSelectControl(xformsDocument, choices, enumValues, resourceBundle); - return control; } @@ -2487,13 +2336,17 @@ public class Schema2XForms { final XSAnnotation annotation = this.getAnnotation(node); if (annotation == null) + { return null; + } final String s = this.extractPropertyFromAnnotation(NamespaceService.ALFRESCO_URI, "hint", annotation, resourceBundle); if (s == null) + { return null; + } final Element hintElement = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":hint"); @@ -2615,9 +2468,11 @@ public class Schema2XForms ? minConstraint : maxConstraint)); if (constraint != null) + { bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":constraint", constraint); + } return bindElement; } @@ -2873,13 +2728,11 @@ public class Schema2XForms final Element rootGroup) { - Element submission = this.createSubmissionElement(xformsDocument, "submission-validate", true); + Element submission = + this.createSubmissionElement(xformsDocument, "submission-validate", true); modelSection.appendChild(submission); - Element submit = this.createSubmitControl(xformsDocument, - submission, - "submit", - "Submit"); + Element submit = this.createSubmitControl(xformsDocument, submission, "submit", "Submit"); rootGroup.appendChild(submit); submission = this.createSubmissionElement(xformsDocument, "submission-draft", false); @@ -2896,13 +2749,15 @@ public class Schema2XForms final String label, final String value) { - final Element item = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":item"); + final Element item = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":item"); this.setXFormsId(item); item.appendChild(this.createLabel(xformsDocument, label)); - final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":value"); + final Element e = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":value"); this.setXFormsId(e); e.appendChild(xformsDocument.createTextNode(value)); item.appendChild(e); @@ -2912,8 +2767,9 @@ public class Schema2XForms private Element createLabel(final Document xformsDocument, final String label) { - final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":label"); + final Element e = + xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":label"); this.setXFormsId(e); e.appendChild(xformsDocument.createTextNode(label)); return e; diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index 60f917a255..96bfd20af4 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -660,12 +660,13 @@ public class XFormsBean private static void rewriteInlineURIs(final Document schemaDocument, final String cwdAvmPath) { - final NodeList includes = - schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include"); - LOGGER.debug("rewriting " + includes.getLength() + " includes"); - for (int i = 0; i < includes.getLength(); i++) + final NodeList nl = + XMLUtil.combine(schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "include"), + schemaDocument.getElementsByTagNameNS(NamespaceConstants.XMLSCHEMA_NS, "import")); + LOGGER.debug("rewriting " + nl.getLength() + " includes"); + for (int i = 0; i < nl.getLength(); i++) { - final Element includeEl = (Element)includes.item(i); + final Element includeEl = (Element)nl.item(i); if (includeEl.hasAttribute("schemaLocation")) { String uri = includeEl.getAttribute("schemaLocation"); diff --git a/source/test-resources/xforms/customer-tests/berekely-grants-RR_SF424-V1.1.xsd b/source/test-resources/xforms/customer-tests/berekely-grants-RR_SF424-V1.1.xsd new file mode 100644 index 0000000000..571cb9b0d8 --- /dev/null +++ b/source/test-resources/xforms/customer-tests/berekely-grants-RR_SF424-V1.1.xsd @@ -0,0 +1,294 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/simple-test/list-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/list-test.xsd new file mode 100644 index 0000000000..f77efbb4ea --- /dev/null +++ b/source/test-resources/xforms/unit-tests/simple-test/list-test.xsd @@ -0,0 +1,214 @@ + + + + + + + + + + Teddy Roosevelt + + + + + + + + + + + + + new hampshire + + + + + new york + + + + + + rhode island + + + + + new jersey + + + + + + + + + north carolina + + + + + south carolina + + + + + + + + + + + + + + + + + + + + + full + + + + + + + compact + + + + + + + + + + + + + + full + + + + + + + compact + + + + + + + + + + + + + + + + + + + + full + + + + + + + compact + + + + + + + + + + + + + + full + + + + + + + compact + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test-other.xsd b/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test-other.xsd new file mode 100644 index 0000000000..235cb2b282 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test-other.xsd @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test.xsd b/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test.xsd new file mode 100644 index 0000000000..733ee46081 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/xml-namespaces-test/multi-namespace-test.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/source/web/jsp/wcm/create-web-content-wizard/details.jsp b/source/web/jsp/wcm/create-web-content-wizard/details.jsp index 2af8307fa3..8119344a61 100644 --- a/source/web/jsp/wcm/create-web-content-wizard/details.jsp +++ b/source/web/jsp/wcm/create-web-content-wizard/details.jsp @@ -94,7 +94,12 @@ - + + diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index 80ea061780..bd22450475 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -457,6 +457,14 @@ dojo.declare("alfresco.xforms.Widget", } }, + /** Returns the value of the appearance attribute for widget */ + getAppearance: function() + { + var result = (this.xformsNode.getAttribute("appearance") || + this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":appearance")); + return result == null || result.length == 0 ? null : result; + }, + /** Updates the display of the widget. This is intended to be overridden. */ _updateDisplay: function() { @@ -520,10 +528,10 @@ dojo.declare("alfresco.xforms.Widget", /** The file picker widget which handles xforms widget xf:upload. */ dojo.declare("alfresco.xforms.FilePicker", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -583,10 +591,10 @@ dojo.declare("alfresco.xforms.FilePicker", /** The textfield widget which handle xforms widget xf:input with any string or numerical type */ dojo.declare("alfresco.xforms.TextField", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -737,11 +745,11 @@ dojo.declare("alfresco.xforms.NumericalRange", /** The textfield widget which handle xforms widget xf:textarea. */ dojo.declare("alfresco.xforms.TextArea", alfresco.xforms.Widget, + function(xform, xformsNode) + { + this.focused = false; + }, { - initializer: function(xform, xformsNode) - { - this.focused = false; - }, ///////////////////////////////////////////////////////////////// // methods @@ -952,7 +960,7 @@ dojo.declare("alfresco.xforms.Select", var initial_value = this.getInitialValue(); initial_value = initial_value ? initial_value.split(' ') : []; this._selectedValues = []; - if (values.length <= 5) + if (this.getAppearance() == "full") { this.widget = document.createElement("div"); this.widget.style.width = "100%"; @@ -1051,7 +1059,7 @@ dojo.declare("alfresco.xforms.Select", { if (event.target.options[i].selected) { - this._selectedValues.push(event.target.options[i].value); + this._selectedValues.push(event.target.options[i].getAttribute("value")); } } this._commitValueChange(); @@ -1060,12 +1068,12 @@ dojo.declare("alfresco.xforms.Select", _checkbox_clickHandler: function(event) { this._selectedValues = []; - for (var i = 0; i < 5; i++) + var all_checkboxes = this.widget.getElementsByTagName("input"); + for (var i = 0; i < all_checkboxes.length; i++) { - var checkbox = document.getElementById(this.id + "_" + i + "-widget"); - if (checkbox && checkbox.checked) + if (all_checkboxes[i] && all_checkboxes[i].checked) { - this._selectedValues.push(checkbox.value); + this._selectedValues.push(all_checkboxes[i].getAttribute("value")); } } this._commitValueChange(); @@ -1090,13 +1098,19 @@ dojo.declare("alfresco.xforms.Select1", { var values = this._getItemValues(); var initial_value = this.getInitialValue(); - if (values.length <= 5) + if (this.getAppearance() == "full") { this.widget = document.createElement("div"); this.widget.style.width = "100%"; attach_point.appendChild(this.widget); for (var i = 0; i < values.length; i++) { + if (!values[i].valid) + { + // always skip the invalid values for radios + continue; + } + var radio_div = document.createElement("div"); radio_div.style.lineHeight = "16px"; this.widget.appendChild(radio_div); @@ -1273,10 +1287,10 @@ dojo.declare("alfresco.xforms.Checkbox", /** The date picker widget which handles xforms widget xf:input with type xf:date */ dojo.declare("alfresco.xforms.DatePicker", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1363,10 +1377,10 @@ dojo.declare("alfresco.xforms.DatePicker", /** The date picker widget which handles xforms widget xf:input with type xf:date */ dojo.declare("alfresco.xforms.TimePicker", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1438,10 +1452,10 @@ dojo.declare("alfresco.xforms.TimePicker", /** The year picker handles xforms widget xf:input with a gYear type */ dojo.declare("alfresco.xforms.YearPicker", alfresco.xforms.TextField, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1479,10 +1493,10 @@ dojo.declare("alfresco.xforms.YearPicker", /** The day picker widget which handles xforms widget xf:input with type xf:gDay */ dojo.declare("alfresco.xforms.DayPicker", alfresco.xforms.Select1, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1506,10 +1520,10 @@ dojo.declare("alfresco.xforms.DayPicker", /** The month picker widget which handles xforms widget xf:input with type xf:gMonth */ dojo.declare("alfresco.xforms.MonthPicker", alfresco.xforms.Select1, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1535,15 +1549,15 @@ dojo.declare("alfresco.xforms.MonthPicker", /** The month day picker widget which handles xforms widget xf:input with type xf:gMonthDay */ dojo.declare("alfresco.xforms.MonthDayPicker", alfresco.xforms.Widget, + function(xform, xformsNode) + { + this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode); + this.monthPicker._compositeParent = this; + + this.dayPicker = new alfresco.xforms.DayPicker(xform, xformsNode); + this.dayPicker._compositeParent = this; + }, { - initializer: function(xform, xformsNode) - { - this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode); - this.monthPicker._compositeParent = this; - - this.dayPicker = new alfresco.xforms.DayPicker(xform, xformsNode); - this.dayPicker._compositeParent = this; - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1575,15 +1589,15 @@ dojo.declare("alfresco.xforms.MonthDayPicker", /** The year month picker widget which handles xforms widget xf:input with type xf:gYearMonth */ dojo.declare("alfresco.xforms.YearMonthPicker", alfresco.xforms.Widget, + function(xform, xformsNode) + { + this.yearPicker = new alfresco.xforms.YearPicker(xform, xformsNode); + this.yearPicker._compositeParent = this; + + this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode); + this.monthPicker._compositeParent = this; + }, { - initializer: function(xform, xformsNode) - { - this.yearPicker = new alfresco.xforms.YearPicker(xform, xformsNode); - this.yearPicker._compositeParent = this; - - this.monthPicker = new alfresco.xforms.MonthPicker(xform, xformsNode); - this.monthPicker._compositeParent = this; - }, ///////////////////////////////////////////////////////////////// // overridden methods @@ -1625,23 +1639,17 @@ dojo.declare("alfresco.xforms.YearMonthPicker", */ dojo.declare("alfresco.xforms.Group", alfresco.xforms.Widget, + function(xform, xformsNode) + { + this._children = []; + dojo.html.removeClass(this.domNode, "xformsItem"); + }, { - initializer: function(xform, xformsNode) - { - this._children = []; - dojo.html.removeClass(this.domNode, "xformsItem"); - }, - ///////////////////////////////////////////////////////////////// // methods & properties ///////////////////////////////////////////////////////////////// - /** Returns the value of the appearance attribute for widget */ - getAppearance: function() - { - return (this.xformsNode.getAttribute("appearance") || - this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":appearance")); - }, + _groupHeaderNode: null, /** Returns the child at the specified index or null if the index is out of range. */ getChildAt: function(index) @@ -1704,11 +1712,38 @@ dojo.declare("alfresco.xforms.Group", this._children.splice(position, 0, child); } - if (this.getAppearance() == "full" && - !(this instanceof alfresco.xforms.Repeat) && - child.isVisible() && - ((child instanceof alfresco.xforms.Group && position != 0) || - this._children[position - 1] instanceof alfresco.xforms.Group)) + function shouldInsertDivider(group, child, position) + { + if (group.getAppearance() != "full") + { + return false; + } + if (group instanceof alfresco.xforms.Repeat) + { + return false; + } + if (!child.isVisible()) + { + return false; + } + if (group._children[position - 1] instanceof alfresco.xforms.Group) + { + return true; + } + if (child instanceof alfresco.xforms.Group) + { + for (var i = position - 1; i > 0; i--) + { + if (group._children[i].isVisible()) + { + return true; + } + } + } + return false; + } + + if (shouldInsertDivider(this, child, position)) { var divider = document.createElement("div"); dojo.html.setClass(divider, "xformsGroupDivider"); @@ -1898,13 +1933,13 @@ dojo.declare("alfresco.xforms.Group", attach_point.offsetWidth)) * 100 + "%"; } - this.groupHeaderNode = document.createElement("div"); - this.groupHeaderNode.id = this.id + "-groupHeaderNode"; - dojo.html.setClass(this.groupHeaderNode, "xformsGroupHeader"); - this.domNode.appendChild(this.groupHeaderNode); + this._groupHeaderNode = document.createElement("div"); + this._groupHeaderNode.setAttribute("id", this.id + "-groupHeaderNode"); + dojo.html.setClass(this._groupHeaderNode, "xformsGroupHeader"); + this.domNode.appendChild(this._groupHeaderNode); this.toggleExpandedImage = document.createElement("img"); - this.groupHeaderNode.appendChild(this.toggleExpandedImage); + this._groupHeaderNode.appendChild(this.toggleExpandedImage); this.toggleExpandedImage.setAttribute("src", alfresco_xforms_constants.EXPANDED_IMAGE.src); this.toggleExpandedImage.align = "absmiddle"; this.toggleExpandedImage.style.marginLeft = "5px"; @@ -1915,7 +1950,7 @@ dojo.declare("alfresco.xforms.Group", this, this._toggleExpanded_clickHandler); - this.groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); + this._groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); } attach_point.appendChild(this.domNode); @@ -2037,17 +2072,86 @@ dojo.declare("alfresco.xforms.SwitchGroup", alfresco.xforms.Group, function(xform, xformsNode) { - this.selectedCaseId = null; - var widgets = this.xform.getBinding(this.xformsNode).widgets; - for (var i in widgets) + if (this.getInitialValue()) { - if (widgets[i] instanceof alfresco.xforms.Select1) - { - widgets[i].setValue(this.getInitialValue(), "true"); - } + var initialValueTrigger = this._getCaseToggleTriggerByTypeValue(this.getInitialValue()); + this._selectedCaseId = initialValueTrigger.getActions()["toggle"].properties["case"]; } }, { + ///////////////////////////////////////////////////////////////// + // methods & properties + ///////////////////////////////////////////////////////////////// + _getCaseToggleTriggers: function() + { + var bw = this.xform.getBinding(this.xformsNode).widgets; + var result = []; + for (var i in bw) + { + if (! (bw[i] instanceof alfresco.xforms.Trigger)) + { + continue; + } + + var action = bw[i].getActions()["toggle"]; + if (action) + { + result.push(bw[i]); + } + } + return result; + }, + + _getCaseToggleTriggerByCaseId: function(caseId) + { + var bw = this.xform.getBinding(this.xformsNode).widgets; + for (var i in bw) + { + if (! (bw[i] instanceof alfresco.xforms.Trigger)) + { + continue; + } + + var action = bw[i].getActions()["toggle"]; + if (!action) + { + continue; + } + if (action.properties["case"] == caseId) + { + return bw[i]; + } + } + throw new Error("unable to find trigger " + type + + ", properties " + properties + + " for " + this.id); + + }, + + _getCaseToggleTriggerByTypeValue: function(typeValue) + { + var bw = this.xform.getBinding(this.xformsNode).widgets; + for (var i in bw) + { + if (! (bw[i] instanceof alfresco.xforms.Trigger)) + { + continue; + } + + var action = bw[i].getActions()["setvalue"]; + if (!action) + { + continue; + } + if (action.properties["value"] == typeValue) + { + return bw[i]; + } + } + throw new Error("unable to find toggle trigger for type value " + typeValue + + " for " + this.id); + }, + ///////////////////////////////////////////////////////////////// // overridden methods & properties ///////////////////////////////////////////////////////////////// @@ -2057,15 +2161,43 @@ dojo.declare("alfresco.xforms.SwitchGroup", { var childDomContainer = alfresco.xforms.SwitchGroup.superclass._insertChildAt.call(this, child, position); - this.selectedCaseId = this.selectedCaseId || child.id; - if (this.selectedCaseId != child.id) + if (child.id == this._selectedCaseId) + { + this._getCaseToggleTriggerByCaseId(this._selectedCaseId).fire(); + } + else { childDomContainer.style.display = "none"; } return childDomContainer; }, - + render: function(attach_point) + { + alfresco.xforms.SwitchGroup.superclass.render.call(this, attach_point); + this._groupHeaderNode = document.createElement("div"); + this._groupHeaderNode.setAttribute("id", this.id + "-groupHeaderNode"); + this.domNode.appendChild(this._groupHeaderNode); + this._groupHeaderNode.style.backgroundColor = "orange"; + var cases = this._getCaseToggleTriggers(); + for (var i = 0; i < cases.length; i++) + { + var d = document.createElement("div"); + this._groupHeaderNode.appendChild(d); + var link = document.createElement("a"); + link.setAttribute("id", cases[i].id); + link.trigger = cases[i]; + link.appendChild(document.createTextNode(cases[i].getLabel())); + d.appendChild(link); + dojo.event.browser.addListener(link, + "onclick", + function(event) + { + event.target.trigger.fire(); + }); + } + }, + ///////////////////////////////////////////////////////////////// // XForms event handlers ///////////////////////////////////////////////////////////////// @@ -2091,6 +2223,15 @@ dojo.declare("alfresco.xforms.SwitchGroup", } }); +/** */ +dojo.declare("alfresco.xforms.CaseGroup", + alfresco.xforms.Group, + function(xform, xformsNode) + { + }, + { + }); + /** * Handles xforms widget xf:group for the root group. Does some special rendering * to present a title rather than a group header. @@ -2109,18 +2250,18 @@ dojo.declare("alfresco.xforms.ViewRoot", this.domNode.style.width = "100%"; dojo.html.setClass(this.domNode, "xformsViewRoot"); - this.groupHeaderNode = document.createElement("div"); - this.groupHeaderNode.id = this.id + "-groupHeaderNode"; - dojo.html.setClass(this.groupHeaderNode, "xformsViewRootHeader"); - this.domNode.appendChild(this.groupHeaderNode); + this._groupHeaderNode = document.createElement("div"); + this._groupHeaderNode.id = this.id + "-groupHeaderNode"; + dojo.html.setClass(this._groupHeaderNode, "xformsViewRootHeader"); + this.domNode.appendChild(this._groupHeaderNode); var icon = document.createElement("img"); - this.groupHeaderNode.appendChild(icon); + this._groupHeaderNode.appendChild(icon); icon.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/file_large.gif"); icon.align = "absmiddle"; icon.style.marginLeft = "5px"; icon.style.marginRight = "5px"; - this.groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); + this._groupHeaderNode.appendChild(document.createTextNode(this.getLabel())); attach_point.appendChild(this.domNode); this.domNode.childContainerNode = document.createElement("div"); @@ -2211,8 +2352,8 @@ dojo.declare("alfresco.xforms.Repeat", continue; } - var action = bw[i].getAction(); - if (action.getType() != type) + var action = bw[i].getActions()[type]; + if (!action) { continue; } @@ -2432,10 +2573,10 @@ dojo.declare("alfresco.xforms.Repeat", // clear the border bottom for the group header since we'll be getting it // from the repeat item border - this.groupHeaderNode.style.borderBottomWidth = "0px"; + this._groupHeaderNode.style.borderBottomWidth = "0px"; - this.groupHeaderNode.repeat = this; - dojo.event.connect(this.groupHeaderNode, "onclick", function(event) + this._groupHeaderNode.repeat = this; + dojo.event.connect(this._groupHeaderNode, "onclick", function(event) { if (event.target == event.currentTarget) { @@ -2445,7 +2586,7 @@ dojo.declare("alfresco.xforms.Repeat", this.headerInsertRepeatItemImage = document.createElement("img"); this.headerInsertRepeatItemImage.repeat = this; - this.groupHeaderNode.appendChild(this.headerInsertRepeatItemImage); + this._groupHeaderNode.appendChild(this.headerInsertRepeatItemImage); this.headerInsertRepeatItemImage.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/plus.gif"); @@ -2469,14 +2610,14 @@ dojo.declare("alfresco.xforms.Repeat", (this.getViewRoot().focusedRepeat == this || this.getViewRoot().focusedRepeat.isAncestorOf(this))) { - if (!dojo.html.hasClass(this.groupHeaderNode, "xformsRepeatFocusedHeader")) + if (!dojo.html.hasClass(this._groupHeaderNode, "xformsRepeatFocusedHeader")) { - dojo.html.addClass(this.groupHeaderNode, "xformsRepeatFocusedHeader"); + dojo.html.addClass(this._groupHeaderNode, "xformsRepeatFocusedHeader"); } } - else if (dojo.html.hasClass(this.groupHeaderNode, "xformsRepeatFocusedHeader")) + else if (dojo.html.hasClass(this._groupHeaderNode, "xformsRepeatFocusedHeader")) { - dojo.html.removeClass(this.groupHeaderNode, "xformsRepeatFocusedHeader"); + dojo.html.removeClass(this._groupHeaderNode, "xformsRepeatFocusedHeader"); } for (var i = 0; i < this._children.length; i++) @@ -2533,7 +2674,7 @@ dojo.declare("alfresco.xforms.Repeat", var repeatItem = repeat.getChildAt(index); this.setFocusedChild(repeatItem); var trigger = this._getRepeatItemTrigger("insert", { position: "after" }); - this.xform.fireAction(trigger.id); + trigger.fire(); } }, @@ -2551,7 +2692,7 @@ dojo.declare("alfresco.xforms.Repeat", { this.setFocusedChild(null); var trigger = this._getRepeatItemTrigger("insert", { position: "before" }); - this.xform.fireAction(trigger.id); + trigger.fire(); } } }, @@ -2570,7 +2711,7 @@ dojo.declare("alfresco.xforms.Repeat", var repeatItem = repeat.getChildAt(index); this.setFocusedChild(repeatItem); var trigger = this._getRepeatItemTrigger("delete", {}); - this.xform.fireAction(trigger.id); + trigger.fire(); } }, @@ -2666,24 +2807,44 @@ dojo.declare("alfresco.xforms.Repeat", */ dojo.declare("alfresco.xforms.Trigger", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, ///////////////////////////////////////////////////////////////// // methods & properties ///////////////////////////////////////////////////////////////// /** TODO: DOCUMENT */ - getAction: function() + getActions: function() { - var action = _getElementsByTagNameNS(this.xformsNode, - alfresco_xforms_constants.XFORMS_NS, - alfresco_xforms_constants.XFORMS_PREFIX, - "action")[0]; - return new alfresco.xforms.XFormsAction(this.xform, dojo.dom.firstElement(action)); - }, + if (typeof this._actions == "undefined") + { + var actionNode = _getElementsByTagNameNS(this.xformsNode, + alfresco_xforms_constants.XFORMS_NS, + alfresco_xforms_constants.XFORMS_PREFIX, + "action")[0]; + this._actions = {}; + for (var i = 0; i < actionNode.childNodes.length; i++) + { + if (actionNode.childNodes[i].nodeType != dojo.dom.ELEMENT_NODE) + { + continue; + } + var a = new alfresco.xforms.XFormsAction(this.xform, actionNode.childNodes[i]); + this._actions[a.getType()] = a; + } + } + return this._actions; + }, + + /** fires the xforms action associated with the trigger */ + fire: function() + { + this.xform.fireAction(this.id); + }, + ///////////////////////////////////////////////////////////////// // overridden methods ///////////////////////////////////////////////////////////////// @@ -2717,7 +2878,7 @@ dojo.declare("alfresco.xforms.Trigger", ///////////////////////////////////////////////////////////////// _clickHandler: function(event) { - this.xform.fireAction(this.id); + this.fire(); } }); @@ -2726,53 +2887,53 @@ dojo.declare("alfresco.xforms.Trigger", */ dojo.declare("alfresco.xforms.Submit", alfresco.xforms.Trigger, + function(xform, xformsNode) { - initializer: function(xform, xformsNode) + var submit_buttons = (this.id == "submit" + ? _xforms_getSubmitButtons() + : (this.id == "save-draft" + ? _xforms_getSaveDraftButtons() + : null)); + if (submit_buttons == null) { - var submit_buttons = (this.id == "submit" - ? _xforms_getSubmitButtons() - : (this.id == "save-draft" - ? _xforms_getSaveDraftButtons() - : null)); - if (submit_buttons == null) - { - throw new Error("unknown submit button " + this.id); - } - for (var i = 0; i < submit_buttons.length; i++) - { - dojo.debug("adding submit handler for " + submit_buttons[i].getAttribute('id')); - submit_buttons[i].widget = this; - dojo.event.browser.addListener(submit_buttons[i], - "onclick", - function(event) + throw new Error("unknown submit button " + this.id); + } + for (var i = 0; i < submit_buttons.length; i++) + { + dojo.debug("adding submit handler for " + submit_buttons[i].getAttribute('id')); + submit_buttons[i].widget = this; + dojo.event.browser.addListener(submit_buttons[i], + "onclick", + function(event) + { + if (!event.target.widget) { - if (!event.target.widget) - { - return true; - } - - var xform = event.target.widget.xform; - if (xform.submitWidget && xform.submitWidget.done) - { - dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id); - xform.submitWidget.currentButton = null; - xform.submitWidget = null; - return true; - } - else - { - dojo.debug("triggering submit from handler " + event.target.id); - dojo.event.browser.stopEvent(event); - _hide_errors(); - xform.submitWidget = event.target.widget; - xform.submitWidget.currentButton = event.target; - xform.submitWidget.widget.buttonClick(); - return false; - } - }, - false); - } - }, + return true; + } + + var xform = event.target.widget.xform; + if (xform.submitWidget && xform.submitWidget.done) + { + dojo.debug("done - doing base click on " + xform.submitWidget.currentButton.id); + xform.submitWidget.currentButton = null; + xform.submitWidget = null; + return true; + } + else + { + dojo.debug("triggering submit from handler " + event.target.id); + dojo.event.browser.stopEvent(event); + _hide_errors(); + xform.submitWidget = event.target.widget; + xform.submitWidget.currentButton = event.target; + xform.submitWidget.widget.buttonClick(); + return false; + } + }, + false); + } + }, + { ///////////////////////////////////////////////////////////////// // DOM event handlers @@ -2782,7 +2943,7 @@ dojo.declare("alfresco.xforms.Submit", { this.done = false; _hide_errors(); - this.xform.fireAction(this.id); + this.fire(); } }); @@ -2791,24 +2952,27 @@ dojo.declare("alfresco.xforms.Submit", */ dojo.declare("alfresco.xforms.XFormsAction", null, + function(xform, xformsNode) { - initializer: function(xform, xformsNode) + this.xform = xform; + this.xformsNode = xformsNode; + /** All properties of the action as map of key value pairs */ + this.properties = []; + for (var i = 0; i < this.xformsNode.attributes.length; i++) { - this.xform = xform; - this.xformsNode = xformsNode; - /** All properties of the action as map of key value pairs */ - this.properties = []; - for (var i = 0; i < this.xformsNode.attributes.length; i++) + var attr = this.xformsNode.attributes[i]; + if (attr.nodeName.match(new RegExp("^" + alfresco_xforms_constants.XFORMS_PREFIX + ":"))) { - var attr = this.xformsNode.attributes[i]; - if (attr.nodeName.match(new RegExp("^" + alfresco_xforms_constants.XFORMS_PREFIX + ":"))) - { - this.properties[attr.nodeName.substring((alfresco_xforms_constants.XFORMS_PREFIX + ":").length)] = - attr.nodeValue; - } + this.properties[attr.nodeName.substring((alfresco_xforms_constants.XFORMS_PREFIX + ":").length)] = + attr.nodeValue; } - }, - + } + if (this.getType() == "setvalue" && !this.properties["value"]) + { + this.properties["value"] = this.xformsNode.firstChild.nodeValue; + } + }, + { /** Returns the action type. */ getType: function() { @@ -2826,20 +2990,22 @@ dojo.declare("alfresco.xforms.XFormsAction", */ dojo.declare("alfresco.xforms.XFormsEvent", null, + function(node) { - initializer: function(node) + this.type = node.nodeName; + this.targetId = node.getAttribute("targetId"); + this.targetName = node.getAttribute("targetName"); + this.properties = {}; + for (var i = 0; i < node.childNodes.length; i++) { - this.type = node.nodeName; - this.targetId = node.getAttribute("targetId"); - this.targetName = node.getAttribute("targetName"); - this.properties = {}; - for (var i = 0; i < node.childNodes.length; i++) + if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) { - if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) - this.properties[node.childNodes[i].getAttribute("name")] = - node.childNodes[i].getAttribute("value"); + this.properties[node.childNodes[i].getAttribute("name")] = + node.childNodes[i].getAttribute("value"); } - }, + } + }, + { /** Returns the widget managing the specified target id. */ getTarget: function() { @@ -2857,35 +3023,34 @@ dojo.declare("alfresco.xforms.XFormsEvent", */ dojo.declare("alfresco.xforms.Binding", null, + function(xformsNode, parent) + { + this.xformsNode = xformsNode; + this.id = this.xformsNode.getAttribute("id"); + this.nodeset = this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":nodeset"); + this._readonly = + (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") + ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") == "true()" + : null); + this._required = + (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":required") + ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":required") == "true()" + : null); + + this._type = + (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":type") + ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":type") + : null); + this.constraint = + (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":constraint") + ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":constraint") + : null); + this.maximum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":maximum")); + this.minimum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":minimum")); + this.parent = parent; + this.widgets = {}; + }, { - initializer: function(xformsNode, parent) - { - this.xformsNode = xformsNode; - this.id = this.xformsNode.getAttribute("id"); - this.nodeset = this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":nodeset"); - this._readonly = - (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") - ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":readonly") == "true()" - : null); - this._required = - (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":required") - ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":required") == "true()" - : null); - - this._type = - (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":type") - ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":type") - : null); - this.constraint = - (_hasAttribute(this.xformsNode, alfresco_xforms_constants.XFORMS_PREFIX + ":constraint") - ? this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":constraint") - : null); - this.maximum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":maximum")); - this.minimum = parseInt(this.xformsNode.getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + ":minimum")); - this.parent = parent; - this.widgets = {}; - }, - /** Returns the expected schema type for this binding. */ getType: function() { @@ -2923,24 +3088,23 @@ dojo.declare("alfresco.xforms.Binding", */ dojo.declare("alfresco.xforms.XForm", null, + /** Makes a request to the XFormsBean to load the xforms document. */ + function() + { + var req = AjaxHelper.createRequest(this, + "getXForm", + {}, + function(type, data, evt) + { + this.target._loadHandler(data); + }); + AjaxHelper.sendRequest(req); + }, { ///////////////////////////////////////////////////////////////// // Initialization ///////////////////////////////////////////////////////////////// - /** Makes a request to the XFormsBean to load the xforms document. */ - initializer: function() - { - var req = AjaxHelper.createRequest(this, - "getXForm", - {}, - function(type, data, evt) - { - this.target._loadHandler(data); - }); - AjaxHelper.sendRequest(req); - }, - /** Parses the xforms document and produces the widget tree. */ _loadHandler: function(xformDocument) { @@ -3074,8 +3238,7 @@ dojo.declare("alfresco.xforms.XForm", case alfresco_xforms_constants.XFORMS_PREFIX + ":switch": return new alfresco.xforms.SwitchGroup(this, xformsNode); case alfresco_xforms_constants.XFORMS_PREFIX + ":case": - return new alfresco.xforms.Group(this, xformsNode); - + return new alfresco.xforms.CaseGroup(this, xformsNode); default: throw new Error("unknown type " + xformsNode.nodeName); } @@ -3086,26 +3249,27 @@ dojo.declare("alfresco.xforms.XForm", { for (var i = 0; i < xformsNode.childNodes.length; i++) { - if (xformsNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) + if (xformsNode.childNodes[i].nodeType != dojo.dom.ELEMENT_NODE) { - dojo.debug("loading " + xformsNode.childNodes[i].nodeName + - " into " + parentWidget.id); - if (xformsNode.childNodes[i].getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + - ":prototype") == "true") + continue; + } + dojo.debug("loading " + xformsNode.childNodes[i].nodeName + + " into " + parentWidget.id); + if (xformsNode.childNodes[i].getAttribute(alfresco_xforms_constants.ALFRESCO_PREFIX + + ":prototype") == "true") + { + dojo.debug(xformsNode.childNodes[i].getAttribute("id") + + " is a prototype, ignoring"); + continue; + } + var w = this.createWidget(xformsNode.childNodes[i]); + if (w != null) + { + dojo.debug("created " + w.id + " for " + xformsNode.childNodes[i].nodeName); + parentWidget.addChild(w); + if (w instanceof alfresco.xforms.Group) { - dojo.debug(xformsNode.childNodes[i].getAttribute("id") + - " is a prototype, ignoring"); - continue; - } - var w = this.createWidget(xformsNode.childNodes[i]); - if (w != null) - { - dojo.debug("created " + w.id + " for " + xformsNode.childNodes[i].nodeName); - parentWidget.addChild(w); - if (w instanceof alfresco.xforms.Group) - { - this.loadWidgets(xformsNode.childNodes[i], w); - } + this.loadWidgets(xformsNode.childNodes[i], w); } } }