cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r497899 - in /cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources: forms-field-styling.xsl js/DropdownDateTimePicker.js
Date Fri, 19 Jan 2007 18:38:42 GMT
Author: bruno
Date: Fri Jan 19 10:38:42 2007
New Revision: 497899

URL: http://svn.apache.org/viewvc?view=rev&rev=497899
Log:
Fix Ajax-issue from last commit, was caused by trying to destroy a widget which was never
displayed.
Optimized the datetime picker so that date resp. time picker are only instantiated when needed,
fix/improve some other things.

Modified:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/DropdownDateTimePicker.js

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl?view=diff&rev=497899&r1=497898&r2=497899
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
Fri Jan 19 10:38:42 2007
@@ -228,9 +228,7 @@
       +-->
   <xsl:template match="fi:validation-message">
     <span dojoType="forms:infopopup" style="display:none" class="forms-validation-message-popup"
-           icon="validation-message.gif">
-      <!-- temporarily removed id attribute as it gave problems in ajax mode (duplicate
id),
-            need to research this further id="forms-validation-message-{../@id}"-->
+          id="forms-validation-message-{../@id}" icon="validation-message.gif">
       <xsl:copy-of select="node()"/>
     </span>
   </xsl:template>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/DropdownDateTimePicker.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/DropdownDateTimePicker.js?view=diff&rev=497899&r1=497898&r2=497899
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/DropdownDateTimePicker.js
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/DropdownDateTimePicker.js
Fri Jan 19 10:38:42 2007
@@ -71,11 +71,11 @@
 
             this.templateString = "<span style='white-space: nowrap'><input dojoAttachPoint='inputNode'
autocomplete='off' style='vertical-align: middle'/>";
 
