Web Interface For Lite Argus Control modules
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.

805 lines
30 KiB

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