Author: pyaschenko
Date: 2010-12-29 11:46:42 -0500 (Wed, 29 Dec 2010)
New Revision: 20841
Modified:
trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
trunk/ui/input/ui/src/main/templates/calendar.template.xml
Log:
http://jira.jboss.com/jira/browse/RF-4865
Modified: trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2010-12-29 16:31:41
UTC (rev 20840)
+++ trunk/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2010-12-29 16:46:42
UTC (rev 20841)
@@ -72,6 +72,8 @@
style="width:200px;border:10px solid #000000"
styleClass="hello"
boundaryDatesMode = "scroll"
+ defaultLabel = "bla-bla-bla"
+ enableManualInput="false"
</calendar:calendar>
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-12-29
16:31:41 UTC (rev 20840)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-12-29
16:46:42 UTC (rev 20841)
@@ -165,7 +165,10 @@
public abstract int getZindex();
@Attribute(defaultValue = "client")
- public abstract String getMode();
+ public abstract String getMode();
+
+ @Attribute
+ public abstract String getDefaultLabel();
@Attribute
public abstract String getStyle();
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-12-29
16:31:41 UTC (rev 20840)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-12-29
16:46:42 UTC (rev 20841)
@@ -262,15 +262,29 @@
currentDate: null,
defaultTime: {hours:12,minutes:0, seconds:0},
mode: "client",
- hidePopupOnScroll: true
+ hidePopupOnScroll: true,
+ defaultLabel:""
};
var defaultLabels = {apply:'Apply', today:'Today',
clean:'Clean', ok:'OK', cancel:'Cancel', close:'x'};
var eventHandlerNames = ["change", "dateselect",
"beforedateselect", "currentdateselect",
"beforecurrentdateselect", "currentdateselect", "clean",
"complete", "collapse",
- "datemouseout", "datemouseover", "show",
"hide", "timeselect", "beforetimeselect"];
+ "datemouseout", "datemouseover", "show",
"hide", "timeselect", "beforetimeselect"];
+ var updateDefaultLabel = function (value) {
+ if (!this.selectedDate) {
+ var field = rf.getDomElement(this.INPUT_DATE_ID);
+ field.value = value;
+ }
+ }
+
+ var onFocusBlur = function (event) {
+ this.isFocused = event.type=="focus";
+ if (!this.isFocused && this.isVisible) return;
+ updateDefaultLabel.call(this, (event.type=="focus" ? "" :
this.options.defaultLabel));
+ }
+
// Constructor definition
rf.ui.Calendar = function(componentId, locale, options, markups) {
@@ -496,22 +510,18 @@
{
rf.Event.bindById(this.INPUT_DATE_ID, "click"+this.namespace, handler,
this);
}
+ if (this.options.defaultLabel) {
+ updateDefaultLabel.call(this, this.options.defaultLabel);
+ rf.Event.bindById(this.INPUT_DATE_ID, "focus"+this.namespace+"
blur"+this.namespace, onFocusBlur, this);
+ }
}
this.scrollElements = null;
- //alert(new Date().getTime()-_d.getTime());
-
//define isAjaxMode variable
- "ajax" == this.options.mode ? this.isAjaxMode = true : this.isAjaxMode =
false;
+ this.isAjaxMode = this.options.mode == "ajax";
- /*
- //events handler binding
- for (var i in eventHandlerNames) {
- var handler = this.options["on"+eventHandlerNames[i]];
- if (handler) rf.Event.bindById(this.id, eventHandlerNames[i], handler, this);
- }
- */
+ //alert(new Date().getTime()-_d.getTime());
};
// Extend component class and add protected methods from parent class to our container
@@ -892,7 +902,9 @@
$(rf.getDomElement(this.CALENDAR_CONTENT)).hide();
this.isVisible = false;
-
+ if (this.options.defaultLabel && !this.isFocused) {
+ updateDefaultLabel.call(this, this.options.defaultLabel);
+ }
}
},
@@ -917,7 +929,9 @@
var baseInput = base.firstChild;
var baseButton = baseInput.nextSibling;
- if (baseInput && baseInput.value!=undefined)
+ if (this.options.defaultLabel) {
+ if (!this.isFocused) updateDefaultLabel.call(this, "");
+ } else if (baseInput.value!=undefined)
{
this.selectDate(baseInput.value, false, {event:e, element:element});
}
Modified: trunk/ui/input/ui/src/main/templates/calendar.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/calendar.template.xml 2010-12-29 16:31:41 UTC
(rev 20840)
+++ trunk/ui/input/ui/src/main/templates/calendar.template.xml 2010-12-29 16:46:42 UTC
(rev 20841)
@@ -69,7 +69,7 @@
<script type="text/javascript">
<cdk:scriptObject name="options">
- <cdk:scriptOption attributes="enableManualInput disabled readonly
resetTimeOnDateSelect showApplyButton popup showInput showHeader showFooter showWeeksBar
todayControlMode datePattern jointPoint direction boundaryDatesMode horizontalOffset
verticalOffset hidePopupOnScrol showWeekDaysBar styleClass mode" />
+ <cdk:scriptOption attributes="enableManualInput disabled readonly
resetTimeOnDateSelect showApplyButton popup showInput showHeader showFooter showWeeksBar
todayControlMode datePattern jointPoint direction boundaryDatesMode horizontalOffset
verticalOffset hidePopupOnScrol showWeekDaysBar styleClass mode defaultLabel" />
<cdk:scriptOption attributes="onchange ondateselect onbeforedateselect
onbeforecurrentdateselect onhide onshow ondatemouseover ondatemouseout onclean
ontimeselect onbeforetimeselect" wrapper="eventHandler" />
<cdk:scriptOption name="currentDate"
value="#{getCurrentDate(facesContext, component)}" />
<cdk:scriptOption name="selectedDate"
value="#{getSelectedDate(facesContext, component)}" />