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.

482 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.calendar.MonthView
  9. * @extends Ext.calendar.CalendarView
  10. * <p>Displays a calendar view by month. This class does not usually need ot be used directly as you can
  11. * use a {@link Ext.calendar.CalendarPanel CalendarPanel} to manage multiple calendar views at once including
  12. * the month view.</p>
  13. * @constructor
  14. * @param {Object} config The config object
  15. */
  16. Ext.calendar.MonthView = Ext.extend(Ext.calendar.CalendarView, {
  17. /**
  18. * @cfg {Boolean} showTime
  19. * True to display the current time in today's box in the calendar, false to not display it (defautls to true)
  20. */
  21. showTime: true,
  22. /**
  23. * @cfg {Boolean} showTodayText
  24. * True to display the {@link #todayText} string in today's box in the calendar, false to not display it (defautls to true)
  25. */
  26. showTodayText: true,
  27. /**
  28. * @cfg {String} todayText
  29. * The text to display in the current day's box in the calendar when {@link #showTodayText} is true (defaults to 'Today')
  30. */
  31. todayText: 'Today',
  32. /**
  33. * @cfg {Boolean} showHeader
  34. * True to display a header beneath the navigation bar containing the week names above each week's column, false not to
  35. * show it and instead display the week names in the first row of days in the calendar (defaults to false).
  36. */
  37. showHeader: false,
  38. /**
  39. * @cfg {Boolean} showWeekLinks
  40. * True to display an extra column before the first day in the calendar that links to the {@link Ext.calendar.WeekView view}
  41. * for each individual week, false to not show it (defaults to false). If true, the week links can also contain the week
  42. * number depending on the value of {@link #showWeekNumbers}.
  43. */
  44. showWeekLinks: false,
  45. /**
  46. * @cfg {Boolean} showWeekNumbers
  47. * True to show the week number for each week in the calendar in the week link column, false to show nothing (defaults to false).
  48. * Note that if {@link #showWeekLinks} is false this config will have no affect even if true.
  49. */
  50. showWeekNumbers: false,
  51. /**
  52. * @cfg {String} weekLinkOverClass
  53. * The CSS class name applied when the mouse moves over a week link element (only applies when {@link #showWeekLinks} is true,
  54. * defaults to 'ext-week-link-over').
  55. */
  56. weekLinkOverClass: 'ext-week-link-over',
  57. //private properties -- do not override:
  58. daySelector: '.ext-cal-day',
  59. moreSelector: '.ext-cal-ev-more',
  60. weekLinkSelector: '.ext-cal-week-link',
  61. weekCount: -1,
  62. // defaults to auto by month
  63. dayCount: 7,
  64. moreElIdDelimiter: '-more-',
  65. weekLinkIdDelimiter: 'ext-cal-week-',
  66. // private
  67. initComponent: function() {
  68. Ext.calendar.MonthView.superclass.initComponent.call(this);
  69. this.addEvents({
  70. /**
  71. * @event dayclick
  72. * Fires after the user clicks within the view container and not on an event element
  73. * @param {Ext.calendar.MonthView} this
  74. * @param {Date} dt The date/time that was clicked on
  75. * @param {Boolean} allday True if the day clicked on represents an all-day box, else false. Clicks within the
  76. * MonthView always return true for this param.
  77. * @param {Ext.Element} el The Element that was clicked on
  78. */
  79. dayclick: true,
  80. /**
  81. * @event weekclick
  82. * Fires after the user clicks within a week link (when {@link #showWeekLinks is true)
  83. * @param {Ext.calendar.MonthView} this
  84. * @param {Date} dt The start date of the week that was clicked on
  85. */
  86. weekclick: true,
  87. // inherited docs
  88. dayover: true,
  89. // inherited docs
  90. dayout: true
  91. });
  92. },
  93. // private
  94. initDD: function() {
  95. var cfg = {
  96. view: this,
  97. createText: this.ddCreateEventText,
  98. moveText: this.ddMoveEventText,
  99. ddGroup: 'MonthViewDD'
  100. };
  101. this.dragZone = new Ext.calendar.DragZone(this.el, cfg);
  102. this.dropZone = new Ext.calendar.DropZone(this.el, cfg);
  103. },
  104. // private
  105. onDestroy: function() {
  106. Ext.destroy(this.ddSelector);
  107. Ext.destroy(this.dragZone);
  108. Ext.destroy(this.dropZone);
  109. Ext.calendar.MonthView.superclass.onDestroy.call(this);
  110. },
  111. // private
  112. afterRender: function() {
  113. if (!this.tpl) {
  114. this.tpl = new Ext.calendar.MonthViewTemplate({
  115. id: this.id,
  116. showTodayText: this.showTodayText,
  117. todayText: this.todayText,
  118. showTime: this.showTime,
  119. showHeader: this.showHeader,
  120. showWeekLinks: this.showWeekLinks,
  121. showWeekNumbers: this.showWeekNumbers
  122. });
  123. }
  124. this.tpl.compile();
  125. this.addClass('ext-cal-monthview ext-cal-ct');
  126. Ext.calendar.MonthView.superclass.afterRender.call(this);
  127. },
  128. // private
  129. onResize: function() {
  130. if (this.monitorResize) {
  131. this.maxEventsPerDay = this.getMaxEventsPerDay();
  132. this.refresh();
  133. }
  134. },
  135. // private
  136. forceSize: function() {
  137. // Compensate for the week link gutter width if visible
  138. if (this.showWeekLinks && this.el && this.el.child) {
  139. var hd = this.el.select('.ext-cal-hd-days-tbl'),
  140. bgTbl = this.el.select('.ext-cal-bg-tbl'),
  141. evTbl = this.el.select('.ext-cal-evt-tbl'),
  142. wkLinkW = this.el.child('.ext-cal-week-link').getWidth(),
  143. w = this.el.getWidth() - wkLinkW;
  144. hd.setWidth(w);
  145. bgTbl.setWidth(w);
  146. evTbl.setWidth(w);
  147. }
  148. Ext.calendar.MonthView.superclass.forceSize.call(this);
  149. },
  150. //private
  151. initClock: function() {
  152. if (Ext.fly(this.id + '-clock') !== null) {
  153. this.prevClockDay = new Date().getDay();
  154. if (this.clockTask) {
  155. Ext.TaskMgr.stop(this.clockTask);
  156. }
  157. this.clockTask = Ext.TaskMgr.start({
  158. run: function() {
  159. var el = Ext.fly(this.id + '-clock'),
  160. t = new Date();
  161. if (t.getDay() == this.prevClockDay) {
  162. if (el) {
  163. el.update(t.format('g:i a'));
  164. }
  165. }
  166. else {
  167. this.prevClockDay = t.getDay();
  168. this.moveTo(t);
  169. }
  170. },
  171. scope: this,
  172. interval: 1000
  173. });
  174. }
  175. },
  176. // inherited docs
  177. getEventBodyMarkup: function() {
  178. if (!this.eventBodyMarkup) {
  179. this.eventBodyMarkup = ['{Title}',
  180. '<tpl if="_isReminder">',
  181. '<i class="ext-cal-ic ext-cal-ic-rem">&nbsp;</i>',
  182. '</tpl>',
  183. '<tpl if="_isRecurring">',
  184. '<i class="ext-cal-ic ext-cal-ic-rcr">&nbsp;</i>',
  185. '</tpl>',
  186. '<tpl if="spanLeft">',
  187. '<i class="ext-cal-spl">&nbsp;</i>',
  188. '</tpl>',
  189. '<tpl if="spanRight">',
  190. '<i class="ext-cal-spr">&nbsp;</i>',
  191. '</tpl>'
  192. ].join('');
  193. }
  194. return this.eventBodyMarkup;
  195. },
  196. // inherited docs
  197. getEventTemplate: function() {
  198. if (!this.eventTpl) {
  199. var tpl,
  200. body = this.getEventBodyMarkup();
  201. tpl = !(Ext.isIE || Ext.isOpera) ?
  202. new Ext.XTemplate(
  203. '<div id="{_elId}" class="{_selectorCls} {_colorCls} {values.spanCls} ext-cal-evt ext-cal-evr">',
  204. body,
  205. '</div>'
  206. )
  207. : new Ext.XTemplate(
  208. '<tpl if="_renderAsAllDay">',
  209. '<div id="{_elId}" class="{_selectorCls} {values.spanCls} {_colorCls} ext-cal-evt ext-cal-evo">',
  210. '<div class="ext-cal-evm">',
  211. '<div class="ext-cal-evi">',
  212. '</tpl>',
  213. '<tpl if="!_renderAsAllDay">',
  214. '<div id="{_elId}" class="{_selectorCls} {_colorCls} ext-cal-evt ext-cal-evr">',
  215. '</tpl>',
  216. body,
  217. '<tpl if="_renderAsAllDay">',
  218. '</div>',
  219. '</div>',
  220. '</tpl>',
  221. '</div>'
  222. );
  223. tpl.compile();
  224. this.eventTpl = tpl;
  225. }
  226. return this.eventTpl;
  227. },
  228. // private
  229. getTemplateEventData: function(evt) {
  230. var M = Ext.calendar.EventMappings,
  231. selector = this.getEventSelectorCls(evt[M.EventId.name]),
  232. title = evt[M.Title.name];
  233. return Ext.applyIf({
  234. _selectorCls: selector,
  235. _colorCls: 'ext-color-' + (evt[M.CalendarId.name] ?
  236. evt[M.CalendarId.name] : 'default') + (evt._renderAsAllDay ? '-ad': ''),
  237. _elId: selector + '-' + evt._weekIndex,
  238. _isRecurring: evt.Recurrence && evt.Recurrence != '',
  239. _isReminder: evt[M.Reminder.name] && evt[M.Reminder.name] != '',
  240. Title: (evt[M.IsAllDay.name] ? '': evt[M.StartDate.name].format('g:ia ')) + (!title || title.length == 0 ? '(No title)': title)
  241. },
  242. evt);
  243. },
  244. // private
  245. refresh: function() {
  246. if (this.detailPanel) {
  247. this.detailPanel.hide();
  248. }
  249. Ext.calendar.MonthView.superclass.refresh.call(this);
  250. if (this.showTime !== false) {
  251. this.initClock();
  252. }
  253. },
  254. // private
  255. renderItems: function() {
  256. Ext.calendar.WeekEventRenderer.render({
  257. eventGrid: this.allDayOnly ? this.allDayGrid: this.eventGrid,
  258. viewStart: this.viewStart,
  259. tpl: this.getEventTemplate(),
  260. maxEventsPerDay: this.maxEventsPerDay,
  261. id: this.id,
  262. templateDataFn: this.getTemplateEventData.createDelegate(this),
  263. evtMaxCount: this.evtMaxCount,
  264. weekCount: this.weekCount,
  265. dayCount: this.dayCount
  266. });
  267. this.fireEvent('eventsrendered', this);
  268. },
  269. // private
  270. getDayEl: function(dt) {
  271. return Ext.get(this.getDayId(dt));
  272. },
  273. // private
  274. getDayId: function(dt) {
  275. if (Ext.isDate(dt)) {
  276. dt = dt.format('Ymd');
  277. }
  278. return this.id + this.dayElIdDelimiter + dt;
  279. },
  280. // private
  281. getWeekIndex: function(dt) {
  282. var el = this.getDayEl(dt).up('.ext-cal-wk-ct');
  283. return parseInt(el.id.split('-wk-')[1], 10);
  284. },
  285. // private
  286. getDaySize: function(contentOnly) {
  287. var box = this.el.getBox(),
  288. w = box.width / this.dayCount,
  289. h = box.height / this.getWeekCount();
  290. if (contentOnly) {
  291. var hd = this.el.select('.ext-cal-dtitle').first().parent('tr');
  292. h = hd ? h - hd.getHeight(true) : h;
  293. }
  294. return {
  295. height: h,
  296. width: w
  297. };
  298. },
  299. // private
  300. getEventHeight: function() {
  301. if (!this.eventHeight) {
  302. var evt = this.el.select('.ext-cal-evt').first();
  303. this.eventHeight = evt ? evt.parent('tr').getHeight() : 18;
  304. }
  305. return this.eventHeight;
  306. },
  307. // private
  308. getMaxEventsPerDay: function() {
  309. var dayHeight = this.getDaySize(true).height,
  310. h = this.getEventHeight(),
  311. max = Math.max(Math.floor((dayHeight - h) / h), 0);
  312. return max;
  313. },
  314. // private
  315. getDayAt: function(x, y) {
  316. var box = this.el.getBox(),
  317. daySize = this.getDaySize(),
  318. dayL = Math.floor(((x - box.x) / daySize.width)),
  319. dayT = Math.floor(((y - box.y) / daySize.height)),
  320. days = (dayT * 7) + dayL,
  321. dt = this.viewStart.add(Date.DAY, days);
  322. return {
  323. date: dt,
  324. el: this.getDayEl(dt)
  325. };
  326. },
  327. // inherited docs
  328. moveNext: function() {
  329. return this.moveMonths(1);
  330. },
  331. // inherited docs
  332. movePrev: function() {
  333. return this.moveMonths( - 1);
  334. },
  335. // private
  336. onInitDrag: function() {
  337. Ext.calendar.MonthView.superclass.onInitDrag.call(this);
  338. Ext.select(this.daySelector).removeClass(this.dayOverClass);
  339. if (this.detailPanel) {
  340. this.detailPanel.hide();
  341. }
  342. },
  343. // private
  344. onMoreClick: function(dt) {
  345. if (!this.detailPanel) {
  346. this.detailPanel = new Ext.Panel({
  347. id: this.id + '-details-panel',
  348. title: dt.format('F j'),
  349. layout: 'fit',
  350. floating: true,
  351. renderTo: Ext.getBody(),
  352. tools: [{
  353. id: 'close',
  354. handler: function(e, t, p) {
  355. p.hide();
  356. }
  357. }],
  358. items: {
  359. xtype: 'monthdaydetailview',
  360. id: this.id + '-details-view',
  361. date: dt,
  362. view: this,
  363. store: this.store,
  364. listeners: {
  365. 'eventsrendered': this.onDetailViewUpdated.createDelegate(this)
  366. }
  367. }
  368. });
  369. }
  370. else {
  371. this.detailPanel.setTitle(dt.format('F j'));
  372. }
  373. this.detailPanel.getComponent(this.id + '-details-view').update(dt);
  374. },
  375. // private
  376. onDetailViewUpdated: function(view, dt, numEvents) {
  377. var p = this.detailPanel,
  378. frameH = p.getFrameHeight(),
  379. evtH = this.getEventHeight(),
  380. bodyH = frameH + (numEvents * evtH) + 3,
  381. dayEl = this.getDayEl(dt),
  382. box = dayEl.getBox();
  383. p.updateBox(box);
  384. p.setHeight(bodyH);
  385. p.setWidth(Math.max(box.width, 220));
  386. p.show();
  387. p.getPositionEl().alignTo(dayEl, 't-t?');
  388. },
  389. // private
  390. onHide: function() {
  391. Ext.calendar.MonthView.superclass.onHide.call(this);
  392. if (this.detailPanel) {
  393. this.detailPanel.hide();
  394. }
  395. },
  396. // private
  397. onClick: function(e, t) {
  398. if (this.detailPanel) {
  399. this.detailPanel.hide();
  400. }
  401. if (Ext.calendar.MonthView.superclass.onClick.apply(this, arguments)) {
  402. // The superclass handled the click already so exit
  403. return;
  404. }
  405. if (this.dropZone) {
  406. this.dropZone.clearShims();
  407. }
  408. var el = e.getTarget(this.weekLinkSelector, 3),
  409. dt,
  410. parts;
  411. if (el) {
  412. dt = el.id.split(this.weekLinkIdDelimiter)[1];
  413. this.fireEvent('weekclick', this, Date.parseDate(dt, 'Ymd'));
  414. return;
  415. }
  416. el = e.getTarget(this.moreSelector, 3);
  417. if (el) {
  418. dt = el.id.split(this.moreElIdDelimiter)[1];
  419. this.onMoreClick(Date.parseDate(dt, 'Ymd'));
  420. return;
  421. }
  422. el = e.getTarget('td', 3);
  423. if (el) {
  424. if (el.id && el.id.indexOf(this.dayElIdDelimiter) > -1) {
  425. parts = el.id.split(this.dayElIdDelimiter);
  426. dt = parts[parts.length - 1];
  427. this.fireEvent('dayclick', this, Date.parseDate(dt, 'Ymd'), false, Ext.get(this.getDayId(dt)));
  428. return;
  429. }
  430. }
  431. },
  432. // private
  433. handleDayMouseEvent: function(e, t, type) {
  434. var el = e.getTarget(this.weekLinkSelector, 3, true);
  435. if (el) {
  436. el[type == 'over' ? 'addClass': 'removeClass'](this.weekLinkOverClass);
  437. return;
  438. }
  439. Ext.calendar.MonthView.superclass.handleDayMouseEvent.apply(this, arguments);
  440. }
  441. });
  442. Ext.reg('monthview', Ext.calendar.MonthView);