diff --git a/project-build.xml b/project-build.xml index 53cfc3ebcf..018cf18960 100644 --- a/project-build.xml +++ b/project-build.xml @@ -48,7 +48,7 @@ - + diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java index c3b9de73a9..bb91852771 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java @@ -75,12 +75,6 @@ public class Schema2XForms private static final String PROPERTY_PREFIX = "http://www.chiba.org/properties/schemaFormBuilder/"; - /** - * Property to control the cascading style sheet used for the XForm - corresponds to envelope@chiba:css-style. - */ - public static final String CSS_STYLE_PROP = - PROPERTY_PREFIX + "envelope@css-style"; - private static final String DEFAULT_CSS_STYLE_PROP = "style.css"; /** * Property to control the selection of UI control for a selectOne control. @@ -379,7 +373,6 @@ public class Schema2XForms public void reset() { this.counter.clear(); - setProperty(CSS_STYLE_PROP, DEFAULT_CSS_STYLE_PROP); setProperty(SELECTMANY_LONG_LIST_SIZE_PROP, DEFAULT_LONG_LIST_MAX_SIZE); setProperty(SELECTMANY_UI_CONTROL_SHORT_PROP, DEFAULT_SELECTMANY_UI_CONTROL_SHORT_PROP); @@ -612,12 +605,19 @@ public class Schema2XForms final Map result = new HashMap(); for (XSTypeDefinition type : choiceValues) { - String textValue = type.getName(); - + final String textValue = type.getName(); + if (LOGGER.isDebugEnabled()) { LOGGER.debug("addChoicesForSelectSwitchControl, processing " + textValue); } + + //build the case element + final Element caseElement = xForm.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":case"); + final String caseId = this.setXFormsId(caseElement); + result.put(textValue, caseElement); + final Element item = this.createXFormsItem(xForm, this.createCaption(textValue), textValue); @@ -637,12 +637,6 @@ public class Schema2XForms NamespaceConstants.XFORMS_PREFIX + ":toggle"); this.setXFormsId(toggle); - //build the case element - final Element caseElement = xForm.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":case"); - final String caseId = this.setXFormsId(caseElement); - result.put(textValue, caseElement); - toggle.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":case", caseId); @@ -2234,41 +2228,66 @@ public class Schema2XForms String caption, XSSimpleTypeDefinition controlType) { - Element control; + LOGGER.debug("creating a control for atomic type {name: " + controlType.getName() + + ", numeric: " + controlType.getNumeric() + + ", bounded: " + controlType.getBounded() + + ", finite: " + controlType.getFinite() + + ", ordered: " + controlType.getOrdered() + + ", final: " + controlType.getFinal() + + ", minInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE) + + ", maxInc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE) + + ", minExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE) + + ", maxExc: " + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE) + + ", builtInTypeName: " + SchemaUtil.getBuiltInTypeName(controlType) + + "}"); + Element result = null; if ("boolean".equals(controlType.getName())) { - control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":select1"); - this.setXFormsId(control); + result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":select1"); final String[] values = { "true", "false" }; for (String v : values) { final Element item = this.createXFormsItem(xformsDocument, v, v); - control.appendChild(item); + result.appendChild(item); } } else if ("anyURI".equals(controlType.getName())) { - control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":upload"); + result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":upload"); final Element e = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":filename"); - control.appendChild(e); + NamespaceConstants.XFORMS_PREFIX + ":filename"); + this.setXFormsId(e); + result.appendChild(e); e.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":ref", "."); - this.setXFormsId(control); + } + else if (controlType.getBounded() && + controlType.getNumeric() && + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE) != null && + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE) != null) + { + result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":range"); + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":start", + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE)); + result.setAttributeNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":end", + controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE)); } else { - control = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":input"); - this.setXFormsId(control); + result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, + NamespaceConstants.XFORMS_PREFIX + ":input"); } + this.setXFormsId(result); + result.appendChild(this.createLabel(xformsDocument, caption)); - control.appendChild(this.createLabel(xformsDocument, caption)); - - return control; + return result; } /** @@ -2441,7 +2460,7 @@ public class Schema2XForms ? getProperty(SELECTMANY_UI_CONTROL_SHORT_PROP) : getProperty(SELECTMANY_UI_CONTROL_LONG_PROP))); Element choices = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, - NamespaceConstants.XFORMS_PREFIX + ":choices"); + NamespaceConstants.XFORMS_PREFIX + ":choices"); this.setXFormsId(choices); control.appendChild(choices); diff --git a/source/test-resources/xforms/unit-tests/simple-test/components-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/components-test.xsd index 097f423710..5b21d53597 100644 --- a/source/test-resources/xforms/unit-tests/simple-test/components-test.xsd +++ b/source/test-resources/xforms/unit-tests/simple-test/components-test.xsd @@ -94,8 +94,24 @@ + + + + + + + + + + + + + + + + diff --git a/source/test-resources/xforms/unit-tests/simple-test/range-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/range-test.xsd new file mode 100644 index 0000000000..6d00c3383e --- /dev/null +++ b/source/test-resources/xforms/unit-tests/simple-test/range-test.xsd @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index cf5fd52e71..80ea061780 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -28,11 +28,13 @@ // // Initiliaze dojo requirements, tinymce, and add a hook to load the xform. //////////////////////////////////////////////////////////////////////////////// -dojo.require("dojo.date"); +dojo.require("dojo.debug.console"); +dojo.require("dojo.date.common"); dojo.require("dojo.widget.DebugConsole"); dojo.require("dojo.widget.DatePicker"); dojo.require("dojo.widget.TimePicker"); dojo.require("dojo.widget.Button"); +dojo.require("dojo.widget.Slider"); dojo.require("dojo.lfx.html"); dojo.hostenv.writeIncludes(); @@ -88,30 +90,29 @@ alfresco_xforms_constants.COLLAPSED_IMAGE.src = */ dojo.declare("alfresco.xforms.Widget", null, + function(xform, xformsNode) { - initializer: function(xform, xformsNode) + this.xform = xform; + this.xformsNode = xformsNode; + this.id = this.xformsNode.getAttribute("id"); + this._modified = false; + this._valid = true; + var b = this.xform.getBinding(this.xformsNode); + if (b) { - this.xform = xform; - this.xformsNode = xformsNode; - this.id = this.xformsNode.getAttribute("id"); - this._modified = false; - this._valid = true; - var b = this.xform.getBinding(this.xformsNode); - if (b) - { - dojo.debug("adding " + this.id + " to binding " + b.id); - b.widgets[this.id] = this; - } - else - { - dojo.debug("no binding found for " + this.id); - } - this.domNode = document.createElement("div"); - this.domNode.setAttribute("id", this.id + "-domNode") - this.domNode.widget = this; - dojo.html.setClass(this.domNode, "xformsItem"); - }, - + dojo.debug("adding " + this.id + " to binding " + b.id); + b.widgets[this.id] = this; + } + else + { + dojo.debug("no binding found for " + this.id); + } + this.domNode = document.createElement("div"); + this.domNode.setAttribute("id", this.id + "-domNode"); + this.domNode.widget = this; + dojo.html.setClass(this.domNode, "xformsItem"); + }, + { ///////////////////////////////////////////////////////////////// // properties ///////////////////////////////////////////////////////////////// @@ -146,7 +147,10 @@ dojo.declare("alfresco.xforms.Widget", { this._modified = b; this._updateDisplay(); - this.hideAlert(); + if (this.isValidForSubmit()) + { + this.hideAlert(); + } }, /** Sets the widget's valid state, as indicated by an XFormsEvent */ @@ -154,7 +158,14 @@ dojo.declare("alfresco.xforms.Widget", { this._valid = b; this._updateDisplay(); - this.hideAlert(); + if (this.isValidForSubmit()) + { + this.hideAlert(); + } + else + { + this.showAlert(); + } }, /** @@ -163,7 +174,7 @@ dojo.declare("alfresco.xforms.Widget", */ isValidForSubmit: function() { - if (!this._valid) + if (typeof this._valid != "undefined" && !this._valid) { dojo.debug(this.id + " is invalid"); return false; @@ -427,7 +438,7 @@ dojo.declare("alfresco.xforms.Widget", var node = this._getAlertNode(); return node ? dojo.dom.textContent(node) : ""; }, - + /** Makes the label red. */ showAlert: function() { @@ -545,7 +556,7 @@ dojo.declare("alfresco.xforms.FilePicker", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.FilePicker.superclass.setValue.call(this, value, forceCommit); this.widget.setValue(value); } }, @@ -564,7 +575,7 @@ dojo.declare("alfresco.xforms.FilePicker", var w = fpw.node.widget; w.domContainer.style.height = Math.max(fpw.node.offsetHeight + - dojo.style.getMarginHeight(w.domNode.parentNode), + dojo.html.getMargin(w.domNode.parentNode).height, 20) + "px"; } }); @@ -615,7 +626,7 @@ dojo.declare("alfresco.xforms.TextField", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.TextField.superclass.setValue.call(this, value, forceCommit); this.widget.value = value; } }, @@ -637,6 +648,92 @@ dojo.declare("alfresco.xforms.TextField", } }); +/** The number range widget which handle xforms widget xf:range with any numerical type */ +dojo.declare("alfresco.xforms.NumericalRange", + alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, + { + ///////////////////////////////////////////////////////////////// + // overridden methods + ///////////////////////////////////////////////////////////////// + + render: function(attach_point) + { + var initial_value = this.getInitialValue() || ""; + attach_point.appendChild(this.domNode); + var sliderDiv = document.createElement("div"); + sliderDiv.style.fontWeight = "bold"; + sliderDiv.style.marginBottom = "5px"; + this.domNode.appendChild(sliderDiv); + + var minimum = Number(this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":start")); + var maximum = Number(this.xformsNode.getAttribute(alfresco_xforms_constants.XFORMS_PREFIX + ":end")); + var snapValues = 0; + if (this.xform.getBinding(this.xformsNode).getType() == "integer") + { + snapValues = maximum - minimum + 1; + } + sliderDiv.appendChild(document.createTextNode(minimum)); + + var sliderWidgetDiv = document.createElement("div"); + sliderDiv.appendChild(sliderWidgetDiv); + this.widget = dojo.widget.createWidget("SliderHorizontal", + { + initialValue: initial_value, + minimumX: minimum, + maximumX: maximum, + showButtons: false, + activeDrag: false, + snapValues: snapValues + }, + sliderWidgetDiv); + sliderDiv.appendChild(document.createTextNode(maximum)); + + this.currentValueDiv = document.createElement("div"); + this.domNode.appendChild(this.currentValueDiv); + this.currentValueDiv.appendChild(document.createTextNode("Value: " + initial_value)); + + dojo.event.connect(this.widget, + "onValueChanged", + this, + this._hSlider_valueChangedHandler); + }, + + setValue: function(value, forceCommit) + { + if (!this.widget) + { + this.setInitialValue(value, forceCommit); + } + else + { + alfresco.xforms.NumericalRange.superclass.setValue.call(this, value, forceCommit); + this.widget.setValue(value); + } + }, + + getValue: function() + { + return this.widget.getValue(); + }, + + ///////////////////////////////////////////////////////////////// + // DOM event handlers + ///////////////////////////////////////////////////////////////// + + _hSlider_valueChangedHandler: function(value) + { + this.currentValueDiv.replaceChild(document.createTextNode("Value: " + value), + this.currentValueDiv.firstChild); + if (!this.widget._isDragInProgress) + { + this._commitValueChange(); + } + } + }); + /** The textfield widget which handle xforms widget xf:textarea. */ dojo.declare("alfresco.xforms.TextArea", alfresco.xforms.Widget, @@ -715,7 +812,7 @@ dojo.declare("alfresco.xforms.TextArea", setReadonly: function(readonly) { - this.inherited("setReadonly", [ readonly ]); + alfresco.xforms.TextArea.superclass.setReadonly.call(this, readonly); var mce = tinyMCE.getInstanceById(this.id); if (readonly && mce) { @@ -729,7 +826,7 @@ dojo.declare("alfresco.xforms.TextArea", _destroy: function() { - this.inherited("_destroy", []); + alfresco.xforms.TextArea.superclass._destroy.call(this); if (!this.isReadonly()) { dojo.debug("removing mce control " + this.id); @@ -751,6 +848,7 @@ dojo.declare("alfresco.xforms.TextArea", widget._commitValueChange(); this.focused = false; }, + _tinyMCE_focusHandler: function(event) { var widget = event.target.widget; @@ -781,11 +879,10 @@ dojo.declare("alfresco.xforms.TextArea", /** Base class for all select widgets. */ dojo.declare("alfresco.xforms.AbstractSelectWidget", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, - ///////////////////////////////////////////////////////////////// // methods ///////////////////////////////////////////////////////////////// @@ -802,30 +899,34 @@ dojo.declare("alfresco.xforms.AbstractSelectWidget", alfresco_xforms_constants.XFORMS_PREFIX, "item"); var result = []; - for (var v = 0; v < values.length; v++) + for (var i = 0; i < values.length; i++) { - var label = _getElementsByTagNameNS(values[v], + var label = _getElementsByTagNameNS(values[i], alfresco_xforms_constants.XFORMS_NS, alfresco_xforms_constants.XFORMS_PREFIX, "label")[0]; - var value = _getElementsByTagNameNS(values[v], + var value = _getElementsByTagNameNS(values[i], alfresco_xforms_constants.XFORMS_NS, alfresco_xforms_constants.XFORMS_PREFIX, "value")[0]; var valid = true; if (binding.constraint) { - dojo.debug("testing " + binding.constraint + - " on " + dojo.dom.textContent(value)); valid = _evaluateXPath(binding.constraint, value, XPathResult.BOOLEAN_TYPE); + dojo.debug("evaludated constraint " + binding.constraint + + " on " + dojo.dom.textContent(value) + + " to " + valid); } - dojo.debug("valid " + dojo.dom.textContent(value) + "? " + valid); result.push({ id: value.getAttribute("id"), label: valid ? dojo.dom.textContent(label) : "", value: valid ? dojo.dom.textContent(value) : "_invalid_value_", valid: valid }); + + dojo.debug("values["+ i + "] = {id: " + result[i].id + + ",label: " + result[i].label + ",value: " + result[i].value + + ",valid: " + result[i].valid + "}"); } return result; } @@ -837,11 +938,10 @@ dojo.declare("alfresco.xforms.AbstractSelectWidget", */ dojo.declare("alfresco.xforms.Select", alfresco.xforms.AbstractSelectWidget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, - ///////////////////////////////////////////////////////////////// // overridden methods ///////////////////////////////////////////////////////////////// @@ -849,11 +949,6 @@ dojo.declare("alfresco.xforms.Select", render: function(attach_point) { var values = this._getItemValues(); - for (var i in values) - { - dojo.debug("values["+ i + "] = " + values[i].id + - ", " + values[i].label + ", " + values[i].value); - } var initial_value = this.getInitialValue(); initial_value = initial_value ? initial_value.split(' ') : []; this._selectedValues = []; @@ -913,7 +1008,7 @@ dojo.declare("alfresco.xforms.Select", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.Select.superclass.setValue(this, value, forceCommit); this._selectedValues = value.split(' '); if (this.widget.nodeName.toLowerCase() == "div") { @@ -983,11 +1078,10 @@ dojo.declare("alfresco.xforms.Select", */ dojo.declare("alfresco.xforms.Select1", alfresco.xforms.AbstractSelectWidget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, - ///////////////////////////////////////////////////////////////// // overridden methods ///////////////////////////////////////////////////////////////// @@ -995,11 +1089,6 @@ dojo.declare("alfresco.xforms.Select1", render: function(attach_point) { var values = this._getItemValues(); - for (var i in values) - { - dojo.debug("values["+ i + "] = " + values[i].id + - ", " + values[i].label + ", " + values[i].value); - } var initial_value = this.getInitialValue(); if (values.length <= 5) { @@ -1063,7 +1152,7 @@ dojo.declare("alfresco.xforms.Select1", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.Select1.superclass.setValue.call(this, value, forceCommit); this._selectedValue = value; if (this.widget.nodeName.toLowerCase() == "div") { @@ -1126,11 +1215,10 @@ dojo.declare("alfresco.xforms.Select1", */ dojo.declare("alfresco.xforms.Checkbox", alfresco.xforms.Widget, + function(xform, xformsNode) + { + }, { - initializer: function(xform, xformsNode) - { - }, - ///////////////////////////////////////////////////////////////// // overridden methods ///////////////////////////////////////////////////////////////// @@ -1158,7 +1246,7 @@ dojo.declare("alfresco.xforms.Checkbox", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.Checkbox.superclass.setValue.call(this, value, forceCommit); this.widget.checked = value == "true"; } }, @@ -1197,7 +1285,6 @@ dojo.declare("alfresco.xforms.DatePicker", render: function(attach_point) { var initial_value = this.getInitialValue() || ""; - attach_point.appendChild(this.domNode); this.widget = document.createElement("input"); this.widget.setAttribute("id", this.id + "-widget"); @@ -1211,18 +1298,18 @@ dojo.declare("alfresco.xforms.DatePicker", var dp_initial_value = (initial_value ? initial_value - : dojo.widget.DatePicker.util.toRfcDate(new Date())); + : dojo.date.toRfc3339(new Date())); this.widget.picker = dojo.widget.createWidget("DatePicker", { isHidden: true, - storedDate: dp_initial_value + value: dp_initial_value }, datePickerDiv); this.widget.picker.hide(); dojo.event.connect(this.widget.picker, - "onSetDate", + "onValueChanged", this, - this._datePicker_setDateHandler); + this._datePicker_valueChangedHandler); }, setValue: function(value, forceCommit) @@ -1233,7 +1320,7 @@ dojo.declare("alfresco.xforms.DatePicker", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.DatePicker.superclass.setValue.call(this, value, forceCommit); this.widget.setAttribute("value", value); this.widget.picker.setDate(value); } @@ -1252,23 +1339,23 @@ dojo.declare("alfresco.xforms.DatePicker", _dateTextBox_focusHandler: function(event) { - dojo.style.hide(this.widget); + dojo.html.hide(this.widget); this.widget.picker.show(); this.domContainer.style.height = Math.max(this.widget.picker.domNode.offsetHeight + - dojo.style.getMarginHeight(this.domNode.parentNode), + dojo.html.getMargin(this.domNode.parentNode).height, 20) + "px"; }, - _datePicker_setDateHandler: function(event) + _datePicker_valueChangedHandler: function(date) { this.widget.picker.hide(); - dojo.style.show(this.widget); + dojo.html.show(this.widget); this.domContainer.style.height = Math.max(this.domNode.parentNode.offsetHeight + - dojo.style.getMarginHeight(this.domNode.parentNode), + dojo.html.getMargin(this.domNode.parentNode).height, 20) + "px"; - this.widget.value = dojo.widget.DatePicker.util.toRfcDate(this.widget.picker.date); + this.widget.value = dojo.date.toRfc3339(date, "dateOnly"); this._commitValueChange(); } }); @@ -1313,7 +1400,7 @@ dojo.declare("alfresco.xforms.TimePicker", // don't let it float - it screws up layout somehow this.widget.picker.domNode.style.cssFloat = "none"; - this.domNode.style.height = dojo.style.getMarginBoxHeight(this.widget.picker.domNode) + "px"; + this.domNode.style.height = dojo.html.getMarginBox(this.widget.picker.domNode).height + "px"; dojo.event.connect(this.widget.picker, "onSetTime", this, @@ -1328,14 +1415,14 @@ dojo.declare("alfresco.xforms.TimePicker", } else { - this.inherited("setValue", [ value, forceCommit ]); + alfresco.xforms.TimePicker.superclass.setValue.call(this, value, forceCommit); this.widget.picker.setDateTime(value); } }, getValue: function() { - return dojo.date.format(this.widget.picker.time, "%H:%M:00"); + return dojo.date.strftime(this.widget.picker.time, "%H:%M:00"); }, ///////////////////////////////////////////////////////////////// @@ -1362,26 +1449,29 @@ dojo.declare("alfresco.xforms.YearPicker", render: function(attach_point) { - this.inherited("render", [ attach_point ]); + alfresco.xforms.YearPicker.superclass.render.call(this, attach_point); this.widget.size = "4"; this.widget.setAttribute("maxlength", "4"); }, getInitialValue: function() { - var result = this.inherited("getInitialValue", []); + var result = alfresco.xforms.YearPicker.superclass.getInitialValue.call(this); return result ? result.replace(/^0*([^0]+)$/, "$1") : result; }, setValue: function(value, forceCommit) { - this.inherited("setValue", - [ value ? value.replace(/^0*([^0]+)$/, "$1") : null, forceCommit ]); + alfresco.xforms.YearPicker.superclass.setValue.call(this, + (value + ? value.replace(/^0*([^0]+)$/, "$1") + : null), + forceCommit); }, getValue: function() { - var result = this.inherited("getValue", []); + var result = alfresco.xforms.YearPicker.superclass.getValue.call(this); return result ? dojo.string.padLeft(result, 4, "0") : null; } }); @@ -1428,15 +1518,13 @@ dojo.declare("alfresco.xforms.MonthPicker", { var result = []; result.push({id: "month_empty", label: "", value: "", valid: false}); - for (var i = 0; i <= dojo.date.months.length; i++) + for (var i = 0; i <= 12; i++) { - if (typeof dojo.date.months[i] != "string") - { - continue; - } + var d = new Date(); + d.setMonth(i); result.push({ id: "month_" + i, - label: dojo.date.months[i], + label: dojo.date.getMonthName(d), value: "--" + (i + 1 < 10 ? "0" + (i + 1) : i + 1), valid: true}); } @@ -1681,14 +1769,13 @@ dojo.declare("alfresco.xforms.Group", { child.domContainer.style.height = Math.max(contentDiv.offsetHeight + - dojo.style.getMarginHeight(contentDiv), 20) + "px"; + dojo.html.getMargin(contentDiv).height, 20) + "px"; // child.domContainer.style.lineHeight = child.domContainer.style.height; } dojo.debug(contentDiv.getAttribute("id") + " offsetTop is " + contentDiv.offsetTop); -// alert(contentDiv.offsetTop - dojo.style.getPixelValue(contentDiv, "margin-top")); contentDiv.style.top = "-" + Math.max(0, contentDiv.offsetTop - - dojo.style.getPixelValue(contentDiv, "margin-top")) + "px"; + dojo.html.getPixelValue(contentDiv, "margin-top")) + "px"; if (labelDiv) { labelDiv.style.top = (contentDiv.offsetTop + ((.5 * contentDiv.offsetHeight) - @@ -1740,6 +1827,11 @@ dojo.declare("alfresco.xforms.Group", // overridden methods & properties ///////////////////////////////////////////////////////////////// + isValidForSubmit: function() + { + return true; + }, + /** Iterates all children a produces an array of widgets which are invalid for submit. */ getWidgetsInvalidForSubmit: function() { @@ -1761,7 +1853,7 @@ dojo.declare("alfresco.xforms.Group", /** Recusively destroys all children. */ _destroy: function() { - this.inherited("_destroy", []); + alfresco.xforms.Group.superclass._destroy.call(this); for (var i = 0; i < this._children.length; i++) { this._children[i]._destroy(); @@ -1770,7 +1862,7 @@ dojo.declare("alfresco.xforms.Group", setReadonly: function(readonly) { - this.inherited("setReadonly", [ readonly ]); + alfresco.xforms.Group.superclass.setReadonly.call(this, readonly); for (var i = 0; i < this._children.length; i++) { this._children[i].setReadonly(readonly); @@ -1800,9 +1892,9 @@ dojo.declare("alfresco.xforms.Group", } else { - this.domNode.style.width = (1 - ((dojo.style.getBorderWidth(this.domNode) + - dojo.style.getPaddingWidth(this.domNode) + - dojo.style.getMarginWidth(this.domNode)) / + this.domNode.style.width = (1 - ((dojo.html.getBorder(this.domNode).width + + dojo.html.getPadding(this.domNode).width + + dojo.html.getMargin(this.domNode).width) / attach_point.offsetWidth)) * 100 + "%"; } @@ -1866,9 +1958,9 @@ dojo.declare("alfresco.xforms.Group", } else { - this.domNode.style.width = (1 - ((dojo.style.getBorderWidth(this.domNode) + - dojo.style.getPaddingWidth(this.domNode) + - dojo.style.getMarginWidth(this.domNode)) / + this.domNode.style.width = (1 - ((dojo.html.getBorder(this.domNode).width + + dojo.html.getPadding(this.domNode).width + + dojo.html.getMargin(this.domNode).width) / this.domNode.parentNode.offsetWidth)) * 100 + "%"; } @@ -1895,11 +1987,11 @@ dojo.declare("alfresco.xforms.Group", { this._children[i].domContainer.style.height = Math.max(contentDiv.offsetHeight + - dojo.style.getMarginHeight(contentDiv), 20) + "px"; + dojo.html.getMargin(contentDiv).height, 20) + "px"; } contentDiv.style.top = "-" + Math.max(0, contentDiv.offsetTop - - dojo.style.getPixelValue(contentDiv, "margin-top")) + "px"; + dojo.html.getPixelValue(contentDiv, "margin-top")) + "px"; var labelDiv = document.getElementById(this._children[i].id + "-label"); if (labelDiv) @@ -1934,6 +2026,7 @@ dojo.declare("alfresco.xforms.Group", ///////////////////////////////////////////////////////////////// // DOM event handlers ///////////////////////////////////////////////////////////////// + _toggleExpanded_clickHandler: function(event) { this.setExpanded(!this.isExpanded()); @@ -1942,20 +2035,19 @@ dojo.declare("alfresco.xforms.Group", dojo.declare("alfresco.xforms.SwitchGroup", alfresco.xforms.Group, + function(xform, xformsNode) { - initializer: function(xform, xformsNode) + this.selectedCaseId = null; + var widgets = this.xform.getBinding(this.xformsNode).widgets; + for (var i in widgets) { - this.selectedCaseId = null; - var widgets = this.xform.getBinding(this.xformsNode).widgets; - for (var i in widgets) + if (widgets[i] instanceof alfresco.xforms.Select1) { - if (widgets[i] instanceof alfresco.xforms.Select1) - { - widgets[i].setValue(this.getInitialValue(), "true"); - } + widgets[i].setValue(this.getInitialValue(), "true"); } - }, - + } + }, + { ///////////////////////////////////////////////////////////////// // overridden methods & properties ///////////////////////////////////////////////////////////////// @@ -1963,7 +2055,8 @@ dojo.declare("alfresco.xforms.SwitchGroup", /** */ _insertChildAt: function(child, position) { - var childDomContainer = this.inherited("_insertChildAt", [child, position]); + var childDomContainer = + alfresco.xforms.SwitchGroup.superclass._insertChildAt.call(this, child, position); this.selectedCaseId = this.selectedCaseId || child.id; if (this.selectedCaseId != child.id) { @@ -2004,11 +2097,11 @@ dojo.declare("alfresco.xforms.SwitchGroup", */ dojo.declare("alfresco.xforms.ViewRoot", alfresco.xforms.Group, + function(xform, xformsNode) + { + this.focusedRepeat = null; + }, { - initializer: function(xform, xformsNode) - { - this.focusedRepeat = null; - }, render: function(attach_point) { this.domNode.widget = this; @@ -2055,13 +2148,12 @@ alfresco.xforms.RepeatIndexData = function(repeat, index) */ dojo.declare("alfresco.xforms.Repeat", alfresco.xforms.Group, + function(xform, xformsNode) + { + this.repeatControls = []; + this._selectedIndex = -1; + }, { - initializer: function(xform, xformsNode) - { - this.repeatControls = []; - this._selectedIndex = -1; - }, - ///////////////////////////////////////////////////////////////// // methods & properties ///////////////////////////////////////////////////////////////// @@ -2211,13 +2303,13 @@ dojo.declare("alfresco.xforms.Repeat", var removeEnabled = this.isRemoveRepeatItemEnabled(); for (var i = 0; i < this.repeatControls.length; i++) { - dojo.style.setOpacity(this.repeatControls[i].moveRepeatItemUpImage, + dojo.html.setOpacity(this.repeatControls[i].moveRepeatItemUpImage, i == 0 ? .3 : 1); - dojo.style.setOpacity(this.repeatControls[i].moveRepeatItemDownImage, + dojo.html.setOpacity(this.repeatControls[i].moveRepeatItemDownImage, i == this.repeatControls.length - 1 ? .3 : 1); - dojo.style.setOpacity(this.repeatControls[i].insertRepeatItemImage, + dojo.html.setOpacity(this.repeatControls[i].insertRepeatItemImage, insertEnabled ? 1 : .3); - dojo.style.setOpacity(this.repeatControls[i].removeRepeatItemImage, + dojo.html.setOpacity(this.repeatControls[i].removeRepeatItemImage, removeEnabled ? 1 : .3); } }, @@ -2260,12 +2352,12 @@ dojo.declare("alfresco.xforms.Repeat", img.style.margin = "2px 5px 2px " + (i == 0 ? 5 : 0) + "px"; img.repeat = this; repeatControlsWidth += (parseInt(img.style.width) + - dojo.style.getMarginWidth(img)); + dojo.html.getMargin(img).width); this.repeatControls[position].appendChild(img); dojo.event.connect(img, "onclick", this, images[i].action); } - var result = this.inherited("_insertChildAt", [ child, position ]); + var result = alfresco.xforms.Repeat.superclass._insertChildAt.call(this, child, position); child.repeat = this; dojo.event.connect(result, "onclick", function(event) { @@ -2291,8 +2383,8 @@ dojo.declare("alfresco.xforms.Repeat", result.style.paddingBottom = (.5 * this.repeatControls[position].offsetHeight) + "px"; this.repeatControls[position].style.top = -(.5 * (this.repeatControls[position].offsetHeight ) + - dojo.style.getPixelValue(result, "margin-bottom") + - dojo.style.getBorderExtent(result, "bottom")) + "px"; + dojo.html.getPixelValue(result, "margin-bottom") + + dojo.html.getBorderExtent(result, "bottom")) + "px"; this.repeatControls[position].style.marginRight = (.5 * result.offsetWidth - .5 * this.repeatControls[position].offsetWidth) + "px"; @@ -2313,13 +2405,13 @@ dojo.declare("alfresco.xforms.Repeat", dojo.dom.removeChildren(this.repeatControls[position]); dojo.dom.removeNode(this.repeatControls[position]); this.repeatControls.splice(position, 1); - return this.inherited("_removeChildAt", [ position ]); + return alfresco.xforms.Repeat.superclass._removeChildAt.call(this, position); }, /** Disables insert before. */ _childAdded: function(child) { - dojo.style.setOpacity(this.headerInsertRepeatItemImage, .3); + dojo.html.setOpacity(this.headerInsertRepeatItemImage, .3); this._updateRepeatControls(); }, @@ -2328,14 +2420,14 @@ dojo.declare("alfresco.xforms.Repeat", { if (this._children.length == 0) { - dojo.style.setOpacity(this.headerInsertRepeatItemImage, 1); + dojo.html.setOpacity(this.headerInsertRepeatItemImage, 1); } this._updateRepeatControls(); }, render: function(attach_point) { - this.domNode = this.inherited("render", [ attach_point ]); + this.domNode = alfresco.xforms.Repeat.superclass.render.call(this, attach_point); dojo.html.addClass(this.domNode, "xformsRepeat"); // clear the border bottom for the group header since we'll be getting it @@ -2372,7 +2464,7 @@ dojo.declare("alfresco.xforms.Repeat", _updateDisplay: function() { - this.inherited("_updateDisplay", []); + alfresco.xforms.Repeat.superclass._updateDisplay.call(this); if (this.getViewRoot().focusedRepeat != null && (this.getViewRoot().focusedRepeat == this || this.getViewRoot().focusedRepeat.isAncestorOf(this))) @@ -2681,10 +2773,6 @@ dojo.declare("alfresco.xforms.Submit", false); } }, - render: function(attach_point) - { - this.inherited("render", [ attach_point ]); - }, ///////////////////////////////////////////////////////////////// // DOM event handlers @@ -2861,7 +2949,7 @@ dojo.declare("alfresco.xforms.XForm", this._bindings = this._loadBindings(this.getModel()); var bindings = this.getBindings(); - for (var i in bindings) + for (var i = 0; false && i < bindings.length; i++) { dojo.debug("bindings[" + i + "]=" + bindings[i].id + ", parent = " + (bindings[i].parent @@ -2894,6 +2982,32 @@ dojo.declare("alfresco.xforms.XForm", return new alfresco.xforms.TextArea(this, xformsNode); case alfresco_xforms_constants.XFORMS_PREFIX + ":upload": return new alfresco.xforms.FilePicker(this, xformsNode); + case alfresco_xforms_constants.XFORMS_PREFIX + ":range": + { + var type = this.getBinding(xformsNode).getType(); + switch (type) + { + // number types + 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.NumericalRange(this, xformsNode); + default: + throw new Error("range not supported for type " + type); + } + } case alfresco_xforms_constants.XFORMS_PREFIX + ":input": { var type = this.getBinding(xformsNode).getType(); @@ -3001,7 +3115,6 @@ dojo.declare("alfresco.xforms.XForm", _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() == @@ -3168,22 +3281,26 @@ dojo.declare("alfresco.xforms.XForm", { dojo.debug("handleStateChanged(" + xfe.targetId + ")"); xfe.getTarget().setModified(true); - xfe.getTarget().setValid(xfe.properties["valid"] == "true"); - xfe.getTarget().setRequired(xfe.properties["required"] == "true"); - xfe.getTarget().setReadonly(xfe.properties["readonly"] == "true"); - xfe.getTarget().setEnabled(xfe.properties["enabled"] == "true"); + if ("valid" in xfe.properties) + { + xfe.getTarget().setValid(xfe.properties["valid"] == "true"); + } + if ("required" in xfe.properties) + { + xfe.getTarget().setRequired(xfe.properties["required"] == "true"); + } + if ("readonly" in xfe.properties) + { + xfe.getTarget().setReadonly(xfe.properties["readonly"] == "true"); + } + if ("enabled" in xfe.properties) + { + xfe.getTarget().setEnabled(xfe.properties["enabled"] == "true"); + } if ("value" in xfe.properties) { dojo.debug("setting " + xfe.getTarget().id + " = " + xfe.properties["value"]); - try - { - xfe.getTarget().setValue(xfe.properties["value"]); - } - catch(e) - { - //XXXarielb remove once setValues are implemented. - dojo.debug("Error in set value: " + e); - } + xfe.getTarget().setValue(xfe.properties["value"]); } break; } @@ -3430,7 +3547,7 @@ AjaxHelper._getLoaderElement = function() result = document.createElement("div"); result.setAttribute("id", alfresco_xforms_constants.AJAX_LOADER_DIV_ID); dojo.html.setClass(result, "xformsAjaxLoader"); - dojo.style.hide(result); + dojo.html.hide(result); document.body.appendChild(result); return result; } @@ -3450,11 +3567,11 @@ AjaxHelper._updateLoaderDisplay = function() dojo.debug(ajaxLoader.innerHTML); if (/* djConfig.isDebug && */ AjaxHelper._requests.length != 0) { - dojo.style.show(ajaxLoader); + dojo.html.show(ajaxLoader); } else { - dojo.style.hide(ajaxLoader); + dojo.html.hide(ajaxLoader); } } @@ -3723,7 +3840,7 @@ _showStatus: function(text, isError) } this.statusDiv.appendChild(d.createTextNode(text)); this.node.style.height = (parseInt(this.node.style.height) + - dojo.style.getMarginHeight(this.statusDiv) + + dojo.html.getMargin(this.statusDiv).height + this.statusDiv.offsetHeight) + "px"; this.resize_callback(this); } @@ -3788,8 +3905,8 @@ _showSelectedValue: function() this.selectedPathInput.style.width = (1 - ((this.selectButton.offsetWidth + - dojo.style.getMarginWidth(this.selectButton)) / - dojo.style.getContentBoxWidth(this.node))) * 100 + "%"; + dojo.html.getMargin(this.selectButton).width) / + dojo.html.getContentBox(this.node).width)) * 100 + "%"; dojo.event.browser.addListener(this.selectButton, "click", function(event) @@ -3946,7 +4063,7 @@ _showPicker: function(data) var navigateToParentNodeImage = d.createElement("img"); navigateToParentNodeImage.style.borderWidth = "0px"; - dojo.style.setOpacity(navigateToParentNodeImage, (currentPathName == "/" ? .3 : 1)); + dojo.html.setOpacity(navigateToParentNodeImage, (currentPathName == "/" ? .3 : 1)); navigateToParentNodeImage.style.margin = "0px 2px 0px 2px"; navigateToParentNodeImage.align = "absmiddle"; navigateToParentNodeImage.setAttribute("src", alfresco_xforms_constants.WEBAPP_CONTEXT + "/images/icons/up.gif");