diff --git a/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java b/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java index 5ff9df5f11..b9d596c1a1 100644 --- a/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java +++ b/source/java/org/alfresco/web/bean/wcm/CreateFormWizard.java @@ -46,6 +46,7 @@ import org.alfresco.web.data.IDataContainer; import org.alfresco.web.data.QuickSort; import org.alfresco.web.forms.*; import org.alfresco.web.forms.xforms.SchemaFormBuilder; +import org.alfresco.web.ui.common.Utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xerces.xs.*; @@ -126,6 +127,7 @@ public class CreateFormWizard extends BaseWizardBean private String schemaRootElementName; private String formName; + private String formTitle; private String formDescription; private Class renderingEngineType = null; protected ContentService contentService; @@ -172,7 +174,7 @@ public class CreateFormWizard extends BaseWizardBean // apply the titled aspect - title and description Map props = new HashMap(2, 1.0f); - props.put(ContentModel.PROP_TITLE, this.getFormName()); + props.put(ContentModel.PROP_TITLE, this.getFormTitle()); props.put(ContentModel.PROP_DESCRIPTION, this.getFormDescription()); this.nodeService.addAspect(schemaNodeRef, ContentModel.ASPECT_TITLED, props); @@ -228,6 +230,7 @@ public class CreateFormWizard extends BaseWizardBean this.removeUploadedRenderingEngineFile(); this.schemaRootElementName = null; this.formName = null; + this.formTitle = null; this.formDescription = null; this.renderingEngineType = null; this.renderingEngines = new ArrayList(); @@ -575,9 +578,9 @@ public class CreateFormWizard extends BaseWizardBean final List result = new LinkedList(); if (this.getSchemaFile() != null) { + final FormsService ts = FormsService.getInstance(); try { - final FormsService ts = FormsService.getInstance(); final Document d = ts.parseXML(this.getSchemaFile()); final XSModel xsm = SchemaFormBuilder.loadSchema(d); final XSNamedMap elementsMap = xsm.getComponents(XSConstants.ELEMENT_DECLARATION); @@ -591,6 +594,7 @@ public class CreateFormWizard extends BaseWizardBean { final String msg = "unable to parse " + this.getSchemaFileName(); this.removeUploadedSchemaFile(); + Utils.addErrorMessage(msg, e); throw new AlfrescoRuntimeException(msg, e); } } @@ -615,6 +619,24 @@ public class CreateFormWizard extends BaseWizardBean : this.formName); } + /** + * Sets the title for this form. + */ + public void setFormTitle(final String formTitle) + { + this.formTitle = formTitle; + } + + /** + * @return the title for this form. + */ + public String getFormTitle() + { + return (this.formTitle == null && this.getSchemaFileName() != null + ? this.getSchemaFileName().replaceAll("(.+)\\..*", "$1") + : this.formTitle); + } + /** * Sets the description for this form. */ diff --git a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java index 5adbaa8ce7..5dadbc5069 100644 --- a/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java +++ b/source/java/org/alfresco/web/forms/xforms/SchemaFormBuilder.java @@ -1049,7 +1049,8 @@ public class SchemaFormBuilder //(modelSection is the enclosing bind of the element) final NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); String bindId = null; - for (int j = 0; j < binds.getLength() && bindId == null; j++) { + for (int j = 0; j < binds.getLength() && bindId == null; j++) + { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null) @@ -1073,7 +1074,7 @@ public class SchemaFormBuilder context.getPointer("//*[@" + SchemaFormBuilder.XFORMS_NS_PREFIX + "bind='" + bindId + "']"); if (pointer != null) - control = (Element) pointer.getNode(); + control = (Element)pointer.getNode(); } //copy it @@ -1087,7 +1088,6 @@ public class SchemaFormBuilder formSection.appendChild(newControl); } - } else { @@ -1423,8 +1423,6 @@ public class SchemaFormBuilder { final TreeSet compatibleTypes = this.typeTree.get(controlType.getName()); - //TreeSet compatibleTypes = (TreeSet) typeTree.get(controlType); - if (compatibleTypes == null) { if (LOGGER.isDebugEnabled()) @@ -1434,7 +1432,7 @@ public class SchemaFormBuilder { relative = false; - if (true || LOGGER.isDebugEnabled()) + if (LOGGER.isDebugEnabled()) { LOGGER.debug("compatible types for " + typeName + ":"); for (XSTypeDefinition compType : compatibleTypes) @@ -1843,7 +1841,9 @@ public class SchemaFormBuilder return found; } - private boolean doesElementComeFromExtension(XSElementDeclaration element, XSComplexTypeDefinition controlType) { + private boolean doesElementComeFromExtension(XSElementDeclaration element, + XSComplexTypeDefinition controlType) + { if (LOGGER.isDebugEnabled()) LOGGER.debug("doesElementComeFromExtension for " + element.getName() + " and controlType=" + controlType.getName()); boolean comesFromExtension = false; @@ -1868,7 +1868,8 @@ public class SchemaFormBuilder /** * check that the element defined by this name is declared directly in the type */ - private boolean isAttributeDeclaredIn(XSAttributeUse attr, XSComplexTypeDefinition type, boolean recursive) { + private boolean isAttributeDeclaredIn(XSAttributeUse attr, XSComplexTypeDefinition type, boolean recursive) + { boolean found = false; if (LOGGER.isDebugEnabled()) @@ -1912,7 +1913,8 @@ public class SchemaFormBuilder * check that the element defined by this name is declared directly in the type * -> idem with string */ - private boolean isAttributeDeclaredIn(String attrName, XSComplexTypeDefinition type, boolean recursive) { + private boolean isAttributeDeclaredIn(String attrName, XSComplexTypeDefinition type, boolean recursive) + { boolean found = false; if (LOGGER.isDebugEnabled()) @@ -1960,9 +1962,11 @@ public class SchemaFormBuilder return found; } - private boolean doesAttributeComeFromExtension(XSAttributeUse attr, XSComplexTypeDefinition controlType) { + private boolean doesAttributeComeFromExtension(XSAttributeUse attr, XSComplexTypeDefinition controlType) + { if (LOGGER.isDebugEnabled()) - LOGGER.debug("doesAttributeComeFromExtension for " + attr.getAttrDeclaration().getName() + " and controlType=" + controlType.getName()); + LOGGER.debug("doesAttributeComeFromExtension for " + attr.getAttrDeclaration().getName() + + " and controlType=" + controlType.getName()); boolean comesFromExtension = false; if (controlType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION) { XSTypeDefinition baseType = controlType.getBaseType(); @@ -2036,10 +2040,10 @@ public class SchemaFormBuilder if (term instanceof XSModelGroup) { - + if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is a group"); - + this.addGroup(xForm, modelSection, defaultInstanceElement, @@ -2105,13 +2109,12 @@ public class SchemaFormBuilder LOGGER.warn("Corresponding control not found"); else { - Element newControl = (Element) control.cloneNode(true); + Element newControl = (Element)control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatContentWrapper.appendChild(newControl); } - } else { @@ -2121,7 +2124,7 @@ public class SchemaFormBuilder final String path = (pathToRoot.length() == 0 ? elementName : pathToRoot + "/" + elementName); - + final Element newDefaultInstanceElement = xForm.createElement(elementName); defaultInstanceElement.appendChild(newDefaultInstanceElement); if (element.getConstraintType() != XSConstants.VC_NONE) @@ -2138,6 +2141,10 @@ public class SchemaFormBuilder element, element.getTypeDefinition(), path); + for (int i = 1; i < this.getOccurance(element).minimum; i++) + { + defaultInstanceElement.appendChild(newDefaultInstanceElement.cloneNode(true)); + } } } else @@ -2185,11 +2192,8 @@ public class SchemaFormBuilder bindId = bind.getAttributeNS(SchemaFormBuilder.XFORMS_NS, "id"); else { - LOGGER.warn("addRepeatIfNecessary: bind not found: " - + bind - + " (model selection name=" - + modelSection.getNodeName() - + ")"); + LOGGER.warn("addRepeatIfNecessary: bind not found: " + bind + + " (model selection name=" + modelSection.getNodeName() + ")"); //if no bind is found -> modelSection is already a bind, get its parent last child bind = DOMUtil.getLastChildElement(modelSection.getParentNode()); @@ -2257,11 +2261,8 @@ public class SchemaFormBuilder Element bindElement = xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); String bindId = this.setXFormsId(bindElement); - bindElement.setAttributeNS(XFORMS_NS, - SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", - pathToRoot); modelSection.appendChild(bindElement); - bindElement = this.startBindElement(bindElement, schema, controlType, owner, o); + bindElement = this.startBindElement(bindElement, schema, controlType, owner, pathToRoot, o); // add a group if a repeat ! if (owner instanceof XSElementDeclaration && o.maximum != 1) @@ -2295,17 +2296,17 @@ public class SchemaFormBuilder contentWrapper = this.wrapper.createGroupContentWrapper(repeatSection); //if there is a repeat -> create another bind with "." - Element bindElement2 = - xForm.createElementNS(XFORMS_NS, - SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); - String bindId2 = this.setXFormsId(bindElement2); - bindElement2.setAttributeNS(XFORMS_NS, - SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", - "."); - bindElement.appendChild(bindElement2); - - bindElement = bindElement2; - bindId = bindId2; +// Element bindElement2 = +// xForm.createElementNS(XFORMS_NS, +// SchemaFormBuilder.XFORMS_NS_PREFIX + "bind"); +// String bindId2 = this.setXFormsId(bindElement2); +// bindElement2.setAttributeNS(XFORMS_NS, +// SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", +// "."); +// bindElement.appendChild(bindElement2); +// +// bindElement = bindElement2; +// bindId = bindId2; } final String caption = owner != null ? createCaption(owner) : createCaption(owningElementName); @@ -2565,9 +2566,9 @@ public class SchemaFormBuilder final TreeSet newDescendents = new TreeSet(this.typeExtensionSorter); newDescendents.addAll(descendents); - -//extension (we only add it to "newDescendants" because we don't want -//to have a type descendant to itself, but to consider it for the parent + + //extension (we only add it to "newDescendants" because we don't want + //to have a type descendant to itself, but to consider it for the parent if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition)type; @@ -2576,7 +2577,7 @@ public class SchemaFormBuilder !descendents.contains(type)) newDescendents.add(type); } -//note: extensions are impossible on simpleTypes ! + //note: extensions are impossible on simpleTypes ! this.buildTypeTree(parentType, newDescendents); } @@ -2599,7 +2600,8 @@ public class SchemaFormBuilder } // build the type tree for simple types - for (int i = 0; i < types.getLength(); i++) { + for (int i = 0; i < types.getLength(); i++) + { final XSTypeDefinition t = (XSTypeDefinition) types.item(i); if (t.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { @@ -2609,7 +2611,7 @@ public class SchemaFormBuilder } // print out type hierarchy for debugging purposes - if (true || LOGGER.isDebugEnabled()) + if (LOGGER.isDebugEnabled()) { for (String typeName : this.typeTree.keySet()) { @@ -3332,6 +3334,7 @@ public class SchemaFormBuilder final XSModel schema, final XSTypeDefinition controlType, final XSObject owner, + final String pathToRoot, final Occurs o) { // START WORKAROUND @@ -3341,6 +3344,15 @@ public class SchemaFormBuilder // // type.getName() may be 'null' for anonymous types, so compare against // static string (see bug #1172541 on sf.net) + + String nodeset = pathToRoot; +// if (o.maximum > 1 || o.isUnbounded()) +// nodeset = pathToRoot + "[position() != last()]"; + + bindElement.setAttributeNS(XFORMS_NS, + SchemaFormBuilder.XFORMS_NS_PREFIX + "nodeset", + nodeset); + if (!"anyType".equals(controlType.getName())) { Element enveloppe = bindElement.getOwnerDocument().getDocumentElement(); @@ -3386,7 +3398,7 @@ public class SchemaFormBuilder : (minConstraint != null ? minConstraint : maxConstraint)); - if (constraint != null && constraint.length() != 0) + if (constraint != null) bindElement.setAttributeNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "constraint", constraint); @@ -3486,7 +3498,12 @@ public class SchemaFormBuilder final XSImplementation xsImpl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); final XSLoader schemaLoader = xsImpl.createXSLoader(null); - return schemaLoader.load(in); + final XSModel result = schemaLoader.load(in); + if (result == null) + { + throw new FormBuilderException("invalid schema"); + } + return result; } catch (ClassNotFoundException x) { diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index 3180bc0eeb..a74e5d0e22 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -38,9 +38,14 @@ import org.w3c.dom.Node; import org.alfresco.web.bean.wcm.AVMBrowseBean; import org.alfresco.web.app.servlet.FacesHelper; import org.chiba.xml.xforms.ChibaBean; +import org.chiba.xml.xforms.Instance; +import org.chiba.xml.xforms.XFormsElement; +import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector; +import org.chiba.xml.xforms.core.ModelItem; 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.ui.BoundElement; import org.w3c.dom.*; import org.w3c.dom.bootstrap.DOMImplementationRegistry; @@ -48,7 +53,6 @@ import org.w3c.dom.ls.*; import org.w3c.dom.events.Event; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventTarget; -import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector; /** * Bean for interacting with the chiba processor from the ui using ajax requests. @@ -56,317 +60,376 @@ import org.chiba.xml.xforms.connector.http.AbstractHTTPConnector; */ public class XFormsBean { - private static final Log LOGGER = LogFactory.getLog(XFormsBean.class); + private static final Log LOGGER = LogFactory.getLog(XFormsBean.class); - private Form tt; - private FormProcessor.InstanceData instanceData = null; - private ChibaBean chibaBean; - private final LinkedList eventLog = new LinkedList(); + private Form tt; + private FormProcessor.InstanceData instanceData = null; + private ChibaBean chibaBean; + private final LinkedList eventLog = new LinkedList(); - /** @return the form */ - public Form getForm() - { - return this.tt; - } + /** @return the form */ + public Form getForm() + { + return this.tt; + } - /** @param tt the template type */ - public void setForm(final Form tt) - { - this.tt = tt; - } + /** @param tt the template type */ + public void setForm(final Form tt) + { + this.tt = tt; + } - /** @param instanceData the instance data being modified. */ - public void setInstanceData(final FormProcessor.InstanceData instanceData) - { - this.instanceData = instanceData; - } + /** @param instanceData the instance data being modified. */ + public void setInstanceData(final FormProcessor.InstanceData instanceData) + { + this.instanceData = instanceData; + } - /** - * Initializes the chiba process with the xform and registers any necessary - * event listeners. - */ - public void init() - throws XFormsException - { - LOGGER.debug("initializing " + this + " with tt " + tt.getName()); - this.chibaBean = new ChibaBean(); - final FacesContext facesContext = FacesContext.getCurrentInstance(); - final ExternalContext externalContext = facesContext.getExternalContext(); - final HttpServletRequest request = (HttpServletRequest) - externalContext.getRequest(); - final HttpSession session = (HttpSession) - externalContext.getSession(true); - final AVMBrowseBean browseBean = (AVMBrowseBean) - session.getAttribute("AVMBrowseBean"); - LOGGER.debug("avm cwd is " + browseBean.getCurrentPath()); + /** + * Initializes the chiba process with the xform and registers any necessary + * event listeners. + */ + public void init() + throws XFormsException + { + LOGGER.debug("initializing " + this + " with tt " + tt.getName()); + this.chibaBean = new ChibaBean(); + final FacesContext facesContext = FacesContext.getCurrentInstance(); + final ExternalContext externalContext = facesContext.getExternalContext(); + final HttpServletRequest request = (HttpServletRequest) + externalContext.getRequest(); + final HttpSession session = (HttpSession) + externalContext.getSession(true); + final AVMBrowseBean browseBean = (AVMBrowseBean) + session.getAttribute("AVMBrowseBean"); + LOGGER.debug("avm cwd is " + browseBean.getCurrentPath()); - XFormsBean.storeCookies(request.getCookies(), this.chibaBean); + XFormsBean.storeCookies(request.getCookies(), this.chibaBean); - try - { - final Document form = this.buildXForm(instanceData.getContent(), - tt, - browseBean.getCurrentPath(), - request); - this.chibaBean.setXMLContainer(form); + try + { + final Document form = this.buildXForm(instanceData.getContent(), + tt, + browseBean.getCurrentPath(), + request); + this.chibaBean.setXMLContainer(form); - final EventTarget et = (EventTarget) - this.chibaBean.getXMLContainer().getDocumentElement(); - final EventListener el = new EventListener() - { - 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); + final EventTarget et = (EventTarget) + this.chibaBean.getXMLContainer().getDocumentElement(); + final EventListener el = new EventListener() + { + 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(); + this.chibaBean.init(); - // register for notification events - et.addEventListener(XFormsEventFactory.SUBMIT_DONE, el, true); - et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, el, true); - et.addEventListener(XFormsEventFactory.REQUIRED, el, true); - et.addEventListener(XFormsEventFactory.OPTIONAL, el, true); - et.addEventListener(XFormsEventFactory.VALID, el, true); - et.addEventListener(XFormsEventFactory.INVALID, el, true); - et.addEventListener(XFormsEventFactory.OUT_OF_RANGE, 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) - { - LOGGER.error(fbe); - } - } + // register for notification events + et.addEventListener(XFormsEventFactory.SUBMIT_DONE, el, true); + et.addEventListener(XFormsEventFactory.SUBMIT_ERROR, el, true); + et.addEventListener(XFormsEventFactory.REQUIRED, el, true); + et.addEventListener(XFormsEventFactory.OPTIONAL, el, true); + et.addEventListener(XFormsEventFactory.VALID, el, true); + et.addEventListener(XFormsEventFactory.INVALID, el, true); + et.addEventListener(XFormsEventFactory.OUT_OF_RANGE, 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) + { + LOGGER.error(fbe); + } + } - /** - * Writes the xform out to the http servlet response. This allows - * us to use the browser to parse the xform using XMLHttpRequest. - */ - public void getXForm() - throws IOException, - XFormsException - { - LOGGER.debug(this + " building xform"); - final FacesContext context = FacesContext.getCurrentInstance(); - final ResponseWriter out = context.getResponseWriter(); - final Map requestParameters = context.getExternalContext().getRequestParameterMap(); - LOGGER.debug("building xform for " + this.tt.getName()); - final Node form = this.chibaBean.getXMLContainer(); - final FormsService ts = FormsService.getInstance(); - ts.writeXML(form, out); - } + /** + * Writes the xform out to the http servlet response. This allows + * us to use the browser to parse the xform using XMLHttpRequest. + */ + public void getXForm() + throws IOException, + XFormsException + { + LOGGER.debug(this + " building xform"); + final FacesContext context = FacesContext.getCurrentInstance(); + final ResponseWriter out = context.getResponseWriter(); + final Map requestParameters = context.getExternalContext().getRequestParameterMap(); + LOGGER.debug("building xform for " + this.tt.getName()); + final Node form = this.chibaBean.getXMLContainer(); + final FormsService ts = FormsService.getInstance(); + ts.writeXML(form, out); + } - /** - * 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 setXFormsValue() - throws XFormsException, IOException - { - final FacesContext context = FacesContext.getCurrentInstance(); - final Map requestParameters = context.getExternalContext().getRequestParameterMap(); - final String id = (String)requestParameters.get("id"); - final String value = (String)requestParameters.get("value"); + /** + * 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 setXFormsValue() + throws XFormsException, IOException + { + final FacesContext context = FacesContext.getCurrentInstance(); + final Map requestParameters = context.getExternalContext().getRequestParameterMap(); + final String id = (String)requestParameters.get("id"); + final String value = (String)requestParameters.get("value"); - LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")"); - this.chibaBean.updateControlValue(id, value); + LOGGER.debug(this + " setXFormsValue(" + id + ", " + value + ")"); + this.chibaBean.updateControlValue(id, value); - final FormsService ts = FormsService.getInstance(); - final ResponseWriter out = context.getResponseWriter(); - ts.writeXML(this.getEventLog(), out); - out.close(); - } + final FormsService ts = FormsService.getInstance(); + final ResponseWriter out = context.getResponseWriter(); + 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")); + /** + * 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); + LOGGER.debug(this + " setRepeatIndex(" + id + ", " + index + ")"); + this.chibaBean.updateRepeatIndex(id, index); - final FormsService ts = FormsService.getInstance(); - final ResponseWriter out = context.getResponseWriter(); - ts.writeXML(this.getEventLog(), out); - out.close(); - } + final FormsService ts = FormsService.getInstance(); + final ResponseWriter out = context.getResponseWriter(); + ts.writeXML(this.getEventLog(), out); + out.close(); + } - /** - * fires an action associated with a trigger. - * - * @param id the id of the control in the host document - */ - public void fireAction() - throws XFormsException, IOException - { - final FacesContext context = FacesContext.getCurrentInstance(); - final Map requestParameters = context.getExternalContext().getRequestParameterMap(); - final String id = (String)requestParameters.get("id"); + /** + * fires an action associated with a trigger. + * + * @param id the id of the control in the host document + */ + public void fireAction() + throws XFormsException, IOException + { + final FacesContext context = FacesContext.getCurrentInstance(); + final Map requestParameters = context.getExternalContext().getRequestParameterMap(); + final String id = (String)requestParameters.get("id"); - LOGGER.debug(this + " fireAction(" + id + ")"); - this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE); + LOGGER.debug(this + " fireAction(" + id + ")"); + this.chibaBean.dispatch(id, XFormsEventFactory.DOM_ACTIVATE); - final FormsService ts = FormsService.getInstance(); - final ResponseWriter out = context.getResponseWriter(); - ts.writeXML(this.getEventLog(), out); - out.close(); - } + final FormsService ts = FormsService.getInstance(); + final ResponseWriter out = context.getResponseWriter(); + ts.writeXML(this.getEventLog(), out); + out.close(); + } - /** - * handles submits and sets the instance data. - */ - public void handleAction() - throws Exception - { - LOGGER.debug(this + " handleAction"); - final FacesContext context = FacesContext.getCurrentInstance(); - final HttpServletRequest request = (HttpServletRequest) - context.getExternalContext().getRequest(); - final FormsService ts = FormsService.getInstance(); - final Document result = ts.parseXML(request.getInputStream()); - this.instanceData.setContent(result); + /** + * handles submits and sets the instance data. + */ + public void handleAction() + throws Exception + { + LOGGER.debug(this + " handleAction"); + final FacesContext context = FacesContext.getCurrentInstance(); + final HttpServletRequest request = (HttpServletRequest) + context.getExternalContext().getRequest(); + final FormsService ts = FormsService.getInstance(); + final Document result = ts.parseXML(request.getInputStream()); + this.instanceData.setContent(result); - final ResponseWriter out = context.getResponseWriter(); - ts.writeXML(result, out); - out.close(); - } + final ResponseWriter out = context.getResponseWriter(); + ts.writeXML(result, out); + out.close(); + } + /** + * Swaps model nodes to implement reordering within repeats. + */ + public void swapRepeatItems() + throws Exception + { + LOGGER.debug(this + " handleAction"); + final FacesContext context = FacesContext.getCurrentInstance(); + final HttpServletRequest request = (HttpServletRequest) + context.getExternalContext().getRequest(); + final Map requestParameters = context.getExternalContext().getRequestParameterMap(); - private void rewriteInlineURIs(final Document schemaDocument, - final String cwdAvmPath) - { - final NodeList includes = - schemaDocument.getElementsByTagNameNS(SchemaFormBuilder.XMLSCHEMA_NS, "include"); - LOGGER.debug("rewriting " + includes.getLength() + " includes"); - for (int i = 0; i < includes.getLength(); i++) - { - final Element includeEl = (Element)includes.item(i); - if (includeEl.hasAttribute("schemaLocation")) - { - String uri = includeEl.getAttribute("schemaLocation"); - final String baseURI = (uri.charAt(0) == '/' - ? AVMConstants.buildAVMStoreUrl(cwdAvmPath) - : AVMConstants.buildAVMAssetUrl(cwdAvmPath)); + final String fromItemId = (String)requestParameters.get("fromItemId"); + final String toItemId = (String)requestParameters.get("toItemId"); + LOGGER.debug("swapping from " + fromItemId + " to " + toItemId); + this.swapRepeatItems(this.chibaBean.lookup(fromItemId), + this.chibaBean.lookup(toItemId)); - LOGGER.debug("rewriting " + uri + " as " + (baseURI + uri)); - includeEl.setAttribute("schemaLocation", baseURI + uri); - } - } - } + final FormsService ts = FormsService.getInstance(); + final ResponseWriter out = context.getResponseWriter(); + ts.writeXML(this.getEventLog(), out); + out.close(); + } - /** - * Generates the xforms based on the schema. - */ - private Document buildXForm(Document xmlContent, - final Form tt, - final String cwdAvmPath, - final HttpServletRequest request) - throws FormBuilderException - { - final Document schemaDocument = tt.getSchema(); - this.rewriteInlineURIs(schemaDocument, cwdAvmPath); - final String baseUrl = (request.getScheme() + "://" + - request.getServerName() + ':' + - request.getServerPort() + - request.getContextPath()); - LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder"); - final SchemaFormBuilder builder = - new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction", - SchemaFormBuilder.SUBMIT_METHOD_POST, - new XHTMLWrapperElementsBuilder(), - baseUrl); - LOGGER.debug("building xform for schema " + tt.getName()); - final Document result = builder.buildForm(xmlContent, - schemaDocument, - tt.getRootTagName()); - LOGGER.debug("generated xform: " + result); - // LOGGER.debug(ts.writeXMLToString(result)); - return result; - } + private void swapRepeatItems(final XFormsElement from, + final XFormsElement to) + { + LOGGER.debug("swapping repeat item " + from + " with " + to); - private Node getEventLog() - { - final FormsService ts = FormsService.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(); - LOGGER.debug("adding event " + type + " to the event log"); - final Element target = (Element)xfe.getTarget(); + if (from instanceof BoundElement && to instanceof BoundElement) + { + LOGGER.debug("from instance id " + ((BoundElement)from).getInstanceId()); + final Instance instance = from.getModel().getInstance(((BoundElement)from).getInstanceId()); + assert instance == to.getModel().getInstance(((BoundElement)to).getInstanceId()); - final Element eventElement = result.createElement(type); - eventsElement.appendChild(eventElement); - eventElement.setAttribute("targetId", target.getAttributeNS(null, "id")); - eventElement.setAttribute("targetName", target.getLocalName()); + final String fromLocationPath = ((BoundElement)from).getLocationPath(); + final ModelItem fromModelItem = instance.getModelItem(fromLocationPath); - final Collection properties = xfe.getPropertyNames(); - if (properties != null) - { - for (Object name : properties) - { - final Object value = xfe.getContextInfo((String)name); - LOGGER.debug("adding property {" + name + - ":" + value + "} to event " + type); - final Element propertyElement = result.createElement("property"); - eventElement.appendChild(propertyElement); - propertyElement.setAttribute("name", name.toString()); - propertyElement.setAttribute("value", - value != null ? value.toString() : null); - } - } - } - this.eventLog.clear(); - return result; - } + final String toLocationPath = ((BoundElement)to).getLocationPath(); + final ModelItem toModelItem = instance.getModelItem(toLocationPath); - /** - * stores cookies that may exist in request and passes them on to processor for usage in - * HTTPConnectors. Instance loading and submission then uses these cookies. Important for - * applications using auth. - */ - @SuppressWarnings("unchecked") - private static void storeCookies(final javax.servlet.http.Cookie[] cookiesIn, - final ChibaBean chibaBean){ - if (cookiesIn != null) { - org.apache.commons.httpclient.Cookie[] commonsCookies = - new org.apache.commons.httpclient.Cookie[cookiesIn.length]; - for (int i = 0; i < cookiesIn.length; i += 1) { - commonsCookies[i] = - new org.apache.commons.httpclient.Cookie(cookiesIn[i].getDomain(), - cookiesIn[i].getName(), - cookiesIn[i].getValue(), - cookiesIn[i].getPath(), - cookiesIn[i].getMaxAge(), - cookiesIn[i].getSecure()); - } - chibaBean.getContext().put(AbstractHTTPConnector.REQUEST_COOKIE, - commonsCookies); - } - } + LOGGER.debug("from[" + from.getId() + "] " + fromLocationPath + "=" + fromModelItem.getValue()); + LOGGER.debug("to[" + to.getId() + "] " + toLocationPath + "=" + toModelItem.getValue()); + + final Node fromNode = (Node)fromModelItem.getNode(); + final Node toNode = (Node)toModelItem.getNode(); + Node swapNode = fromNode; + fromModelItem.setNode(toNode); + toModelItem.setNode(swapNode); + + final Node parentNode = fromNode.getParentNode(); + assert parentNode.equals(toNode.getParentNode()); + + swapNode = parentNode.getOwnerDocument().createTextNode("swap"); + parentNode.replaceChild(swapNode, fromNode); + parentNode.replaceChild(fromNode, toNode); + parentNode.replaceChild(toNode, swapNode); + } + } + + private void rewriteInlineURIs(final Document schemaDocument, + final String cwdAvmPath) + { + final NodeList includes = + schemaDocument.getElementsByTagNameNS(SchemaFormBuilder.XMLSCHEMA_NS, "include"); + LOGGER.debug("rewriting " + includes.getLength() + " includes"); + for (int i = 0; i < includes.getLength(); i++) + { + final Element includeEl = (Element)includes.item(i); + if (includeEl.hasAttribute("schemaLocation")) + { + String uri = includeEl.getAttribute("schemaLocation"); + final String baseURI = (uri.charAt(0) == '/' + ? AVMConstants.buildAVMStoreUrl(cwdAvmPath) + : AVMConstants.buildAVMAssetUrl(cwdAvmPath)); + + LOGGER.debug("rewriting " + uri + " as " + (baseURI + uri)); + includeEl.setAttribute("schemaLocation", baseURI + uri); + } + } + } + + /** + * Generates the xforms based on the schema. + */ + private Document buildXForm(Document xmlContent, + final Form tt, + final String cwdAvmPath, + final HttpServletRequest request) + throws FormBuilderException + { + final Document schemaDocument = tt.getSchema(); + this.rewriteInlineURIs(schemaDocument, cwdAvmPath); + final String baseUrl = (request.getScheme() + "://" + + request.getServerName() + ':' + + request.getServerPort() + + request.getContextPath()); + LOGGER.debug("using baseUrl " + baseUrl + " for schemaformbuilder"); + final SchemaFormBuilder builder = + new SchemaFormBuilder("/ajax/invoke/XFormsBean.handleAction", + SchemaFormBuilder.SUBMIT_METHOD_POST, + new XHTMLWrapperElementsBuilder(), + baseUrl); + LOGGER.debug("building xform for schema " + tt.getName()); + final Document result = builder.buildForm(xmlContent, + schemaDocument, + tt.getRootTagName()); + LOGGER.debug("generated xform: " + result); + // LOGGER.debug(ts.writeXMLToString(result)); + return result; + } + + private Node getEventLog() + { + final FormsService ts = FormsService.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(); + LOGGER.debug("adding event " + type + " to the event log"); + 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()); + + final Collection properties = xfe.getPropertyNames(); + if (properties != null) + { + for (Object name : properties) + { + final Object value = xfe.getContextInfo((String)name); + LOGGER.debug("adding property {" + name + + ":" + value + "} to event " + type); + final Element propertyElement = result.createElement("property"); + eventElement.appendChild(propertyElement); + propertyElement.setAttribute("name", name.toString()); + propertyElement.setAttribute("value", + value != null ? value.toString() : null); + } + } + } + this.eventLog.clear(); + return result; + } + + /** + * stores cookies that may exist in request and passes them on to processor for usage in + * HTTPConnectors. Instance loading and submission then uses these cookies. Important for + * applications using auth. + */ + @SuppressWarnings("unchecked") + private static void storeCookies(final javax.servlet.http.Cookie[] cookiesIn, + final ChibaBean chibaBean){ + if (cookiesIn != null) { + org.apache.commons.httpclient.Cookie[] commonsCookies = + new org.apache.commons.httpclient.Cookie[cookiesIn.length]; + for (int i = 0; i < cookiesIn.length; i += 1) { + commonsCookies[i] = + new org.apache.commons.httpclient.Cookie(cookiesIn[i].getDomain(), + cookiesIn[i].getName(), + cookiesIn[i].getValue(), + cookiesIn[i].getPath(), + cookiesIn[i].getMaxAge(), + cookiesIn[i].getSecure()); + } + chibaBean.getContext().put(AbstractHTTPConnector.REQUEST_COOKIE, + commonsCookies); + } + } } diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsd b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsd new file mode 100644 index 0000000000..32e3c0b954 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsd @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsl b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsl new file mode 100644 index 0000000000..ae49080b76 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-components.xsl @@ -0,0 +1,135 @@ + + + + + + + + + + repeat-components + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
zero-to-one
one-to-one
+ + one-to-inf + +
    + +
  • +
    +
