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.

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