From 172b86dab4bcd13f6a480caaab5194fa55fbadd3 Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Sat, 28 Apr 2007 21:34:15 +0000 Subject: [PATCH] updates to date time pickers - make them behave better as inline elements for hgroup support - respect minInclusive, maxInclusive, minExclusive and maxExclusive restrictions for date types. no support in dojo to support the same with the TimePicker. addresses feature request WCM-379. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5574 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/forms/xforms/Schema2XForms.java | 59 +++++++++++++++++++ .../unit-tests/simple-test/datetime-test.xsd | 49 +++++++++++++-- source/web/scripts/ajax/xforms.js | 26 ++++++-- 3 files changed, 124 insertions(+), 10 deletions(-) diff --git a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java index cbfad2dd0b..6dc8e707b3 100644 --- a/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java +++ b/source/java/org/alfresco/web/forms/xforms/Schema2XForms.java @@ -25,6 +25,8 @@ package org.alfresco.web.forms.xforms; import java.io.File; import java.io.IOException; import java.io.StringWriter; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import javax.xml.transform.*; import org.alfresco.service.namespace.NamespaceService; @@ -2442,6 +2444,63 @@ public class Schema2XForms controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXLENGTH)); } } + if (SchemaUtil.getBuiltInType(controlType) == XSConstants.DATE_DT) + { + String minInclusive = null; + String maxInclusive = null; + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + final Calendar calendar = Calendar.getInstance(); + if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE)) + { + minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINEXCLUSIVE); + try + { + final Date d = sdf.parse(minInclusive); + calendar.setTime(d); + } + catch (ParseException pe) + { + LOGGER.error(pe); + } + calendar.roll(Calendar.DATE, true); + minInclusive = sdf.format(calendar.getTime()); + } + else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE)) + { + minInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE); + } + if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE)) + { + maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXEXCLUSIVE); + try + { + final Date d = sdf.parse(maxInclusive); + calendar.setTime(d); + } + catch (ParseException pe) + { + LOGGER.error(pe); + } + calendar.roll(Calendar.DATE, false); + maxInclusive = sdf.format(calendar.getTime()); + } + else if (controlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE)) + { + maxInclusive = controlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE); + } + if (minInclusive != null) + { + result.setAttributeNS(NamespaceService.ALFRESCO_URI, + NamespaceService.ALFRESCO_PREFIX + ":minInclusive", + minInclusive); + } + if (maxInclusive != null) + { + result.setAttributeNS(NamespaceService.ALFRESCO_URI, + NamespaceService.ALFRESCO_PREFIX + ":maxInclusive", + maxInclusive); + } + } } this.setXFormsId(result); result.appendChild(this.createLabel(xformsDocument, caption)); diff --git a/source/test-resources/xforms/unit-tests/simple-test/datetime-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/datetime-test.xsd index bedcf3e8b1..a5f527991e 100644 --- a/source/test-resources/xforms/unit-tests/simple-test/datetime-test.xsd +++ b/source/test-resources/xforms/unit-tests/simple-test/datetime-test.xsd @@ -7,12 +7,51 @@ + + + + + + + + + + + + + + + + - - - - - + + minimal + + + + + + + + + minimal + + + + + + + + + + minimal + + + + + + + diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index d3f4980feb..fe1872c62f 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -590,7 +590,7 @@ dojo.declare("alfresco.xforms.TextField", : -1); this._length = (_hasAttribute(this.xformsNode, alfresco.xforms.constants.ALFRESCO_PREFIX + ":length") ? Number(this.xformsNode.getAttribute(alfresco.xforms.constants.ALFRESCO_PREFIX + ":length")) - : -1) + : -1); }, { @@ -1455,6 +1455,14 @@ dojo.declare("alfresco.xforms.DatePicker", function(xform, xformsNode) { dojo.require("dojo.widget.DatePicker"); + this._minInclusive = (_hasAttribute(this.xformsNode, alfresco.xforms.constants.ALFRESCO_PREFIX + ":minInclusive") + ? this.xformsNode.getAttribute(alfresco.xforms.constants.ALFRESCO_PREFIX + ":minInclusive") + : null); + this._maxInclusive = (_hasAttribute(this.xformsNode, alfresco.xforms.constants.ALFRESCO_PREFIX + ":maxInclusive") + ? this.xformsNode.getAttribute(alfresco.xforms.constants.ALFRESCO_PREFIX + ":maxInclusive") + : null); + + // XXXarielb - change to a static this._noValueSet = (alfresco.xforms.constants.resources["eg"] + " " + dojo.date.format(new Date(), {datePattern: alfresco.xforms.constants.DATE_FORMAT, @@ -1466,11 +1474,19 @@ dojo.declare("alfresco.xforms.DatePicker", var datePickerDiv = document.createElement("div"); this.domNode.parentNode.appendChild(datePickerDiv); - var dp_initial_value = this.getValue() || dojo.date.toRfc3339(new Date()); + var dp_initial_value = this.getValue() || null; //dojo.date.toRfc3339(new Date()); + var datePickerProperties = { value: dp_initial_value }; + if (this._minInclusive) + { + datePickerProperties.startDate = this._minInclusive; + } + if (this._maxInclusive) + { + datePickerProperties.endDate = this._maxInclusive; + } + this.widget.picker = dojo.widget.createWidget("DatePicker", - { - value: dp_initial_value - }, + datePickerProperties, datePickerDiv); this.domContainer.style.height = Math.max(this.widget.picker.domNode.offsetHeight +