You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
8.3 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-form-TimeField-method-constructor'><span id='Ext-form-TimeField'>/**
  19. </span></span> * @class Ext.form.TimeField
  20. * @extends Ext.form.ComboBox
  21. * Provides a time input field with a time dropdown and automatic time validation. Example usage:
  22. * &lt;pre&gt;&lt;code&gt;
  23. new Ext.form.TimeField({
  24. minValue: '9:00 AM',
  25. maxValue: '6:00 PM',
  26. increment: 30
  27. });
  28. &lt;/code&gt;&lt;/pre&gt;
  29. * @constructor
  30. * Create a new TimeField
  31. * @param {Object} config
  32. * @xtype timefield
  33. */
  34. Ext.form.TimeField = Ext.extend(Ext.form.ComboBox, {
  35. <span id='Ext-form-TimeField-cfg-minValue'> /**
  36. </span> * @cfg {Date/String} minValue
  37. * The minimum allowed time. Can be either a Javascript date object with a valid time value or a string
  38. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  39. */
  40. minValue : undefined,
  41. <span id='Ext-form-TimeField-cfg-maxValue'> /**
  42. </span> * @cfg {Date/String} maxValue
  43. * The maximum allowed time. Can be either a Javascript date object with a valid time value or a string
  44. * time in a valid format -- see {@link #format} and {@link #altFormats} (defaults to undefined).
  45. */
  46. maxValue : undefined,
  47. <span id='Ext-form-TimeField-cfg-minText'> /**
  48. </span> * @cfg {String} minText
  49. * The error text to display when the date in the cell is before minValue (defaults to
  50. * 'The time in this field must be equal to or after {0}').
  51. */
  52. minText : &quot;The time in this field must be equal to or after {0}&quot;,
  53. <span id='Ext-form-TimeField-cfg-maxText'> /**
  54. </span> * @cfg {String} maxText
  55. * The error text to display when the time is after maxValue (defaults to
  56. * 'The time in this field must be equal to or before {0}').
  57. */
  58. maxText : &quot;The time in this field must be equal to or before {0}&quot;,
  59. <span id='Ext-form-TimeField-cfg-invalidText'> /**
  60. </span> * @cfg {String} invalidText
  61. * The error text to display when the time in the field is invalid (defaults to
  62. * '{value} is not a valid time').
  63. */
  64. invalidText : &quot;{0} is not a valid time&quot;,
  65. <span id='Ext-form-TimeField-cfg-format'> /**
  66. </span> * @cfg {String} format
  67. * The default time format string which can be overriden for localization support. The format must be
  68. * valid according to {@link Date#parseDate} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time
  69. * format try 'H:i' instead.
  70. */
  71. format : &quot;g:i A&quot;,
  72. <span id='Ext-form-TimeField-cfg-altFormats'> /**
  73. </span> * @cfg {String} altFormats
  74. * Multiple date formats separated by &quot;|&quot; to try when parsing a user input value and it doesn't match the defined
  75. * format (defaults to '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|gi a|hi a|giA|hiA|gi A|hi A').
  76. */
  77. altFormats : &quot;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|gi a|hi a|giA|hiA|gi A|hi A&quot;,
  78. <span id='Ext-form-TimeField-cfg-increment'> /**
  79. </span> * @cfg {Number} increment
  80. * The number of minutes between each time value in the list (defaults to 15).
  81. */
  82. increment: 15,
  83. <span id='Ext-form-TimeField-cfg-mode'> // private override
  84. </span> mode: 'local',
  85. <span id='Ext-form-TimeField-cfg-triggerAction'> // private override
  86. </span> triggerAction: 'all',
  87. <span id='Ext-form-TimeField-cfg-typeAhead'> // private override
  88. </span> typeAhead: false,
  89. <span id='Ext-form-TimeField-property-initDate'> // private - This is the date to use when generating time values in the absence of either minValue
  90. </span> // or maxValue. Using the current date causes DST issues on DST boundary dates, so this is an
  91. // arbitrary &quot;safe&quot; date that can be any date aside from DST boundary dates.
  92. initDate: '1/1/2008',
  93. <span id='Ext-form-TimeField-property-initDateFormat'> initDateFormat: 'j/n/Y',
  94. </span>
  95. <span id='Ext-form-TimeField-method-initComponent'> // private
  96. </span> initComponent : function(){
  97. if(Ext.isDefined(this.minValue)){
  98. this.setMinValue(this.minValue, true);
  99. }
  100. if(Ext.isDefined(this.maxValue)){
  101. this.setMaxValue(this.maxValue, true);
  102. }
  103. if(!this.store){
  104. this.generateStore(true);
  105. }
  106. Ext.form.TimeField.superclass.initComponent.call(this);
  107. },
  108. <span id='Ext-form-TimeField-method-setMinValue'> /**
  109. </span> * Replaces any existing {@link #minValue} with the new time and refreshes the store.
  110. * @param {Date/String} value The minimum time that can be selected
  111. */
  112. setMinValue: function(value, /* private */ initial){
  113. this.setLimit(value, true, initial);
  114. return this;
  115. },
  116. <span id='Ext-form-TimeField-method-setMaxValue'> /**
  117. </span> * Replaces any existing {@link #maxValue} with the new time and refreshes the store.
  118. * @param {Date/String} value The maximum time that can be selected
  119. */
  120. setMaxValue: function(value, /* private */ initial){
  121. this.setLimit(value, false, initial);
  122. return this;
  123. },
  124. <span id='Ext-form-TimeField-method-generateStore'> // private
  125. </span> generateStore: function(initial){
  126. var min = this.minValue || new Date(this.initDate).clearTime(),
  127. max = this.maxValue || new Date(this.initDate).clearTime().add('mi', (24 * 60) - 1),
  128. times = [];
  129. while(min &lt;= max){
  130. times.push(min.dateFormat(this.format));
  131. min = min.add('mi', this.increment);
  132. }
  133. this.bindStore(times, initial);
  134. },
  135. <span id='Ext-form-TimeField-method-setLimit'> // private
  136. </span> setLimit: function(value, isMin, initial){
  137. var d;
  138. if(Ext.isString(value)){
  139. d = this.parseDate(value);
  140. }else if(Ext.isDate(value)){
  141. d = value;
  142. }
  143. if(d){
  144. var val = new Date(this.initDate).clearTime();
  145. val.setHours(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
  146. this[isMin ? 'minValue' : 'maxValue'] = val;
  147. if(!initial){
  148. this.generateStore();
  149. }
  150. }
  151. },
  152. <span id='Ext-form-TimeField-method-getValue'> // inherited docs
  153. </span> getValue : function(){
  154. var v = Ext.form.TimeField.superclass.getValue.call(this);
  155. return this.formatDate(this.parseDate(v)) || '';
  156. },
  157. <span id='Ext-form-TimeField-method-setValue'> // inherited docs
  158. </span> setValue : function(value){
  159. return Ext.form.TimeField.superclass.setValue.call(this, this.formatDate(this.parseDate(value)));
  160. },
  161. <span id='Ext-form-TimeField-property-validateValue'> // private overrides
  162. </span> validateValue : Ext.form.DateField.prototype.validateValue,
  163. <span id='Ext-form-TimeField-property-formatDate'> formatDate : Ext.form.DateField.prototype.formatDate,
  164. </span>
  165. <span id='Ext-form-TimeField-method-parseDate'> parseDate: function(value) {
  166. </span> if (!value || Ext.isDate(value)) {
  167. return value;
  168. }
  169. var id = this.initDate + ' ',
  170. idf = this.initDateFormat + ' ',
  171. v = Date.parseDate(id + value, idf + this.format), // *** handle DST. note: this.format is a TIME-only format
  172. af = this.altFormats;
  173. if (!v &amp;&amp; af) {
  174. if (!this.altFormatsArray) {
  175. this.altFormatsArray = af.split(&quot;|&quot;);
  176. }
  177. for (var i = 0, afa = this.altFormatsArray, len = afa.length; i &lt; len &amp;&amp; !v; i++) {
  178. v = Date.parseDate(id + value, idf + afa[i]);
  179. }
  180. }
  181. return v;
  182. }
  183. });
  184. Ext.reg('timefield', Ext.form.TimeField);</pre>
  185. </body>
  186. </html>