PageRenderTime 152ms CodeModel.GetById 100ms RepoModel.GetById 19ms app.codeStats 1ms

/ext-4.0.7/docs/source/Time2.html

https://bitbucket.org/srogerf/javascript
HTML | 181 lines | 160 code | 21 blank | 0 comment | 0 complexity | ef538ac92d2e6cbb012d9a21d3ac3f9a MD5 | raw file
  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. <span id='Ext-picker-Time-cfg-format'> /**
  57. </span> * @cfg {String} format
  58. * The default time format string which can be overriden for localization support. The format must be valid
  59. * according to {@link Ext.Date#parse} (defaults to 'g:i A', e.g., '3:15 PM'). For 24-hour time format try 'H:i'
  60. * instead.
  61. */
  62. format : &quot;g:i A&quot;,
  63. <span id='Ext-picker-Time-property-displayField'> /**
  64. </span> * @hide
  65. * The field in the implicitly-generated Model objects that gets displayed in the list. This is
  66. * an internal field name only and is not useful to change via config.
  67. */
  68. displayField: 'disp',
  69. <span id='Ext-picker-Time-property-initDate'> /**
  70. </span> * @private
  71. * Year, month, and day that all times will be normalized into internally.
  72. */
  73. initDate: [2008,0,1],
  74. componentCls: Ext.baseCSSPrefix + 'timepicker',
  75. <span id='Ext-picker-Time-property-loadMask'> /**
  76. </span> * @hide
  77. */
  78. loadMask: false,
  79. initComponent: function() {
  80. var me = this,
  81. dateUtil = Ext.Date,
  82. clearTime = dateUtil.clearTime,
  83. initDate = me.initDate;
  84. // Set up absolute min and max for the entire day
  85. me.absMin = clearTime(new Date(initDate[0], initDate[1], initDate[2]));
  86. me.absMax = dateUtil.add(clearTime(new Date(initDate[0], initDate[1], initDate[2])), 'mi', (24 * 60) - 1);
  87. me.store = me.createStore();
  88. me.updateList();
  89. me.callParent();
  90. },
  91. <span id='Ext-picker-Time-method-setMinValue'> /**
  92. </span> * Set the {@link #minValue} and update the list of available times. This must be a Date object (only the time
  93. * fields will be used); no parsing of String values will be done.
  94. * @param {Date} value
  95. */
  96. setMinValue: function(value) {
  97. this.minValue = value;
  98. this.updateList();
  99. },
  100. <span id='Ext-picker-Time-method-setMaxValue'> /**
  101. </span> * Set the {@link #maxValue} and update the list of available times. This must be a Date object (only the time
  102. * fields will be used); no parsing of String values will be done.
  103. * @param {Date} value
  104. */
  105. setMaxValue: function(value) {
  106. this.maxValue = value;
  107. this.updateList();
  108. },
  109. <span id='Ext-picker-Time-method-normalizeDate'> /**
  110. </span> * @private
  111. * Sets the year/month/day of the given Date object to the {@link #initDate}, so that only
  112. * the time fields are significant. This makes values suitable for time comparison.
  113. * @param {Date} date
  114. */
  115. normalizeDate: function(date) {
  116. var initDate = this.initDate;
  117. date.setFullYear(initDate[0], initDate[1], initDate[2]);
  118. return date;
  119. },
  120. <span id='Ext-picker-Time-method-updateList'> /**
  121. </span> * Update the list of available times in the list to be constrained within the {@link #minValue}
  122. * and {@link #maxValue}.
  123. */
  124. updateList: function() {
  125. var me = this,
  126. min = me.normalizeDate(me.minValue || me.absMin),
  127. max = me.normalizeDate(me.maxValue || me.absMax);
  128. me.store.filterBy(function(record) {
  129. var date = record.get('date');
  130. return date &gt;= min &amp;&amp; date &lt;= max;
  131. });
  132. },
  133. <span id='Ext-picker-Time-method-createStore'> /**
  134. </span> * @private
  135. * Creates the internal {@link Ext.data.Store} that contains the available times. The store
  136. * is loaded with all possible times, and it is later filtered to hide those times outside
  137. * the minValue/maxValue.
  138. */
  139. createStore: function() {
  140. var me = this,
  141. utilDate = Ext.Date,
  142. times = [],
  143. min = me.absMin,
  144. max = me.absMax;
  145. while(min &lt;= max){
  146. times.push({
  147. disp: utilDate.dateFormat(min, me.format),
  148. date: min
  149. });
  150. min = utilDate.add(min, 'mi', me.increment);
  151. }
  152. return Ext.create('Ext.data.Store', {
  153. fields: ['disp', 'date'],
  154. data: times
  155. });
  156. }
  157. });
  158. </pre>
  159. </body>
  160. </html>