diff --git a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java
index 6c2b46c0e2..beebb39c1b 100644
--- a/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java
+++ b/source/java/org/alfresco/web/templating/xforms/SchemaFormBuilder.java
@@ -538,19 +538,19 @@ public class SchemaFormBuilder
? this.submitMethod
: SchemaFormBuilder.SUBMIT_METHOD_POST));
- //Element submitButton = (Element) formSection.appendChild(xForm.createElementNS(XFORMS_NS,SchemaFormBuilder.XFORMS_NS_PREFIX+"submit"));
- Element submitButton =
+ final Element submitButton =
xForm.createElementNS(XFORMS_NS, SchemaFormBuilder.XFORMS_NS_PREFIX + "submit");
- Element submitControlWrapper = this.wrapper.createControlsWrapper(submitButton);
+ final Element submitControlWrapper = this.wrapper.createControlsWrapper(submitButton);
formContentWrapper.appendChild(submitControlWrapper);
submitButton.setAttributeNS(XFORMS_NS,
SchemaFormBuilder.XFORMS_NS_PREFIX + "submission",
submissionId);
this.setXFormsId(submitButton);
- Element submitButtonCaption = (Element)
- submitButton.appendChild(xForm.createElementNS(XFORMS_NS,
- SchemaFormBuilder.XFORMS_NS_PREFIX + "label"));
+ final Element submitButtonCaption =
+ xForm.createElementNS(XFORMS_NS,
+ SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
+ submitButton.appendChild(submitButtonCaption);
submitButtonCaption.appendChild(xForm.createTextNode("Submit"));
this.setXFormsId(submitButtonCaption);
return xForm;
@@ -2407,9 +2407,6 @@ public class SchemaFormBuilder
SchemaFormBuilder.XFORMS_NS_PREFIX + "label");
this.setXFormsId(triggerLabel);
trigger.appendChild(triggerLabel);
- //triggerLabel_insert.setAttributeNS(SchemaFormBuilder.XLINK_NS,
- // SchemaFormBuilder.XLINK_NS_PREFIX + "href",
- // "images/add_new.gif");
triggerLabel.appendChild(xForm.createTextNode(label));
diff --git a/source/java/org/alfresco/web/templating/xforms/XFormsBean.java b/source/java/org/alfresco/web/templating/xforms/XFormsBean.java
index d1ec3a55b0..a64e30339d 100644
--- a/source/java/org/alfresco/web/templating/xforms/XFormsBean.java
+++ b/source/java/org/alfresco/web/templating/xforms/XFormsBean.java
@@ -132,6 +132,8 @@ public class XFormsBean
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);
diff --git a/source/test-resources/xforms/unit-tests/components/components.xsd b/source/test-resources/xforms/unit-tests/components/components.xsd
index 4da3d0ed70..addca3956c 100644
--- a/source/test-resources/xforms/unit-tests/components/components.xsd
+++ b/source/test-resources/xforms/unit-tests/components/components.xsd
@@ -42,7 +42,7 @@
-
+
diff --git a/source/test-resources/xforms/unit-tests/components/components.xsl b/source/test-resources/xforms/unit-tests/components/components.xsl
index 50dc57ea2c..67cb66b1fe 100644
--- a/source/test-resources/xforms/unit-tests/components/components.xsl
+++ b/source/test-resources/xforms/unit-tests/components/components.xsl
@@ -43,7 +43,7 @@ body
Integer:
-
+
Positive Integer:
diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js
index 9143536504..24ca66db71 100644
--- a/source/web/scripts/ajax/xforms.js
+++ b/source/web/scripts/ajax/xforms.js
@@ -29,212 +29,220 @@ tinyMCE.init({
dojo.declare("alfresco.xforms.Widget",
null,
{
- initializer: function(xform, node)
- {
+ initializer: function(xform, node)
+ {
this.xform = xform;
this.node = node;
this.node.widget = this;
this.id = this.node.getAttribute("id");
+ this.modified = false;
+ this.valid = true;
},
- parent: null,
- domContainer: null,
- _getBinding: function()
- {
- return this.xform.getBinding(this.node);
- },
- getDepth: function()
- {
- var result = 1;
- var p = this.parent;
- while (p)
+ parent: null,
+ domContainer: null,
+ _getBinding: function()
{
- result++;
- p = p.parent;
- }
- return result;
- },
- isRequired: function()
- {
- var binding = this._getBinding();
- var required = binding && binding.required == "true()";
- return required;
- },
- getInitialValue: function()
- {
- var chibaData = this.node.getElementsByTagName("data");
- if (chibaData.length == 0)
- return null;
-
- chibaData = chibaData[chibaData.length - 1];
- var xpath = "/" + chibaData.getAttribute("chiba:xpath");
- var d = this.node.ownerDocument;
- var nsResolver = d.createNSResolver(d.documentElement);
- var contextNode = this.xform.getInstance();
- dojo.debug("locating " + xpath +
- " from " + chibaData.nodeName +
- " in " + contextNode.nodeName);
- var result = d.evaluate(xpath,
- this.xform.getInstance(),
- nsResolver,
- XPathResult.STRING_TYPE,
- null);
- return result.stringValue;
- },
- _getLabelNode: function()
- {
- var labels = this.node.getElementsByTagName("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)
- return labels[i];
- }
- return null;
- },
- getLabel: function()
- {
- var node = this._getLabelNode();
- return node ? dojo.dom.textContent(node) : "";
- }
- });
-
-dojo.declare("alfresco.xforms.NumericStepper",
- alfresco.xforms.Widget,
- {
- initializer: function(xform, node, stepper_type)
- {
- this.inherited("initializer", [ xform, node ]);
- this.stepper_type = stepper_type;
- },
- render: function(attach_point)
- {
- var nodeRef = document.createElement("div");
- attach_point.appendChild(nodeRef);
- var initial_value = this.getInitialValue() || "";
-
- var w = dojo.widget.createWidget((this.stepper_type == "double"
- ? "AdjustableRealNumberTextBox"
- : "AdjustableIntegerTextBox"),
- {
- widgetId: this.id + "-widget",
- required: this.isRequired(),
- value: initial_value
- },
- nodeRef);
- w.widget = this;
- this.widget = w;
- dojo.event.connect(w, "adjustValue", this, this._widget_changeHandler);
- dojo.event.connect(w, "onkeyup", this, this._widget_changeHandler);
- },
- getValue: function()
- {
- return this.widget.getValue();
- },
- _widget_changeHandler: function(event)
- {
- this.xform.setXFormsValue(this.id, this.getValue());
- }
+ return this.xform.getBinding(this.node);
+ },
+ setModified: function(b)
+ {
+ this.modified = b;
+ this._updateDisplay();
+ },
+ setValid: function(b)
+ {
+ this.valid = b;
+ this._updateDisplay();
+ },
+ setRequired: function(b)
+ {
+ this.required = b;
+ this._updateDisplay();
+ },
+ isValidForSubmit: function()
+ {
+ var result = true;
+ if (!this.valid)
+ result = false;
+ else if (!this.modified &&
+ this.isRequired() &&
+ this.getInitialValue() == null)
+ result = false;
+ return result;
+ },
+ getDepth: function()
+ {
+ var result = 1;
+ var p = this.parent;
+ while (p)
+ {
+ result++;
+ p = p.parent;
+ }
+ return result;
+ },
+ isRequired: function()
+ {
+ var binding = this._getBinding();
+ var required = binding && binding.required == "true()";
+ return required;
+ },
+ getInitialValue: function()
+ {
+ var chibaData = this.node.getElementsByTagName("data");
+ if (chibaData.length == 0)
+ return null;
+
+ chibaData = chibaData[chibaData.length - 1];
+ var xpath = "/" + chibaData.getAttribute("chiba:xpath");
+ var d = this.node.ownerDocument;
+ var nsResolver = d.createNSResolver(d.documentElement);
+ var contextNode = this.xform.getInstance();
+ dojo.debug("locating " + xpath +
+ " from " + chibaData.nodeName +
+ " in " + contextNode.nodeName);
+ var result = d.evaluate(xpath,
+ this.xform.getInstance(),
+ nsResolver,
+ XPathResult.STRING_TYPE,
+ null);
+ return (result.stringValue != null && result.stringValue.length > 0
+ ? result.stringValue
+ : null);
+ },
+ _getLabelNode: function()
+ {
+ var labels = this.node.getElementsByTagName("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)
+ return labels[i];
+ }
+ return null;
+ },
+ getLabel: function()
+ {
+ var node = this._getLabelNode();
+ return node ? dojo.dom.textContent(node) : "";
+ },
+ _updateDisplay: function()
+ {
+// this.domContainer.style.backgroundColor =
+// (!this.valid ? "yellow" : this.modified ? "lightgreen" : "white");
+ }
});
dojo.declare("alfresco.xforms.DatePicker",
alfresco.xforms.Widget,
{
- initializer: function(xform, node)
- {
- this.inherited("initializer", [ xform, node ]);
- },
- render: function(attach_point)
- {
- var initial_value = this.getInitialValue();
-
- var dateTextBoxDiv = document.createElement("div");
- attach_point.appendChild(dateTextBoxDiv);
- this.dateTextBox = dojo.widget.createWidget("DateTextBox",
- {
- widgetId: this.id + "-widget",
- required: this.isRequired(),
- format: "YYYY-MM-DD",
- value: initial_value
- },
- dateTextBoxDiv);
- dojo.event.connect(this.dateTextBox,
- "onfocus",
- this,
- this._dateTextBox_focusHandler);
-
- var datePickerDiv = document.createElement("div");
- attach_point.appendChild(datePickerDiv);
-
- var dp_initial_value = (initial_value
- ? initial_value
- : dojo.widget.DatePicker.util.toRfcDate(new Date()));
- this.dateTextBox.picker = dojo.widget.createWidget("DatePicker",
- {
- isHidden: true,
- storedDate: dp_initial_value
- },
- datePickerDiv);
- this.dateTextBox.picker.hide();
- dojo.event.connect(this.dateTextBox.picker,
- "onSetDate",
- this,
- this._datePicker_setDateHandler);
- },
- getValue: function()
- {
- return this.dateTextBox.getValue();
- },
- _dateTextBox_focusHandler: function(event)
- {
- this.dateTextBox.hide();
- this.dateTextBox.picker.show();
- this.domContainer.style.height =
- this.dateTextBox.picker.domNode.offsetHeight + "px";
- },
- _datePicker_setDateHandler: function(event)
- {
- this.dateTextBox.picker.hide();
- this.dateTextBox.show();
- this.domContainer.style.height =
- this.dateTextBox.domNode.offsetHeight + "px";
- this.dateTextBox.setValue(dojo.widget.DatePicker.util.toRfcDate(this.dateTextBox.picker.date));
- this.xform.setXFormsValue(this.id, this.getValue());
- }
+ initializer: function(xform, node)
+ {
+ this.inherited("initializer", [ xform, node ]);
+ },
+ render: function(attach_point)
+ {
+ var initial_value = this.getInitialValue() || "";
+
+ this.domNode = document.createElement("div");
+ attach_point.appendChild(this.domNode);
+ this.widget = document.createElement("input");
+ this.widget.setAttribute("id", this.id + "-widget");
+ this.widget.setAttribute("type", "text");
+ this.widget.setAttribute("value", initial_value);
+ this.domNode.appendChild(this.widget);
+ dojo.event.connect(this.widget, "onfocus", this, this._dateTextBox_focusHandler);
+
+ var datePickerDiv = document.createElement("div");
+ attach_point.appendChild(datePickerDiv);
+
+ var dp_initial_value = (initial_value
+ ? initial_value
+ : dojo.widget.DatePicker.util.toRfcDate(new Date()));
+ this.widget.picker = dojo.widget.createWidget("DatePicker",
+ {
+ isHidden: true,
+ storedDate: dp_initial_value
+ },
+ datePickerDiv);
+ this.widget.picker.hide();
+ dojo.event.connect(this.widget.picker,
+ "onSetDate",
+ this,
+ this._datePicker_setDateHandler);
+ },
+ getValue: function()
+ {
+ return this.widget.value;
+ },
+ _dateTextBox_focusHandler: function(event)
+ {
+ dojo.style.hide(this.widget);
+ this.widget.picker.show();
+ this.domContainer.style.height =
+ this.widget.picker.domNode.offsetHeight + "px";
+ },
+ _datePicker_setDateHandler: function(event)
+ {
+ this.widget.picker.hide();
+ dojo.style.show(this.widget);
+ this.domContainer.style.height =
+ Math.max(this.widget.offsetHeight, 20) + "px";
+ this.widget.value = dojo.widget.DatePicker.util.toRfcDate(this.widget.picker.date);
+ this.xform.setXFormsValue(this.id, this.getValue());
+ }
});
dojo.declare("alfresco.xforms.TextField",
alfresco.xforms.Widget,
{
- initializer: function(xform, node)
- {
- this.inherited("initializer", [ xform, node ]);
- },
- render: function(attach_point)
- {
- var nodeRef = document.createElement("div");
- attach_point.appendChild(nodeRef);
- var initial_value = this.getInitialValue() || "";
+ initializer: function(xform, node)
+ {
+ this.inherited("initializer", [ xform, node ]);
+ },
+ isValidForSubmit: function()
+ {
+ var result = this.inherited("isValidForSubmit", []);
+ if (!result)
+ return false;
+ if (this.isRequired() && this.getValue() == null)
+ return false;
+ return true;
+ },
- var w = dojo.widget.createWidget("ValidationTextBox",
- {
- widgetId: this.id + "-widget",
- required: this.isRequired(),
- value: initial_value
- },
- nodeRef);
- w.widget = this;
- this.widget = w;
- dojo.event.connect(w, "onkeyup", this, this._widget_keyUpHandler);
- },
- getValue: function()
- {
- return this.widget.getValue();
- },
- _widget_keyUpHandler: function(event)
- {
- this.xform.setXFormsValue(this.id, this.getValue());
- }
+ render: function(attach_point)
+ {
+ var initial_value = this.getInitialValue() || "";
+ this.domNode = document.createElement("div");
+ this.domNode.setAttribute("id", this.id + "-domNode");
+ attach_point.appendChild(this.domNode);
+
+ this.widget = document.createElement("input");
+ this.widget.setAttribute("type", "text");
+ this.widget.setAttribute("id", this.id + "-widget");
+ this.widget.setAttribute("value", initial_value);
+ this.domNode.appendChild(this.widget);
+// this.widget = dojo.widget.createWidget("ValidationTextBox",
+// {
+// widgetId: this.id + "-widget",
+// required: this.isRequired(),
+// value: initial_value
+// },
+// this.domNode);
+ dojo.event.connect(this.widget, "onkeyup", this, this._widget_keyUpHandler);
+ },
+ getValue: function()
+ {
+ var result = this.widget.value;
+ if (result != null && result.length == 0)
+ result = null;
+ return result;
+ },
+ _widget_keyUpHandler: function(event)
+ {
+ this.xform.setXFormsValue(this.id, this.getValue());
+ }
});
dojo.declare("alfresco.xforms.TextArea",
@@ -335,6 +343,7 @@ dojo.declare("alfresco.xforms.Select",
}
else
{
+ initial_value = initial_value ? initial_value.split(' ') : [];
var list = document.createElement("select");
list.setAttribute("id", this.id + "-widget");
list.setAttribute("multiple", true);
@@ -344,7 +353,7 @@ dojo.declare("alfresco.xforms.Select",
var option = document.createElement("option");
option.appendChild(document.createTextNode(values[i].label));
option.setAttribute("value", values[i].value);
- if (values[i].value == initial_value)
+ if (initial_value.indexOf(values[i].value) != -1)
option.setAttribute("selected", "true");
list.appendChild(option);
}
@@ -462,707 +471,754 @@ dojo.declare("alfresco.xforms.Checkbox",
dojo.declare("alfresco.xforms.Group",
alfresco.xforms.Widget,
{
- initializer: function(xform, node)
+ initializer: function(xform, node)
{
- this.inherited("initializer", [ xform, node ]);
- this.children = [];
+ this.inherited("initializer", [ xform, node ]);
+ this.children = [];
},
- children: null,
- getChildAt: function(index)
- {
- return index < this.children.length ? this.children[index] : null;
- },
- getChildIndex: function(child)
- {
- for (var i = 0; i < this.children.length; i++)
+ children: null,
+ getWidgetsInvalidForSubmit: function()
{
- dojo.debug(this.id + "[" + i + "]: " +
- " is " + this.children[i].id + " the same as " + child.id + "?");
- if (this.children[i] == child)
- return i;
+ var result = [];
+ for (var i = 0; i < this.children.length; i++)
+ {
+ if (this.children[i] instanceof alfresco.xforms.Group)
+ result = result.concat(this.children[i].getWidgetsInvalidForSubmit());
+ else if (!this.children[i].isValidForSubmit())
+ result.push(this.children[i]);
+ }
+ return result;
+ },
+ getChildAt: function(index)
+ {
+ return index < this.children.length ? this.children[index] : null;
+ },
+ getChildIndex: function(child)
+ {
+ for (var i = 0; i < this.children.length; i++)
+ {
+ dojo.debug(this.id + "[" + i + "]: " +
+ " is " + this.children[i].id + " the same as " + child.id + "?");
+ if (this.children[i] == child)
+ return i;
+ }
+ return -1;
+ },
+ domNode: null,
+ addChild: function(child)
+ {
+ return this.insertChildAt(child, this.children.length);
+ },
+ insertChildAt: function(child, position)
+ {
+ dojo.debug(this.id + ".insertChildAt(" + child.id + ", " + position + ")");
+ child.parent = this;
+
+ child.domContainer = document.createElement("div");
+ child.domContainer.setAttribute("style", "position: relative; border: 0px solid green; margin-top: 2px; margin-bottom: 2px;");
+ child.domContainer.style.width = "100%";
+ if (this.parent && this.parent.domNode)
+ child.domContainer.style.top = this.parent.domNode.style.bottom;
+
+ if (position == this.children.length)
+ {
+ this.domNode.appendChild(child.domContainer);
+ this.children.push(child);
+ }
+ else
+ {
+ this.domNode.insertBefore(child.domContainer,
+ this.getChildAt(position).domContainer);
+ this.children.splice(position, 0, child);
+ }
+
+ if (!(child instanceof alfresco.xforms.Group))
+ {
+ var requiredImage = document.createElement("img");
+ requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
+ requiredImage.setAttribute("style", "margin: 0px 5px 0px 5px;");
+ child.domContainer.appendChild(requiredImage);
+
+ if (!child.isRequired())
+ requiredImage.style.visibility = "hidden";
+ var label = child._getLabelNode();
+ if (label)
+ {
+ var labelNode = document.createTextNode(dojo.dom.textContent(label));
+ child.domContainer.appendChild(labelNode);
+ }
+ }
+ var contentDiv = document.createElement("div");
+ contentDiv.setAttribute("id", child.id + "-content");
+ child.domContainer.appendChild(contentDiv);
+ contentDiv.style.position = "relative";
+ contentDiv.style.left = (child instanceof alfresco.xforms.Group
+ ? "0px"
+ : "30%");
+ if (!(child instanceof alfresco.xforms.Group))
+ {
+ contentDiv.style.width = (child.domContainer.offsetWidth * .55) + "px";
+ // contentDiv.style.width = ((child.domContainer.offsetWidth - contentDiv.offsetLeft) - 10) + "px";
+ }
+ child.render(contentDiv);
+ if (!(child instanceof alfresco.xforms.Group))
+ {
+ child.domContainer.style.height = Math.max(contentDiv.offsetHeight, 20) + "px";
+ child.domContainer.style.lineHeight = child.domContainer.style.height;
+ }
+ contentDiv.style.top = "-" + contentDiv.offsetTop + "px";
+ contentDiv.widget = child;
+
+ this._updateDisplay();
+ return child.domContainer;
+ },
+ removeChildAt: function(position)
+ {
+ var child = this.getChildAt(position);
+ if (!child)
+ throw new Error("unabled to find child at " + position);
+ this.children.splice(position, 1);
+ child.domContainer.group = this;
+ var anim = dojo.lfx.html.fadeOut(child.domContainer, 500);
+ anim.onEnd = function()
+ {
+ child.domContainer.style.display = "none";
+ dojo.dom.removeChildren(child.domContainer);
+ dojo.dom.removeNode(child.domContainer);
+ child.domContainer.group._updateDisplay();
+ };
+ anim.play();
+ },
+ isIndented: function()
+ {
+ return false && this.parent != null;
+ },
+ render: function(attach_point)
+ {
+ this.domNode = document.createElement("div");
+ this.domNode.setAttribute("id", this.id + "-domNode");
+ this.domNode.widget = this;
+ attach_point.appendChild(this.domNode);
+
+ this.domNode.setAttribute("style", "border: 0px solid blue;");
+ this.domNode.style.width = "100%";
+ if (this.isIndented())
+ this.domNode.style.marginLeft = "10px";
+ return this.domNode;
+ },
+ _updateDisplay: function()
+ {
+ for (var i = 0; i < this.children.length; i++)
+ {
+ this.children[i]._updateDisplay();
+ }
}
- return -1;
- },
- domNode: null,
- addChild: function(child)
- {
- return this.insertChildAt(child, this.children.length);
- },
- insertChildAt: function(child, position)
- {
- dojo.debug(this.id + ".insertChildAt(" + child.id + ", " + position + ")");
- child.parent = this;
-
- child.domContainer = document.createElement("div");
- child.domContainer.setAttribute("style", "position: relative; border: 0px solid green; margin-top: 2px; margin-bottom: 2px;");
- child.domContainer.style.width = "100%";
- if (this.parent && this.parent.domNode)
- child.domContainer.style.top = this.parent.domNode.style.bottom;
-
- if (position == this.children.length)
- {
- this.domNode.appendChild(child.domContainer);
- this.children.push(child);
- }
- else
- {
- this.domNode.insertBefore(child.domContainer,
- this.getChildAt(position).domContainer);
- this.children.splice(position, 0, child);
- }
-
- if (!(child instanceof alfresco.xforms.Group))
- {
- var requiredImage = document.createElement("img");
- requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
- requiredImage.setAttribute("style", "margin: 0px 5px 0px 5px;");
- child.domContainer.appendChild(requiredImage);
-
- if (!child.isRequired())
- requiredImage.style.visibility = "hidden";
- var label = child._getLabelNode();
- if (label)
- {
- var labelNode = document.createTextNode(dojo.dom.textContent(label));
- child.domContainer.appendChild(labelNode);
- }
- }
- var contentDiv = document.createElement("div");
- contentDiv.setAttribute("id", child.id + "-content");
- child.domContainer.appendChild(contentDiv);
- contentDiv.style.position = "relative";
- contentDiv.style.left = (child instanceof alfresco.xforms.Group
- ? "0px"
- : "30%");
- if (!(child instanceof alfresco.xforms.Group))
- {
- contentDiv.style.width = (child.domContainer.offsetWidth * .55) + "px";
- // contentDiv.style.width = ((child.domContainer.offsetWidth - contentDiv.offsetLeft) - 10) + "px";
- }
- child.render(contentDiv);
- if (!(child instanceof alfresco.xforms.Group))
- {
- child.domContainer.style.height = Math.max(contentDiv.offsetHeight, 20) + "px";
- child.domContainer.style.lineHeight = child.domContainer.style.height;
- }
- contentDiv.style.top = "-" + contentDiv.offsetTop + "px";
-
-
- this._updateDisplay();
- return child.domContainer;
- },
- removeChildAt: function(position)
- {
- var child = this.getChildAt(position);
- if (!child)
- throw new Error("unabled to find child at " + position);
- this.children.splice(position, 1);
- child.domContainer.group = this;
- var anim = dojo.lfx.html.fadeOut(child.domContainer, 500);
- anim.onEnd = function()
- {
- child.domContainer.style.display = "none";
- dojo.dom.removeChildren(child.domContainer);
- dojo.dom.removeNode(child.domContainer);
- child.domContainer.group._updateDisplay();
- };
- anim.play();
- },
- isIndented: function()
- {
- return false && this.parent != null;
- },
- render: function(attach_point)
- {
- this.domNode = document.createElement("div");
- this.domNode.setAttribute("id", this.id + "-domNode");
- this.domNode.widget = this;
- attach_point.appendChild(this.domNode);
-
- this.domNode.setAttribute("style", "border: 0px solid blue;");
- this.domNode.style.width = "100%";
- if (this.isIndented())
- this.domNode.style.marginLeft = "10px";
- return this.domNode;
- },
- _updateDisplay: function()
- {
- }
});
dojo.declare("alfresco.xforms.Repeat",
alfresco.xforms.Group,
{
- initializer: function(xform, node)
- {
- this.inherited("initializer", [ xform, node ]);
- },
- _selectedIndex: -1,
- insertChildAt: function(child, position)
- {
- var result = this.inherited("insertChildAt", [ child, position ]);
- child.repeat = this;
-
- dojo.event.connect(result, "onclick", function(event)
- {
- child.repeat.setFocusedChild(child);
- });
-
- var controls = document.createElement("div");
- result.appendChild(controls);
- controls.style.position = "absolute";
- controls.style.right = "5px";
- controls.style.bottom = "0px";
-
- var images = [
- { src: "plus", action: this._insertRepeatItemAfter_handler },
- { src: "arrow_up", action: this._moveRepeatItemUp_handler },
- { src: "arrow_down", action: this._moveRepeatItemDown_handler },
- { src: "minus", action: this._removeRepeatItem_handler }
- ];
- for (var i in images)
+ initializer: function(xform, node)
+ {
+ this.inherited("initializer", [ xform, node ]);
+ },
+ _selectedIndex: -1,
+ insertChildAt: function(child, position)
{
- var img = document.createElement("img");
- img.setAttribute("src", (WEBAPP_CONTEXT + "/images/icons/" +
- images[i].src + ".gif"));
- img.style.width = "16px";
- img.style.height = "16px";
- img.style.marginRight = "4px";
- img.repeatItem = child;
- img.repeat = this;
- controls.appendChild(img);
- dojo.event.connect(img, "onclick", this, images[i].action);
- }
-
- return result;
- },
- getSelectedIndex: function()
- {
- this._selectedIndex = Math.min(this.children.length - 1, this._selectedIndex);
- if (this.children.length == 0)
- this._selectedIndex = -1;
- return this._selectedIndex;
- },
- _updateDisplay: function()
- {
- for (var i = 0; i < this.children.length; i++)
+ var result = this.inherited("insertChildAt", [ child, position ]);
+ child.repeat = this;
+
+ dojo.event.connect(result, "onclick", function(event)
+ {
+ child.repeat.setFocusedChild(child);
+ });
+
+ var controls = document.createElement("div");
+ result.appendChild(controls);
+ controls.style.position = "absolute";
+ controls.style.right = "5px";
+ controls.style.bottom = "0px";
+
+ var images = [
+ { src: "plus", action: this._insertRepeatItemAfter_handler },
+ { src: "arrow_up", action: this._moveRepeatItemUp_handler },
+ { src: "arrow_down", action: this._moveRepeatItemDown_handler },
+ { src: "minus", action: this._removeRepeatItem_handler }
+ ];
+ for (var i in images)
+ {
+ var img = document.createElement("img");
+ img.setAttribute("src", (WEBAPP_CONTEXT + "/images/icons/" +
+ images[i].src + ".gif"));
+ img.style.width = "16px";
+ img.style.height = "16px";
+ img.style.marginRight = "4px";
+ img.repeatItem = child;
+ img.repeat = this;
+ controls.appendChild(img);
+ dojo.event.connect(img, "onclick", this, images[i].action);
+ }
+
+ return result;
+ },
+ getSelectedIndex: function()
{
- this.children[i].domContainer.style.backgroundColor =
- i % 2 ? "#f0f0ee" : "#ffffff";
- }
- },
- _insertRepeatItemAfter_handler: function(event)
- {
- dojo.event.browser.stopEvent(event);
- this.setFocusedChild(event.target.repeatItem);
- if (!this.insertRepeatItemAfterTrigger)
- this.insertRepeatItemAfterTrigger =
- _findElementById(this.node.parentNode, this.id + "-insert_after");
- this.xform.fireAction(this.insertRepeatItemAfterTrigger.getAttribute("id"));
- },
- _insertRepeatItemBefore_handler: function(event)
- {
- dojo.event.browser.stopEvent(event);
- this.setFocusedChild(event.target.repeatItem);
- if (!this.insertRepeatItemBeforeTrigger)
- this.insertRepeatItemBeforeTrigger =
- _findElementById(this.node.parentNode, this.id + "-insert_before");
- this.xform.fireAction(this.insertRepeatItemBeforeTrigger.getAttribute("id"));
- },
- _removeRepeatItem_handler: function(event)
- {
- dojo.event.browser.stopEvent(event);
- this.setFocusedChild(event.target.repeatItem);
- if (!this.removeRepeatItemTrigger)
- this.removeRepeatItemTrigger = _findElementById(this.node.parentNode,
- this.id + "-delete");
- this.xform.fireAction(this.removeRepeatItemTrigger.getAttribute("id"));
- },
- _moveRepeatItemUp_handler: function(event)
- {
- dojo.event.browser.stopEvent(event);
- var r = event.target.repeat;
- var index = r.getChildIndex(event.target.repeatItem);
- if (index == 0 || r.children.length == 1)
- return;
- event.target.repeat.swapChildren(index, index - 1);
- },
- _moveRepeatItemDown_handler: function(event)
- {
- dojo.event.browser.stopEvent(event);
- var r = event.target.repeat;
- var index = r.getChildIndex(event.target.repeatItem);
- if (index == r.children.length - 1 || r.children.length == 1)
- return;
- event.target.repeat.swapChildren(index, index + 1);
- },
- swapChildren: function(fromIndex, toIndex)
- {
- dojo.debug(this.id + ".swapChildren(" + fromIndex +
- ", " + toIndex + ")");
- var fromChild = this.getChildAt(fromIndex);
- var toChild = this.getChildAt(toIndex);
-// var toChildCoords = dojo.style.getAbsolutePosition(toChild.domContainer);
-// toChildCoords = [ toChildCoords.x, toChildCoords.y ];
-// alert("to coords [ " + toChildCoords[0] + ", " + toChildCoords[0] + "]");
-// var fromChildCoords = dojo.style.getAbsolutePosition(fromChild.domContainer);
-// fromChildCoords = [ fromChildCoords.x, fromChildCoords.y ];
-// alert("from coords [ " + fromChildCoords[0] + ", " + fromChildCoords[0] + "]");
-// dojo.lfx.html.slideTo(fromChild.domContainer, 5000, toChildCoords);
-// dojo.lfx.html.slideTo(toChild.domContainer, 5000, fromChildCoords);
-
-
- var swapNode = document.createElement("div");
-// dojo.dom.removeNode(toChild.domContainer);
-// dojo.dom.removeNode(fromChild.domContainer);
- this.domNode.replaceChild(swapNode, fromChild.domContainer);
- this.domNode.replaceChild(fromChild.domContainer, toChild.domContainer);
- this.domNode.replaceChild(toChild.domContainer, swapNode);
-
- this.children[fromIndex] = toChild;
- this.children[toIndex] = fromChild;
- this._selectedIndex = toIndex;
- this._updateDisplay();
- },
- setFocusedChild: function(child)
- {
- if (!child)
- this.xform.setRepeatIndex(this.id, 0);
- else
+ this._selectedIndex = Math.min(this.children.length - 1, this._selectedIndex);
+ if (this.children.length == 0)
+ this._selectedIndex = -1;
+ return this._selectedIndex;
+ },
+ _updateDisplay: function()
{
- var index = this.getChildIndex(child);
- if (index < 0)
- throw new Error("unable to find child " + child.id + " in " + this.id);
-
- // chiba thinks indexes are initialized to 1 so just
- // highlight the thing
- if (this.getSelectedIndex() == -1 && index == 0)
- this.handleIndexChanged(0);
- else
- // xforms repeat indexes are 1-based
- this.xform.setRepeatIndex(this.id, index + 1);
+ this.inherited("_updateDisplay", []);
+ for (var i = 0; i < this.children.length; i++)
+ {
+ this.children[i].domContainer.style.backgroundColor =
+ i % 2 ? "#f0f0ee" : "#ffffff";
+ }
+ },
+ _insertRepeatItemAfter_handler: function(event)
+ {
+ dojo.event.browser.stopEvent(event);
+ this.setFocusedChild(event.target.repeatItem);
+ if (!this.insertRepeatItemAfterTrigger)
+ this.insertRepeatItemAfterTrigger =
+ _findElementById(this.node.parentNode, this.id + "-insert_after");
+ this.xform.fireAction(this.insertRepeatItemAfterTrigger.getAttribute("id"));
+ },
+ _insertRepeatItemBefore_handler: function(event)
+ {
+ dojo.event.browser.stopEvent(event);
+ this.setFocusedChild(event.target.repeatItem);
+ if (!this.insertRepeatItemBeforeTrigger)
+ this.insertRepeatItemBeforeTrigger =
+ _findElementById(this.node.parentNode, this.id + "-insert_before");
+ this.xform.fireAction(this.insertRepeatItemBeforeTrigger.getAttribute("id"));
+ },
+ _removeRepeatItem_handler: function(event)
+ {
+ dojo.event.browser.stopEvent(event);
+ this.setFocusedChild(event.target.repeatItem);
+ if (!this.removeRepeatItemTrigger)
+ this.removeRepeatItemTrigger = _findElementById(this.node.parentNode,
+ this.id + "-delete");
+ this.xform.fireAction(this.removeRepeatItemTrigger.getAttribute("id"));
+ },
+ _moveRepeatItemUp_handler: function(event)
+ {
+ dojo.event.browser.stopEvent(event);
+ var r = event.target.repeat;
+ var index = r.getChildIndex(event.target.repeatItem);
+ if (index == 0 || r.children.length == 1)
+ return;
+ event.target.repeat.swapChildren(index, index - 1);
+ },
+ _moveRepeatItemDown_handler: function(event)
+ {
+ dojo.event.browser.stopEvent(event);
+ var r = event.target.repeat;
+ var index = r.getChildIndex(event.target.repeatItem);
+ if (index == r.children.length - 1 || r.children.length == 1)
+ return;
+ event.target.repeat.swapChildren(index, index + 1);
+ },
+ swapChildren: function(fromIndex, toIndex)
+ {
+ dojo.debug(this.id + ".swapChildren(" + fromIndex +
+ ", " + toIndex + ")");
+ var fromChild = this.getChildAt(fromIndex);
+ var toChild = this.getChildAt(toIndex);
+// var toChildCoords = dojo.style.getAbsolutePosition(toChild.domContainer);
+// toChildCoords = [ toChildCoords.x, toChildCoords.y ];
+// alert("to coords [ " + toChildCoords[0] + ", " + toChildCoords[0] + "]");
+// var fromChildCoords = dojo.style.getAbsolutePosition(fromChild.domContainer);
+// fromChildCoords = [ fromChildCoords.x, fromChildCoords.y ];
+// alert("from coords [ " + fromChildCoords[0] + ", " + fromChildCoords[0] + "]");
+// dojo.lfx.html.slideTo(fromChild.domContainer, 5000, toChildCoords);
+// dojo.lfx.html.slideTo(toChild.domContainer, 5000, fromChildCoords);
+
+
+ var swapNode = document.createElement("div");
+// dojo.dom.removeNode(toChild.domContainer);
+// dojo.dom.removeNode(fromChild.domContainer);
+ this.domNode.replaceChild(swapNode, fromChild.domContainer);
+ this.domNode.replaceChild(fromChild.domContainer, toChild.domContainer);
+ this.domNode.replaceChild(toChild.domContainer, swapNode);
+
+ this.children[fromIndex] = toChild;
+ this.children[toIndex] = fromChild;
+ this._selectedIndex = toIndex;
+ this._updateDisplay();
+ },
+ setFocusedChild: function(child)
+ {
+ if (!child)
+ this.xform.setRepeatIndex(this.id, 0);
+ else
+ {
+ var index = this.getChildIndex(child);
+ if (index < 0)
+ throw new Error("unable to find child " + child.id + " in " + this.id);
+
+ // chiba thinks indexes are initialized to 1 so just
+ // highlight the thing
+ if (this.getSelectedIndex() == -1 && index == 0)
+ this.handleIndexChanged(0);
+ else
+ // xforms repeat indexes are 1-based
+ this.xform.setRepeatIndex(this.id, index + 1);
+ }
+ },
+ isIndented: function()
+ {
+ return false;
+ },
+ render: function(attach_point)
+ {
+ this.domNode = this.inherited("render", [ attach_point ]);
+ this.domNode.style.borderColor = "black";
+ this.domNode.style.borderWidth = "1px";
+
+ var d = document.createElement("div");
+ d.repeat = this;
+ this.domNode.appendChild(d);
+ d.setAttribute("style", "position: relative; height: 20px; line-height: 20px; background-color: #cddbe8; font-weight: bold;");
+ d.style.width = "100%";
+ dojo.event.connect(d, "onclick", function(event)
+ {
+ if (event.target == event.currentTarget)
+ event.currentTarget.repeat.setFocusedChild(null);
+ });
+
+ //used only for positioning the label accurately
+ var requiredImage = document.createElement("img");
+ requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
+ requiredImage.setAttribute("style", "margin: 0px 5px 0px 5px;");
+ d.appendChild(requiredImage);
+// requiredImage.style.position = "relative";
+// requiredImage.style.top = "0px";
+// requiredImage.style.left = "0px";
+ requiredImage.style.visibility = "hidden";
+
+ var labelElement = document.createTextNode(this.parent.getLabel());//document.createElement("span");
+ d.appendChild(labelElement);
+
+ var addElement = document.createElement("img");
+ d.appendChild(addElement);
+ addElement.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/plus.gif");
+ addElement.style.width = "16px";
+ addElement.style.height = "16px";
+ addElement.style.position = "absolute";
+ addElement.style.top = "0px";
+ addElement.style.right = 5 + (16 * 4) + "px";
+
+ dojo.event.connect(addElement, "onclick", this, this._insertRepeatItemBefore_handler);
+
+ return this.domNode;
+ },
+ handleIndexChanged: function(index)
+ {
+ dojo.debug(this.id + ".handleIndexChanged(" + index + ")");
+ this._selectedIndex = index;
+ this._updateDisplay();
+ },
+ handlePrototypeCloned: function(prototypeId)
+ {
+ dojo.debug(this.id + ".handlePrototypeCloned("+ prototypeId +")");
+ var chibaData = this.node.getElementsByTagName("data");
+ dojo.debug("repeat node == " +dojo.dom.innerXML(this.node));
+ dojo.debug(chibaData + " l = " + chibaData.length);
+ chibaData = chibaData[chibaData.length - 1];
+ dojo.debug("chiba:data == " + dojo.dom.innerXML(chibaData));
+ var prototypeToClone = dojo.dom.firstElement(chibaData);
+ if (prototypeToClone.getAttribute("id") != prototypeId)
+ throw new Error("unable to locate " + prototypeId +
+ " in " + this.id);
+ return prototypeToClone.cloneNode(true);
+ },
+ handleItemInserted: function(clonedPrototype, position)
+ {
+ dojo.debug(this.id + ".handleItemInserted(" + clonedPrototype.nodeName +
+ ", " + position + ")");
+ var w = this.xform.createWidget(clonedPrototype);
+ this.insertChildAt(w, position);
+ this.xform.loadWidgets(w.node, w);
+ },
+ handleItemDeleted: function(position)
+ {
+ dojo.debug(this.id + ".handleItemDeleted(" + position + ")");
+ this.removeChildAt(position);
}
- },
- isIndented: function()
- {
- return false;
- },
- render: function(attach_point)
- {
- this.domNode = this.inherited("render", [ attach_point ]);
- this.domNode.style.borderColor = "black";
- this.domNode.style.borderWidth = "1px";
-
- var d = document.createElement("div");
- d.repeat = this;
- this.domNode.appendChild(d);
- d.setAttribute("style", "position: relative; height: 20px; line-height: 20px; background-color: #cddbe8; font-weight: bold;");
- d.style.width = "100%";
- dojo.event.connect(d, "onclick", function(event)
- {
- if (event.target == event.currentTarget)
- event.currentTarget.repeat.setFocusedChild(null);
- });
-
- //used only for positioning the label accurately
- var requiredImage = document.createElement("img");
- requiredImage.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/required_field.gif");
- requiredImage.setAttribute("style", "margin: 0px 5px 0px 5px;");
- d.appendChild(requiredImage);
-// requiredImage.style.position = "relative";
-// requiredImage.style.top = "0px";
-// requiredImage.style.left = "0px";
- requiredImage.style.visibility = "hidden";
-
- var labelElement = document.createTextNode(this.parent.getLabel());//document.createElement("span");
- d.appendChild(labelElement);
-
- var addElement = document.createElement("img");
- d.appendChild(addElement);
- addElement.setAttribute("src", WEBAPP_CONTEXT + "/images/icons/plus.gif");
- addElement.style.width = "16px";
- addElement.style.height = "16px";
- addElement.style.position = "absolute";
- addElement.style.top = "0px";
- addElement.style.right = 5 + (16 * 4) + "px";
-
- dojo.event.connect(addElement, "onclick", this, this._insertRepeatItemBefore_handler);
-
- return this.domNode;
- },
- handleIndexChanged: function(index)
- {
- dojo.debug(this.id + ".handleIndexChanged(" + index + ")");
- this._selectedIndex = index;
- this._updateDisplay();
- },
- handlePrototypeCloned: function(prototypeId)
- {
- dojo.debug(this.id + ".handlePrototypeCloned("+ prototypeId +")");
- var chibaData = this.node.getElementsByTagName("data");
- dojo.debug("repeat node == " +dojo.dom.innerXML(this.node));
- dojo.debug(chibaData + " l = " + chibaData.length);
- chibaData = chibaData[chibaData.length - 1];
- dojo.debug("chiba:data == " + dojo.dom.innerXML(chibaData));
- var prototypeToClone = dojo.dom.firstElement(chibaData);
- if (prototypeToClone.getAttribute("id") != prototypeId)
- throw new Error("unable to locate " + prototypeId +
- " in " + this.id);
- return prototypeToClone.cloneNode(true);
- },
- handleItemInserted: function(clonedPrototype, position)
- {
- dojo.debug(this.id + ".handleItemInserted(" + clonedPrototype.nodeName +
- ", " + position + ")");
- var w = this.xform.createWidget(clonedPrototype);
- this.insertChildAt(w, position);
- this.xform.loadWidgets(w.node, w);
- },
- handleItemDeleted: function(position)
- {
- dojo.debug(this.id + ".handleItemDeleted(" + position + ")");
- this.removeChildAt(position);
- }
});
dojo.declare("alfresco.xforms.Trigger",
alfresco.xforms.Widget,
{
- initializer: function(xform, node)
- {
- this.inherited("initializer", [ xform, node ]);
- },
- render: function(attach_point)
- {
- var nodeRef = document.createElement("div");
- attach_point.appendChild(nodeRef);
- this.widget = dojo.widget.createWidget("Button",
- {
- widgetId: this.id + "-widget",
- caption: this.getLabel() + " " + this.id
- },
- nodeRef);
- dojo.event.connect(this.widget, "onClick", this, this._clickHandler);
- this.domContainer.style.display = "none";
- },
- _clickHandler: function(event)
- {
- this.xform.fireAction(this.id);
- }
+ initializer: function(xform, node)
+ {
+ this.inherited("initializer", [ xform, node ]);
+ },
+ render: function(attach_point)
+ {
+ var nodeRef = document.createElement("div");
+ attach_point.appendChild(nodeRef);
+ this.widget = dojo.widget.createWidget("Button",
+ {
+ widgetId: this.id + "-widget",
+ caption: this.getLabel() + " " + this.id
+ },
+ nodeRef);
+ dojo.event.connect(this.widget, "onClick", this, this._clickHandler);
+ this.domContainer.style.display = "none";
+ },
+ _clickHandler: function(event)
+ {
+ this.xform.fireAction(this.id);
+ }
});
dojo.declare("alfresco.xforms.Submit",
alfresco.xforms.Trigger,
{
- initializer: function(xform, node)
- {
- this.inherited("initializer", [ xform, node ]);
- },
- render: function(attach_point)
- {
- this.inherited("render", [ attach_point ]);
- document.submitWidget = this;
- },
- _clickHandler: function(event)
- {
- document.submitWidget.done = false;
- this.xform.fireAction(this.id);
- }
+ initializer: function(xform, node)
+ {
+ this.inherited("initializer", [ xform, node ]);
+ },
+ render: function(attach_point)
+ {
+ this.inherited("render", [ attach_point ]);
+ document.submitWidget = this;
+ },
+ _clickHandler: function(event)
+ {
+ document.submitWidget.done = false;
+ this.xform.fireAction(this.id);
+ }
});
dojo.declare("alfresco.xforms.XFormsEvent",
null,
{
- 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++)
+ 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++)
+ {
+ if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
+ this.properties[node.childNodes[i].getAttribute("name")] =
+ node.childNodes[i].getAttribute("value");
+ }
+ },
+ getTarget: function()
{
- if (node.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
- this.properties[node.childNodes[i].getAttribute("name")] =
- node.childNodes[i].getAttribute("value");
+ var targetDomNode = document.getElementById(this.targetId + "-content");
+ if (!targetDomNode)
+ throw new Error("unable to find node " + this.targetId + "-content");
+ return targetDomNode.widget;
}
- },
- getTarget: function()
- {
- var targetDomNode = document.getElementById(this.targetId + "-domNode");
- if (!targetDomNode)
- throw new Error("unable to find node " + this.targetId + "-domNode");
- return targetDomNode.widget;
- }
});
dojo.declare("alfresco.xforms.XForm",
null,
{
- initializer: function()
- {
- send_ajax_request(create_ajax_request(this,
- "getXForm",
- {},
- function(type, data, evt)
- {
- this.xform._loadHandler(data);
- }));
- },
- _loadHandler: function(xformDocument)
- {
- this.xformDocument = xformDocument;
- this.node = xformDocument.documentElement;
- this._bindings = this._loadBindings(this.getModel());
-
- var bindings = this.getBindings();
- for (var i in bindings)
- {
- dojo.debug("bindings[" + i + "]=" + bindings[i].id +
- ", parent = " + (bindings[i].parent
- ? bindings[i].parent.id
- : 'null'));
- }
- var alfUI = document.getElementById("alf-ui");
- alfUI.style.width = "100%";
-
- var root = new alfresco.xforms.Group(this, alfUI);
- root.render(alfUI);
- this.loadWidgets(this.getBody(), root);
- },
- createWidget: function(node)
- {
- switch (node.nodeName.toLowerCase())
- {
- case "xforms:group":
- return new alfresco.xforms.Group(this, node);
- case "xforms:repeat":
- return new alfresco.xforms.Repeat(this, node);
- case "xforms:textarea":
- return new alfresco.xforms.TextArea(this, node);
- case "xforms:input":
- var type = this.getType(node);
- switch (type)
- {
- case "date":
- return new alfresco.xforms.DatePicker(this, node);
- case "byte":
- case "double":
- case "float":
- case "int":
- case "integer":
- case "long":
- case "negativeInteger":
- case "nonNegativeInteger":
- case "nonPositiveInteger":
- case "short":
- case "unsignedByte":
- case "unsignedInt":
- case "unsignedLong":
- case "unsignedShort":
- case "positiveInteger":
- return new alfresco.xforms.NumericStepper(this, node, type);
- case "string":
- default:
- return new alfresco.xforms.TextField(this, node);
- }
- case "xforms:select":
- return new alfresco.xforms.Select(this, node);
- case "xforms:select1":
- return (this.getType(node) == "boolean"
- ? new alfresco.xforms.Checkbox(this, node)
- : new alfresco.xforms.Select1(this, node));
- case "xforms:submit":
- return new alfresco.xforms.Submit(this, node);
- case "xforms:trigger":
- return new alfresco.xforms.Trigger(this, node);
- case "chiba:data":
- case "xforms:label":
- case "xforms:alert":
- return null;
- default:
- throw new Error("unknown type " + node.nodeName);
- }
- },
- loadWidgets: function(modelNode, parentWidget)
- {
- for (var i = 0; i < modelNode.childNodes.length; i++)
+ initializer: function()
{
- if (modelNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
+ send_ajax_request(create_ajax_request(this,
+ "getXForm",
+ {},
+ function(type, data, evt)
+ {
+ this.xform._loadHandler(data);
+ }));
+ },
+ _loadHandler: function(xformDocument)
+ {
+ this.xformDocument = xformDocument;
+ this.node = xformDocument.documentElement;
+ this._bindings = this._loadBindings(this.getModel());
+
+ var bindings = this.getBindings();
+ for (var i in bindings)
+ {
+ dojo.debug("bindings[" + i + "]=" + bindings[i].id +
+ ", parent = " + (bindings[i].parent
+ ? bindings[i].parent.id
+ : 'null'));
+ }
+ var alfUI = document.getElementById("alf-ui");
+ alfUI.style.width = "100%";
+
+ this.rootWidget = new alfresco.xforms.Group(this, alfUI);
+ this.rootWidget.render(alfUI);
+ this.loadWidgets(this.getBody(), this.rootWidget);
+ this.rootWidget._updateDisplay();
+ },
+ createWidget: function(node)
+ {
+ switch (node.nodeName.toLowerCase())
+ {
+ case "xforms:group":
+ return new alfresco.xforms.Group(this, node);
+ case "xforms:repeat":
+ return new alfresco.xforms.Repeat(this, node);
+ case "xforms:textarea":
+ return new alfresco.xforms.TextArea(this, node);
+ case "xforms:input":
+ var type = this.getType(node);
+ switch (type)
+ {
+ case "date":
+ return new alfresco.xforms.DatePicker(this, node);
+ case "byte":
+ case "double":
+ case "float":
+ case "int":
+ case "integer":
+ case "long":
+ case "negativeInteger":
+ case "nonNegativeInteger":
+ case "nonPositiveInteger":
+ case "short":
+ case "unsignedByte":
+ case "unsignedInt":
+ case "unsignedLong":
+ case "unsignedShort":
+ case "positiveInteger":
+ case "string":
+ default:
+ return new alfresco.xforms.TextField(this, node);
+ }
+ case "xforms:select":
+ return new alfresco.xforms.Select(this, node);
+ case "xforms:select1":
+ return (this.getType(node) == "boolean"
+ ? new alfresco.xforms.Checkbox(this, node)
+ : new alfresco.xforms.Select1(this, node));
+ case "xforms:submit":
+ return new alfresco.xforms.Submit(this, node);
+ case "xforms:trigger":
+ return new alfresco.xforms.Trigger(this, node);
+ case "chiba:data":
+ case "xforms:label":
+ case "xforms:alert":
+ return null;
+ default:
+ throw new Error("unknown type " + node.nodeName);
+ }
+ },
+ loadWidgets: function(modelNode, parentWidget)
+ {
+ for (var i = 0; i < modelNode.childNodes.length; i++)
{
- dojo.debug("loading " + modelNode.childNodes[i] +
- " nodeName " + modelNode.childNodes[i].nodeName +
- " into " + parentWidget);
- var w = this.createWidget(modelNode.childNodes[i]);
- if (w != null)
- {
- parentWidget.addChild(w);
- if (w instanceof alfresco.xforms.Group)
- this.loadWidgets(modelNode.childNodes[i], w);
+ if (modelNode.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
+ {
+ dojo.debug("loading " + modelNode.childNodes[i] +
+ " nodeName " + modelNode.childNodes[i].nodeName +
+ " into " + parentWidget);
+ var w = this.createWidget(modelNode.childNodes[i]);
+ if (w != null)
+ {
+ parentWidget.addChild(w);
+ if (w instanceof alfresco.xforms.Group)
+ this.loadWidgets(modelNode.childNodes[i], w);
+ }
}
}
- }
- },
- getModel: function()
- {
- return this.node.getElementsByTagName("model")[0];
- },
- getInstance: function()
- {
- var model = this.getModel();
- return model.getElementsByTagName("instance")[0];
- },
- getBody: function()
- {
- var b = this.node.getElementsByTagName("body");
- return b[b.length - 1];
- },
- getType: function(node)
- {
- return this.getBinding(node).type;
- },
- getBinding: function(node)
- {
- return this._bindings[node.getAttribute("xforms:bind")];
- },
- getBindings: function()
- {
- return this._bindings;
- },
- _loadBindings: function(bind, parent, result)
- {
- result = result || [];
- dojo.debug("loading bindings for " + bind.nodeName);
- for (var i = 0; i < bind.childNodes.length; i++)
+ },
+ getModel: function()
{
- if (bind.childNodes[i].nodeName.toLowerCase() == "xforms:bind")
- {
- var id = bind.childNodes[i].getAttribute("id");
- dojo.debug("loading binding " + id);
- result[id] = {
- id: bind.childNodes[i].getAttribute("id"),
- required: bind.childNodes[i].getAttribute("xforms:required"),
- nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"),
- type: bind.childNodes[i].getAttribute("xforms:type"),
- constraint: bind.childNodes[i].getAttribute("xforms:constraint"),
- parent: parent
- };
- this._loadBindings(bind.childNodes[i], result[id], result);
- }
- }
- return result;
- },
- setRepeatIndex: function(id, index)
- {
- dojo.debug("setting repeat index " + index + " on " + id);
- var req = create_ajax_request(this,
- "setRepeatIndex",
- { id: id, index: index },
- function(type, data, evt)
- {
- this.xform._handleEventLog(data.documentElement);
- });
- send_ajax_request(req);
- },
- fireAction: function(id)
- {
- var req = create_ajax_request(this,
- "fireAction",
- { id: id },
- function(type, data, evt)
- {
- dojo.debug("fireAction." + type);
- this.xform._handleEventLog(data.documentElement);
- });
- send_ajax_request(req);
- },
- setXFormsValue: function(id, value)
- {
- dojo.debug("setting value " + id + " = " + value);
- var req = create_ajax_request(this,
- "setXFormsValue",
- { id: id, value: value },
- function(type, data, evt)
- {
- this.xform._handleEventLog(data.documentElement);
- });
- send_ajax_request(req);
- },
- _handleEventLog: function(events)
- {
- var prototypeClones = [];
- for (var i = 0; i < events.childNodes.length; i++)
+ return this.node.getElementsByTagName("model")[0];
+ },
+ getInstance: function()
{
- if (events.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
- {
- var xfe = new alfresco.xforms.XFormsEvent(events.childNodes[i]);
- dojo.debug("parsing " + xfe.type +
- "(" + xfe.targetId + ", " + xfe.targetName + ")");
- switch (xfe.type)
- {
- case "chiba-index-changed":
- {
- var index = Number(xfe.properties["index"]) - 1;
- xfe.getTarget().handleIndexChanged(index);
- break;
- }
- case "chiba-prototype-cloned":
- {
- var prototypeId = xfe.properties["prototypeId"];
- var clone = xfe.getTarget().handlePrototypeCloned(prototypeId);
- prototypeClones.push(clone);
- break;
- }
- case "chiba-id-generated":
- {
- var originalId = xfe.properties["originalId"];
-
- dojo.debug("handleIdGenerated(" + xfe.targetId + ", " + originalId + ")");
- var clone = prototypeClones[prototypeClones.length - 1];
- var node = _findElementById(clone, originalId);
- if (node)
- {
- dojo.debug("applying id " + xfe.targetId +
- " to " + node.nodeName + "(" + originalId + ")");
- node.setAttribute("id", xfe.targetId);
- }
- else
- throw new Error("unable to find " + originalId +
- " in clone " + dojo.dom.innerXML(clone));
- break;
- }
- case "chiba-item-inserted":
- {
- var position = Number(xfe.properties["position"]) - 1;
-
- var clone = prototypeClones.pop();
- xfe.getTarget().handleItemInserted(clone, position);
- break;
- }
- case "chiba-item-deleted":
- {
- var position = Number(xfe.properties["position"]) - 1;
- xfe.getTarget().handleItemDeleted(position);
- break;
- }
- case "chiba-replace-all":
- if (document.submitWidget)
- {
- document.submitWidget.done = true;
- document.submitWidget.currentButton.click();
- document.submitWidget.currentButton = null;
- }
- break;
- case "xforms-submit-error":
- _show_error("Please provide values for all required fields.");
- break;
- default:
- {
- dojo.debug("unhandled event " + events.childNodes[i].nodeName);
- }
- }
- }
+ var model = this.getModel();
+ return model.getElementsByTagName("instance")[0];
+ },
+ getBody: function()
+ {
+ var b = this.node.getElementsByTagName("body");
+ return b[b.length - 1];
+ },
+ getType: function(node)
+ {
+ return this.getBinding(node).type;
+ },
+ getBinding: function(node)
+ {
+ return this._bindings[node.getAttribute("xforms:bind")];
+ },
+ getBindings: function()
+ {
+ return this._bindings;
+ },
+ _loadBindings: function(bind, parent, result)
+ {
+ result = result || [];
+ dojo.debug("loading bindings for " + bind.nodeName);
+ for (var i = 0; i < bind.childNodes.length; i++)
+ {
+ if (bind.childNodes[i].nodeName.toLowerCase() == "xforms:bind")
+ {
+ var id = bind.childNodes[i].getAttribute("id");
+ dojo.debug("loading binding " + id);
+ result[id] = {
+ id: bind.childNodes[i].getAttribute("id"),
+ required: bind.childNodes[i].getAttribute("xforms:required"),
+ nodeset: bind.childNodes[i].getAttribute("xforms:nodeset"),
+ type: bind.childNodes[i].getAttribute("xforms:type"),
+ constraint: bind.childNodes[i].getAttribute("xforms:constraint"),
+ parent: parent
+ };
+ this._loadBindings(bind.childNodes[i], result[id], result);
+ }
+ }
+ return result;
+ },
+ setRepeatIndex: function(id, index)
+ {
+ dojo.debug("setting repeat index " + index + " on " + id);
+ var req = create_ajax_request(this,
+ "setRepeatIndex",
+ { id: id, index: index },
+ function(type, data, evt)
+ {
+ this.xform._handleEventLog(data.documentElement);
+ });
+ send_ajax_request(req);
+ },
+ fireAction: function(id)
+ {
+ var req = create_ajax_request(this,
+ "fireAction",
+ { id: id },
+ function(type, data, evt)
+ {
+ dojo.debug("fireAction." + type);
+ this.xform._handleEventLog(data.documentElement);
+ });
+ send_ajax_request(req);
+ },
+ setXFormsValue: function(id, value)
+ {
+ value = value == null ? "" : value;
+ dojo.debug("setting value " + id + " = " + value);
+ var req = create_ajax_request(this,
+ "setXFormsValue",
+ { id: id, value: value },
+ function(type, data, evt)
+ {
+ this.xform._handleEventLog(data.documentElement);
+ });
+ send_ajax_request(req);
+ },
+ _handleEventLog: function(events)
+ {
+ var prototypeClones = [];
+ for (var i = 0; i < events.childNodes.length; i++)
+ {
+ if (events.childNodes[i].nodeType == dojo.dom.ELEMENT_NODE)
+ {
+ var xfe = new alfresco.xforms.XFormsEvent(events.childNodes[i]);
+ dojo.debug("parsing " + xfe.type +
+ "(" + xfe.targetId + ", " + xfe.targetName + ")");
+ switch (xfe.type)
+ {
+ case "chiba-index-changed":
+ {
+ var index = Number(xfe.properties["index"]) - 1;
+ xfe.getTarget().handleIndexChanged(index);
+ break;
+ }
+ case "chiba-state-changed":
+ {
+ var valid = xfe.properties["valid"] == "true";
+ xfe.getTarget().setValid(valid);
+ xfe.getTarget().setModified(true);
+ break;
+ }
+ case "chiba-prototype-cloned":
+ {
+ var prototypeId = xfe.properties["prototypeId"];
+ var clone = xfe.getTarget().handlePrototypeCloned(prototypeId);
+ prototypeClones.push(clone);
+ break;
+ }
+ case "chiba-id-generated":
+ {
+ var originalId = xfe.properties["originalId"];
+
+ dojo.debug("handleIdGenerated(" + xfe.targetId + ", " + originalId + ")");
+ var clone = prototypeClones[prototypeClones.length - 1];
+ var node = _findElementById(clone, originalId);
+ if (node)
+ {
+ dojo.debug("applying id " + xfe.targetId +
+ " to " + node.nodeName + "(" + originalId + ")");
+ node.setAttribute("id", xfe.targetId);
+ }
+ else
+ throw new Error("unable to find " + originalId +
+ " in clone " + dojo.dom.innerXML(clone));
+ break;
+ }
+ case "chiba-item-inserted":
+ {
+ var position = Number(xfe.properties["position"]) - 1;
+
+ var clone = prototypeClones.pop();
+ xfe.getTarget().handleItemInserted(clone, position);
+ break;
+ }
+ case "chiba-item-deleted":
+ {
+ var position = Number(xfe.properties["position"]) - 1;
+ xfe.getTarget().handleItemDeleted(position);
+ break;
+ }
+ case "chiba-replace-all":
+ if (document.submitWidget)
+ {
+ document.submitWidget.done = true;
+ document.submitWidget.currentButton.click();
+ document.submitWidget.currentButton = null;
+ }
+ break;
+ case "xforms-valid":
+ xfe.getTarget().setValid(true);
+ xfe.getTarget().setModified(true);
+ break;
+ case "xforms-invalid":
+ xfe.getTarget().setValid(false);
+ xfe.getTarget().setModified(true);
+ break;
+ case "xforms-required":
+ xfe.getTarget().setRequired(true);
+ break;
+ case "xforms-optional":
+ xfe.getTarget().setRequired(false);
+ break;
+ case "xforms-submit-error":
+ var invalid = this.rootWidget.getWidgetsInvalidForSubmit();
+ var msg = "Please provide values for all required fields.";
+ msg += "
";
+ for (var j = 0; j < invalid.length; j++)
+ {
+ msg += "- " + invalid[j].getLabel() + "
";
+ }
+ msg += "
";
+ _show_error(msg);
+ break;
+ default:
+ {
+ dojo.debug("unhandled event " + events.childNodes[i].nodeName);
+ }
+ }
+ }
+ }
}
- }
});
function addSubmitHandlerToButton(b)
@@ -1174,6 +1230,7 @@ function addSubmitHandlerToButton(b)
{
dojo.debug("not done, resubmitting");
tinyMCE.triggerSave();
+ _hide_errors();
document.submitWidget.currentButton = this;
document.submitWidget.widget.buttonClick();
return false;
@@ -1247,7 +1304,7 @@ function _show_error(msg)
dojo.dom.prependChild(errorDiv, alfUI);
}
if (errorDiv.style.display == "block")
- errorDiv.innerHTML = errorDiv.innerHTML + "
" + e.message;
+ errorDiv.innerHTML = errorDiv.innerHTML + "
" + msg;
else
{
errorDiv.innerHTML = msg;
@@ -1318,4 +1375,4 @@ function ajax_request_load_handler(req)
else
throw new Error("unable to find " + req.url);
ajax_loader_update_display();
-}
\ No newline at end of file
+}