Time2.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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-picker-Time'>/**
  19. </span> * A time picker which provides a list of times from which to choose. This is used by the Ext.form.field.Time
  20. * class to allow browsing and selection of valid times, but could also be used with other components.
  21. *
  22. * By default, all times starting at midnight and incrementing every 15 minutes will be presented. This list of
  23. * available times can be controlled using the {@link #minValue}, {@link #maxValue}, and {@link #increment}
  24. * configuration properties. The format of the times presented in the list can be customized with the {@link #format}
  25. * config.
  26. *
  27. * To handle when the user selects a time from the list, you can subscribe to the {@link #selectionchange} event.
  28. *
  29. * @example
  30. * Ext.create('Ext.picker.Time', {
  31. * width: 60,
  32. * minValue: Ext.Date.parse('04:30:00 AM', 'h:i:s A'),
  33. * maxValue: Ext.Date.parse('08:00:00 AM', 'h:i:s A'),
  34. * renderTo: Ext.getBody()
  35. * });
  36. */
  37. Ext.define('Ext.picker.Time', {
  38. extend: 'Ext.view.BoundList',
  39. alias: 'widget.timepicker',
  40. requires: ['Ext.data.Store', 'Ext.Date'],
  41. <span id='Ext-picker-Time-cfg-minValue'> /**
  42. </span> * @cfg {Date} minValue
  43. * The minimum time to be shown in the list of times. This must be a Date object (only the time fields will be
  44. * used); no parsing of String values will be done.
  45. */
  46. <span id='Ext-picker-Time-cfg-maxValue'> /**
  47. </span> * @cfg {Date} maxValue
  48. * The maximum time to be shown in the list of times. This must be a Date object (only the time fields will be
  49. * used); no parsing of String values will be done.
  50. */
  51. <span id='Ext-picker-Time-cfg-increment'> /**
  52. </span> * @cfg {Number} increment
  53. * The number of minutes between each time value in the list.
  54. */
  55. increment: 15,
  56. //&lt;locale&gt;
  57. <span id='Ext-picker-Time-cfg-format'> /**
  58. </span> * @cfg {String} [format=undefined]
  59. * The default time format string which can be overriden for localization support. The format must be valid
  60. * according to {@link Ext.Date#parse}.
  61. *
  62. * Defaults to `'g:i A'`, e.g., `'3:15 PM'`. For 24-hour time format try `'H:i'` instead.
  63. */
  64. format : &quot;g:i A&quot;,
  65. //&lt;/locale&gt;
  66. <span id='Ext-picker-Time-property-displayField'> /**
  67. </span> * @private
  68. * The field in the implicitly-generated Model objects that gets displayed in the list. This is
  69. * an internal field name only and is not useful to change via config.
  70. */
  71. displayField: 'disp',
  72. <span id='Ext-picker-Time-property-initDate'> /**
  73. </span> * @private
  74. * Year, month, and day that all times will be normalized into internally.
  75. */
  76. initDate: [2008,0,1],
  77. componentCls: Ext.baseCSSPrefix + 'timepicker',
  78. <span id='Ext-picker-Time-cfg-loadMask'> /**
  79. </span> * @cfg
  80. * @private
  81. */
  82. loadMask: false,
  83. initComponent: function() {
  84. var me = this,
  85. dateUtil = Ext.Date,
  86. clearTime = dateUtil.clearTime,
  87. initDate = me.initDate;
  88. // Set up absolute min and max for the entire day
  89. me.absMin = clearTime(new Date(initDate[0], initDate[1], initDate[2]));
  90. me.absMax = dateUtil.add(clearTime(new Date(initDate[0], initDate[1], initDate[2])), 'mi', (24 * 60) - 1);
  91. me.store = me.createStore();
  92. me.updateList();
  93. me.callParent();
  94. },
  95. <span id='Ext-picker-Time-method-setMinValue'> /**
  96. </span> * Set the {@link #minValue} and update the list of available times. This must be a Date object (only the time
  97. * fields will be used); no parsing of String values will be done.
  98. * @param {Date} value
  99. */
  100. setMinValue: function(value) {
  101. this.minValue = value;
  102. this.updateList();
  103. },
  104. <span id='Ext-picker-Time-method-setMaxValue'> /**
  105. </span> * Set the {@link #maxValue} and update the list of available times. This must be a Date object (only the time
  106. * fields will be used); no parsing of String values will be done.
  107. * @param {Date} value
  108. */
  109. setMaxValue: function(value) {
  110. this.maxValue = value;
  111. this.updateList();
  112. },
  113. <span id='Ext-picker-Time-method-normalizeDate'> /**
  114. </span> * @private
  115. * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
  116. * the time fields are significant. This makes values suitable for time comparison.
  117. * @param {Date} date
  118. */
  119. normalizeDate: function(date) {
  120. var initDate = this.initDate;
  121. date.setFullYear(initDate[0], initDate[1], initDate[2]);
  122. return date;
  123. },
  124. <span id='Ext-picker-Time-method-updateList'> /**
  125. </span> * Update the list of available times in the list to be constrained within the {@link #minValue}
  126. * and {@link #maxValue}.
  127. */
  128. updateList: function() {
  129. var me = this,
  130. min = me.normalizeDate(me.minValue || me.absMin),
  131. max = me.normalizeDate(me.maxValue || me.absMax);
  132. me.store.filterBy(function(record) {
  133. var date = record.get('date');
  134. return date &gt;= min &amp;&amp; date &lt;= max;
  135. });
  136. },
  137. <span id='Ext-picker-Time-method-createStore'> /**
  138. </span> * @private
  139. * Creates the internal {@link Ext.data.Store} that contains the available times. The store
  140. * is loaded with all possible times, and it is later filtered to hide those times outside
  141. * the minValue/maxValue.
  142. */
  143. createStore: function() {
  144. var me = this,
  145. utilDate = Ext.Date,
  146. times = [],
  147. min = me.absMin,
  148. max = me.absMax;
  149. while(min &lt;= max){
  150. times.push({
  151. disp: utilDate.dateFormat(min, me.format),
  152. date: min
  153. });
  154. min = utilDate.add(min, 'mi', me.increment);
  155. }
  156. return new Ext.data.Store({
  157. fields: ['disp', 'date'],
  158. data: times
  159. });
  160. }
  161. });
  162. </pre>
  163. </body>
  164. </html>