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.

456 lines
17 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.form.DateField"></div>/**
  16. * @class Ext.form.DateField
  17. * @extends Ext.form.TriggerField
  18. * Provides a date input field with a {@link Ext.DatePicker} dropdown and automatic date validation.
  19. * @constructor
  20. * Create a new DateField
  21. * @param {Object} config
  22. * @xtype datefield
  23. */
  24. Ext.form.DateField = Ext.extend(Ext.form.TriggerField, {
  25. <div id="cfg-Ext.form.DateField-format"></div>/**
  26. * @cfg {String} format
  27. * The default date format string which can be overriden for localization support. The format must be
  28. * valid according to {@link Date#parseDate} (defaults to <tt>'m/d/Y'</tt>).
  29. */
  30. format : "m/d/Y",
  31. <div id="cfg-Ext.form.DateField-altFormats"></div>/**
  32. * @cfg {String} altFormats
  33. * Multiple date formats separated by "<tt>|</tt>" to try when parsing a user input value and it
  34. * does not match the defined format (defaults to
  35. * <tt>'m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j'</tt>).
  36. */
  37. altFormats : "m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j",
  38. <div id="cfg-Ext.form.DateField-disabledDaysText"></div>/**
  39. * @cfg {String} disabledDaysText
  40. * The tooltip to display when the date falls on a disabled day (defaults to <tt>'Disabled'</tt>)
  41. */
  42. disabledDaysText : "Disabled",
  43. <div id="cfg-Ext.form.DateField-disabledDatesText"></div>/**
  44. * @cfg {String} disabledDatesText
  45. * The tooltip text to display when the date falls on a disabled date (defaults to <tt>'Disabled'</tt>)
  46. */
  47. disabledDatesText : "Disabled",
  48. <div id="cfg-Ext.form.DateField-minText"></div>/**
  49. * @cfg {String} minText
  50. * The error text to display when the date in the cell is before <tt>{@link #minValue}</tt> (defaults to
  51. * <tt>'The date in this field must be after {minValue}'</tt>).
  52. */
  53. minText : "The date in this field must be equal to or after {0}",
  54. <div id="cfg-Ext.form.DateField-maxText"></div>/**
  55. * @cfg {String} maxText
  56. * The error text to display when the date in the cell is after <tt>{@link #maxValue}</tt> (defaults to
  57. * <tt>'The date in this field must be before {maxValue}'</tt>).
  58. */
  59. maxText : "The date in this field must be equal to or before {0}",
  60. <div id="cfg-Ext.form.DateField-invalidText"></div>/**
  61. * @cfg {String} invalidText
  62. * The error text to display when the date in the field is invalid (defaults to
  63. * <tt>'{value} is not a valid date - it must be in the format {format}'</tt>).
  64. */
  65. invalidText : "{0} is not a valid date - it must be in the format {1}",
  66. <div id="cfg-Ext.form.DateField-triggerClass"></div>/**
  67. * @cfg {String} triggerClass
  68. * An additional CSS class used to style the trigger button. The trigger will always get the
  69. * class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  70. * (defaults to <tt>'x-form-date-trigger'</tt> which displays a calendar icon).
  71. */
  72. triggerClass : 'x-form-date-trigger',
  73. <div id="cfg-Ext.form.DateField-showToday"></div>/**
  74. * @cfg {Boolean} showToday
  75. * <tt>false</tt> to hide the footer area of the DatePicker containing the Today button and disable
  76. * the keyboard handler for spacebar that selects the current date (defaults to <tt>true</tt>).
  77. */
  78. showToday : true,
  79. <div id="cfg-Ext.form.DateField-startDay"></div>/**
  80. * @cfg {Number} startDay
  81. * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
  82. */
  83. startDay : 0,
  84. <div id="cfg-Ext.form.DateField-minValue"></div>/**
  85. * @cfg {Date/String} minValue
  86. * The minimum allowed date. Can be either a Javascript date object or a string date in a
  87. * valid format (defaults to null).
  88. */
  89. <div id="cfg-Ext.form.DateField-maxValue"></div>/**
  90. * @cfg {Date/String} maxValue
  91. * The maximum allowed date. Can be either a Javascript date object or a string date in a
  92. * valid format (defaults to null).
  93. */
  94. <div id="cfg-Ext.form.DateField-disabledDays"></div>/**
  95. * @cfg {Array} disabledDays
  96. * An array of days to disable, 0 based (defaults to null). Some examples:<pre><code>
  97. // disable Sunday and Saturday:
  98. disabledDays: [0, 6]
  99. // disable weekdays:
  100. disabledDays: [1,2,3,4,5]
  101. * </code></pre>
  102. */
  103. <div id="cfg-Ext.form.DateField-disabledDates"></div>/**
  104. * @cfg {Array} disabledDates
  105. * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
  106. * expression so they are very powerful. Some examples:<pre><code>
  107. // disable these exact dates:
  108. disabledDates: ["03/08/2003", "09/16/2003"]
  109. // disable these days for every year:
  110. disabledDates: ["03/08", "09/16"]
  111. // only match the beginning (useful if you are using short years):
  112. disabledDates: ["^03/08"]
  113. // disable every day in March 2006:
  114. disabledDates: ["03/../2006"]
  115. // disable every day in every March:
  116. disabledDates: ["^03"]
  117. * </code></pre>
  118. * Note that the format of the dates included in the array should exactly match the {@link #format} config.
  119. * In order to support regular expressions, if you are using a {@link #format date format} that has "." in
  120. * it, you will have to escape the dot when restricting dates. For example: <tt>["03\\.08\\.03"]</tt>.
  121. */
  122. <div id="cfg-Ext.form.DateField-autoCreate"></div>/**
  123. * @cfg {String/Object} autoCreate
  124. * A {@link Ext.DomHelper DomHelper element specification object}, or <tt>true</tt> for the default element
  125. * specification object:<pre><code>
  126. * autoCreate: {tag: "input", type: "text", size: "10", autocomplete: "off"}
  127. * </code></pre>
  128. */
  129. // private
  130. defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
  131. // in the absence of a time value, a default value of 12 noon will be used
  132. // (note: 12 noon was chosen because it steers well clear of all DST timezone changes)
  133. initTime: '12', // 24 hour format
  134. initTimeFormat: 'H',
  135. // PUBLIC -- to be documented
  136. safeParse : function(value, format) {
  137. if (/[gGhH]/.test(format.replace(/(\\.)/g, ''))) {
  138. // if parse format contains hour information, no DST adjustment is necessary
  139. return Date.parseDate(value, format);
  140. } else {
  141. // set time to 12 noon, then clear the time
  142. var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
  143. if (parsedDate) {
  144. return parsedDate.clearTime();
  145. }
  146. }
  147. },
  148. initComponent : function(){
  149. Ext.form.DateField.superclass.initComponent.call(this);
  150. this.addEvents(
  151. <div id="event-Ext.form.DateField-select"></div>/**
  152. * @event select
  153. * Fires when a date is selected via the date picker.
  154. * @param {Ext.form.DateField} this
  155. * @param {Date} date The date that was selected
  156. */
  157. 'select'
  158. );
  159. if(Ext.isString(this.minValue)){
  160. this.minValue = this.parseDate(this.minValue);
  161. }
  162. if(Ext.isString(this.maxValue)){
  163. this.maxValue = this.parseDate(this.maxValue);
  164. }
  165. this.disabledDatesRE = null;
  166. this.initDisabledDays();
  167. },
  168. initEvents: function() {
  169. Ext.form.DateField.superclass.initEvents.call(this);
  170. this.keyNav = new Ext.KeyNav(this.el, {
  171. "down": function(e) {
  172. this.onTriggerClick();
  173. },
  174. scope: this,
  175. forceKeyDown: true
  176. });
  177. },
  178. // private
  179. initDisabledDays : function(){
  180. if(this.disabledDates){
  181. var dd = this.disabledDates,
  182. len = dd.length - 1,
  183. re = "(?:";
  184. Ext.each(dd, function(d, i){
  185. re += Ext.isDate(d) ? '^' + Ext.escapeRe(d.dateFormat(this.format)) + '$' : dd[i];
  186. if(i != len){
  187. re += '|';
  188. }
  189. }, this);
  190. this.disabledDatesRE = new RegExp(re + ')');
  191. }
  192. },
  193. <div id="method-Ext.form.DateField-setDisabledDates"></div>/**
  194. * Replaces any existing disabled dates with new values and refreshes the DatePicker.
  195. * @param {Array} disabledDates An array of date strings (see the <tt>{@link #disabledDates}</tt> config
  196. * for details on supported values) used to disable a pattern of dates.
  197. */
  198. setDisabledDates : function(dd){
  199. this.disabledDates = dd;
  200. this.initDisabledDays();
  201. if(this.menu){
  202. this.menu.picker.setDisabledDates(this.disabledDatesRE);
  203. }
  204. },
  205. <div id="method-Ext.form.DateField-setDisabledDays"></div>/**
  206. * Replaces any existing disabled days (by index, 0-6) with new values and refreshes the DatePicker.
  207. * @param {Array} disabledDays An array of disabled day indexes. See the <tt>{@link #disabledDays}</tt>
  208. * config for details on supported values.
  209. */
  210. setDisabledDays : function(dd){
  211. this.disabledDays = dd;
  212. if(this.menu){
  213. this.menu.picker.setDisabledDays(dd);
  214. }
  215. },
  216. <div id="method-Ext.form.DateField-setMinValue"></div>/**
  217. * Replaces any existing <tt>{@link #minValue}</tt> with the new value and refreshes the DatePicker.
  218. * @param {Date} value The minimum date that can be selected
  219. */
  220. setMinValue : function(dt){
  221. this.minValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  222. if(this.menu){
  223. this.menu.picker.setMinDate(this.minValue);
  224. }
  225. },
  226. <div id="method-Ext.form.DateField-setMaxValue"></div>/**
  227. * Replaces any existing <tt>{@link #maxValue}</tt> with the new value and refreshes the DatePicker.
  228. * @param {Date} value The maximum date that can be selected
  229. */
  230. setMaxValue : function(dt){
  231. this.maxValue = (Ext.isString(dt) ? this.parseDate(dt) : dt);
  232. if(this.menu){
  233. this.menu.picker.setMaxDate(this.maxValue);
  234. }
  235. },
  236. <div id="method-Ext.form.DateField-getErrors"></div>/**
  237. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  238. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  239. * The additional validation checks are testing that the date format is valid, that the chosen
  240. * date is within the min and max date constraints set, that the date chosen is not in the disabledDates
  241. * regex and that the day chosed is not one of the disabledDays.
  242. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  243. * @return {Array} All validation errors for this field
  244. */
  245. getErrors: function(value) {
  246. var errors = Ext.form.DateField.superclass.getErrors.apply(this, arguments);
  247. value = this.formatDate(value || this.processValue(this.getRawValue()));
  248. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  249. return errors;
  250. }
  251. var svalue = value;
  252. value = this.parseDate(value);
  253. if (!value) {
  254. errors.push(String.format(this.invalidText, svalue, this.format));
  255. return errors;
  256. }
  257. var time = value.getTime();
  258. if (this.minValue && time < this.minValue.clearTime().getTime()) {
  259. errors.push(String.format(this.minText, this.formatDate(this.minValue)));
  260. }
  261. if (this.maxValue && time > this.maxValue.clearTime().getTime()) {
  262. errors.push(String.format(this.maxText, this.formatDate(this.maxValue)));
  263. }
  264. if (this.disabledDays) {
  265. var day = value.getDay();
  266. for(var i = 0; i < this.disabledDays.length; i++) {
  267. if (day === this.disabledDays[i]) {
  268. errors.push(this.disabledDaysText);
  269. break;
  270. }
  271. }
  272. }
  273. var fvalue = this.formatDate(value);
  274. if (this.disabledDatesRE && this.disabledDatesRE.test(fvalue)) {
  275. errors.push(String.format(this.disabledDatesText, fvalue));
  276. }
  277. return errors;
  278. },
  279. // private
  280. // Provides logic to override the default TriggerField.validateBlur which just returns true
  281. validateBlur : function(){
  282. return !this.menu || !this.menu.isVisible();
  283. },
  284. <div id="method-Ext.form.DateField-getValue"></div>/**
  285. * Returns the current date value of the date field.
  286. * @return {Date} The date value
  287. */
  288. getValue : function(){
  289. return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || "";
  290. },
  291. <div id="method-Ext.form.DateField-setValue"></div>/**
  292. * Sets the value of the date field. You can pass a date object or any string that can be
  293. * parsed into a valid date, using <tt>{@link #format}</tt> as the date format, according
  294. * to the same rules as {@link Date#parseDate} (the default format used is <tt>"m/d/Y"</tt>).
  295. * <br />Usage:
  296. * <pre><code>
  297. //All of these calls set the same date value (May 4, 2006)
  298. //Pass a date object:
  299. var dt = new Date('5/4/2006');
  300. dateField.setValue(dt);
  301. //Pass a date string (default format):
  302. dateField.setValue('05/04/2006');
  303. //Pass a date string (custom format):
  304. dateField.format = 'Y-m-d';
  305. dateField.setValue('2006-05-04');
  306. </code></pre>
  307. * @param {String/Date} date The date or valid date string
  308. * @return {Ext.form.Field} this
  309. */
  310. setValue : function(date){
  311. return Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
  312. },
  313. // private
  314. parseDate : function(value) {
  315. if(!value || Ext.isDate(value)){
  316. return value;
  317. }
  318. var v = this.safeParse(value, this.format),
  319. af = this.altFormats,
  320. afa = this.altFormatsArray;
  321. if (!v && af) {
  322. afa = afa || af.split("|");
  323. for (var i = 0, len = afa.length; i < len && !v; i++) {
  324. v = this.safeParse(value, afa[i]);
  325. }
  326. }
  327. return v;
  328. },
  329. // private
  330. onDestroy : function(){
  331. Ext.destroy(this.menu, this.keyNav);
  332. Ext.form.DateField.superclass.onDestroy.call(this);
  333. },
  334. // private
  335. formatDate : function(date){
  336. return Ext.isDate(date) ? date.dateFormat(this.format) : date;
  337. },
  338. <div id="method-Ext.form.DateField-onTriggerClick"></div>/**
  339. * @method onTriggerClick
  340. * @hide
  341. */
  342. // private
  343. // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
  344. onTriggerClick : function(){
  345. if(this.disabled){
  346. return;
  347. }
  348. if(this.menu == null){
  349. this.menu = new Ext.menu.DateMenu({
  350. hideOnClick: false,
  351. focusOnSelect: false
  352. });
  353. }
  354. this.onFocus();
  355. Ext.apply(this.menu.picker, {
  356. minDate : this.minValue,
  357. maxDate : this.maxValue,
  358. disabledDatesRE : this.disabledDatesRE,
  359. disabledDatesText : this.disabledDatesText,
  360. disabledDays : this.disabledDays,
  361. disabledDaysText : this.disabledDaysText,
  362. format : this.format,
  363. showToday : this.showToday,
  364. startDay: this.startDay,
  365. minText : String.format(this.minText, this.formatDate(this.minValue)),
  366. maxText : String.format(this.maxText, this.formatDate(this.maxValue))
  367. });
  368. this.menu.picker.setValue(this.getValue() || new Date());
  369. this.menu.show(this.el, "tl-bl?");
  370. this.menuEvents('on');
  371. },
  372. //private
  373. menuEvents: function(method){
  374. this.menu[method]('select', this.onSelect, this);
  375. this.menu[method]('hide', this.onMenuHide, this);
  376. this.menu[method]('show', this.onFocus, this);
  377. },
  378. onSelect: function(m, d){
  379. this.setValue(d);
  380. this.fireEvent('select', this, d);
  381. this.menu.hide();
  382. },
  383. onMenuHide: function(){
  384. this.focus(false, 60);
  385. this.menuEvents('un');
  386. },
  387. // private
  388. beforeBlur : function(){
  389. var v = this.parseDate(this.getRawValue());
  390. if(v){
  391. this.setValue(v);
  392. }
  393. }
  394. <div id="cfg-Ext.form.DateField-grow"></div>/**
  395. * @cfg {Boolean} grow @hide
  396. */
  397. <div id="cfg-Ext.form.DateField-growMin"></div>/**
  398. * @cfg {Number} growMin @hide
  399. */
  400. <div id="cfg-Ext.form.DateField-growMax"></div>/**
  401. * @cfg {Number} growMax @hide
  402. */
  403. <div id="method-Ext.form.DateField-autoSize"></div>/**
  404. * @hide
  405. * @method autoSize
  406. */
  407. });
  408. Ext.reg('datefield', Ext.form.DateField);
  409. </pre>
  410. </body>
  411. </html>