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.

310 lines
14 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. * Calendar sample code originally written by Brian Moeskau (brian@ext-calendar.com)
  9. * See additional calendar examples at http://ext-calendar.com
  10. */
  11. App = function() {
  12. return {
  13. init : function() {
  14. Ext.BLANK_IMAGE_URL = 'http://extjs.cachefly.net/ext-3.1.0/resources/images/default/s.gif';
  15. // This is an example calendar store that enables the events to have
  16. // different colors based on CalendarId. This is not a fully-implmented
  17. // multi-calendar implementation, which is beyond the scope of this sample app
  18. this.calendarStore = new Ext.data.JsonStore({
  19. storeId: 'calendarStore',
  20. root: 'calendars',
  21. idProperty: 'id',
  22. data: calendarList, // defined in calendar-list.js
  23. proxy: new Ext.data.MemoryProxy(),
  24. autoLoad: true,
  25. fields: [
  26. {name:'CalendarId', mapping: 'id', type: 'int'},
  27. {name:'Title', mapping: 'title', type: 'string'}
  28. ],
  29. sortInfo: {
  30. field: 'CalendarId',
  31. direction: 'ASC'
  32. }
  33. });
  34. // A sample event store that loads static JSON from a local file. Obviously a real
  35. // implementation would likely be loading remote data via an HttpProxy, but the
  36. // underlying store functionality is the same. Note that if you would like to
  37. // provide custom data mappings for events, see EventRecord.js.
  38. this.eventStore = new Ext.data.JsonStore({
  39. id: 'eventStore',
  40. root: 'evts',
  41. data: eventList, // defined in event-list.js
  42. proxy: new Ext.data.MemoryProxy(),
  43. fields: Ext.calendar.EventRecord.prototype.fields.getRange(),
  44. sortInfo: {
  45. field: 'StartDate',
  46. direction: 'ASC'
  47. }
  48. });
  49. // This is the app UI layout code. All of the calendar views are subcomponents of
  50. // CalendarPanel, but the app title bar and sidebar/navigation calendar are separate
  51. // pieces that are composed in app-specific layout code since they could be ommitted
  52. // or placed elsewhere within the application.
  53. new Ext.Viewport({
  54. layout: 'border',
  55. renderTo: 'calendar-ct',
  56. items: [{
  57. id: 'app-header',
  58. region: 'north',
  59. height: 35,
  60. border: false,
  61. contentEl: 'app-header-content'
  62. },{
  63. id: 'app-center',
  64. title: '...', // will be updated to view date range
  65. region: 'center',
  66. layout: 'border',
  67. items: [{
  68. id:'app-west',
  69. region: 'west',
  70. width: 176,
  71. border: false,
  72. items: [{
  73. xtype: 'datepicker',
  74. id: 'app-nav-picker',
  75. cls: 'ext-cal-nav-picker',
  76. listeners: {
  77. 'select': {
  78. fn: function(dp, dt){
  79. App.calendarPanel.setStartDate(dt);
  80. },
  81. scope: this
  82. }
  83. }
  84. }]
  85. },{
  86. xtype: 'calendarpanel',
  87. eventStore: this.eventStore,
  88. calendarStore: this.calendarStore,
  89. border: false,
  90. id:'app-calendar',
  91. region: 'center',
  92. activeItem: 2, // month view
  93. // CalendarPanel supports view-specific configs that are passed through to the
  94. // underlying views to make configuration possible without explicitly having to
  95. // create those views at this level:
  96. monthViewCfg: {
  97. showHeader: true,
  98. showWeekLinks: true,
  99. showWeekNumbers: true
  100. },
  101. // Some optional CalendarPanel configs to experiment with:
  102. //showDayView: false,
  103. //showWeekView: false,
  104. //showMonthView: false,
  105. //showNavBar: false,
  106. //showTodayText: false,
  107. //showTime: false,
  108. //title: 'My Calendar', // the header of the calendar, could be a subtitle for the app
  109. // Once this component inits it will set a reference to itself as an application
  110. // member property for easy reference in other functions within App.
  111. initComponent: function() {
  112. App.calendarPanel = this;
  113. this.constructor.prototype.initComponent.apply(this, arguments);
  114. },
  115. listeners: {
  116. 'eventclick': {
  117. fn: function(vw, rec, el){
  118. this.showEditWindow(rec, el);
  119. this.clearMsg();
  120. },
  121. scope: this
  122. },
  123. 'eventover': function(vw, rec, el){
  124. //console.log('Entered evt rec='+rec.data.Title+', view='+ vw.id +', el='+el.id);
  125. },
  126. 'eventout': function(vw, rec, el){
  127. //console.log('Leaving evt rec='+rec.data.Title+', view='+ vw.id +', el='+el.id);
  128. },
  129. 'eventadd': {
  130. fn: function(cp, rec){
  131. this.showMsg('Event '+ rec.data.Title +' was added');
  132. },
  133. scope: this
  134. },
  135. 'eventupdate': {
  136. fn: function(cp, rec){
  137. this.showMsg('Event '+ rec.data.Title +' was updated');
  138. },
  139. scope: this
  140. },
  141. 'eventdelete': {
  142. fn: function(cp, rec){
  143. this.showMsg('Event '+ rec.data.Title +' was deleted');
  144. },
  145. scope: this
  146. },
  147. 'eventcancel': {
  148. fn: function(cp, rec){
  149. // edit canceled
  150. },
  151. scope: this
  152. },
  153. 'viewchange': {
  154. fn: function(p, vw, dateInfo){
  155. if(this.editWin){
  156. this.editWin.hide();
  157. };
  158. if(dateInfo !== null){
  159. // will be null when switching to the event edit form so ignore
  160. Ext.getCmp('app-nav-picker').setValue(dateInfo.activeDate);
  161. this.updateTitle(dateInfo.viewStart, dateInfo.viewEnd);
  162. }
  163. },
  164. scope: this
  165. },
  166. 'dayclick': {
  167. fn: function(vw, dt, ad, el){
  168. this.showEditWindow({
  169. StartDate: dt,
  170. IsAllDay: ad
  171. }, el);
  172. this.clearMsg();
  173. },
  174. scope: this
  175. },
  176. 'rangeselect': {
  177. fn: function(win, dates, onComplete){
  178. this.showEditWindow(dates);
  179. this.editWin.on('hide', onComplete, this, {single:true});
  180. this.clearMsg();
  181. },
  182. scope: this
  183. },
  184. 'eventmove': {
  185. fn: function(vw, rec){
  186. rec.commit();
  187. var time = rec.data.IsAllDay ? '' : ' \\a\\t g:i a';
  188. this.showMsg('Event '+ rec.data.Title +' was moved to '+rec.data.StartDate.format('F jS'+time));
  189. },
  190. scope: this
  191. },
  192. 'eventresize': {
  193. fn: function(vw, rec){
  194. rec.commit();
  195. this.showMsg('Event '+ rec.data.Title +' was updated');
  196. },
  197. scope: this
  198. },
  199. 'eventdelete': {
  200. fn: function(win, rec){
  201. this.eventStore.remove(rec);
  202. this.showMsg('Event '+ rec.data.Title +' was deleted');
  203. },
  204. scope: this
  205. },
  206. 'initdrag': {
  207. fn: function(vw){
  208. if(this.editWin && this.editWin.isVisible()){
  209. this.editWin.hide();
  210. }
  211. },
  212. scope: this
  213. }
  214. }
  215. }]
  216. }]
  217. });
  218. },
  219. // The edit popup window is not part of the CalendarPanel itself -- it is a separate component.
  220. // This makes it very easy to swap it out with a different type of window or custom view, or omit
  221. // it altogether. Because of this, it's up to the application code to tie the pieces together.
  222. // Note that this function is called from various event handlers in the CalendarPanel above.
  223. showEditWindow : function(rec, animateTarget){
  224. if(!this.editWin){
  225. this.editWin = new Ext.calendar.EventEditWindow({
  226. calendarStore: this.calendarStore,
  227. listeners: {
  228. 'eventadd': {
  229. fn: function(win, rec){
  230. win.hide();
  231. rec.data.IsNew = false;
  232. this.eventStore.add(rec);
  233. this.showMsg('Event '+ rec.data.Title +' was added');
  234. },
  235. scope: this
  236. },
  237. 'eventupdate': {
  238. fn: function(win, rec){
  239. win.hide();
  240. rec.commit();
  241. this.showMsg('Event '+ rec.data.Title +' was updated');
  242. },
  243. scope: this
  244. },
  245. 'eventdelete': {
  246. fn: function(win, rec){
  247. this.eventStore.remove(rec);
  248. win.hide();
  249. this.showMsg('Event '+ rec.data.Title +' was deleted');
  250. },
  251. scope: this
  252. },
  253. 'editdetails': {
  254. fn: function(win, rec){
  255. win.hide();
  256. App.calendarPanel.showEditForm(rec);
  257. }
  258. }
  259. }
  260. });
  261. }
  262. this.editWin.show(rec, animateTarget);
  263. },
  264. // The CalendarPanel itself supports the standard Panel title config, but that title
  265. // only spans the calendar views. For a title that spans the entire width of the app
  266. // we added a title to the layout's outer center region that is app-specific. This code
  267. // updates that outer title based on the currently-selected view range anytime the view changes.
  268. updateTitle: function(startDt, endDt){
  269. var p = Ext.getCmp('app-center');
  270. if(startDt.clearTime().getTime() == endDt.clearTime().getTime()){
  271. p.setTitle(startDt.format('F j, Y'));
  272. }
  273. else if(startDt.getFullYear() == endDt.getFullYear()){
  274. if(startDt.getMonth() == endDt.getMonth()){
  275. p.setTitle(startDt.format('F j') + ' - ' + endDt.format('j, Y'));
  276. }
  277. else{
  278. p.setTitle(startDt.format('F j') + ' - ' + endDt.format('F j, Y'));
  279. }
  280. }
  281. else{
  282. p.setTitle(startDt.format('F j, Y') + ' - ' + endDt.format('F j, Y'));
  283. }
  284. },
  285. // This is an application-specific way to communicate CalendarPanel event messages back to the user.
  286. // This could be replaced with a function to do "toast" style messages, growl messages, etc. This will
  287. // vary based on application requirements, which is why it's not baked into the CalendarPanel.
  288. showMsg: function(msg){
  289. Ext.fly('app-msg').update(msg).removeClass('x-hidden');
  290. },
  291. clearMsg: function(){
  292. Ext.fly('app-msg').update('').addClass('x-hidden');
  293. }
  294. }
  295. }();
  296. Ext.onReady(App.init, App);