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.

457 lines
17 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.DayBodyView"></div>/**S
  16. * @class Ext.calendar.DayBodyView
  17. * @extends Ext.calendar.CalendarView
  18. * <p>This is the scrolling container within the day and week views where non-all-day events are displayed.
  19. * Normally you should not need to use this class directly -- instead you should use {@link Ext.calendar.DayView DayView}
  20. * which aggregates this class and the {@link Ext.calendar.DayHeaderView DayHeaderView} into the single unified view
  21. * presented by {@link Ext.calendar.CalendarPanel CalendarPanel}.</p>
  22. * @constructor
  23. * @param {Object} config The config object
  24. */
  25. Ext.calendar.DayBodyView = Ext.extend(Ext.calendar.CalendarView, {
  26. //private
  27. dayColumnElIdDelimiter: '-day-col-',
  28. //private
  29. initComponent: function() {
  30. Ext.calendar.DayBodyView.superclass.initComponent.call(this);
  31. this.addEvents({
  32. <div id="event-Ext.calendar.DayBodyView-eventresize"></div>/**
  33. * @event eventresize
  34. * Fires after the user drags the resize handle of an event to resize it
  35. * @param {Ext.calendar.DayBodyView} this
  36. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was resized
  37. * containing the updated start and end dates
  38. */
  39. eventresize: true,
  40. <div id="event-Ext.calendar.DayBodyView-dayclick"></div>/**
  41. * @event dayclick
  42. * Fires after the user clicks within the day view container and not on an event element
  43. * @param {Ext.calendar.DayBodyView} this
  44. * @param {Date} dt The date/time that was clicked on
  45. * @param {Boolean} allday True if the day clicked on represents an all-day box, else false. Clicks within the
  46. * DayBodyView always return false for this param.
  47. * @param {Ext.Element} el The Element that was clicked on
  48. */
  49. dayclick: true
  50. });
  51. },
  52. //private
  53. initDD: function() {
  54. var cfg = {
  55. createText: this.ddCreateEventText,
  56. moveText: this.ddMoveEventText,
  57. resizeText: this.ddResizeEventText
  58. };
  59. this.el.ddScrollConfig = {
  60. // scrolling is buggy in IE/Opera for some reason. A larger vthresh
  61. // makes it at least functional if not perfect
  62. vthresh: Ext.isIE || Ext.isOpera ? 100: 40,
  63. hthresh: -1,
  64. frequency: 50,
  65. increment: 100,
  66. ddGroup: 'DayViewDD'
  67. };
  68. this.dragZone = new Ext.calendar.DayViewDragZone(this.el, Ext.apply({
  69. view: this,
  70. containerScroll: true
  71. },
  72. cfg));
  73. this.dropZone = new Ext.calendar.DayViewDropZone(this.el, Ext.apply({
  74. view: this
  75. },
  76. cfg));
  77. },
  78. //private
  79. refresh: function() {
  80. var top = this.el.getScroll().top;
  81. this.prepareData();
  82. this.renderTemplate();
  83. this.renderItems();
  84. // skip this if the initial render scroll position has not yet been set.
  85. // necessary since IE/Opera must be deferred, so the first refresh will
  86. // override the initial position by default and always set it to 0.
  87. if (this.scrollReady) {
  88. this.scrollTo(top);
  89. }
  90. },
  91. <div id="method-Ext.calendar.DayBodyView-scrollTo"></div>/**
  92. * Scrolls the container to the specified vertical position. If the view is large enough that
  93. * there is no scroll overflow then this method will have no affect.
  94. * @param {Number} y The new vertical scroll position in pixels
  95. * @param {Boolean} defer (optional) <p>True to slightly defer the call, false to execute immediately.</p>
  96. * <p>This method will automatically defer itself for IE and Opera (even if you pass false) otherwise
  97. * the scroll position will not update in those browsers. You can optionally pass true, however, to
  98. * force the defer in all browsers, or use your own custom conditions to determine whether this is needed.</p>
  99. * <p>Note that this method should not generally need to be called directly as scroll position is managed internally.</p>
  100. */
  101. scrollTo: function(y, defer) {
  102. defer = defer || (Ext.isIE || Ext.isOpera);
  103. if (defer) {
  104. (function() {
  105. this.el.scrollTo('top', y);
  106. this.scrollReady = true;
  107. }).defer(10, this);
  108. }
  109. else {
  110. this.el.scrollTo('top', y);
  111. this.scrollReady = true;
  112. }
  113. },
  114. // private
  115. afterRender: function() {
  116. if (!this.tpl) {
  117. this.tpl = new Ext.calendar.DayBodyTemplate({
  118. id: this.id,
  119. dayCount: this.dayCount,
  120. showTodayText: this.showTodayText,
  121. todayText: this.todayText,
  122. showTime: this.showTime
  123. });
  124. }
  125. this.tpl.compile();
  126. this.addClass('ext-cal-body-ct');
  127. Ext.calendar.DayBodyView.superclass.afterRender.call(this);
  128. // default scroll position to 7am:
  129. this.scrollTo(7 * 42);
  130. },
  131. // private
  132. forceSize: Ext.emptyFn,
  133. // private
  134. onEventResize: function(rec, data) {
  135. var D = Ext.calendar.Date,
  136. start = Ext.calendar.EventMappings.StartDate.name,
  137. end = Ext.calendar.EventMappings.EndDate.name;
  138. if (D.compare(rec.data[start], data.StartDate) === 0 &&
  139. D.compare(rec.data[end], data.EndDate) === 0) {
  140. // no changes
  141. return;
  142. }
  143. rec.set(start, data.StartDate);
  144. rec.set(end, data.EndDate);
  145. this.fireEvent('eventresize', this, rec);
  146. },
  147. // inherited docs
  148. getEventBodyMarkup: function() {
  149. if (!this.eventBodyMarkup) {
  150. this.eventBodyMarkup = ['{Title}',
  151. '<tpl if="_isReminder">',
  152. '<i class="ext-cal-ic ext-cal-ic-rem">&nbsp;</i>',
  153. '</tpl>',
  154. '<tpl if="_isRecurring">',
  155. '<i class="ext-cal-ic ext-cal-ic-rcr">&nbsp;</i>',
  156. '</tpl>'
  157. // '<tpl if="spanLeft">',
  158. // '<i class="ext-cal-spl">&nbsp;</i>',
  159. // '</tpl>',
  160. // '<tpl if="spanRight">',
  161. // '<i class="ext-cal-spr">&nbsp;</i>',
  162. // '</tpl>'
  163. ].join('');
  164. }
  165. return this.eventBodyMarkup;
  166. },
  167. // inherited docs
  168. getEventTemplate: function() {
  169. if (!this.eventTpl) {
  170. this.eventTpl = !(Ext.isIE || Ext.isOpera) ?
  171. new Ext.XTemplate(
  172. '<div id="{_elId}" class="{_selectorCls} {_colorCls} ext-cal-evt ext-cal-evr" style="left: {_left}%; width: {_width}%; top: {_top}px; height: {_height}px;">',
  173. '<div class="ext-evt-bd">', this.getEventBodyMarkup(), '</div>',
  174. '<div class="ext-evt-rsz"><div class="ext-evt-rsz-h">&nbsp;</div></div>',
  175. '</div>'
  176. )
  177. : new Ext.XTemplate(
  178. '<div id="{_elId}" class="ext-cal-evt {_selectorCls} {_colorCls}-x" style="left: {_left}%; width: {_width}%; top: {_top}px;">',
  179. '<div class="ext-cal-evb">&nbsp;</div>',
  180. '<dl style="height: {_height}px;" class="ext-cal-evdm">',
  181. '<dd class="ext-evt-bd">',
  182. this.getEventBodyMarkup(),
  183. '</dd>',
  184. '<div class="ext-evt-rsz"><div class="ext-evt-rsz-h">&nbsp;</div></div>',
  185. '</dl>',
  186. '<div class="ext-cal-evb">&nbsp;</div>',
  187. '</div>'
  188. );
  189. this.eventTpl.compile();
  190. }
  191. return this.eventTpl;
  192. },
  193. <div id="method-Ext.calendar.DayBodyView-getEventAllDayTemplate"></div>/**
  194. * <p>Returns the XTemplate that is bound to the calendar's event store (it expects records of type
  195. * {@link Ext.calendar.EventRecord}) to populate the calendar views with <strong>all-day</strong> events.
  196. * Internally this method by default generates different markup for browsers that support CSS border radius
  197. * and those that don't. This method can be overridden as needed to customize the markup generated.</p>
  198. * <p>Note that this method calls {@link #getEventBodyMarkup} to retrieve the body markup for events separately
  199. * from the surrounding container markup. This provdes the flexibility to customize what's in the body without
  200. * having to override the entire XTemplate. If you do override this method, you should make sure that your
  201. * overridden version also does the same.</p>
  202. * @return {Ext.XTemplate} The event XTemplate
  203. */
  204. getEventAllDayTemplate: function() {
  205. if (!this.eventAllDayTpl) {
  206. var tpl,
  207. body = this.getEventBodyMarkup();
  208. tpl = !(Ext.isIE || Ext.isOpera) ?
  209. new Ext.XTemplate(
  210. '<div id="{_elId}" class="{_selectorCls} {_colorCls} {values.spanCls} ext-cal-evt ext-cal-evr" style="left: {_left}%; width: {_width}%; top: {_top}px; height: {_height}px;">',
  211. body,
  212. '</div>'
  213. )
  214. : new Ext.XTemplate(
  215. '<div id="{_elId}" class="ext-cal-evt" style="left: {_left}%; width: {_width}%; top: {_top}px; height: {_height}px;">',
  216. '<div class="{_selectorCls} {values.spanCls} {_colorCls} ext-cal-evo">',
  217. '<div class="ext-cal-evm">',
  218. '<div class="ext-cal-evi">',
  219. body,
  220. '</div>',
  221. '</div>',
  222. '</div></div>'
  223. );
  224. tpl.compile();
  225. this.eventAllDayTpl = tpl;
  226. }
  227. return this.eventAllDayTpl;
  228. },
  229. // private
  230. getTemplateEventData: function(evt) {
  231. var selector = this.getEventSelectorCls(evt[Ext.calendar.EventMappings.EventId.name]),
  232. data = {},
  233. M = Ext.calendar.EventMappings;
  234. this.getTemplateEventBox(evt);
  235. data._selectorCls = selector;
  236. data._colorCls = 'ext-color-' + evt[M.CalendarId.name] + (evt._renderAsAllDay ? '-ad': '');
  237. data._elId = selector + (evt._weekIndex ? '-' + evt._weekIndex: '');
  238. data._isRecurring = evt.Recurrence && evt.Recurrence != '';
  239. data._isReminder = evt[M.Reminder.name] && evt[M.Reminder.name] != '';
  240. var title = evt[M.Title.name];
  241. data.Title = (evt[M.IsAllDay.name] ? '': evt[M.StartDate.name].format('g:ia ')) + (!title || title.length == 0 ? '(No title)': title);
  242. return Ext.applyIf(data, evt);
  243. },
  244. // private
  245. getTemplateEventBox: function(evt) {
  246. var heightFactor = 0.7,
  247. start = evt[Ext.calendar.EventMappings.StartDate.name],
  248. end = evt[Ext.calendar.EventMappings.EndDate.name],
  249. startMins = start.getHours() * 60 + start.getMinutes(),
  250. endMins = end.getHours() * 60 + end.getMinutes(),
  251. diffMins = endMins - startMins;
  252. evt._left = 0;
  253. evt._width = 100;
  254. evt._top = Math.round(startMins * heightFactor) + 1;
  255. evt._height = Math.max((diffMins * heightFactor) - 2, 15);
  256. },
  257. // private
  258. renderItems: function() {
  259. var day = 0,
  260. evts = [],
  261. ev,
  262. d,
  263. ct,
  264. item,
  265. i,
  266. j,
  267. l,
  268. overlapCols,
  269. prevCol,
  270. colWidth,
  271. evtWidth,
  272. markup,
  273. target;
  274. for (; day < this.dayCount; day++) {
  275. ev = emptyCells = skipped = 0;
  276. d = this.eventGrid[0][day];
  277. ct = d ? d.length: 0;
  278. for (; ev < ct; ev++) {
  279. evt = d[ev];
  280. if (!evt) {
  281. continue;
  282. }
  283. item = evt.data || evt.event.data;
  284. if (item._renderAsAllDay) {
  285. continue;
  286. }
  287. Ext.apply(item, {
  288. cls: 'ext-cal-ev',
  289. _positioned: true
  290. });
  291. evts.push({
  292. data: this.getTemplateEventData(item),
  293. date: this.viewStart.add(Date.DAY, day)
  294. });
  295. }
  296. }
  297. // overlapping event pre-processing loop
  298. i = j = overlapCols = prevCol = 0;
  299. l = evts.length;
  300. for (; i < l; i++) {
  301. evt = evts[i].data;
  302. evt2 = null;
  303. prevCol = overlapCols;
  304. for (j = 0; j < l; j++) {
  305. if (i == j) {
  306. continue;
  307. }
  308. evt2 = evts[j].data;
  309. if (this.isOverlapping(evt, evt2)) {
  310. evt._overlap = evt._overlap == undefined ? 1: evt._overlap + 1;
  311. if (i < j) {
  312. if (evt._overcol === undefined) {
  313. evt._overcol = 0;
  314. }
  315. evt2._overcol = evt._overcol + 1;
  316. overlapCols = Math.max(overlapCols, evt2._overcol);
  317. }
  318. }
  319. }
  320. }
  321. // rendering loop
  322. for (i = 0; i < l; i++) {
  323. evt = evts[i].data;
  324. if (evt._overlap !== undefined) {
  325. colWidth = 100 / (overlapCols + 1);
  326. evtWidth = 100 - (colWidth * evt._overlap);
  327. evt._width = colWidth;
  328. evt._left = colWidth * evt._overcol;
  329. }
  330. markup = this.getEventTemplate().apply(evt);
  331. target = this.id + '-day-col-' + evts[i].date.format('Ymd');
  332. Ext.DomHelper.append(target, markup);
  333. }
  334. this.fireEvent('eventsrendered', this);
  335. },
  336. // private
  337. getDayEl: function(dt) {
  338. return Ext.get(this.getDayId(dt));
  339. },
  340. // private
  341. getDayId: function(dt) {
  342. if (Ext.isDate(dt)) {
  343. dt = dt.format('Ymd');
  344. }
  345. return this.id + this.dayColumnElIdDelimiter + dt;
  346. },
  347. // private
  348. getDaySize: function() {
  349. var box = this.el.child('.ext-cal-day-col-inner').getBox();
  350. return {
  351. height: box.height,
  352. width: box.width
  353. };
  354. },
  355. // private
  356. getDayAt: function(x, y) {
  357. var sel = '.ext-cal-body-ct',
  358. xoffset = this.el.child('.ext-cal-day-times').getWidth(),
  359. viewBox = this.el.getBox(),
  360. daySize = this.getDaySize(false),
  361. relX = x - viewBox.x - xoffset,
  362. dayIndex = Math.floor(relX / daySize.width),
  363. // clicked col index
  364. scroll = this.el.getScroll(),
  365. row = this.el.child('.ext-cal-bg-row'),
  366. // first avail row, just to calc size
  367. rowH = row.getHeight() / 2,
  368. // 30 minute increment since a row is 60 minutes
  369. relY = y - viewBox.y - rowH + scroll.top,
  370. rowIndex = Math.max(0, Math.ceil(relY / rowH)),
  371. mins = rowIndex * 30,
  372. dt = this.viewStart.add(Date.DAY, dayIndex).add(Date.MINUTE, mins),
  373. el = this.getDayEl(dt),
  374. timeX = x;
  375. if (el) {
  376. timeX = el.getLeft();
  377. }
  378. return {
  379. date: dt,
  380. el: el,
  381. // this is the box for the specific time block in the day that was clicked on:
  382. timeBox: {
  383. x: timeX,
  384. y: (rowIndex * 21) + viewBox.y - scroll.top,
  385. width: daySize.width,
  386. height: rowH
  387. }
  388. };
  389. },
  390. // private
  391. onClick: function(e, t) {
  392. if (this.dragPending || Ext.calendar.DayBodyView.superclass.onClick.apply(this, arguments)) {
  393. // The superclass handled the click already so exit
  394. return;
  395. }
  396. if (e.getTarget('.ext-cal-day-times', 3) !== null) {
  397. // ignore clicks on the times-of-day gutter
  398. return;
  399. }
  400. var el = e.getTarget('td', 3);
  401. if (el) {
  402. if (el.id && el.id.indexOf(this.dayElIdDelimiter) > -1) {
  403. var dt = this.getDateFromId(el.id, this.dayElIdDelimiter);
  404. this.fireEvent('dayclick', this, Date.parseDate(dt, 'Ymd'), true, Ext.get(this.getDayId(dt, true)));
  405. return;
  406. }
  407. }
  408. var day = this.getDayAt(e.xy[0], e.xy[1]);
  409. if (day && day.date) {
  410. this.fireEvent('dayclick', this, day.date, false, null);
  411. }
  412. }
  413. });
  414. Ext.reg('daybodyview', Ext.calendar.DayBodyView);
  415. </pre>
  416. </body>
  417. </html>