CallBackery
view release on metacpan or search on metacpan
lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/form/DateTime.js view on Meta::CPAN
/* ************************************************************************
After Qooxdoo DateField widget
Copyright:
2015 Oetiker+Partner AG
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Martin Wittemann (martinwittemann)
* Fritz Zaucker
************************************************************************ */
// FIX ME: should be derived from Qooxdoo DateField.
/**
* A *date field* is like a combo box with the date as popup. As button to
* open the calendar a calendar icon is shown at the right to the datefield.
*
* In addition a time textfield.
*
* To be conform with all form widgets, the {@link qx.ui.form.IForm} interface
* is implemented.
*
* The following example creates a date field and sets the current
* date as selected.
*
* <pre class='javascript'>
* var dateTimeField = new callbackery.ui.form.DateTime();
* this.getRoot().add(dateTimeField, {top: 20, left: 20});
* dateField.setValue(new Date());
* </pre>
*
* @childControl list {qx.ui.control.DateChooser} date chooser component
* @childControl popup {qx.ui.popup.Popup} popup which shows the list control
* @childControl datefield {qx.ui.form.TextField} text field for manual date entry
* @childControl timefield {qx.ui.form.TextField} text field for manual date entry
* @childControl button {qx.ui.form.Button} button that opens the list control
*/
qx.Class.define("callbackery.ui.form.DateTime",
{
extend : qx.ui.core.Widget,
include : [
qx.ui.core.MRemoteChildrenHandling,
qx.ui.form.MForm
],
implement : [
qx.ui.form.IForm,
qx.ui.form.IDateForm
],
/*
*****************************************************************************
CONSTRUCTOR
*****************************************************************************
*/
construct : function()
{
this.base(arguments);
// set the layout
var layout = new qx.ui.layout.HBox();
this._setLayout(layout);
layout.setAlignY("middle");
this.setMaxWidth(220);
// datefield and button
var dateField = this._createChildControl("datefield");
this._createChildControl("button");
// timefield
var timeField = this._createChildControl("timefield");
// register listeners
this.addListener("tap", this._onTap, this);
this.addListener("blur", this._onBlur, this);
lib/CallBackery/qooxdoo/callbackery/source/class/callbackery/ui/form/DateTime.js view on Meta::CPAN
MEMBERS
*****************************************************************************
*/
members :
{
__localeListenerId : null,
/**
* @lint ignoreReferenceField(_forwardStates)
*/
_forwardStates : {
focused : true,
invalid : true
},
/*
---------------------------------------------------------------------------
PROTECTED METHODS
---------------------------------------------------------------------------
*/
/**
* Sets the default date format which is returned by
* {@link #getDefaultDateFormatter}. You can overrride this method to
* define your own default format.
*/
_setDefaultDateFormat : function() {
this.setDateFormat(qx.ui.form.DateField.getDefaultDateFormatter());
},
/**
* Checks for "qx.dynlocale" and adds a listener to the locale changes.
* On every change, {@link #_setDefaultDateFormat} is called to reinitialize
* the format. You can easily override that method to prevent that behavior.
*/
_addLocaleChangeListener : function() {
// listen for locale changes
if (qx.core.Environment.get("qx.dynlocale"))
{
this.__localeListenerId =
qx.locale.Manager.getInstance().addListener("changeLocale", function() {
this._setDefaultDateFormat();
}, this);
}
},
/*
---------------------------------------------------------------------------
PUBLIC METHODS
---------------------------------------------------------------------------
*/
/**
* This method sets the date, which will be formatted according to
* #dateFormat to the date field. It will also select the date in the
* calendar popup.
*
* @param value {Date} The date to set.
*/
setValue : function(value)
{
// set the date to the textfield
if (value != null) {
this.getChildControl("datefield").setValue(this.getDateFormat().format(value));
var h = value.getHours();
var m = value.getMinutes();
while (m.length<2) {
m = '0'+m;
}
while (h.length<2) {
h = '0'+h;
}
this.getChildControl("timefield").setValue(h+':'+m);
// set the date in the datechooser
var dateChooser = this.getChildControl("list");
dateChooser.setValue(value);
}
},
/**
* Returns the current set date, parsed from the input-field
* corresponding to the {@link #dateFormat}.
* If the given text could not be parsed, <code>null</code> will be returned.
*
* @return {Date} The currently set date.
*/
getValue : function()
{
// get the value of the textfields
var dc = this.getChildControl("datefield");
var tc = this.getChildControl("timefield");
var datefieldValue = dc.getValue();
var timefieldValue = tc.getValue();
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setMilliseconds(0);
var value = today;
// this.debug('getValue(): date=', datefieldValue, ', time=', timefieldValue);
// return the parsed date
try {
if (datefieldValue != null) {
try {
value = this.getDateFormat().parse(datefieldValue);
}
catch (ex) {
this.debug('getValue(): Invalid date format');
}
}
var t = value.getTime();
var ta = ['00','00'];
if (timefieldValue != null && timefieldValue != '') {
( run in 2.595 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )