7d3b9e2c014707450db9e3d76db0e1c14adc0155.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /**
  7. * @class Ext.form.TimeField
  8. * @extends Ext.form.ComboBox Provides a time input field with a time dropdown
  9. * and automatic time validation.
  10. * @constructor Create a new TimeField
  11. * @param {Object}
  12. * config
  13. */
  14. Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
  15. /**
  16. * @cfg {Date/String} minValue The minimum allowed time. Can be either a
  17. * Javascript date object or a string date in a valid format (defaults
  18. * to null).
  19. */
  20. minValue : null,
  21. /**
  22. * @cfg {Date/String} maxValue The maximum allowed time. Can be either a
  23. * Javascript date object or a string date in a valid format (defaults
  24. * to null).
  25. */
  26. maxValue : null,
  27. /**
  28. * @cfg {String} minText The error text to display when the date in the cell
  29. * is before minValue (defaults to 'The time in this field must be
  30. * equal to or after {0}').
  31. */
  32. minText : "The time in this field must be equal to or after {0}",
  33. /**
  34. * @cfg {String} maxText The error text to display when the time is after
  35. * maxValue (defaults to 'The time in this field must be equal to or
  36. * before {0}').
  37. */
  38. maxText : "The time in this field must be equal to or before {0}",
  39. /**
  40. * @cfg {String} invalidText The error text to display when the time in the
  41. * field is invalid (defaults to '{value} is not a valid time - it must
  42. * be in the format {format}').
  43. */
  44. invalidText : "{0} is not a valid time",
  45. /**
  46. * @cfg {String} format The default date format string which can be
  47. * overriden for localization support. The format must be valid
  48. * according to {@link Date#parseDate} (defaults to 'm/d/y').
  49. */
  50. format : "g:i A",
  51. /**
  52. * @cfg {String} altFormats Multiple date formats separated by "|" to try
  53. * when parsing a user input value and it doesn't match the defined
  54. * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
  55. */
  56. altFormats : "g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H",
  57. /**
  58. * @cfg {Number} increment The number of minutes between each time value in
  59. * the list (defaults to 15).
  60. */
  61. increment : 15,
  62. // private override
  63. mode : 'local',
  64. // private override
  65. triggerAction : 'all',
  66. // private override
  67. typeAhead : false,
  68. // private
  69. initComponent : function() {
  70. Ext.form.TimeField.superclass.initComponent.call(this);
  71. if (typeof this.minValue == "string") {
  72. this.minValue = this.parseDate(this.minValue);
  73. }
  74. if (typeof this.maxValue == "string") {
  75. this.maxValue = this.parseDate(this.maxValue);
  76. }
  77. if (!this.store) {
  78. var min = this.parseDate(this.minValue);
  79. if (!min) {
  80. min = allGetServerTime().clearTime();
  81. }
  82. var max = this.parseDate(this.maxValue);
  83. if (!max) {
  84. max = allGetServerTime().clearTime().add('mi', (24 * 60) - 1);
  85. }
  86. var times = [];
  87. while (min <= max) {
  88. times.push([min.dateFormat(this.format)]);
  89. min = min.add('mi', this.increment);
  90. }
  91. this.store = new Ext.data.SimpleStore({
  92. fields : ['text'],
  93. data : times
  94. });
  95. this.displayField = 'text';
  96. }
  97. },
  98. // inherited docs
  99. getValue : function() {
  100. var v = Ext.form.TimeField.superclass.getValue.call(this);
  101. return this.formatDate(this.parseDate(v)) || '';
  102. },
  103. // inherited docs
  104. setValue : function(value) {
  105. Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this
  106. .parseDate(value)));
  107. },
  108. // private overrides
  109. validateValue : Ext.form.DateField.prototype.validateValue,
  110. parseDate : Ext.form.DateField.prototype.parseDate,
  111. formatDate : Ext.form.DateField.prototype.formatDate,
  112. // private
  113. beforeBlur : function() {
  114. var v = this.parseDate(this.getRawValue());
  115. if (v) {
  116. this.setValue(v.dateFormat(this.format));
  117. }
  118. }
  119. /**
  120. * @cfg {Boolean} grow
  121. * @hide
  122. */
  123. /**
  124. * @cfg {Number} growMin
  125. * @hide
  126. */
  127. /**
  128. * @cfg {Number} growMax
  129. * @hide
  130. */
  131. /**
  132. * @hide
  133. * @method autoSize
  134. */
  135. });
  136. Ext.reg('timefield', Ext.form.TimeField);