+
+ + zero-to-inf + +
    + +
  • +
    +
+
+ + one-to-five + +
    + +
  • +
    +
+
+ + zero-to-five + +
    + +
  • +
    +
+
+ + one-to-five-multi + +
    + +
      +
    • +
    • +
    +
    +
+
+ + zero-to-five-multi + +
    + +
  • +
      +
    • +
    • +
    +
  • +
    +
+
+ + +
+
diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-constraints.xsd b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-constraints.xsd new file mode 100644 index 0000000000..0fcfae6ec9 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-constraints.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsd b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsd new file mode 100644 index 0000000000..99e96df297 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsd @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsl b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsl new file mode 100644 index 0000000000..cafd1af2e6 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-simple-test.xsl @@ -0,0 +1,135 @@ + + + + + + + + + + repeat-simple + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
zero-to-one
one-to-one
+ + one-to-inf + +
    + +
  • +
    +
+
+ + zero-to-inf + +
    + +
  • +
    +
+
+ + one-to-five + +
    + +
  • +
    +
+
+ + zero-to-five + +
    + +
  • +
    +
+
+ + one-to-five-multi + +
    + +
      +
    • +
    • +
    +
    +
+
+ + zero-to-five-multi + +
    + +
  • +
      +
    • +
    • +
    +
  • +
    +