-            if (this.variant == "date" || this.variant == "datetime") {
+            if (this._datePickerNeeded()) {
                 this.templateString += "<img src='${this.dateIconURL}' dojoAttachEvent='onclick:_onDateIconClick'
dojoAttachPoint='dateButtonNode' style='vertical-align: middle; cursor: pointer; cursor: hand'/>";
             }
 
-            if (this.variant == "time" || this.variant == "datetime") {
+            if (this._timePickerNeeded()) {
                 this.templateString += "<img src='${this.timeIconURL}' dojoAttachEvent='onclick:_onTimeIconClick'
dojoAttachPoint='timeButtonNode' style='vertical-align: middle; cursor: pointer; cursor: hand'/>";
             }
 
@@ -91,18 +91,24 @@
             // summary: use attachTemplateNodes to specify containerNode, as fillInTemplate
is too late for this
             cocoon.forms.DropdownDateTimePicker.superclass.attachTemplateNodes.apply(this,
arguments);
 
-            this.datePopup = dojo.widget.createWidget("PopupContainer", {toggle: this.containerToggle,
toggleDuration: this.containerToggleDuration});
-            this.timePopup = dojo.widget.createWidget("PopupContainer", {toggle: this.containerToggle,
toggleDuration: this.containerToggleDuration});
+            if (this._datePickerNeeded()) {
+                this.datePopup = dojo.widget.createWidget("PopupContainer", {toggle: this.containerToggle,
toggleDuration: this.containerToggleDuration});
+                this.datePopupContainerNode = this.datePopup.domNode;
+            }
 
-            this.datePopupContainerNode = this.datePopup.domNode;
-            this.timePopupContainerNode = this.timePopup.domNode;
+            if (this._timePickerNeeded()) {
+                this.timePopup = dojo.widget.createWidget("PopupContainer", {toggle: this.containerToggle,
toggleDuration: this.containerToggleDuration});
+                this.timePopupContainerNode = this.timePopup.domNode;
+            }
         },
 
         fillInTemplate: function(args, frag) {
             cocoon.forms.DropdownDateTimePicker.superclass.fillInTemplate(this, args, frag);
 
-            this.domNode.appendChild(this.datePopup.domNode);
-            this.domNode.appendChild(this.timePopup.domNode);
+            if (this._datePickerNeeded())
+                this.domNode.appendChild(this.datePopup.domNode);
+            if (this._timePickerNeeded())
+                this.domNode.appendChild(this.timePopup.domNode);
 
             // Copy some stuff from the original input field
             var fragNode = this.getFragNodeRef(frag);
@@ -114,17 +120,29 @@
             this.inputNode.value = fragNode.value;
 
             // Construct date picker
-            var dpArgs = {widgetContainerId: this.widgetId, lang: this.locale, value: this.value};
-            this.datePicker = dojo.widget.createWidget("DatePicker", dpArgs, this.datePopupContainerNode,
"child");
-            dojo.event.connect(this.datePicker, "onValueChanged", this, "_updateDate");
+            if (this._datePickerNeeded()) {
+                var dpArgs = {widgetContainerId: this.widgetId, lang: this.locale, value:
this.value};
+                this.datePicker = dojo.widget.createWidget("DatePicker", dpArgs, this.datePopupContainerNode,
"child");
+                dojo.event.connect(this.datePicker, "onValueChanged", this, "_updateDate");
+            }
 
             // Construct time picker
-            var tpArgs = { widgetContainerId: this.widgetId, lang: this.locale, value: this.value
};
-            this.timePicker = dojo.widget.createWidget("TimePicker", tpArgs, this.timePopupContainerNode,
"child");
-            dojo.event.connect(this.timePicker, "onValueChanged", this, "_updateTime");
+            if (this._timePickerNeeded()) {
+                var tpArgs = { widgetContainerId: this.widgetId, lang: this.locale, value:
this.value };
+                this.timePicker = dojo.widget.createWidget("TimePicker", tpArgs, this.timePopupContainerNode,
"child");
+                dojo.event.connect(this.timePicker, "onValueChanged", this, "_updateTime");
+            }
 
         },
 
+        _datePickerNeeded: function() {
+            return this.variant == "date" || this.variant == "datetime";
+        },
+
+        _timePickerNeeded: function() {
+            return this.variant == "time" || this.variant == "datetime";
+        },
+
         _onDateIconClick: function() {
             if (this.inputNode.disabled)
                 return;
@@ -154,8 +172,8 @@
         },
 
         _updateDate: function(value) {
-            // in case there's a time component, preserve it
-            if (this.variant = "datetime") {
+            // in case there's a time component, preserve it if current input is parseable
+            if (this.variant == "datetime") {
                 var currentValue = this._parseCurrentInput();
                 if (currentValue != null) {
                     value.setHours(currentValue.getHours());
@@ -171,8 +189,8 @@
         },
 
         _updateTime: function(value) {
-            // in case there's a date component, preserve it
-            if (this.variant = "datetime") {
+            // in case there's a date component, preserve it if current input is parseable
+            if (this.variant == "datetime") {
                 var currentValue = this._parseCurrentInput();
                 if (currentValue != null) {
                     value.setFullYear(currentValue.getFullYear(), currentValue.getMonth(),
currentValue.getDate());
@@ -205,6 +223,7 @@
                 return;
             }
 
+            // pattern characters for times
             // http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
             var timeFormattingChars = ["a", "h", "H", "K", "k", "m", "s", "S", "A", "z",
"Z"];
 
@@ -212,6 +231,7 @@
             if (pattern == null || pattern == "")
                 return;
 
+            // search position of first time pattern character
             var beginTimePattern = -1;
             for (var i = 0; i < pattern.length; i++) {
                 var c = pattern.charAt(i);
@@ -221,6 +241,7 @@
                 }
             }
 
+            // split pattern in date and time component
             if (beginTimePattern == -1) {
                 // pure date pattern
                 this.datePattern = pattern;
@@ -231,6 +252,7 @@
         },
 
         _initDateFormatOptions: function() {
+            // These are the options to be passed to dojo's date format/parse functions
             var options = {};
 
             switch (this.variant) {
@@ -250,12 +272,24 @@
             options.locale = this.locale;
 
             this.dateFormatOptions = options;
-        }
+        },
 
-//        destroy: function(/*Boolean*/finalize){
-//            this.datePicker.destroy(finalize);
-//            this.timePicker.destory(finalize);
-//            cocoon.forms.DropdownDateTimePicker.superclass.destroy.apply(this, arguments);
-//        }
+        destroy: function(/*Boolean*/finalize) {
+            if (this._datePickerNeeded()) {
+                if (this.datePicker != null)
+                    this.datePicker.destroy(finalize);
+                else
+                    dojo.debug("DropdownDateTimePicker: no datePicker to destroy?");
+            }
+
+            if (this._timePickerNeeded()) {
+                if (this.timePicker != null)
+                    this.timePicker.destory(finalize);
+                else
+                    dojo.debug("DropdownDateTimePicker: no timePicker to destroy?");
+            }
+
+            cocoon.forms.DropdownDateTimePicker.superclass.destroy.apply(this, arguments);
+        }
     }
 );



Mime
View raw message