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.

324 lines
15 KiB

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