123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- if (!dojo._hasResource["dijit.form.TimeTextBox"]) { // _hasResource checks added
- // by build. Do not use
- // _hasResource directly in
- // your code.
- dojo._hasResource["dijit.form.TimeTextBox"] = true;
- dojo.provide("dijit.form.TimeTextBox");
- dojo.require("dojo.date");
- dojo.require("dojo.date.locale");
- dojo.require("dojo.date.stamp");
- dojo.require("dijit._TimePicker");
- dojo.require("dijit.form.ValidationTextBox");
- dojo.declare("dijit.form.TimeTextBox", dijit.form.RangeBoundTextBox, {
- // summary:
- // A validating, serializable, range-bound date text box.
- // constraints object: min, max
- regExpGen : dojo.date.locale.regexp,
- compare : dojo.date.compare,
- format : function(/* Date */value, /* Object */constraints) {
- if (!value || value.toString() == this._invalid) {
- return null;
- }
- return dojo.date.locale.format(value, constraints);
- },
- parse : dojo.date.locale.parse,
- serialize : dojo.date.stamp.toISOString,
- value : new Date(""), // NaN
- _invalid : (new Date("")).toString(), // NaN
- _popupClass : "dijit._TimePicker",
- postMixInProperties : function() {
- // dijit.form.RangeBoundTextBox.prototype.postMixInProperties.apply(this,
- // arguments);
- this.inherited("postMixInProperties", arguments);
- var constraints = this.constraints;
- constraints.selector = 'time';
- if (typeof constraints.min == "string") {
- constraints.min = dojo.date.stamp
- .fromISOString(constraints.min);
- }
- if (typeof constraints.max == "string") {
- constraints.max = dojo.date.stamp
- .fromISOString(constraints.max);
- }
- },
- _onFocus : function(/* Event */evt) {
- // summary: open the TimePicker popup
- this._open();
- },
- setValue : function(/* Date */value, /* Boolean, optional */
- priorityChange) {
- // summary:
- // Sets the date on this textbox
- this.inherited('setValue', arguments);
- if (this._picker) {
- // #3948: fix blank date on popup only
- if (!value || value.toString() == this._invalid) {
- value = allGetServerTime();
- }
- this._picker.setValue(value);
- }
- },
- _open : function() {
- // summary:
- // opens the TimePicker, and sets the onValueSelected value
- if (this.disabled) {
- return;
- }
- var self = this;
- if (!this._picker) {
- var popupProto = dojo.getObject(this._popupClass, false);
- this._picker = new popupProto({
- onValueSelected : function(value) {
- self.focus(); // focus the textbox before the
- // popup closes to avoid
- // reopening the popup
- setTimeout(dojo.hitch(self, "_close"), 1); // allow
- // focus
- // time
- // to
- // take
- // this will cause InlineEditBox and other
- // handlers to do stuff so make sure it's last
- dijit.form.TimeTextBox.superclass.setValue
- .call(self, value, true);
- },
- lang : this.lang,
- constraints : this.constraints,
- isDisabledDate : function(/* Date */date) {
- // summary:
- // disables dates outside of the min/max of the
- // TimeTextBox
- return self.constraints
- && (dojo.date.compare(
- self.constraints.min, date) > 0 || dojo.date
- .compare(self.constraints.max,
- date) < 0);
- }
- });
- this._picker.setValue(this.getValue() || allGetServerTime());
- }
- if (!this._opened) {
- dijit.popup.open({
- parent : this,
- popup : this._picker,
- around : this.domNode,
- onCancel : dojo.hitch(this, this._close),
- onClose : function() {
- self._opened = false;
- }
- });
- this._opened = true;
- }
- dojo.marginBox(this._picker.domNode, {
- w : this.domNode.offsetWidth
- });
- },
- _close : function() {
- if (this._opened) {
- dijit.popup.close(this._picker);
- this._opened = false;
- }
- },
- _onBlur : function() {
- // summary: called magically when focus has shifted away from this
- // widget and it's dropdown
- this._close();
- this.inherited('_onBlur', arguments);
- // don't focus on <input>. the user has explicitly focused on
- // something else.
- },
- getDisplayedValue : function() {
- return this.textbox.value;
- },
- setDisplayedValue : function(/* String */value) {
- this.textbox.value = value;
- }
- });
- }
|