+
+ + +
+
diff --git a/source/test-resources/xforms/unit-tests/repeat-tests/repeat-submit-test.xsd b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-submit-test.xsd new file mode 100644 index 0000000000..448afcbdcc --- /dev/null +++ b/source/test-resources/xforms/unit-tests/repeat-tests/repeat-submit-test.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/web/jsp/wcm/create-form-wizard/details.jsp b/source/web/jsp/wcm/create-form-wizard/details.jsp index 3aa50ae497..285841fcd8 100644 --- a/source/web/jsp/wcm/create-form-wizard/details.jsp +++ b/source/web/jsp/wcm/create-form-wizard/details.jsp @@ -104,14 +104,29 @@ if (upload == null || upload.getFile() == null) - + - + + + + + - + diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index cc1f7ba25d..81d5657fd7 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -38,24 +38,20 @@ tinyMCE.init({ dojo.declare("alfresco.xforms.Widget", null, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { this.xform = xform; - this.node = node; + this.xformsNode = xformsNode; //XXXarielb this has to come back // this.node.widget = this; - this.id = this.node.getAttribute("id"); + this.id = this.xformsNode.getAttribute("id"); this.modified = false; this.valid = true; }, - node: null, + xformsNode: null, labelNode: null, parent: null, domContainer: null, - _getBinding: function() - { - return this.xform.getBinding(this.node); - }, setModified: function(b) { this.modified = b; @@ -96,17 +92,17 @@ dojo.declare("alfresco.xforms.Widget", }, isRequired: function() { - var binding = this._getBinding(); + var binding = this.xform.getBinding(this.xformsNode); return binding && binding.required == "true()"; }, isReadonly: function() { - var binding = this._getBinding(); + var binding = this.xform.getBinding(this.xformsNode); return binding && binding.readonly == "true()"; }, getInitialValue: function() { - var chibaData = _getElementsByTagNameNS(this.node, + var chibaData = _getElementsByTagNameNS(this.xformsNode, CHIBA_NS, CHIBA_NS_PREFIX, "data"); @@ -115,7 +111,7 @@ dojo.declare("alfresco.xforms.Widget", chibaData = chibaData[chibaData.length - 1]; var xpath = chibaData.getAttribute("chiba:xpath"); - var d = this.node.ownerDocument; + var d = this.xformsNode.ownerDocument; var contextNode = this.xform.getInstance(); dojo.debug("locating " + xpath + " from " + chibaData.nodeName + @@ -131,24 +127,24 @@ dojo.declare("alfresco.xforms.Widget", }, _getLabelNode: function() { - var labels = _getElementsByTagNameNS(this.node, XFORMS_NS, XFORMS_NS_PREFIX, "label"); + var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "label"); for (var i = 0; i < labels.length; i++) { dojo.debug("parent " + labels[i].parentNode.nodeName + - " o " + this.node.nodeName); - if (labels[i].parentNode == this.node) + " o " + this.xformsNode.nodeName); + if (labels[i].parentNode == this.xformsNode) return labels[i]; } return null; }, _getAlertNode: function() { - var labels = _getElementsByTagNameNS(this.node, XFORMS_NS, XFORMS_NS_PREFIX, "alert"); + var labels = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "alert"); for (var i = 0; i < labels.length; i++) { dojo.debug("parent " + labels[i].parentNode.nodeName + - " o " + this.node.nodeName); - if (labels[i].parentNode == this.node) + " o " + this.xformsNode.nodeName); + if (labels[i].parentNode == this.xformsNode) return labels[i]; } return null; @@ -188,9 +184,9 @@ dojo.declare("alfresco.xforms.Widget", dojo.declare("alfresco.xforms.DatePicker", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -250,9 +246,9 @@ dojo.declare("alfresco.xforms.DatePicker", dojo.declare("alfresco.xforms.TextField", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -265,7 +261,7 @@ dojo.declare("alfresco.xforms.TextField", this.widget.setAttribute("type", "text"); this.widget.setAttribute("id", this.id + "-widget"); this.widget.setAttribute("value", initial_value); - if (this.xform.getType(this.node) == "string") + if (this.xform.getType(this.xformsNode) == "string") this.widget.style.width = "100%"; this.domNode.appendChild(this.widget); @@ -302,9 +298,9 @@ dojo.declare("alfresco.xforms.TextField", dojo.declare("alfresco.xforms.TextArea", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -331,14 +327,14 @@ dojo.declare("alfresco.xforms.TextArea", dojo.declare("alfresco.xforms.AbstractSelectWidget", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, getValues: function() { - var binding = this._getBinding(); - var values = _getElementsByTagNameNS(this.node, XFORMS_NS, XFORMS_NS_PREFIX, "item"); + var binding = this.xform.getBinding(this.xformsNode); + var values = _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "item"); var result = []; for (var v = 0; v < values.length; v++) { @@ -368,9 +364,9 @@ dojo.declare("alfresco.xforms.AbstractSelectWidget", dojo.declare("alfresco.xforms.Select", alfresco.xforms.AbstractSelectWidget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -455,9 +451,9 @@ dojo.declare("alfresco.xforms.Select", dojo.declare("alfresco.xforms.Select1", alfresco.xforms.AbstractSelectWidget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -543,9 +539,9 @@ dojo.declare("alfresco.xforms.Select1", dojo.declare("alfresco.xforms.Checkbox", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -572,9 +568,9 @@ dojo.declare("alfresco.xforms.Checkbox", dojo.declare("alfresco.xforms.Group", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); this.children = []; }, children: null, @@ -598,8 +594,9 @@ dojo.declare("alfresco.xforms.Group", { for (var i = 0; i < this.children.length; i++) { - dojo.debug(this.id + "[" + i + "]: " + - " is " + this.children[i].id + " the same as " + child.id + "?"); + dojo.debug(this.id + "[" + i + "]: " + + " is " + this.children[i].id + + " the same as " + child.id + "?"); if (this.children[i] == child) return i; } @@ -754,9 +751,9 @@ dojo.declare("alfresco.xforms.Group", dojo.declare("alfresco.xforms.Repeat", alfresco.xforms.Group, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, _selectedIndex: -1, insertChildAt: function(child, position) @@ -819,7 +816,7 @@ dojo.declare("alfresco.xforms.Repeat", this.setFocusedChild(event.target.repeatItem); if (!this.insertRepeatItemAfterTrigger) this.insertRepeatItemAfterTrigger = - _findElementById(this.node.parentNode, this.id + "-insert_after"); + _findElementById(this.xformsNode.parentNode, this.id + "-insert_after"); this.xform.fireAction(this.insertRepeatItemAfterTrigger.getAttribute("id")); }, _insertRepeatItemBefore_handler: function(event) @@ -828,7 +825,7 @@ dojo.declare("alfresco.xforms.Repeat", this.setFocusedChild(event.target.repeatItem); if (!this.insertRepeatItemBeforeTrigger) this.insertRepeatItemBeforeTrigger = - _findElementById(this.node.parentNode, this.id + "-insert_before"); + _findElementById(this.xformsNode.parentNode, this.id + "-insert_before"); this.xform.fireAction(this.insertRepeatItemBeforeTrigger.getAttribute("id")); }, _removeRepeatItem_handler: function(event) @@ -836,7 +833,7 @@ dojo.declare("alfresco.xforms.Repeat", dojo.event.browser.stopEvent(event); this.setFocusedChild(event.target.repeatItem); if (!this.removeRepeatItemTrigger) - this.removeRepeatItemTrigger = _findElementById(this.node.parentNode, + this.removeRepeatItemTrigger = _findElementById(this.xformsNode.parentNode, this.id + "-delete"); this.xform.fireAction(this.removeRepeatItemTrigger.getAttribute("id")); }, @@ -884,6 +881,19 @@ dojo.declare("alfresco.xforms.Repeat", this.children[toIndex] = fromChild; this._selectedIndex = toIndex; this._updateDisplay(); + + var req = create_ajax_request(this.xform, + "swapRepeatItems", + { + fromItemId: fromChild.xformsNode.getAttribute("id"), + toItemId: toChild.xformsNode.getAttribute("id"), + instanceId: this.xform.getInstance().getAttribute("id") + }, + function(type, data, event) + { + this.xform._handleEventLog(data.documentElement) + }); + send_ajax_request(req); }, setFocusedChild: function(child) { @@ -968,7 +978,7 @@ dojo.declare("alfresco.xforms.Repeat", handlePrototypeCloned: function(prototypeId) { dojo.debug(this.id + ".handlePrototypeCloned("+ prototypeId +")"); - var chibaData = _getElementsByTagNameNS(this.node, CHIBA_NS, CHIBA_NS_PREFIX, "data"); + var chibaData = _getElementsByTagNameNS(this.xformsNode, CHIBA_NS, CHIBA_NS_PREFIX, "data"); chibaData = chibaData[chibaData.length - 1]; dojo.debug("chiba:data == " + dojo.dom.innerXML(chibaData)); var prototypeToClone = dojo.dom.firstElement(chibaData); @@ -983,7 +993,7 @@ dojo.declare("alfresco.xforms.Repeat", ", " + position + ")"); var w = this.xform.createWidget(clonedPrototype); this.insertChildAt(w, position); - this.xform.loadWidgets(w.node, w); + this.xform.loadWidgets(w.xformsNode, w); }, handleItemDeleted: function(position) { @@ -995,9 +1005,9 @@ dojo.declare("alfresco.xforms.Repeat", dojo.declare("alfresco.xforms.Trigger", alfresco.xforms.Widget, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); }, render: function(attach_point) { @@ -1021,9 +1031,9 @@ dojo.declare("alfresco.xforms.Trigger", dojo.declare("alfresco.xforms.Submit", alfresco.xforms.Trigger, { - initializer: function(xform, node) + initializer: function(xform, xformsNode) { - this.inherited("initializer", [ xform, node ]); + this.inherited("initializer", [ xform, xformsNode ]); var submit_buttons = _xforms_getSubmitButtons(); for (var i = 0; i < submit_buttons.length; i++) { @@ -1105,7 +1115,7 @@ dojo.declare("alfresco.xforms.XForm", _loadHandler: function(xformDocument) { this.xformDocument = xformDocument; - this.node = xformDocument.documentElement; + this.xformsNode = xformDocument.documentElement; this._bindings = this._loadBindings(this.getModel()); var bindings = this.getBindings(); @@ -1177,29 +1187,29 @@ dojo.declare("alfresco.xforms.XForm", throw new Error("unknown type " + node.nodeName); } }, - loadWidgets: function(modelNode, parentWidget) + loadWidgets: function(xformsNode, parentWidget) { - for (var i = 0; i < modelNode.childNodes.length; i++) + for (var i = 0; i < xformsNode.childNodes.length; i++) { - if (modelNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) + if (xformsNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE) { - dojo.debug("loading " + modelNode.childNodes[i] + - " nodeName " + modelNode.childNodes[i].nodeName + + dojo.debug("loading " + xformsNode.childNodes[i] + + " nodeName " + xformsNode.childNodes[i].nodeName + " into " + parentWidget.id); - var w = this.createWidget(modelNode.childNodes[i]); + var w = this.createWidget(xformsNode.childNodes[i]); if (w != null) { - dojo.debug("created " + w.id + " for " + modelNode.childNodes[i].nodeName); + dojo.debug("created " + w.id + " for " + xformsNode.childNodes[i].nodeName); parentWidget.addChild(w); if (w instanceof alfresco.xforms.Group) - this.loadWidgets(modelNode.childNodes[i], w); + this.loadWidgets(xformsNode.childNodes[i], w); } } } }, getModel: function() { - return _getElementsByTagNameNS(this.node, + return _getElementsByTagNameNS(this.xformsNode, XFORMS_NS, XFORMS_NS_PREFIX, "model")[0]; @@ -1214,7 +1224,7 @@ dojo.declare("alfresco.xforms.XForm", }, getBody: function() { - var b = _getElementsByTagNameNS(this.node, + var b = _getElementsByTagNameNS(this.xformsNode, XHTML_NS, XHTML_NS_PREFIX, "body");