29d535d026219e2c5a0dd39a414182c85d637483.svn-base 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. if (!dojo._hasResource["dijit.form.TimeTextBox"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dijit.form.TimeTextBox"] = true;
  6. dojo.provide("dijit.form.TimeTextBox");
  7. dojo.require("dojo.date");
  8. dojo.require("dojo.date.locale");
  9. dojo.require("dojo.date.stamp");
  10. dojo.require("dijit._TimePicker");
  11. dojo.require("dijit.form.ValidationTextBox");
  12. dojo.declare("dijit.form.TimeTextBox", dijit.form.RangeBoundTextBox, {
  13. // summary:
  14. // A validating, serializable, range-bound date text box.
  15. // constraints object: min, max
  16. regExpGen : dojo.date.locale.regexp,
  17. compare : dojo.date.compare,
  18. format : function(/* Date */value, /* Object */constraints) {
  19. if (!value || value.toString() == this._invalid) {
  20. return null;
  21. }
  22. return dojo.date.locale.format(value, constraints);
  23. },
  24. parse : dojo.date.locale.parse,
  25. serialize : dojo.date.stamp.toISOString,
  26. value : new Date(""), // NaN
  27. _invalid : (new Date("")).toString(), // NaN
  28. _popupClass : "dijit._TimePicker",
  29. postMixInProperties : function() {
  30. // dijit.form.RangeBoundTextBox.prototype.postMixInProperties.apply(this,
  31. // arguments);
  32. this.inherited("postMixInProperties", arguments);
  33. var constraints = this.constraints;
  34. constraints.selector = 'time';
  35. if (typeof constraints.min == "string") {
  36. constraints.min = dojo.date.stamp
  37. .fromISOString(constraints.min);
  38. }
  39. if (typeof constraints.max == "string") {
  40. constraints.max = dojo.date.stamp
  41. .fromISOString(constraints.max);
  42. }
  43. },
  44. _onFocus : function(/* Event */evt) {
  45. // summary: open the TimePicker popup
  46. this._open();
  47. },
  48. setValue : function(/* Date */value, /* Boolean, optional */
  49. priorityChange) {
  50. // summary:
  51. // Sets the date on this textbox
  52. this.inherited('setValue', arguments);
  53. if (this._picker) {
  54. // #3948: fix blank date on popup only
  55. if (!value || value.toString() == this._invalid) {
  56. value = allGetServerTime();
  57. }
  58. this._picker.setValue(value);
  59. }
  60. },
  61. _open : function() {
  62. // summary:
  63. // opens the TimePicker, and sets the onValueSelected value
  64. if (this.disabled) {
  65. return;
  66. }
  67. var self = this;
  68. if (!this._picker) {
  69. var popupProto = dojo.getObject(this._popupClass, false);
  70. this._picker = new popupProto({
  71. onValueSelected : function(value) {
  72. self.focus(); // focus the textbox before the
  73. // popup closes to avoid
  74. // reopening the popup
  75. setTimeout(dojo.hitch(self, "_close"), 1); // allow
  76. // focus
  77. // time
  78. // to
  79. // take
  80. // this will cause InlineEditBox and other
  81. // handlers to do stuff so make sure it's last
  82. dijit.form.TimeTextBox.superclass.setValue
  83. .call(self, value, true);
  84. },
  85. lang : this.lang,
  86. constraints : this.constraints,
  87. isDisabledDate : function(/* Date */date) {
  88. // summary:
  89. // disables dates outside of the min/max of the
  90. // TimeTextBox
  91. return self.constraints
  92. && (dojo.date.compare(
  93. self.constraints.min, date) > 0 || dojo.date
  94. .compare(self.constraints.max,
  95. date) < 0);
  96. }
  97. });
  98. this._picker.setValue(this.getValue() || allGetServerTime());
  99. }
  100. if (!this._opened) {
  101. dijit.popup.open({
  102. parent : this,
  103. popup : this._picker,
  104. around : this.domNode,
  105. onCancel : dojo.hitch(this, this._close),
  106. onClose : function() {
  107. self._opened = false;
  108. }
  109. });
  110. this._opened = true;
  111. }
  112. dojo.marginBox(this._picker.domNode, {
  113. w : this.domNode.offsetWidth
  114. });
  115. },
  116. _close : function() {
  117. if (this._opened) {
  118. dijit.popup.close(this._picker);
  119. this._opened = false;
  120. }
  121. },
  122. _onBlur : function() {
  123. // summary: called magically when focus has shifted away from this
  124. // widget and it's dropdown
  125. this._close();
  126. this.inherited('_onBlur', arguments);
  127. // don't focus on <input>. the user has explicitly focused on
  128. // something else.
  129. },
  130. getDisplayedValue : function() {
  131. return this.textbox.value;
  132. },
  133. setDisplayedValue : function(/* String */value) {
  134. this.textbox.value = value;
  135. }
  136. });
  137. }