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.

294 lines
10 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.calendar.DateRangeField"></div>/**
  16. * @class Ext.calendar.DateRangeField
  17. * @extends Ext.form.Field
  18. * <p>A combination field that includes start and end dates and times, as well as an optional all-day checkbox.</p>
  19. * @constructor
  20. * @param {Object} config The config object
  21. */
  22. Ext.calendar.DateRangeField = Ext.extend(Ext.form.Field, {
  23. <div id="cfg-Ext.calendar.DateRangeField-toText"></div>/**
  24. * @cfg {String} toText
  25. * The text to display in between the date/time fields (defaults to 'to')
  26. */
  27. toText: 'to',
  28. <div id="cfg-Ext.calendar.DateRangeField-toText"></div>/**
  29. * @cfg {String} toText
  30. * The text to display as the label for the all day checkbox (defaults to 'All day')
  31. */
  32. allDayText: 'All day',
  33. // private
  34. onRender: function(ct, position) {
  35. if (!this.el) {
  36. this.startDate = new Ext.form.DateField({
  37. id: this.id + '-start-date',
  38. format: 'n/j/Y',
  39. width: 100,
  40. listeners: {
  41. 'change': {
  42. fn: function() {
  43. this.checkDates('date', 'start');
  44. },
  45. scope: this
  46. }
  47. }
  48. });
  49. this.startTime = new Ext.form.TimeField({
  50. id: this.id + '-start-time',
  51. hidden: this.showTimes === false,
  52. labelWidth: 0,
  53. hideLabel: true,
  54. width: 90,
  55. listeners: {
  56. 'select': {
  57. fn: function() {
  58. this.checkDates('time', 'start');
  59. },
  60. scope: this
  61. }
  62. }
  63. });
  64. this.endTime = new Ext.form.TimeField({
  65. id: this.id + '-end-time',
  66. hidden: this.showTimes === false,
  67. labelWidth: 0,
  68. hideLabel: true,
  69. width: 90,
  70. listeners: {
  71. 'select': {
  72. fn: function() {
  73. this.checkDates('time', 'end');
  74. },
  75. scope: this
  76. }
  77. }
  78. });
  79. this.endDate = new Ext.form.DateField({
  80. id: this.id + '-end-date',
  81. format: 'n/j/Y',
  82. hideLabel: true,
  83. width: 100,
  84. listeners: {
  85. 'change': {
  86. fn: function() {
  87. this.checkDates('date', 'end');
  88. },
  89. scope: this
  90. }
  91. }
  92. });
  93. this.allDay = new Ext.form.Checkbox({
  94. id: this.id + '-allday',
  95. hidden: this.showTimes === false || this.showAllDay === false,
  96. boxLabel: this.allDayText,
  97. handler: function(chk, checked) {
  98. this.startTime.setVisible(!checked);
  99. this.endTime.setVisible(!checked);
  100. },
  101. scope: this
  102. });
  103. this.toLabel = new Ext.form.Label({
  104. xtype: 'label',
  105. id: this.id + '-to-label',
  106. text: this.toText
  107. });
  108. this.fieldCt = new Ext.Container({
  109. autoEl: {
  110. id: this.id
  111. },
  112. //make sure the container el has the field's id
  113. cls: 'ext-dt-range',
  114. renderTo: ct,
  115. layout: 'table',
  116. layoutConfig: {
  117. columns: 6
  118. },
  119. defaults: {
  120. hideParent: true
  121. },
  122. items: [
  123. this.startDate,
  124. this.startTime,
  125. this.toLabel,
  126. this.endTime,
  127. this.endDate,
  128. this.allDay
  129. ]
  130. });
  131. this.fieldCt.ownerCt = this;
  132. this.el = this.fieldCt.getEl();
  133. this.items = new Ext.util.MixedCollection();
  134. this.items.addAll([this.startDate, this.endDate, this.toLabel, this.startTime, this.endTime, this.allDay]);
  135. }
  136. Ext.calendar.DateRangeField.superclass.onRender.call(this, ct, position);
  137. },
  138. // private
  139. checkDates: function(type, startend) {
  140. var startField = Ext.getCmp(this.id + '-start-' + type),
  141. endField = Ext.getCmp(this.id + '-end-' + type),
  142. startValue = this.getDT('start'),
  143. endValue = this.getDT('end');
  144. if (startValue > endValue) {
  145. if (startend == 'start') {
  146. endField.setValue(startValue);
  147. } else {
  148. startField.setValue(endValue);
  149. this.checkDates(type, 'start');
  150. }
  151. }
  152. if (type == 'date') {
  153. this.checkDates('time', startend);
  154. }
  155. },
  156. <div id="method-Ext.calendar.DateRangeField-getValue"></div>/**
  157. * Returns an array containing the following values in order:<div class="mdetail-params"><ul>
  158. * <li><b><code>DateTime</code></b> : <div class="sub-desc">The start date/time</div></li>
  159. * <li><b><code>DateTime</code></b> : <div class="sub-desc">The end date/time</div></li>
  160. * <li><b><code>Boolean</code></b> : <div class="sub-desc">True if the dates are all-day, false
  161. * if the time values should be used</div></li><ul></div>
  162. * @return {Array} The array of return values
  163. */
  164. getValue: function() {
  165. return [
  166. this.getDT('start'),
  167. this.getDT('end'),
  168. this.allDay.getValue()
  169. ];
  170. },
  171. // private getValue helper
  172. getDT: function(startend) {
  173. var time = this[startend + 'Time'].getValue(),
  174. dt = this[startend + 'Date'].getValue();
  175. if (Ext.isDate(dt)) {
  176. dt = dt.format(this[startend + 'Date'].format);
  177. }
  178. else {
  179. return null;
  180. };
  181. if (time != '' && this[startend + 'Time'].isVisible()) {
  182. return Date.parseDate(dt + ' ' + time, this[startend + 'Date'].format + ' ' + this[startend + 'Time'].format);
  183. }
  184. return Date.parseDate(dt, this[startend + 'Date'].format);
  185. },
  186. <div id="method-Ext.calendar.DateRangeField-setValue"></div>/**
  187. * Sets the values to use in the date range.
  188. * @param {Array/Date/Object} v The value(s) to set into the field. Valid types are as follows:<div class="mdetail-params"><ul>
  189. * <li><b><code>Array</code></b> : <div class="sub-desc">An array containing, in order, a start date, end date and all-day flag.
  190. * This array should exactly match the return type as specified by {@link #getValue}.</div></li>
  191. * <li><b><code>DateTime</code></b> : <div class="sub-desc">A single Date object, which will be used for both the start and
  192. * end dates in the range. The all-day flag will be defaulted to false.</div></li>
  193. * <li><b><code>Object</code></b> : <div class="sub-desc">An object containing properties for StartDate, EndDate and IsAllDay
  194. * as defined in {@link Ext.calendar.EventMappings}.</div></li><ul></div>
  195. */
  196. setValue: function(v) {
  197. if (Ext.isArray(v)) {
  198. this.setDT(v[0], 'start');
  199. this.setDT(v[1], 'end');
  200. this.allDay.setValue( !! v[2]);
  201. }
  202. else if (Ext.isDate(v)) {
  203. this.setDT(v, 'start');
  204. this.setDT(v, 'end');
  205. this.allDay.setValue(false);
  206. }
  207. else if (v[Ext.calendar.EventMappings.StartDate.name]) {
  208. //object
  209. this.setDT(v[Ext.calendar.EventMappings.StartDate.name], 'start');
  210. if (!this.setDT(v[Ext.calendar.EventMappings.EndDate.name], 'end')) {
  211. this.setDT(v[Ext.calendar.EventMappings.StartDate.name], 'end');
  212. }
  213. this.allDay.setValue( !! v[Ext.calendar.EventMappings.IsAllDay.name]);
  214. }
  215. },
  216. // private setValue helper
  217. setDT: function(dt, startend) {
  218. if (dt && Ext.isDate(dt)) {
  219. this[startend + 'Date'].setValue(dt);
  220. this[startend + 'Time'].setValue(dt.format(this[startend + 'Time'].format));
  221. return true;
  222. }
  223. },
  224. // inherited docs
  225. isDirty: function() {
  226. var dirty = false;
  227. if (this.rendered && !this.disabled) {
  228. this.items.each(function(item) {
  229. if (item.isDirty()) {
  230. dirty = true;
  231. return false;
  232. }
  233. });
  234. }
  235. return dirty;
  236. },
  237. // private
  238. onDisable: function() {
  239. this.delegateFn('disable');
  240. },
  241. // private
  242. onEnable: function() {
  243. this.delegateFn('enable');
  244. },
  245. // inherited docs
  246. reset: function() {
  247. this.delegateFn('reset');
  248. },
  249. // private
  250. delegateFn: function(fn) {
  251. this.items.each(function(item) {
  252. if (item[fn]) {
  253. item[fn]();
  254. }
  255. });
  256. },
  257. // private
  258. beforeDestroy: function() {
  259. Ext.destroy(this.fieldCt);
  260. Ext.calendar.DateRangeField.superclass.beforeDestroy.call(this);
  261. },
  262. <div id="method-Ext.calendar.DateRangeField-getRawValue"></div>/**
  263. * @method getRawValue
  264. * @hide
  265. */
  266. getRawValue: Ext.emptyFn,
  267. <div id="method-Ext.calendar.DateRangeField-setRawValue"></div>/**
  268. * @method setRawValue
  269. * @hide
  270. */
  271. setRawValue: Ext.emptyFn
  272. });
  273. Ext.reg('daterangefield', Ext.calendar.DateRangeField);
  274. </pre>
  275. </body>
  276. </html>