Web UI for ARGUS server
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.

1033 lines
41 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.CalendarView"></div>/**
  16. * @class Ext.calendar.CalendarView
  17. * @extends Ext.BoxComponent
  18. * <p>This is an abstract class that serves as the base for other calendar views. This class is not
  19. * intended to be directly instantiated.</p>
  20. * <p>When extending this class to create a custom calendar view, you must provide an implementation
  21. * for the <code>renderItems</code> method, as there is no default implementation for rendering events
  22. * The rendering logic is totally dependent on how the UI structures its data, which
  23. * is determined by the underlying UI template (this base class does not have a template).</p>
  24. * @constructor
  25. * @param {Object} config The config object
  26. */
  27. Ext.calendar.CalendarView = Ext.extend(Ext.BoxComponent, {
  28. <div id="cfg-Ext.calendar.CalendarView-startDay"></div>/**
  29. * @cfg {Number} startDay
  30. * The 0-based index for the day on which the calendar week begins (0=Sunday, which is the default)
  31. */
  32. startDay: 0,
  33. <div id="cfg-Ext.calendar.CalendarView-spansHavePriority"></div>/**
  34. * @cfg {Boolean} spansHavePriority
  35. * Allows switching between two different modes of rendering events that span multiple days. When true,
  36. * span events are always sorted first, possibly at the expense of start dates being out of order (e.g.,
  37. * a span event that starts at 11am one day and spans into the next day would display before a non-spanning
  38. * event that starts at 10am, even though they would not be in date order). This can lead to more compact
  39. * layouts when there are many overlapping events. If false (the default), events will always sort by start date
  40. * first which can result in a less compact, but chronologically consistent layout.
  41. */
  42. spansHavePriority: false,
  43. <div id="cfg-Ext.calendar.CalendarView-trackMouseOver"></div>/**
  44. * @cfg {Boolean} trackMouseOver
  45. * Whether or not the view tracks and responds to the browser mouseover event on contained elements (defaults to
  46. * true). If you don't need mouseover event highlighting you can disable this.
  47. */
  48. trackMouseOver: true,
  49. <div id="cfg-Ext.calendar.CalendarView-enableFx"></div>/**
  50. * @cfg {Boolean} enableFx
  51. * Determines whether or not visual effects for CRUD actions are enabled (defaults to true). If this is false
  52. * it will override any values for {@link #enableAddFx}, {@link #enableUpdateFx} or {@link enableRemoveFx} and
  53. * all animations will be disabled.
  54. */
  55. enableFx: true,
  56. <div id="cfg-Ext.calendar.CalendarView-enableAddFx"></div>/**
  57. * @cfg {Boolean} enableAddFx
  58. * True to enable a visual effect on adding a new event (the default), false to disable it. Note that if
  59. * {@link #enableFx} is false it will override this value. The specific effect that runs is defined in the
  60. * {@link #doAddFx} method.
  61. */
  62. enableAddFx: true,
  63. <div id="cfg-Ext.calendar.CalendarView-enableUpdateFx"></div>/**
  64. * @cfg {Boolean} enableUpdateFx
  65. * True to enable a visual effect on updating an event, false to disable it (the default). Note that if
  66. * {@link #enableFx} is false it will override this value. The specific effect that runs is defined in the
  67. * {@link #doUpdateFx} method.
  68. */
  69. enableUpdateFx: false,
  70. <div id="cfg-Ext.calendar.CalendarView-enableRemoveFx"></div>/**
  71. * @cfg {Boolean} enableRemoveFx
  72. * True to enable a visual effect on removing an event (the default), false to disable it. Note that if
  73. * {@link #enableFx} is false it will override this value. The specific effect that runs is defined in the
  74. * {@link #doRemoveFx} method.
  75. */
  76. enableRemoveFx: true,
  77. <div id="cfg-Ext.calendar.CalendarView-enableDD"></div>/**
  78. * @cfg {Boolean} enableDD
  79. * True to enable drag and drop in the calendar view (the default), false to disable it
  80. */
  81. enableDD: true,
  82. <div id="cfg-Ext.calendar.CalendarView-monitorResize"></div>/**
  83. * @cfg {Boolean} monitorResize
  84. * True to monitor the browser's resize event (the default), false to ignore it. If the calendar view is rendered
  85. * into a fixed-size container this can be set to false. However, if the view can change dimensions (e.g., it's in
  86. * fit layout in a viewport or some other resizable container) it is very important that this config is true so that
  87. * any resize event propagates properly to all subcomponents and layouts get recalculated properly.
  88. */
  89. monitorResize: true,
  90. <div id="cfg-Ext.calendar.CalendarView-ddCreateEventText"></div>/**
  91. * @cfg {String} ddCreateEventText
  92. * The text to display inside the drag proxy while dragging over the calendar to create a new event (defaults to
  93. * 'Create event for {0}' where {0} is a date range supplied by the view)
  94. */
  95. ddCreateEventText: 'Create event for {0}',
  96. <div id="cfg-Ext.calendar.CalendarView-ddMoveEventText"></div>/**
  97. * @cfg {String} ddMoveEventText
  98. * The text to display inside the drag proxy while dragging an event to reposition it (defaults to
  99. * 'Move event to {0}' where {0} is the updated event start date/time supplied by the view)
  100. */
  101. ddMoveEventText: 'Move event to {0}',
  102. <div id="cfg-Ext.calendar.CalendarView-ddResizeEventText"></div>/**
  103. * @cfg {String} ddResizeEventText
  104. * The string displayed to the user in the drag proxy while dragging the resize handle of an event (defaults to
  105. * 'Update event to {0}' where {0} is the updated event start-end range supplied by the view). Note that
  106. * this text is only used in views
  107. * that allow resizing of events.
  108. */
  109. ddResizeEventText: 'Update event to {0}',
  110. //private properties -- do not override:
  111. weekCount: 1,
  112. dayCount: 1,
  113. eventSelector: '.ext-cal-evt',
  114. eventOverClass: 'ext-evt-over',
  115. eventElIdDelimiter: '-evt-',
  116. dayElIdDelimiter: '-day-',
  117. <div id="method-Ext.calendar.CalendarView-getEventBodyMarkup"></div>/**
  118. * Returns a string of HTML template markup to be used as the body portion of the event template created
  119. * by {@link #getEventTemplate}. This provdes the flexibility to customize what's in the body without
  120. * having to override the entire XTemplate. This string can include any valid {@link Ext.Template} code, and
  121. * any data tokens accessible to the containing event template can be referenced in this string.
  122. * @return {String} The body template string
  123. */
  124. getEventBodyMarkup: Ext.emptyFn,
  125. // must be implemented by a subclass
  126. <div id="method-Ext.calendar.CalendarView-getEventTemplate"></div>/**
  127. * <p>Returns the XTemplate that is bound to the calendar's event store (it expects records of type
  128. * {@link Ext.calendar.EventRecord}) to populate the calendar views with events. Internally this method
  129. * by default generates different markup for browsers that support CSS border radius and those that don't.
  130. * This method can be overridden as needed to customize the markup generated.</p>
  131. * <p>Note that this method calls {@link #getEventBodyMarkup} to retrieve the body markup for events separately
  132. * from the surrounding container markup. This provdes the flexibility to customize what's in the body without
  133. * having to override the entire XTemplate. If you do override this method, you should make sure that your
  134. * overridden version also does the same.</p>
  135. * @return {Ext.XTemplate} The event XTemplate
  136. */
  137. getEventTemplate: Ext.emptyFn,
  138. // must be implemented by a subclass
  139. // private
  140. initComponent: function() {
  141. this.setStartDate(this.startDate || new Date());
  142. Ext.calendar.CalendarView.superclass.initComponent.call(this);
  143. this.addEvents({
  144. <div id="event-Ext.calendar.CalendarView-eventsrendered"></div>/**
  145. * @event eventsrendered
  146. * Fires after events are finished rendering in the view
  147. * @param {Ext.calendar.CalendarView} this
  148. */
  149. eventsrendered: true,
  150. <div id="event-Ext.calendar.CalendarView-eventclick"></div>/**
  151. * @event eventclick
  152. * Fires after the user clicks on an event element
  153. * @param {Ext.calendar.CalendarView} this
  154. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was clicked on
  155. * @param {HTMLNode} el The DOM node that was clicked on
  156. */
  157. eventclick: true,
  158. <div id="event-Ext.calendar.CalendarView-eventover"></div>/**
  159. * @event eventover
  160. * Fires anytime the mouse is over an event element
  161. * @param {Ext.calendar.CalendarView} this
  162. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor is over
  163. * @param {HTMLNode} el The DOM node that is being moused over
  164. */
  165. eventover: true,
  166. <div id="event-Ext.calendar.CalendarView-eventout"></div>/**
  167. * @event eventout
  168. * Fires anytime the mouse exits an event element
  169. * @param {Ext.calendar.CalendarView} this
  170. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor exited
  171. * @param {HTMLNode} el The DOM node that was exited
  172. */
  173. eventout: true,
  174. <div id="event-Ext.calendar.CalendarView-datechange"></div>/**
  175. * @event datechange
  176. * Fires after the start date of the view changes
  177. * @param {Ext.calendar.CalendarView} this
  178. * @param {Date} startDate The start date of the view (as explained in {@link #getStartDate}
  179. * @param {Date} viewStart The first displayed date in the view
  180. * @param {Date} viewEnd The last displayed date in the view
  181. */
  182. datechange: true,
  183. <div id="event-Ext.calendar.CalendarView-rangeselect"></div>/**
  184. * @event rangeselect
  185. * Fires after the user drags on the calendar to select a range of dates/times in which to create an event
  186. * @param {Ext.calendar.CalendarView} this
  187. * @param {Object} dates An object containing the start (StartDate property) and end (EndDate property) dates selected
  188. * @param {Function} callback A callback function that MUST be called after the event handling is complete so that
  189. * the view is properly cleaned up (shim elements are persisted in the view while the user is prompted to handle the
  190. * range selection). The callback is already created in the proper scope, so it simply needs to be executed as a standard
  191. * function call (e.g., callback()).
  192. */
  193. rangeselect: true,
  194. <div id="event-Ext.calendar.CalendarView-eventmove"></div>/**
  195. * @event eventmove
  196. * Fires after an event element is dragged by the user and dropped in a new position
  197. * @param {Ext.calendar.CalendarView} this
  198. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was moved with
  199. * updated start and end dates
  200. */
  201. eventmove: true,
  202. <div id="event-Ext.calendar.CalendarView-initdrag"></div>/**
  203. * @event initdrag
  204. * Fires when a drag operation is initiated in the view
  205. * @param {Ext.calendar.CalendarView} this
  206. */
  207. initdrag: true,
  208. <div id="event-Ext.calendar.CalendarView-dayover"></div>/**
  209. * @event dayover
  210. * Fires while the mouse is over a day element
  211. * @param {Ext.calendar.CalendarView} this
  212. * @param {Date} dt The date that is being moused over
  213. * @param {Ext.Element} el The day Element that is being moused over
  214. */
  215. dayover: true,
  216. <div id="event-Ext.calendar.CalendarView-dayout"></div>/**
  217. * @event dayout
  218. * Fires when the mouse exits a day element
  219. * @param {Ext.calendar.CalendarView} this
  220. * @param {Date} dt The date that is exited
  221. * @param {Ext.Element} el The day Element that is exited
  222. */
  223. dayout: true
  224. /*
  225. * @event eventdelete
  226. * Fires after an event element is deleted by the user. Not currently implemented directly at the view level -- currently
  227. * deletes only happen from one of the forms.
  228. * @param {Ext.calendar.CalendarView} this
  229. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was deleted
  230. */
  231. //eventdelete: true
  232. });
  233. },
  234. // private
  235. afterRender: function() {
  236. Ext.calendar.CalendarView.superclass.afterRender.call(this);
  237. this.renderTemplate();
  238. if (this.store) {
  239. this.setStore(this.store, true);
  240. }
  241. this.el.on({
  242. 'mouseover': this.onMouseOver,
  243. 'mouseout': this.onMouseOut,
  244. 'click': this.onClick,
  245. 'resize': this.onResize,
  246. scope: this
  247. });
  248. this.el.unselectable();
  249. if (this.enableDD && this.initDD) {
  250. this.initDD();
  251. }
  252. this.on('eventsrendered', this.forceSize);
  253. this.forceSize.defer(100, this);
  254. },
  255. // private
  256. forceSize: function() {
  257. if (this.el && this.el.child) {
  258. var hd = this.el.child('.ext-cal-hd-ct'),
  259. bd = this.el.child('.ext-cal-body-ct');
  260. if (bd == null || hd == null) return;
  261. var headerHeight = hd.getHeight(),
  262. sz = this.el.parent().getSize();
  263. bd.setHeight(sz.height - headerHeight);
  264. }
  265. },
  266. refresh: function() {
  267. this.prepareData();
  268. this.renderTemplate();
  269. this.renderItems();
  270. },
  271. getWeekCount: function() {
  272. var days = Ext.calendar.Date.diffDays(this.viewStart, this.viewEnd);
  273. return Math.ceil(days / this.dayCount);
  274. },
  275. // private
  276. prepareData: function() {
  277. var lastInMonth = this.startDate.getLastDateOfMonth(),
  278. w = 0,
  279. row = 0,
  280. dt = this.viewStart.clone(),
  281. weeks = this.weekCount < 1 ? 6: this.weekCount;
  282. this.eventGrid = [[]];
  283. this.allDayGrid = [[]];
  284. this.evtMaxCount = [];
  285. var evtsInView = this.store.queryBy(function(rec) {
  286. return this.isEventVisible(rec.data);
  287. },
  288. this);
  289. for (; w < weeks; w++) {
  290. this.evtMaxCount[w] = 0;
  291. if (this.weekCount == -1 && dt > lastInMonth) {
  292. //current week is fully in next month so skip
  293. break;
  294. }
  295. this.eventGrid[w] = this.eventGrid[w] || [];
  296. this.allDayGrid[w] = this.allDayGrid[w] || [];
  297. for (d = 0; d < this.dayCount; d++) {
  298. if (evtsInView.getCount() > 0) {
  299. var evts = evtsInView.filterBy(function(rec) {
  300. var startsOnDate = (dt.getTime() == rec.data[Ext.calendar.EventMappings.StartDate.name].clearTime(true).getTime());
  301. var spansFromPrevView = (w == 0 && d == 0 && (dt > rec.data[Ext.calendar.EventMappings.StartDate.name]));
  302. return startsOnDate || spansFromPrevView;
  303. },
  304. this);
  305. this.sortEventRecordsForDay(evts);
  306. this.prepareEventGrid(evts, w, d);
  307. }
  308. dt = dt.add(Date.DAY, 1);
  309. }
  310. }
  311. this.currentWeekCount = w;
  312. },
  313. // private
  314. prepareEventGrid: function(evts, w, d) {
  315. var row = 0,
  316. dt = this.viewStart.clone(),
  317. max = this.maxEventsPerDay ? this.maxEventsPerDay: 999;
  318. evts.each(function(evt) {
  319. var M = Ext.calendar.EventMappings,
  320. days = Ext.calendar.Date.diffDays(
  321. Ext.calendar.Date.max(this.viewStart, evt.data[M.StartDate.name]),
  322. Ext.calendar.Date.min(this.viewEnd, evt.data[M.EndDate.name])) + 1;
  323. if (days > 1 || Ext.calendar.Date.diffDays(evt.data[M.StartDate.name], evt.data[M.EndDate.name]) > 1) {
  324. this.prepareEventGridSpans(evt, this.eventGrid, w, d, days);
  325. this.prepareEventGridSpans(evt, this.allDayGrid, w, d, days, true);
  326. } else {
  327. row = this.findEmptyRowIndex(w, d);
  328. this.eventGrid[w][d] = this.eventGrid[w][d] || [];
  329. this.eventGrid[w][d][row] = evt;
  330. if (evt.data[M.IsAllDay.name]) {
  331. row = this.findEmptyRowIndex(w, d, true);
  332. this.allDayGrid[w][d] = this.allDayGrid[w][d] || [];
  333. this.allDayGrid[w][d][row] = evt;
  334. }
  335. }
  336. if (this.evtMaxCount[w] < this.eventGrid[w][d].length) {
  337. this.evtMaxCount[w] = Math.min(max + 1, this.eventGrid[w][d].length);
  338. }
  339. return true;
  340. },
  341. this);
  342. },
  343. // private
  344. prepareEventGridSpans: function(evt, grid, w, d, days, allday) {
  345. // this event spans multiple days/weeks, so we have to preprocess
  346. // the events and store special span events as placeholders so that
  347. // the render routine can build the necessary TD spans correctly.
  348. var w1 = w,
  349. d1 = d,
  350. row = this.findEmptyRowIndex(w, d, allday),
  351. dt = this.viewStart.clone();
  352. var start = {
  353. event: evt,
  354. isSpan: true,
  355. isSpanStart: true,
  356. spanLeft: false,
  357. spanRight: (d == 6)
  358. };
  359. grid[w][d] = grid[w][d] || [];
  360. grid[w][d][row] = start;
  361. while (--days) {
  362. dt = dt.add(Date.DAY, 1);
  363. if (dt > this.viewEnd) {
  364. break;
  365. }
  366. if (++d1 > 6) {
  367. // reset counters to the next week
  368. d1 = 0;
  369. w1++;
  370. row = this.findEmptyRowIndex(w1, 0);
  371. }
  372. grid[w1] = grid[w1] || [];
  373. grid[w1][d1] = grid[w1][d1] || [];
  374. grid[w1][d1][row] = {
  375. event: evt,
  376. isSpan: true,
  377. isSpanStart: (d1 == 0),
  378. spanLeft: (w1 > w) && (d1 % 7 == 0),
  379. spanRight: (d1 == 6) && (days > 1)
  380. };
  381. }
  382. },
  383. // private
  384. findEmptyRowIndex: function(w, d, allday) {
  385. var grid = allday ? this.allDayGrid: this.eventGrid,
  386. day = grid[w] ? grid[w][d] || [] : [],
  387. i = 0,
  388. ln = day.length;
  389. for (; i < ln; i++) {
  390. if (day[i] == null) {
  391. return i;
  392. }
  393. }
  394. return ln;
  395. },
  396. // private
  397. renderTemplate: function() {
  398. if (this.tpl) {
  399. this.tpl.overwrite(this.el, this.getParams());
  400. this.lastRenderStart = this.viewStart.clone();
  401. this.lastRenderEnd = this.viewEnd.clone();
  402. }
  403. },
  404. disableStoreEvents: function() {
  405. this.monitorStoreEvents = false;
  406. },
  407. enableStoreEvents: function(refresh) {
  408. this.monitorStoreEvents = true;
  409. if (refresh === true) {
  410. this.refresh();
  411. }
  412. },
  413. // private
  414. onResize: function() {
  415. this.refresh();
  416. },
  417. // private
  418. onInitDrag: function() {
  419. this.fireEvent('initdrag', this);
  420. },
  421. // private
  422. onEventDrop: function(rec, dt) {
  423. if (Ext.calendar.Date.compare(rec.data[Ext.calendar.EventMappings.StartDate.name], dt) === 0) {
  424. // no changes
  425. return;
  426. }
  427. var diff = dt.getTime() - rec.data[Ext.calendar.EventMappings.StartDate.name].getTime();
  428. rec.set(Ext.calendar.EventMappings.StartDate.name, dt);
  429. rec.set(Ext.calendar.EventMappings.EndDate.name, rec.data[Ext.calendar.EventMappings.EndDate.name].add(Date.MILLI, diff));
  430. this.fireEvent('eventmove', this, rec);
  431. },
  432. // private
  433. onCalendarEndDrag: function(start, end, onComplete) {
  434. // set this flag for other event handlers that might conflict while we're waiting
  435. this.dragPending = true;
  436. // have to wait for the user to save or cancel before finalizing the dd interation
  437. var o = {};
  438. o[Ext.calendar.EventMappings.StartDate.name] = start;
  439. o[Ext.calendar.EventMappings.EndDate.name] = end;
  440. this.fireEvent('rangeselect', this, o, this.onCalendarEndDragComplete.createDelegate(this, [onComplete]));
  441. },
  442. // private
  443. onCalendarEndDragComplete: function(onComplete) {
  444. // callback for the drop zone to clean up
  445. onComplete();
  446. // clear flag for other events to resume normally
  447. this.dragPending = false;
  448. },
  449. // private
  450. onUpdate: function(ds, rec, operation) {
  451. if (this.monitorStoreEvents === false) {
  452. return;
  453. }
  454. if (operation == Ext.data.Record.COMMIT) {
  455. this.refresh();
  456. if (this.enableFx && this.enableUpdateFx) {
  457. this.doUpdateFx(this.getEventEls(rec.data[Ext.calendar.EventMappings.EventId.name]), {
  458. scope: this
  459. });
  460. }
  461. }
  462. },
  463. doUpdateFx: function(els, o) {
  464. this.highlightEvent(els, null, o);
  465. },
  466. // private
  467. onAdd: function(ds, records, index) {
  468. if (this.monitorStoreEvents === false) {
  469. return;
  470. }
  471. var rec = records[0];
  472. this.tempEventId = rec.id;
  473. this.refresh();
  474. if (this.enableFx && this.enableAddFx) {
  475. this.doAddFx(this.getEventEls(rec.data[Ext.calendar.EventMappings.EventId.name]), {
  476. scope: this
  477. });
  478. };
  479. },
  480. doAddFx: function(els, o) {
  481. els.fadeIn(Ext.apply(o, {
  482. duration: 2
  483. }));
  484. },
  485. // private
  486. onRemove: function(ds, rec) {
  487. if (this.monitorStoreEvents === false) {
  488. return;
  489. }
  490. if (this.enableFx && this.enableRemoveFx) {
  491. this.doRemoveFx(this.getEventEls(rec.data[Ext.calendar.EventMappings.EventId.name]), {
  492. remove: true,
  493. scope: this,
  494. callback: this.refresh
  495. });
  496. }
  497. else {
  498. this.getEventEls(rec.data[Ext.calendar.EventMappings.EventId.name]).remove();
  499. this.refresh();
  500. }
  501. },
  502. doRemoveFx: function(els, o) {
  503. els.fadeOut(o);
  504. },
  505. <div id="method-Ext.calendar.CalendarView-highlightEvent"></div>/**
  506. * Visually highlights an event using {@link Ext.Fx#highlight} config options.
  507. * If {@link #highlightEventActions} is false this method will have no effect.
  508. * @param {Ext.CompositeElement} els The element(s) to highlight
  509. * @param {Object} color (optional) The highlight color. Should be a 6 char hex
  510. * color without the leading # (defaults to yellow: 'ffff9c')
  511. * @param {Object} o (optional) Object literal with any of the {@link Ext.Fx} config
  512. * options. See {@link Ext.Fx#highlight} for usage examples.
  513. */
  514. highlightEvent: function(els, color, o) {
  515. if (this.enableFx) {
  516. var c;
  517. ! (Ext.isIE || Ext.isOpera) ?
  518. els.highlight(color, o) :
  519. // Fun IE/Opera handling:
  520. els.each(function(el) {
  521. el.highlight(color, Ext.applyIf({
  522. attr: 'color'
  523. },
  524. o));
  525. c = el.child('.ext-cal-evm');
  526. if (c) {
  527. c.highlight(color, o);
  528. }
  529. },
  530. this);
  531. }
  532. },
  533. <div id="method-Ext.calendar.CalendarView-getEventIdFromEl"></div>/**
  534. * Retrieve an Event object's id from its corresponding node in the DOM.
  535. * @param {String/Element/HTMLElement} el An {@link Ext.Element}, DOM node or id
  536. */
  537. getEventIdFromEl: function(el) {
  538. el = Ext.get(el);
  539. var id = el.id.split(this.eventElIdDelimiter)[1];
  540. if (id.indexOf('-') > -1) {
  541. //This id has the index of the week it is rendered in as the suffix.
  542. //This allows events that span across weeks to still have reproducibly-unique DOM ids.
  543. id = id.split('-')[0];
  544. }
  545. return id;
  546. },
  547. // private
  548. getEventId: function(eventId) {
  549. if (eventId === undefined && this.tempEventId) {
  550. eventId = this.tempEventId;
  551. }
  552. return eventId;
  553. },
  554. <div id="method-Ext.calendar.CalendarView-getEventSelectorCls"></div>/**
  555. *
  556. * @param {String} eventId
  557. * @param {Boolean} forSelect
  558. * @return {String} The selector class
  559. */
  560. getEventSelectorCls: function(eventId, forSelect) {
  561. var prefix = forSelect ? '.': '';
  562. return prefix + this.id + this.eventElIdDelimiter + this.getEventId(eventId);
  563. },
  564. <div id="method-Ext.calendar.CalendarView-getEventEls"></div>/**
  565. *
  566. * @param {String} eventId
  567. * @return {Ext.CompositeElement} The matching CompositeElement of nodes
  568. * that comprise the rendered event. Any event that spans across a view
  569. * boundary will contain more than one internal Element.
  570. */
  571. getEventEls: function(eventId) {
  572. var els = Ext.select(this.getEventSelectorCls(this.getEventId(eventId), true), false, this.el.id);
  573. return new Ext.CompositeElement(els);
  574. },
  575. <div id="method-Ext.calendar.CalendarView-isToday"></div>/**
  576. * Returns true if the view is currently displaying today's date, else false.
  577. * @return {Boolean} True or false
  578. */
  579. isToday: function() {
  580. var today = new Date().clearTime().getTime();
  581. return this.viewStart.getTime() <= today && this.viewEnd.getTime() >= today;
  582. },
  583. // private
  584. onDataChanged: function(store) {
  585. this.refresh();
  586. },
  587. // private
  588. isEventVisible: function(evt) {
  589. var start = this.viewStart.getTime(),
  590. end = this.viewEnd.getTime(),
  591. M = Ext.calendar.EventMappings,
  592. evStart = (evt.data ? evt.data[M.StartDate.name] : evt[M.StartDate.name]).getTime(),
  593. evEnd = (evt.data ? evt.data[M.EndDate.name] : evt[M.EndDate.name]).add(Date.SECOND, -1).getTime(),
  594. startsInRange = (evStart >= start && evStart <= end),
  595. endsInRange = (evEnd >= start && evEnd <= end),
  596. spansRange = (evStart < start && evEnd > end);
  597. return (startsInRange || endsInRange || spansRange);
  598. },
  599. // private
  600. isOverlapping: function(evt1, evt2) {
  601. var ev1 = evt1.data ? evt1.data: evt1,
  602. ev2 = evt2.data ? evt2.data: evt2,
  603. M = Ext.calendar.EventMappings,
  604. start1 = ev1[M.StartDate.name].getTime(),
  605. end1 = ev1[M.EndDate.name].add(Date.SECOND, -1).getTime(),
  606. start2 = ev2[M.StartDate.name].getTime(),
  607. end2 = ev2[M.EndDate.name].add(Date.SECOND, -1).getTime();
  608. if (end1 < start1) {
  609. end1 = start1;
  610. }
  611. if (end2 < start2) {
  612. end2 = start2;
  613. }
  614. var ev1startsInEv2 = (start1 >= start2 && start1 <= end2),
  615. ev1EndsInEv2 = (end1 >= start2 && end1 <= end2),
  616. ev1SpansEv2 = (start1 < start2 && end1 > end2);
  617. return (ev1startsInEv2 || ev1EndsInEv2 || ev1SpansEv2);
  618. },
  619. getDayEl: function(dt) {
  620. return Ext.get(this.getDayId(dt));
  621. },
  622. getDayId: function(dt) {
  623. if (Ext.isDate(dt)) {
  624. dt = dt.format('Ymd');
  625. }
  626. return this.id + this.dayElIdDelimiter + dt;
  627. },
  628. <div id="method-Ext.calendar.CalendarView-getStartDate"></div>/**
  629. * Returns the start date of the view, as set by {@link #setStartDate}. Note that this may not
  630. * be the first date displayed in the rendered calendar -- to get the start and end dates displayed
  631. * to the user use {@link #getViewBounds}.
  632. * @return {Date} The start date
  633. */
  634. getStartDate: function() {
  635. return this.startDate;
  636. },
  637. <div id="method-Ext.calendar.CalendarView-setStartDate"></div>/**
  638. * Sets the start date used to calculate the view boundaries to display. The displayed view will be the
  639. * earliest and latest dates that match the view requirements and contain the date passed to this function.
  640. * @param {Date} dt The date used to calculate the new view boundaries
  641. */
  642. setStartDate: function(start, refresh) {
  643. this.startDate = start.clearTime();
  644. this.setViewBounds(start);
  645. this.store.load({
  646. params: {
  647. start: this.viewStart.format('m-d-Y'),
  648. end: this.viewEnd.format('m-d-Y')
  649. }
  650. });
  651. if (refresh === true) {
  652. this.refresh();
  653. }
  654. this.fireEvent('datechange', this, this.startDate, this.viewStart, this.viewEnd);
  655. },
  656. // private
  657. setViewBounds: function(startDate) {
  658. var start = startDate || this.startDate,
  659. offset = start.getDay() - this.startDay;
  660. switch (this.weekCount) {
  661. case 0:
  662. case 1:
  663. this.viewStart = this.dayCount < 7 ? start: start.add(Date.DAY, -offset).clearTime(true);
  664. this.viewEnd = this.viewStart.add(Date.DAY, this.dayCount || 7).add(Date.SECOND, -1);
  665. return;
  666. case - 1:
  667. // auto by month
  668. start = start.getFirstDateOfMonth();
  669. offset = start.getDay() - this.startDay;
  670. if (offset < 0) {
  671. offset += 7;
  672. }
  673. this.viewStart = start.add(Date.DAY, -offset).clearTime(true);
  674. // start from current month start, not view start:
  675. var end = start.add(Date.MONTH, 1).add(Date.SECOND, -1);
  676. // fill out to the end of the week:
  677. this.viewEnd = end.add(Date.DAY, 6 - end.getDay());
  678. return;
  679. default:
  680. this.viewStart = start.add(Date.DAY, -offset).clearTime(true);
  681. this.viewEnd = this.viewStart.add(Date.DAY, this.weekCount * 7).add(Date.SECOND, -1);
  682. }
  683. },
  684. // private
  685. getViewBounds: function() {
  686. return {
  687. start: this.viewStart,
  688. end: this.viewEnd
  689. };
  690. },
  691. /* private
  692. * Sort events for a single day for display in the calendar. This sorts allday
  693. * events first, then non-allday events are sorted either based on event start
  694. * priority or span priority based on the value of {@link #spansHavePriority}
  695. * (defaults to event start priority).
  696. * @param {MixedCollection} evts A {@link Ext.util.MixedCollection MixedCollection}
  697. * of {@link #Ext.calendar.EventRecord EventRecord} objects
  698. */
  699. sortEventRecordsForDay: function(evts) {
  700. if (evts.length < 2) {
  701. return;
  702. }
  703. evts.sort('ASC',
  704. function(evtA, evtB) {
  705. var a = evtA.data,
  706. b = evtB.data,
  707. M = Ext.calendar.EventMappings;
  708. // Always sort all day events before anything else
  709. if (a[M.IsAllDay.name]) {
  710. return - 1;
  711. }
  712. else if (b[M.IsAllDay.name]) {
  713. return 1;
  714. }
  715. if (this.spansHavePriority) {
  716. // This logic always weights span events higher than non-span events
  717. // (at the possible expense of start time order). This seems to
  718. // be the approach used by Google calendar and can lead to a more
  719. // visually appealing layout in complex cases, but event order is
  720. // not guaranteed to be consistent.
  721. var diff = Ext.calendar.Date.diffDays;
  722. if (diff(a[M.StartDate.name], a[M.EndDate.name]) > 0) {
  723. if (diff(b[M.StartDate.name], b[M.EndDate.name]) > 0) {
  724. // Both events are multi-day
  725. if (a[M.StartDate.name].getTime() == b[M.StartDate.name].getTime()) {
  726. // If both events start at the same time, sort the one
  727. // that ends later (potentially longer span bar) first
  728. return b[M.EndDate.name].getTime() - a[M.EndDate.name].getTime();
  729. }
  730. return a[M.StartDate.name].getTime() - b[M.StartDate.name].getTime();
  731. }
  732. return - 1;
  733. }
  734. else if (diff(b[M.StartDate.name], b[M.EndDate.name]) > 0) {
  735. return 1;
  736. }
  737. return a[M.StartDate.name].getTime() - b[M.StartDate.name].getTime();
  738. }
  739. else {
  740. // Doing this allows span and non-span events to intermingle but
  741. // remain sorted sequentially by start time. This seems more proper
  742. // but can make for a less visually-compact layout when there are
  743. // many such events mixed together closely on the calendar.
  744. return a[M.StartDate.name].getTime() - b[M.StartDate.name].getTime();
  745. }
  746. }.createDelegate(this));
  747. },
  748. <div id="method-Ext.calendar.CalendarView-moveTo"></div>/**
  749. * Updates the view to contain the passed date
  750. * @param {Date} dt The date to display
  751. */
  752. moveTo: function(dt, noRefresh) {
  753. if (Ext.isDate(dt)) {
  754. this.setStartDate(dt);
  755. if (noRefresh !== false) {
  756. this.refresh();
  757. }
  758. return this.startDate;
  759. }
  760. return dt;
  761. },
  762. <div id="method-Ext.calendar.CalendarView-moveNext"></div>/**
  763. * Updates the view to the next consecutive date(s)
  764. */
  765. moveNext: function(noRefresh) {
  766. return this.moveTo(this.viewEnd.add(Date.DAY, 1));
  767. },
  768. <div id="method-Ext.calendar.CalendarView-movePrev"></div>/**
  769. * Updates the view to the previous consecutive date(s)
  770. */
  771. movePrev: function(noRefresh) {
  772. var days = Ext.calendar.Date.diffDays(this.viewStart, this.viewEnd) + 1;
  773. return this.moveDays( - days, noRefresh);
  774. },
  775. <div id="method-Ext.calendar.CalendarView-moveMonths"></div>/**
  776. * Shifts the view by the passed number of months relative to the currently set date
  777. * @param {Number} value The number of months (positive or negative) by which to shift the view
  778. */
  779. moveMonths: function(value, noRefresh) {
  780. return this.moveTo(this.startDate.add(Date.MONTH, value), noRefresh);
  781. },
  782. <div id="method-Ext.calendar.CalendarView-moveWeeks"></div>/**
  783. * Shifts the view by the passed number of weeks relative to the currently set date
  784. * @param {Number} value The number of weeks (positive or negative) by which to shift the view
  785. */
  786. moveWeeks: function(value, noRefresh) {
  787. return this.moveTo(this.startDate.add(Date.DAY, value * 7), noRefresh);
  788. },
  789. <div id="method-Ext.calendar.CalendarView-moveDays"></div>/**
  790. * Shifts the view by the passed number of days relative to the currently set date
  791. * @param {Number} value The number of days (positive or negative) by which to shift the view
  792. */
  793. moveDays: function(value, noRefresh) {
  794. return this.moveTo(this.startDate.add(Date.DAY, value), noRefresh);
  795. },
  796. <div id="method-Ext.calendar.CalendarView-moveToday"></div>/**
  797. * Updates the view to show today
  798. */
  799. moveToday: function(noRefresh) {
  800. return this.moveTo(new Date(), noRefresh);
  801. },
  802. <div id="method-Ext.calendar.CalendarView-setStore"></div>/**
  803. * Sets the event store used by the calendar to display {@link Ext.calendar.EventRecord events}.
  804. * @param {Ext.data.Store} store
  805. */
  806. setStore: function(store, initial) {
  807. if (!initial && this.store) {
  808. this.store.un("datachanged", this.onDataChanged, this);
  809. this.store.un("add", this.onAdd, this);
  810. this.store.un("remove", this.onRemove, this);
  811. this.store.un("update", this.onUpdate, this);
  812. this.store.un("clear", this.refresh, this);
  813. }
  814. if (store) {
  815. store.on("datachanged", this.onDataChanged, this);
  816. store.on("add", this.onAdd, this);
  817. store.on("remove", this.onRemove, this);
  818. store.on("update", this.onUpdate, this);
  819. store.on("clear", this.refresh, this);
  820. }
  821. this.store = store;
  822. if (store && store.getCount() > 0) {
  823. this.refresh();
  824. }
  825. },
  826. getEventRecord: function(id) {
  827. var idx = this.store.find(Ext.calendar.EventMappings.EventId.name, id);
  828. return this.store.getAt(idx);
  829. },
  830. getEventRecordFromEl: function(el) {
  831. return this.getEventRecord(this.getEventIdFromEl(el));
  832. },
  833. // private
  834. getParams: function() {
  835. return {
  836. viewStart: this.viewStart,
  837. viewEnd: this.viewEnd,
  838. startDate: this.startDate,
  839. dayCount: this.dayCount,
  840. weekCount: this.weekCount,
  841. title: this.getTitle()
  842. };
  843. },
  844. getTitle: function() {
  845. return this.startDate.format('F Y');
  846. },
  847. /*
  848. * Shared click handling. Each specific view also provides view-specific
  849. * click handling that calls this first. This method returns true if it
  850. * can handle the click (and so the subclass should ignore it) else false.
  851. */
  852. onClick: function(e, t) {
  853. var el = e.getTarget(this.eventSelector, 5);
  854. if (el) {
  855. var id = this.getEventIdFromEl(el);
  856. this.fireEvent('eventclick', this, this.getEventRecord(id), el);
  857. return true;
  858. }
  859. },
  860. // private
  861. onMouseOver: function(e, t) {
  862. if (this.trackMouseOver !== false && (this.dragZone == undefined || !this.dragZone.dragging)) {
  863. if (!this.handleEventMouseEvent(e, t, 'over')) {
  864. this.handleDayMouseEvent(e, t, 'over');
  865. }
  866. }
  867. },
  868. // private
  869. onMouseOut: function(e, t) {
  870. if (this.trackMouseOver !== false && (this.dragZone == undefined || !this.dragZone.dragging)) {
  871. if (!this.handleEventMouseEvent(e, t, 'out')) {
  872. this.handleDayMouseEvent(e, t, 'out');
  873. }
  874. }
  875. },
  876. // private
  877. handleEventMouseEvent: function(e, t, type) {
  878. var el = e.getTarget(this.eventSelector, 5, true),
  879. rel,
  880. els,
  881. evtId;
  882. if (el) {
  883. rel = Ext.get(e.getRelatedTarget());
  884. if (el == rel || el.contains(rel)) {
  885. return true;
  886. }
  887. evtId = this.getEventIdFromEl(el);
  888. if (this.eventOverClass != '') {
  889. els = this.getEventEls(evtId);
  890. els[type == 'over' ? 'addClass': 'removeClass'](this.eventOverClass);
  891. }
  892. this.fireEvent('event' + type, this, this.getEventRecord(evtId), el);
  893. return true;
  894. }
  895. return false;
  896. },
  897. // private
  898. getDateFromId: function(id, delim) {
  899. var parts = id.split(delim);
  900. return parts[parts.length - 1];
  901. },
  902. // private
  903. handleDayMouseEvent: function(e, t, type) {
  904. t = e.getTarget('td', 3);
  905. if (t) {
  906. if (t.id && t.id.indexOf(this.dayElIdDelimiter) > -1) {
  907. var dt = this.getDateFromId(t.id, this.dayElIdDelimiter),
  908. rel = Ext.get(e.getRelatedTarget()),
  909. relTD,
  910. relDate;
  911. if (rel) {
  912. relTD = rel.is('td') ? rel: rel.up('td', 3);
  913. relDate = relTD && relTD.id ? this.getDateFromId(relTD.id, this.dayElIdDelimiter) : '';
  914. }
  915. if (!rel || dt != relDate) {
  916. var el = this.getDayEl(dt);
  917. if (el && this.dayOverClass != '') {
  918. el[type == 'over' ? 'addClass': 'removeClass'](this.dayOverClass);
  919. }
  920. this.fireEvent('day' + type, this, Date.parseDate(dt, "Ymd"), el);
  921. }
  922. }
  923. }
  924. },
  925. // private
  926. renderItems: function() {
  927. throw 'This method must be implemented by a subclass';
  928. }
  929. });
  930. </pre>
  931. </body>
  932. </html>