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.

534 lines
19 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.CalendarPanel
  9. * @extends Ext.Panel
  10. * <p>This is the default container for Ext calendar views. It supports day, week and month views as well
  11. * as a built-in event edit form. The only requirement for displaying a calendar is passing in a valid
  12. * {@link #calendarStore} config containing records of type {@link Ext.calendar.EventRecord EventRecord}. In order
  13. * to make the calendar interactive (enable editing, drag/drop, etc.) you can handle any of the various
  14. * events fired by the underlying views and exposed through the CalendarPanel.</p>
  15. * {@link #layoutConfig} option if needed.</p>
  16. * @constructor
  17. * @param {Object} config The config object
  18. * @xtype calendarpanel
  19. */
  20. Ext.calendar.CalendarPanel = Ext.extend(Ext.Panel, {
  21. /**
  22. * @cfg {Boolean} showDayView
  23. * True to include the day view (and toolbar button), false to hide them (defaults to true).
  24. */
  25. showDayView: true,
  26. /**
  27. * @cfg {Boolean} showWeekView
  28. * True to include the week view (and toolbar button), false to hide them (defaults to true).
  29. */
  30. showWeekView: true,
  31. /**
  32. * @cfg {Boolean} showMonthView
  33. * True to include the month view (and toolbar button), false to hide them (defaults to true).
  34. * If the day and week views are both hidden, the month view will show by default even if
  35. * this config is false.
  36. */
  37. showMonthView: true,
  38. /**
  39. * @cfg {Boolean} showNavBar
  40. * True to display the calendar navigation toolbar, false to hide it (defaults to true). Note that
  41. * if you hide the default navigation toolbar you'll have to provide an alternate means of navigating the calendar.
  42. */
  43. showNavBar: true,
  44. /**
  45. * @cfg {String} todayText
  46. * Alternate text to use for the 'Today' nav bar button.
  47. */
  48. todayText: 'Today',
  49. /**
  50. * @cfg {Boolean} showTodayText
  51. * True to show the value of {@link #todayText} instead of today's date in the calendar's current day box,
  52. * false to display the day number(defaults to true).
  53. */
  54. showTodayText: true,
  55. /**
  56. * @cfg {Boolean} showTime
  57. * True to display the current time next to the date in the calendar's current day box, false to not show it
  58. * (defaults to true).
  59. */
  60. showTime: true,
  61. /**
  62. * @cfg {String} dayText
  63. * Alternate text to use for the 'Day' nav bar button.
  64. */
  65. dayText: 'Day',
  66. /**
  67. * @cfg {String} weekText
  68. * Alternate text to use for the 'Week' nav bar button.
  69. */
  70. weekText: 'Week',
  71. /**
  72. * @cfg {String} monthText
  73. * Alternate text to use for the 'Month' nav bar button.
  74. */
  75. monthText: 'Month',
  76. // private
  77. layoutConfig: {
  78. layoutOnCardChange: true,
  79. deferredRender: true
  80. },
  81. // private property
  82. startDate: new Date(),
  83. // private
  84. initComponent: function() {
  85. this.tbar = {
  86. cls: 'ext-cal-toolbar',
  87. border: true,
  88. buttonAlign: 'center',
  89. items: [{
  90. id: this.id + '-tb-prev',
  91. handler: this.onPrevClick,
  92. scope: this,
  93. iconCls: 'x-tbar-page-prev'
  94. }]
  95. };
  96. this.viewCount = 0;
  97. if (this.showDayView) {
  98. this.tbar.items.push({
  99. id: this.id + '-tb-day',
  100. text: this.dayText,
  101. handler: this.onDayClick,
  102. scope: this,
  103. toggleGroup: 'tb-views'
  104. });
  105. this.viewCount++;
  106. }
  107. if (this.showWeekView) {
  108. this.tbar.items.push({
  109. id: this.id + '-tb-week',
  110. text: this.weekText,
  111. handler: this.onWeekClick,
  112. scope: this,
  113. toggleGroup: 'tb-views'
  114. });
  115. this.viewCount++;
  116. }
  117. if (this.showMonthView || this.viewCount == 0) {
  118. this.tbar.items.push({
  119. id: this.id + '-tb-month',
  120. text: this.monthText,
  121. handler: this.onMonthClick,
  122. scope: this,
  123. toggleGroup: 'tb-views'
  124. });
  125. this.viewCount++;
  126. this.showMonthView = true;
  127. }
  128. this.tbar.items.push({
  129. id: this.id + '-tb-next',
  130. handler: this.onNextClick,
  131. scope: this,
  132. iconCls: 'x-tbar-page-next'
  133. });
  134. this.tbar.items.push('->');
  135. var idx = this.viewCount - 1;
  136. this.activeItem = this.activeItem === undefined ? idx: (this.activeItem > idx ? idx: this.activeItem);
  137. if (this.showNavBar === false) {
  138. delete this.tbar;
  139. this.addClass('x-calendar-nonav');
  140. }
  141. Ext.calendar.CalendarPanel.superclass.initComponent.call(this);
  142. this.addEvents({
  143. /**
  144. * @event eventadd
  145. * Fires after a new event is added to the underlying store
  146. * @param {Ext.calendar.CalendarPanel} this
  147. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was added
  148. */
  149. eventadd: true,
  150. /**
  151. * @event eventupdate
  152. * Fires after an existing event is updated
  153. * @param {Ext.calendar.CalendarPanel} this
  154. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was updated
  155. */
  156. eventupdate: true,
  157. /**
  158. * @event eventdelete
  159. * Fires after an event is removed from the underlying store
  160. * @param {Ext.calendar.CalendarPanel} this
  161. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was removed
  162. */
  163. eventdelete: true,
  164. /**
  165. * @event eventcancel
  166. * Fires after an event add/edit operation is canceled by the user and no store update took place
  167. * @param {Ext.calendar.CalendarPanel} this
  168. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was canceled
  169. */
  170. eventcancel: true,
  171. /**
  172. * @event viewchange
  173. * Fires after a different calendar view is activated (but not when the event edit form is activated)
  174. * @param {Ext.calendar.CalendarPanel} this
  175. * @param {Ext.CalendarView} view The view being activated (any valid {@link Ext.calendar.CalendarView CalendarView} subclass)
  176. * @param {Object} info Extra information about the newly activated view. This is a plain object
  177. * with following properties:<div class="mdetail-params"><ul>
  178. * <li><b><code>activeDate</code></b> : <div class="sub-desc">The currently-selected date</div></li>
  179. * <li><b><code>viewStart</code></b> : <div class="sub-desc">The first date in the new view range</div></li>
  180. * <li><b><code>viewEnd</code></b> : <div class="sub-desc">The last date in the new view range</div></li>
  181. * </ul></div>
  182. */
  183. viewchange: true
  184. //
  185. // NOTE: CalendarPanel also relays the following events from contained views as if they originated from this:
  186. //
  187. /**
  188. * @event eventsrendered
  189. * Fires after events are finished rendering in the view
  190. * @param {Ext.calendar.CalendarPanel} this
  191. */
  192. /**
  193. * @event eventclick
  194. * Fires after the user clicks on an event element
  195. * @param {Ext.calendar.CalendarPanel} this
  196. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was clicked on
  197. * @param {HTMLNode} el The DOM node that was clicked on
  198. */
  199. /**
  200. * @event eventover
  201. * Fires anytime the mouse is over an event element
  202. * @param {Ext.calendar.CalendarPanel} this
  203. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor is over
  204. * @param {HTMLNode} el The DOM node that is being moused over
  205. */
  206. /**
  207. * @event eventout
  208. * Fires anytime the mouse exits an event element
  209. * @param {Ext.calendar.CalendarPanel} this
  210. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that the cursor exited
  211. * @param {HTMLNode} el The DOM node that was exited
  212. */
  213. /**
  214. * @event datechange
  215. * Fires after the start date of the view changes
  216. * @param {Ext.calendar.CalendarPanel} this
  217. * @param {Date} startDate The start date of the view (as explained in {@link #getStartDate}
  218. * @param {Date} viewStart The first displayed date in the view
  219. * @param {Date} viewEnd The last displayed date in the view
  220. */
  221. /**
  222. * @event rangeselect
  223. * Fires after the user drags on the calendar to select a range of dates/times in which to create an event
  224. * @param {Ext.calendar.CalendarPanel} this
  225. * @param {Object} dates An object containing the start (StartDate property) and end (EndDate property) dates selected
  226. * @param {Function} callback A callback function that MUST be called after the event handling is complete so that
  227. * the view is properly cleaned up (shim elements are persisted in the view while the user is prompted to handle the
  228. * range selection). The callback is already created in the proper scope, so it simply needs to be executed as a standard
  229. * function call (e.g., callback()).
  230. */
  231. /**
  232. * @event eventmove
  233. * Fires after an event element is dragged by the user and dropped in a new position
  234. * @param {Ext.calendar.CalendarPanel} this
  235. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was moved with
  236. * updated start and end dates
  237. */
  238. /**
  239. * @event initdrag
  240. * Fires when a drag operation is initiated in the view
  241. * @param {Ext.calendar.CalendarPanel} this
  242. */
  243. /**
  244. * @event eventresize
  245. * Fires after the user drags the resize handle of an event to resize it
  246. * @param {Ext.calendar.CalendarPanel} this
  247. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} for the event that was resized
  248. * containing the updated start and end dates
  249. */
  250. /**
  251. * @event dayclick
  252. * Fires after the user clicks within a day/week view container and not on an event element
  253. * @param {Ext.calendar.CalendarPanel} this
  254. * @param {Date} dt The date/time that was clicked on
  255. * @param {Boolean} allday True if the day clicked on represents an all-day box, else false.
  256. * @param {Ext.Element} el The Element that was clicked on
  257. */
  258. });
  259. this.layout = 'card';
  260. // do not allow override
  261. if (this.showDayView) {
  262. var day = Ext.apply({
  263. xtype: 'dayview',
  264. title: this.dayText,
  265. showToday: this.showToday,
  266. showTodayText: this.showTodayText,
  267. showTime: this.showTime
  268. },
  269. this.dayViewCfg);
  270. day.id = this.id + '-day';
  271. day.store = day.store || this.eventStore;
  272. this.initEventRelay(day);
  273. this.add(day);
  274. }
  275. if (this.showWeekView) {
  276. var wk = Ext.applyIf({
  277. xtype: 'weekview',
  278. title: this.weekText,
  279. showToday: this.showToday,
  280. showTodayText: this.showTodayText,
  281. showTime: this.showTime
  282. },
  283. this.weekViewCfg);
  284. wk.id = this.id + '-week';
  285. wk.store = wk.store || this.eventStore;
  286. this.initEventRelay(wk);
  287. this.add(wk);
  288. }
  289. if (this.showMonthView) {
  290. var month = Ext.applyIf({
  291. xtype: 'monthview',
  292. title: this.monthText,
  293. showToday: this.showToday,
  294. showTodayText: this.showTodayText,
  295. showTime: this.showTime,
  296. listeners: {
  297. 'weekclick': {
  298. fn: function(vw, dt) {
  299. this.showWeek(dt);
  300. },
  301. scope: this
  302. }
  303. }
  304. },
  305. this.monthViewCfg);
  306. month.id = this.id + '-month';
  307. month.store = month.store || this.eventStore;
  308. this.initEventRelay(month);
  309. this.add(month);
  310. }
  311. this.add(Ext.applyIf({
  312. xtype: 'eventeditform',
  313. id: this.id + '-edit',
  314. calendarStore: this.calendarStore,
  315. listeners: {
  316. 'eventadd': {
  317. scope: this,
  318. fn: this.onEventAdd
  319. },
  320. 'eventupdate': {
  321. scope: this,
  322. fn: this.onEventUpdate
  323. },
  324. 'eventdelete': {
  325. scope: this,
  326. fn: this.onEventDelete
  327. },
  328. 'eventcancel': {
  329. scope: this,
  330. fn: this.onEventCancel
  331. }
  332. }
  333. },
  334. this.editViewCfg));
  335. },
  336. // private
  337. initEventRelay: function(cfg) {
  338. cfg.listeners = cfg.listeners || {};
  339. cfg.listeners.afterrender = {
  340. fn: function(c) {
  341. // relay the view events so that app code only has to handle them in one place
  342. this.relayEvents(c, ['eventsrendered', 'eventclick', 'eventover', 'eventout', 'dayclick',
  343. 'eventmove', 'datechange', 'rangeselect', 'eventdelete', 'eventresize', 'initdrag']);
  344. },
  345. scope: this,
  346. single: true
  347. };
  348. },
  349. // private
  350. afterRender: function() {
  351. Ext.calendar.CalendarPanel.superclass.afterRender.call(this);
  352. this.fireViewChange();
  353. },
  354. // private
  355. onLayout: function() {
  356. Ext.calendar.CalendarPanel.superclass.onLayout.call(this);
  357. if (!this.navInitComplete) {
  358. this.updateNavState();
  359. this.navInitComplete = true;
  360. }
  361. },
  362. // private
  363. onEventAdd: function(form, rec) {
  364. rec.data[Ext.calendar.EventMappings.IsNew.name] = false;
  365. this.eventStore.add(rec);
  366. this.hideEditForm();
  367. this.fireEvent('eventadd', this, rec);
  368. },
  369. // private
  370. onEventUpdate: function(form, rec) {
  371. rec.commit();
  372. this.hideEditForm();
  373. this.fireEvent('eventupdate', this, rec);
  374. },
  375. // private
  376. onEventDelete: function(form, rec) {
  377. this.eventStore.remove(rec);
  378. this.hideEditForm();
  379. this.fireEvent('eventdelete', this, rec);
  380. },
  381. // private
  382. onEventCancel: function(form, rec) {
  383. this.hideEditForm();
  384. this.fireEvent('eventcancel', this, rec);
  385. },
  386. /**
  387. * Shows the built-in event edit form for the passed in event record. This method automatically
  388. * hides the calendar views and navigation toolbar. To return to the calendar, call {@link #hideEditForm}.
  389. * @param {Ext.calendar.EventRecord} record The event record to edit
  390. * @return {Ext.calendar.CalendarPanel} this
  391. */
  392. showEditForm: function(rec) {
  393. this.preEditView = this.layout.activeItem.id;
  394. this.setActiveView(this.id + '-edit');
  395. this.layout.activeItem.loadRecord(rec);
  396. return this;
  397. },
  398. /**
  399. * Hides the built-in event edit form and returns to the previous calendar view. If the edit form is
  400. * not currently visible this method has no effect.
  401. * @return {Ext.calendar.CalendarPanel} this
  402. */
  403. hideEditForm: function() {
  404. if (this.preEditView) {
  405. this.setActiveView(this.preEditView);
  406. delete this.preEditView;
  407. }
  408. return this;
  409. },
  410. // private
  411. setActiveView: function(id) {
  412. var l = this.layout;
  413. l.setActiveItem(id);
  414. if (id == this.id + '-edit') {
  415. this.getTopToolbar().hide();
  416. this.doLayout();
  417. }
  418. else {
  419. l.activeItem.refresh();
  420. this.getTopToolbar().show();
  421. this.updateNavState();
  422. }
  423. this.activeView = l.activeItem;
  424. this.fireViewChange();
  425. },
  426. // private
  427. fireViewChange: function() {
  428. var info = null,
  429. view = this.layout.activeItem;
  430. if (view.getViewBounds) {
  431. vb = view.getViewBounds();
  432. info = {
  433. activeDate: view.getStartDate(),
  434. viewStart: vb.start,
  435. viewEnd: vb.end
  436. };
  437. };
  438. this.fireEvent('viewchange', this, view, info);
  439. },
  440. // private
  441. updateNavState: function() {
  442. if (this.showNavBar !== false) {
  443. var item = this.layout.activeItem,
  444. suffix = item.id.split(this.id + '-')[1];
  445. var btn = Ext.getCmp(this.id + '-tb-' + suffix);
  446. btn.toggle(true);
  447. }
  448. },
  449. /**
  450. * Sets the start date for the currently-active calendar view.
  451. * @param {Date} dt
  452. */
  453. setStartDate: function(dt) {
  454. this.layout.activeItem.setStartDate(dt, true);
  455. this.updateNavState();
  456. this.fireViewChange();
  457. },
  458. // private
  459. showWeek: function(dt) {
  460. this.setActiveView(this.id + '-week');
  461. this.setStartDate(dt);
  462. },
  463. // private
  464. onPrevClick: function() {
  465. this.startDate = this.layout.activeItem.movePrev();
  466. this.updateNavState();
  467. this.fireViewChange();
  468. },
  469. // private
  470. onNextClick: function() {
  471. this.startDate = this.layout.activeItem.moveNext();
  472. this.updateNavState();
  473. this.fireViewChange();
  474. },
  475. // private
  476. onDayClick: function() {
  477. this.setActiveView(this.id + '-day');
  478. },
  479. // private
  480. onWeekClick: function() {
  481. this.setActiveView(this.id + '-week');
  482. },
  483. // private
  484. onMonthClick: function() {
  485. this.setActiveView(this.id + '-month');
  486. },
  487. /**
  488. * Return the calendar view that is currently active, which will be a subclass of
  489. * {@link Ext.calendar.CalendarView CalendarView}.
  490. * @return {Ext.calendar.CalendarView} The active view
  491. */
  492. getActiveView: function() {
  493. return this.layout.activeItem;
  494. }
  495. });
  496. Ext.reg('calendarpanel', Ext.calendar.CalendarPanel);