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.

809 lines
33 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-DatePicker-method-constructor'><span id='Ext-DatePicker'>/**
  19. </span></span> * @class Ext.DatePicker
  20. * @extends Ext.Component
  21. * &lt;p&gt;A popup date picker. This class is used by the {@link Ext.form.DateField DateField} class
  22. * to allow browsing and selection of valid dates.&lt;/p&gt;
  23. * &lt;p&gt;All the string values documented below may be overridden by including an Ext locale file in
  24. * your page.&lt;/p&gt;
  25. * @constructor
  26. * Create a new DatePicker
  27. * @param {Object} config The config object
  28. * @xtype datepicker
  29. */
  30. Ext.DatePicker = Ext.extend(Ext.BoxComponent, {
  31. <span id='Ext-DatePicker-cfg-todayText'> /**
  32. </span> * @cfg {String} todayText
  33. * The text to display on the button that selects the current date (defaults to &lt;code&gt;'Today'&lt;/code&gt;)
  34. */
  35. todayText : 'Today',
  36. <span id='Ext-DatePicker-cfg-okText'> /**
  37. </span> * @cfg {String} okText
  38. * The text to display on the ok button (defaults to &lt;code&gt;'&amp;#160;OK&amp;#160;'&lt;/code&gt; to give the user extra clicking room)
  39. */
  40. okText : '&amp;#160;OK&amp;#160;',
  41. <span id='Ext-DatePicker-cfg-cancelText'> /**
  42. </span> * @cfg {String} cancelText
  43. * The text to display on the cancel button (defaults to &lt;code&gt;'Cancel'&lt;/code&gt;)
  44. */
  45. cancelText : 'Cancel',
  46. <span id='Ext-DatePicker-cfg-handler'> /**
  47. </span> * @cfg {Function} handler
  48. * Optional. A function that will handle the select event of this picker.
  49. * The handler is passed the following parameters:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  50. * &lt;li&gt;&lt;code&gt;picker&lt;/code&gt; : DatePicker&lt;div class=&quot;sub-desc&quot;&gt;This DatePicker.&lt;/div&gt;&lt;/li&gt;
  51. * &lt;li&gt;&lt;code&gt;date&lt;/code&gt; : Date&lt;div class=&quot;sub-desc&quot;&gt;The selected date.&lt;/div&gt;&lt;/li&gt;
  52. * &lt;/ul&gt;&lt;/div&gt;
  53. */
  54. <span id='Ext-DatePicker-cfg-scope'> /**
  55. </span> * @cfg {Object} scope
  56. * The scope (&lt;code&gt;&lt;b&gt;this&lt;/b&gt;&lt;/code&gt; reference) in which the &lt;code&gt;{@link #handler}&lt;/code&gt;
  57. * function will be called. Defaults to this DatePicker instance.
  58. */
  59. <span id='Ext-DatePicker-cfg-todayTip'> /**
  60. </span> * @cfg {String} todayTip
  61. * A string used to format the message for displaying in a tooltip over the button that
  62. * selects the current date. Defaults to &lt;code&gt;'{0} (Spacebar)'&lt;/code&gt; where
  63. * the &lt;code&gt;{0}&lt;/code&gt; token is replaced by today's date.
  64. */
  65. todayTip : '{0} (Spacebar)',
  66. <span id='Ext-DatePicker-cfg-minText'> /**
  67. </span> * @cfg {String} minText
  68. * The error text to display if the minDate validation fails (defaults to &lt;code&gt;'This date is before the minimum date'&lt;/code&gt;)
  69. */
  70. minText : 'This date is before the minimum date',
  71. <span id='Ext-DatePicker-cfg-maxText'> /**
  72. </span> * @cfg {String} maxText
  73. * The error text to display if the maxDate validation fails (defaults to &lt;code&gt;'This date is after the maximum date'&lt;/code&gt;)
  74. */
  75. maxText : 'This date is after the maximum date',
  76. <span id='Ext-DatePicker-cfg-format'> /**
  77. </span> * @cfg {String} format
  78. * The default date format string which can be overriden for localization support. The format must be
  79. * valid according to {@link Date#parseDate} (defaults to &lt;code&gt;'m/d/y'&lt;/code&gt;).
  80. */
  81. format : 'm/d/y',
  82. <span id='Ext-DatePicker-cfg-disabledDaysText'> /**
  83. </span> * @cfg {String} disabledDaysText
  84. * The tooltip to display when the date falls on a disabled day (defaults to &lt;code&gt;'Disabled'&lt;/code&gt;)
  85. */
  86. disabledDaysText : 'Disabled',
  87. <span id='Ext-DatePicker-cfg-disabledDatesText'> /**
  88. </span> * @cfg {String} disabledDatesText
  89. * The tooltip text to display when the date falls on a disabled date (defaults to &lt;code&gt;'Disabled'&lt;/code&gt;)
  90. */
  91. disabledDatesText : 'Disabled',
  92. <span id='Ext-DatePicker-cfg-monthNames'> /**
  93. </span> * @cfg {Array} monthNames
  94. * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
  95. */
  96. monthNames : Date.monthNames,
  97. <span id='Ext-DatePicker-cfg-dayNames'> /**
  98. </span> * @cfg {Array} dayNames
  99. * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
  100. */
  101. dayNames : Date.dayNames,
  102. <span id='Ext-DatePicker-cfg-nextText'> /**
  103. </span> * @cfg {String} nextText
  104. * The next month navigation button tooltip (defaults to &lt;code&gt;'Next Month (Control+Right)'&lt;/code&gt;)
  105. */
  106. nextText : 'Next Month (Control+Right)',
  107. <span id='Ext-DatePicker-cfg-prevText'> /**
  108. </span> * @cfg {String} prevText
  109. * The previous month navigation button tooltip (defaults to &lt;code&gt;'Previous Month (Control+Left)'&lt;/code&gt;)
  110. */
  111. prevText : 'Previous Month (Control+Left)',
  112. <span id='Ext-DatePicker-cfg-monthYearText'> /**
  113. </span> * @cfg {String} monthYearText
  114. * The header month selector tooltip (defaults to &lt;code&gt;'Choose a month (Control+Up/Down to move years)'&lt;/code&gt;)
  115. */
  116. monthYearText : 'Choose a month (Control+Up/Down to move years)',
  117. <span id='Ext-DatePicker-cfg-startDay'> /**
  118. </span> * @cfg {Number} startDay
  119. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  120. */
  121. startDay : 0,
  122. <span id='Ext-DatePicker-cfg-showToday'> /**
  123. </span> * @cfg {Boolean} showToday
  124. * False to hide the footer area containing the Today button and disable the keyboard handler for spacebar
  125. * that selects the current date (defaults to &lt;code&gt;true&lt;/code&gt;).
  126. */
  127. showToday : true,
  128. <span id='Ext-DatePicker-cfg-minDate'> /**
  129. </span> * @cfg {Date} minDate
  130. * Minimum allowable date (JavaScript date object, defaults to null)
  131. */
  132. <span id='Ext-DatePicker-cfg-maxDate'> /**
  133. </span> * @cfg {Date} maxDate
  134. * Maximum allowable date (JavaScript date object, defaults to null)
  135. */
  136. <span id='Ext-DatePicker-cfg-disabledDays'> /**
  137. </span> * @cfg {Array} disabledDays
  138. * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
  139. */
  140. <span id='Ext-DatePicker-cfg-disabledDatesRE'> /**
  141. </span> * @cfg {RegExp} disabledDatesRE
  142. * JavaScript regular expression used to disable a pattern of dates (defaults to null). The {@link #disabledDates}
  143. * config will generate this regex internally, but if you specify disabledDatesRE it will take precedence over the
  144. * disabledDates value.
  145. */
  146. <span id='Ext-DatePicker-cfg-disabledDates'> /**
  147. </span> * @cfg {Array} disabledDates
  148. * An array of 'dates' to disable, as strings. These strings will be used to build a dynamic regular
  149. * expression so they are very powerful. Some examples:
  150. * &lt;ul&gt;
  151. * &lt;li&gt;['03/08/2003', '09/16/2003'] would disable those exact dates&lt;/li&gt;
  152. * &lt;li&gt;['03/08', '09/16'] would disable those days for every year&lt;/li&gt;
  153. * &lt;li&gt;['^03/08'] would only match the beginning (useful if you are using short years)&lt;/li&gt;
  154. * &lt;li&gt;['03/../2006'] would disable every day in March 2006&lt;/li&gt;
  155. * &lt;li&gt;['^03'] would disable every day in every March&lt;/li&gt;
  156. * &lt;/ul&gt;
  157. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  158. * In order to support regular expressions, if you are using a date format that has '.' in it, you will have to
  159. * escape the dot when restricting dates. For example: ['03\\.08\\.03'].
  160. */
  161. <span id='Ext-DatePicker-property-focusOnSelect'> // private
  162. </span> // Set by other components to stop the picker focus being updated when the value changes.
  163. focusOnSelect: true,
  164. <span id='Ext-DatePicker-property-initHour'> // default value used to initialise each date in the DatePicker
  165. </span> // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  166. initHour: 12, // 24-hour format
  167. <span id='Ext-DatePicker-method-initComponent'> // private
  168. </span> initComponent : function(){
  169. Ext.DatePicker.superclass.initComponent.call(this);
  170. this.value = this.value ?
  171. this.value.clearTime(true) : new Date().clearTime();
  172. this.addEvents(
  173. <span id='Ext-DatePicker-event-select'> /**
  174. </span> * @event select
  175. * Fires when a date is selected
  176. * @param {DatePicker} this DatePicker
  177. * @param {Date} date The selected date
  178. */
  179. 'select'
  180. );
  181. if(this.handler){
  182. this.on('select', this.handler, this.scope || this);
  183. }
  184. this.initDisabledDays();
  185. },
  186. <span id='Ext-DatePicker-method-initDisabledDays'> // private
  187. </span> initDisabledDays : function(){
  188. if(!this.disabledDatesRE &amp;&amp; this.disabledDates){
  189. var dd = this.disabledDates,
  190. len = dd.length - 1,
  191. re = '(?:';
  192. Ext.each(dd, function(d, i){
  193. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  194. if(i != len){
  195. re += '|';
  196. }
  197. }, this);
  198. this.disabledDatesRE = new RegExp(re + ')');
  199. }
  200. },
  201. <span id='Ext-DatePicker-method-setDisabledDates'> /**
  202. </span> * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  203. * @param {Array/RegExp} disabledDates An array of date strings (see the {@link #disabledDates} config
  204. * for details on supported values), or a JavaScript regular expression used to disable a pattern of dates.
  205. */
  206. setDisabledDates : function(dd){
  207. if(Ext.isArray(dd)){
  208. this.disabledDates = dd;
  209. this.disabledDatesRE = null;
  210. }else{
  211. this.disabledDatesRE = dd;
  212. }
  213. this.initDisabledDays();
  214. this.update(this.value, true);
  215. },
  216. <span id='Ext-DatePicker-method-setDisabledDays'> /**
  217. </span> * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  218. * @param {Array} disabledDays An array of disabled day indexes. See the {@link #disabledDays} config
  219. * for details on supported values.
  220. */
  221. setDisabledDays : function(dd){
  222. this.disabledDays = dd;
  223. this.update(this.value, true);
  224. },
  225. <span id='Ext-DatePicker-method-setMinDate'> /**
  226. </span> * Replaces any existing {@link #minDate} with the new value and refreshes the DatePicker.
  227. * @param {Date} value The minimum date that can be selected
  228. */
  229. setMinDate : function(dt){
  230. this.minDate = dt;
  231. this.update(this.value, true);
  232. },
  233. <span id='Ext-DatePicker-method-setMaxDate'> /**
  234. </span> * Replaces any existing {@link #maxDate} with the new value and refreshes the DatePicker.
  235. * @param {Date} value The maximum date that can be selected
  236. */
  237. setMaxDate : function(dt){
  238. this.maxDate = dt;
  239. this.update(this.value, true);
  240. },
  241. <span id='Ext-DatePicker-method-setValue'> /**
  242. </span> * Sets the value of the date field
  243. * @param {Date} value The date to set
  244. */
  245. setValue : function(value){
  246. this.value = value.clearTime(true);
  247. this.update(this.value);
  248. },
  249. <span id='Ext-DatePicker-method-getValue'> /**
  250. </span> * Gets the current selected value of the date field
  251. * @return {Date} The selected date
  252. */
  253. getValue : function(){
  254. return this.value;
  255. },
  256. <span id='Ext-DatePicker-method-focus'> // private
  257. </span> focus : function(){
  258. this.update(this.activeDate);
  259. },
  260. <span id='Ext-DatePicker-method-onEnable'> // private
  261. </span> onEnable: function(initial){
  262. Ext.DatePicker.superclass.onEnable.call(this);
  263. this.doDisabled(false);
  264. this.update(initial ? this.value : this.activeDate);
  265. if(Ext.isIE9m){
  266. this.el.repaint();
  267. }
  268. },
  269. <span id='Ext-DatePicker-method-onDisable'> // private
  270. </span> onDisable : function(){
  271. Ext.DatePicker.superclass.onDisable.call(this);
  272. this.doDisabled(true);
  273. if(Ext.isIE9m &amp;&amp; !Ext.isIE8){
  274. /* Really strange problem in IE6/7, when disabled, have to explicitly
  275. * repaint each of the nodes to get them to display correctly, simply
  276. * calling repaint on the main element doesn't appear to be enough.
  277. */
  278. Ext.each([].concat(this.textNodes, this.el.query('th span')), function(el){
  279. Ext.fly(el).repaint();
  280. });
  281. }
  282. },
  283. <span id='Ext-DatePicker-method-doDisabled'> // private
  284. </span> doDisabled : function(disabled){
  285. this.keyNav.setDisabled(disabled);
  286. this.prevRepeater.setDisabled(disabled);
  287. this.nextRepeater.setDisabled(disabled);
  288. if(this.showToday){
  289. this.todayKeyListener.setDisabled(disabled);
  290. this.todayBtn.setDisabled(disabled);
  291. }
  292. },
  293. <span id='Ext-DatePicker-method-onRender'> // private
  294. </span> onRender : function(container, position){
  295. var m = [
  296. '&lt;table cellspacing=&quot;0&quot;&gt;',
  297. '&lt;tr&gt;&lt;td class=&quot;x-date-left&quot;&gt;&lt;a href=&quot;#&quot; title=&quot;', this.prevText ,'&quot;&gt;&amp;#160;&lt;/a&gt;&lt;/td&gt;&lt;td class=&quot;x-date-middle&quot; align=&quot;center&quot;&gt;&lt;/td&gt;&lt;td class=&quot;x-date-right&quot;&gt;&lt;a href=&quot;#&quot; title=&quot;', this.nextText ,'&quot;&gt;&amp;#160;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;',
  298. '&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;table class=&quot;x-date-inner&quot; cellspacing=&quot;0&quot;&gt;&lt;thead&gt;&lt;tr&gt;'],
  299. dn = this.dayNames,
  300. i;
  301. for(i = 0; i &lt; 7; i++){
  302. var d = this.startDay+i;
  303. if(d &gt; 6){
  304. d = d-7;
  305. }
  306. m.push('&lt;th&gt;&lt;span&gt;', dn[d].substr(0,1), '&lt;/span&gt;&lt;/th&gt;');
  307. }
  308. m[m.length] = '&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;';
  309. for(i = 0; i &lt; 42; i++) {
  310. if(i % 7 === 0 &amp;&amp; i !== 0){
  311. m[m.length] = '&lt;/tr&gt;&lt;tr&gt;';
  312. }
  313. m[m.length] = '&lt;td&gt;&lt;a href=&quot;#&quot; hidefocus=&quot;on&quot; class=&quot;x-date-date&quot; tabIndex=&quot;1&quot;&gt;&lt;em&gt;&lt;span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/a&gt;&lt;/td&gt;';
  314. }
  315. m.push('&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;',
  316. this.showToday ? '&lt;tr&gt;&lt;td colspan=&quot;3&quot; class=&quot;x-date-bottom&quot; align=&quot;center&quot;&gt;&lt;/td&gt;&lt;/tr&gt;' : '',
  317. '&lt;/table&gt;&lt;div class=&quot;x-date-mp&quot;&gt;&lt;/div&gt;');
  318. var el = document.createElement('div');
  319. el.className = 'x-date-picker';
  320. el.innerHTML = m.join('');
  321. container.dom.insertBefore(el, position);
  322. this.el = Ext.get(el);
  323. this.eventEl = Ext.get(el.firstChild);
  324. this.prevRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-left a'), {
  325. handler: this.showPrevMonth,
  326. scope: this,
  327. preventDefault:true,
  328. stopDefault:true
  329. });
  330. this.nextRepeater = new Ext.util.ClickRepeater(this.el.child('td.x-date-right a'), {
  331. handler: this.showNextMonth,
  332. scope: this,
  333. preventDefault:true,
  334. stopDefault:true
  335. });
  336. this.monthPicker = this.el.down('div.x-date-mp');
  337. this.monthPicker.enableDisplayMode('block');
  338. this.keyNav = new Ext.KeyNav(this.eventEl, {
  339. 'left' : function(e){
  340. if(e.ctrlKey){
  341. this.showPrevMonth();
  342. }else{
  343. this.update(this.activeDate.add('d', -1));
  344. }
  345. },
  346. 'right' : function(e){
  347. if(e.ctrlKey){
  348. this.showNextMonth();
  349. }else{
  350. this.update(this.activeDate.add('d', 1));
  351. }
  352. },
  353. 'up' : function(e){
  354. if(e.ctrlKey){
  355. this.showNextYear();
  356. }else{
  357. this.update(this.activeDate.add('d', -7));
  358. }
  359. },
  360. 'down' : function(e){
  361. if(e.ctrlKey){
  362. this.showPrevYear();
  363. }else{
  364. this.update(this.activeDate.add('d', 7));
  365. }
  366. },
  367. 'pageUp' : function(e){
  368. this.showNextMonth();
  369. },
  370. 'pageDown' : function(e){
  371. this.showPrevMonth();
  372. },
  373. 'enter' : function(e){
  374. e.stopPropagation();
  375. return true;
  376. },
  377. scope : this
  378. });
  379. this.el.unselectable();
  380. this.cells = this.el.select('table.x-date-inner tbody td');
  381. this.textNodes = this.el.query('table.x-date-inner tbody span');
  382. this.mbtn = new Ext.Button({
  383. text: '&amp;#160;',
  384. tooltip: this.monthYearText,
  385. renderTo: this.el.child('td.x-date-middle', true)
  386. });
  387. this.mbtn.el.child('em').addClass('x-btn-arrow');
  388. if(this.showToday){
  389. this.todayKeyListener = this.eventEl.addKeyListener(Ext.EventObject.SPACE, this.selectToday, this);
  390. var today = (new Date()).dateFormat(this.format);
  391. this.todayBtn = new Ext.Button({
  392. renderTo: this.el.child('td.x-date-bottom', true),
  393. text: String.format(this.todayText, today),
  394. tooltip: String.format(this.todayTip, today),
  395. handler: this.selectToday,
  396. scope: this
  397. });
  398. }
  399. this.mon(this.eventEl, 'mousewheel', this.handleMouseWheel, this);
  400. this.mon(this.eventEl, 'click', this.handleDateClick, this, {delegate: 'a.x-date-date'});
  401. this.mon(this.mbtn, 'click', this.showMonthPicker, this);
  402. this.onEnable(true);
  403. },
  404. <span id='Ext-DatePicker-method-createMonthPicker'> // private
  405. </span> createMonthPicker : function(){
  406. if(!this.monthPicker.dom.firstChild){
  407. var buf = ['&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot;&gt;'];
  408. for(var i = 0; i &lt; 6; i++){
  409. buf.push(
  410. '&lt;tr&gt;&lt;td class=&quot;x-date-mp-month&quot;&gt;&lt;a href=&quot;#&quot;&gt;', Date.getShortMonthName(i), '&lt;/a&gt;&lt;/td&gt;',
  411. '&lt;td class=&quot;x-date-mp-month x-date-mp-sep&quot;&gt;&lt;a href=&quot;#&quot;&gt;', Date.getShortMonthName(i + 6), '&lt;/a&gt;&lt;/td&gt;',
  412. i === 0 ?
  413. '&lt;td class=&quot;x-date-mp-ybtn&quot; align=&quot;center&quot;&gt;&lt;a class=&quot;x-date-mp-prev&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;td class=&quot;x-date-mp-ybtn&quot; align=&quot;center&quot;&gt;&lt;a class=&quot;x-date-mp-next&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;' :
  414. '&lt;td class=&quot;x-date-mp-year&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;td class=&quot;x-date-mp-year&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;'
  415. );
  416. }
  417. buf.push(
  418. '&lt;tr class=&quot;x-date-mp-btns&quot;&gt;&lt;td colspan=&quot;4&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;x-date-mp-ok&quot;&gt;',
  419. this.okText,
  420. '&lt;/button&gt;&lt;button type=&quot;button&quot; class=&quot;x-date-mp-cancel&quot;&gt;',
  421. this.cancelText,
  422. '&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;',
  423. '&lt;/table&gt;'
  424. );
  425. this.monthPicker.update(buf.join(''));
  426. this.mon(this.monthPicker, 'click', this.onMonthClick, this);
  427. this.mon(this.monthPicker, 'dblclick', this.onMonthDblClick, this);
  428. this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
  429. this.mpYears = this.monthPicker.select('td.x-date-mp-year');
  430. this.mpMonths.each(function(m, a, i){
  431. i += 1;
  432. if((i%2) === 0){
  433. m.dom.xmonth = 5 + Math.round(i * 0.5);
  434. }else{
  435. m.dom.xmonth = Math.round((i-1) * 0.5);
  436. }
  437. });
  438. }
  439. },
  440. <span id='Ext-DatePicker-method-showMonthPicker'> // private
  441. </span> showMonthPicker : function(){
  442. if(!this.disabled){
  443. this.createMonthPicker();
  444. var size = this.el.getSize();
  445. this.monthPicker.setSize(size);
  446. this.monthPicker.child('table').setSize(size);
  447. this.mpSelMonth = (this.activeDate || this.value).getMonth();
  448. this.updateMPMonth(this.mpSelMonth);
  449. this.mpSelYear = (this.activeDate || this.value).getFullYear();
  450. this.updateMPYear(this.mpSelYear);
  451. this.monthPicker.slideIn('t', {duration:0.2});
  452. }
  453. },
  454. <span id='Ext-DatePicker-method-updateMPYear'> // private
  455. </span> updateMPYear : function(y){
  456. this.mpyear = y;
  457. var ys = this.mpYears.elements;
  458. for(var i = 1; i &lt;= 10; i++){
  459. var td = ys[i-1], y2;
  460. if((i%2) === 0){
  461. y2 = y + Math.round(i * 0.5);
  462. td.firstChild.innerHTML = y2;
  463. td.xyear = y2;
  464. }else{
  465. y2 = y - (5-Math.round(i * 0.5));
  466. td.firstChild.innerHTML = y2;
  467. td.xyear = y2;
  468. }
  469. this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
  470. }
  471. },
  472. <span id='Ext-DatePicker-method-updateMPMonth'> // private
  473. </span> updateMPMonth : function(sm){
  474. this.mpMonths.each(function(m, a, i){
  475. m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
  476. });
  477. },
  478. <span id='Ext-DatePicker-method-selectMPMonth'> // private
  479. </span> selectMPMonth : function(m){
  480. },
  481. <span id='Ext-DatePicker-method-onMonthClick'> // private
  482. </span> onMonthClick : function(e, t){
  483. e.stopEvent();
  484. var el = new Ext.Element(t), pn;
  485. if(el.is('button.x-date-mp-cancel')){
  486. this.hideMonthPicker();
  487. }
  488. else if(el.is('button.x-date-mp-ok')){
  489. var d = new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate());
  490. if(d.getMonth() != this.mpSelMonth){
  491. // 'fix' the JS rolling date conversion if needed
  492. d = new Date(this.mpSelYear, this.mpSelMonth, 1).getLastDateOfMonth();
  493. }
  494. this.update(d);
  495. this.hideMonthPicker();
  496. }
  497. else if((pn = el.up('td.x-date-mp-month', 2))){
  498. this.mpMonths.removeClass('x-date-mp-sel');
  499. pn.addClass('x-date-mp-sel');
  500. this.mpSelMonth = pn.dom.xmonth;
  501. }
  502. else if((pn = el.up('td.x-date-mp-year', 2))){
  503. this.mpYears.removeClass('x-date-mp-sel');
  504. pn.addClass('x-date-mp-sel');
  505. this.mpSelYear = pn.dom.xyear;
  506. }
  507. else if(el.is('a.x-date-mp-prev')){
  508. this.updateMPYear(this.mpyear-10);
  509. }
  510. else if(el.is('a.x-date-mp-next')){
  511. this.updateMPYear(this.mpyear+10);
  512. }
  513. },
  514. <span id='Ext-DatePicker-method-onMonthDblClick'> // private
  515. </span> onMonthDblClick : function(e, t){
  516. e.stopEvent();
  517. var el = new Ext.Element(t), pn;
  518. if((pn = el.up('td.x-date-mp-month', 2))){
  519. this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
  520. this.hideMonthPicker();
  521. }
  522. else if((pn = el.up('td.x-date-mp-year', 2))){
  523. this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
  524. this.hideMonthPicker();
  525. }
  526. },
  527. <span id='Ext-DatePicker-method-hideMonthPicker'> // private
  528. </span> hideMonthPicker : function(disableAnim){
  529. if(this.monthPicker){
  530. if(disableAnim === true){
  531. this.monthPicker.hide();
  532. }else{
  533. this.monthPicker.slideOut('t', {duration:0.2});
  534. }
  535. }
  536. },
  537. <span id='Ext-DatePicker-method-showPrevMonth'> // private
  538. </span> showPrevMonth : function(e){
  539. this.update(this.activeDate.add('mo', -1));
  540. },
  541. <span id='Ext-DatePicker-method-showNextMonth'> // private
  542. </span> showNextMonth : function(e){
  543. this.update(this.activeDate.add('mo', 1));
  544. },
  545. <span id='Ext-DatePicker-method-showPrevYear'> // private
  546. </span> showPrevYear : function(){
  547. this.update(this.activeDate.add('y', -1));
  548. },
  549. <span id='Ext-DatePicker-method-showNextYear'> // private
  550. </span> showNextYear : function(){
  551. this.update(this.activeDate.add('y', 1));
  552. },
  553. <span id='Ext-DatePicker-method-handleMouseWheel'> // private
  554. </span> handleMouseWheel : function(e){
  555. e.stopEvent();
  556. if(!this.disabled){
  557. var delta = e.getWheelDelta();
  558. if(delta &gt; 0){
  559. this.showPrevMonth();
  560. } else if(delta &lt; 0){
  561. this.showNextMonth();
  562. }
  563. }
  564. },
  565. <span id='Ext-DatePicker-method-handleDateClick'> // private
  566. </span> handleDateClick : function(e, t){
  567. e.stopEvent();
  568. if(!this.disabled &amp;&amp; t.dateValue &amp;&amp; !Ext.fly(t.parentNode).hasClass('x-date-disabled')){
  569. this.cancelFocus = this.focusOnSelect === false;
  570. this.setValue(new Date(t.dateValue));
  571. delete this.cancelFocus;
  572. this.fireEvent('select', this, this.value);
  573. }
  574. },
  575. <span id='Ext-DatePicker-method-selectToday'> // private
  576. </span> selectToday : function(){
  577. if(this.todayBtn &amp;&amp; !this.todayBtn.disabled){
  578. this.setValue(new Date().clearTime());
  579. this.fireEvent('select', this, this.value);
  580. }
  581. },
  582. <span id='Ext-DatePicker-method-update'> // private
  583. </span> update : function(date, forceRefresh){
  584. if(this.rendered){
  585. var vd = this.activeDate, vis = this.isVisible();
  586. this.activeDate = date;
  587. if(!forceRefresh &amp;&amp; vd &amp;&amp; this.el){
  588. var t = date.getTime();
  589. if(vd.getMonth() == date.getMonth() &amp;&amp; vd.getFullYear() == date.getFullYear()){
  590. this.cells.removeClass('x-date-selected');
  591. this.cells.each(function(c){
  592. if(c.dom.firstChild.dateValue == t){
  593. c.addClass('x-date-selected');
  594. if(vis &amp;&amp; !this.cancelFocus){
  595. Ext.fly(c.dom.firstChild).focus(50);
  596. }
  597. return false;
  598. }
  599. }, this);
  600. return;
  601. }
  602. }
  603. var days = date.getDaysInMonth(),
  604. firstOfMonth = date.getFirstDateOfMonth(),
  605. startingPos = firstOfMonth.getDay()-this.startDay;
  606. if(startingPos &lt; 0){
  607. startingPos += 7;
  608. }
  609. days += startingPos;
  610. var pm = date.add('mo', -1),
  611. prevStart = pm.getDaysInMonth()-startingPos,
  612. cells = this.cells.elements,
  613. textEls = this.textNodes,
  614. // convert everything to numbers so it's fast
  615. d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)),
  616. today = new Date().clearTime().getTime(),
  617. sel = date.clearTime(true).getTime(),
  618. min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
  619. max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
  620. ddMatch = this.disabledDatesRE,
  621. ddText = this.disabledDatesText,
  622. ddays = this.disabledDays ? this.disabledDays.join('') : false,
  623. ddaysText = this.disabledDaysText,
  624. format = this.format;
  625. if(this.showToday){
  626. var td = new Date().clearTime(),
  627. disable = (td &lt; min || td &gt; max ||
  628. (ddMatch &amp;&amp; format &amp;&amp; ddMatch.test(td.dateFormat(format))) ||
  629. (ddays &amp;&amp; ddays.indexOf(td.getDay()) != -1));
  630. if(!this.disabled){
  631. this.todayBtn.setDisabled(disable);
  632. this.todayKeyListener[disable ? 'disable' : 'enable']();
  633. }
  634. }
  635. var setCellClass = function(cal, cell){
  636. cell.title = '';
  637. var t = d.clearTime(true).getTime();
  638. cell.firstChild.dateValue = t;
  639. if(t == today){
  640. cell.className += ' x-date-today';
  641. cell.title = cal.todayText;
  642. }
  643. if(t == sel){
  644. cell.className += ' x-date-selected';
  645. if(vis){
  646. Ext.fly(cell.firstChild).focus(50);
  647. }
  648. }
  649. // disabling
  650. if(t &lt; min) {
  651. cell.className = ' x-date-disabled';
  652. cell.title = cal.minText;
  653. return;
  654. }
  655. if(t &gt; max) {
  656. cell.className = ' x-date-disabled';
  657. cell.title = cal.maxText;
  658. return;
  659. }
  660. if(ddays){
  661. if(ddays.indexOf(d.getDay()) != -1){
  662. cell.title = ddaysText;
  663. cell.className = ' x-date-disabled';
  664. }
  665. }
  666. if(ddMatch &amp;&amp; format){
  667. var fvalue = d.dateFormat(format);
  668. if(ddMatch.test(fvalue)){
  669. cell.title = ddText.replace('%0', fvalue);
  670. cell.className = ' x-date-disabled';
  671. }
  672. }
  673. };
  674. var i = 0;
  675. for(; i &lt; startingPos; i++) {
  676. textEls[i].innerHTML = (++prevStart);
  677. d.setDate(d.getDate()+1);
  678. cells[i].className = 'x-date-prevday';
  679. setCellClass(this, cells[i]);
  680. }
  681. for(; i &lt; days; i++){
  682. var intDay = i - startingPos + 1;
  683. textEls[i].innerHTML = (intDay);
  684. d.setDate(d.getDate()+1);
  685. cells[i].className = 'x-date-active';
  686. setCellClass(this, cells[i]);
  687. }
  688. var extraDays = 0;
  689. for(; i &lt; 42; i++) {
  690. textEls[i].innerHTML = (++extraDays);
  691. d.setDate(d.getDate()+1);
  692. cells[i].className = 'x-date-nextday';
  693. setCellClass(this, cells[i]);
  694. }
  695. this.mbtn.setText(this.monthNames[date.getMonth()] + ' ' + date.getFullYear());
  696. if(!this.internalRender){
  697. var main = this.el.dom.firstChild,
  698. w = main.offsetWidth;
  699. this.el.setWidth(w + this.el.getBorderWidth('lr'));
  700. Ext.fly(main).setWidth(w);
  701. this.internalRender = true;
  702. // opera does not respect the auto grow header center column
  703. // then, after it gets a width opera refuses to recalculate
  704. // without a second pass
  705. if(Ext.isOpera &amp;&amp; !this.secondPass){
  706. main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + 'px';
  707. this.secondPass = true;
  708. this.update.defer(10, this, [date]);
  709. }
  710. }
  711. }
  712. },
  713. <span id='Ext-DatePicker-method-beforeDestroy'> // private
  714. </span> beforeDestroy : function() {
  715. if(this.rendered){
  716. Ext.destroy(
  717. this.keyNav,
  718. this.monthPicker,
  719. this.eventEl,
  720. this.mbtn,
  721. this.nextRepeater,
  722. this.prevRepeater,
  723. this.cells.el,
  724. this.todayBtn
  725. );
  726. delete this.textNodes;
  727. delete this.cells.elements;
  728. }
  729. }
  730. <span id='Ext-DatePicker-cfg-autoEl'> /**
  731. </span> * @cfg {String} autoEl @hide
  732. */
  733. });
  734. Ext.reg('datepicker', Ext.DatePicker);
  735. </pre>
  736. </body>
  737. </html>