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.

299 lines
9.9 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. * @class Ext.calendar.EventEditWindow
  17. * @extends Ext.Window
  18. * <p>A custom window containing a basic edit form used for quick editing of events.</p>
  19. * <p>This window also provides custom events specific to the calendar so that other calendar components can be easily
  20. * notified when an event has been edited via this component.</p>
  21. * @constructor
  22. * @param {Object} config The config object
  23. */
  24. Ext.calendar.EventEditWindow = function(config) {
  25. var formPanelCfg = {
  26. xtype: 'form',
  27. labelWidth: 65,
  28. frame: false,
  29. bodyStyle: 'background:transparent;padding:5px 10px 10px;',
  30. bodyBorder: false,
  31. border: false,
  32. items: [{
  33. id: 'title',
  34. name: Ext.calendar.EventMappings.Title.name,
  35. fieldLabel: 'Title',
  36. xtype: 'textfield',
  37. anchor: '100%'
  38. },
  39. {
  40. xtype: 'daterangefield',
  41. id: 'date-range',
  42. anchor: '100%',
  43. fieldLabel: 'When'
  44. }]
  45. };
  46. if (config.calendarStore) {
  47. this.calendarStore = config.calendarStore;
  48. delete config.calendarStore;
  49. formPanelCfg.items.push({
  50. xtype: 'calendarpicker',
  51. id: 'calendar',
  52. name: 'calendar',
  53. anchor: '100%',
  54. store: this.calendarStore
  55. });
  56. }
  57. Ext.calendar.EventEditWindow.superclass.constructor.call(this, Ext.apply({
  58. titleTextAdd: 'Add Event',
  59. titleTextEdit: 'Edit Event',
  60. width: 600,
  61. autocreate: true,
  62. border: true,
  63. closeAction: 'hide',
  64. modal: false,
  65. resizable: false,
  66. buttonAlign: 'left',
  67. savingMessage: 'Saving changes...',
  68. deletingMessage: 'Deleting event...',
  69. fbar: [{
  70. xtype: 'tbtext',
  71. text: '<a href="#" id="tblink">Edit Details...</a>'
  72. },
  73. '->', {
  74. text: 'Save',
  75. disabled: false,
  76. handler: this.onSave,
  77. scope: this
  78. },
  79. {
  80. id: 'delete-btn',
  81. text: 'Delete',
  82. disabled: false,
  83. handler: this.onDelete,
  84. scope: this,
  85. hideMode: 'offsets'
  86. },
  87. {
  88. text: 'Cancel',
  89. disabled: false,
  90. handler: this.onCancel,
  91. scope: this
  92. }],
  93. items: formPanelCfg
  94. },
  95. config));
  96. };
  97. Ext.extend(Ext.calendar.EventEditWindow, Ext.Window, {
  98. // private
  99. newId: 10000,
  100. // private
  101. initComponent: function() {
  102. Ext.calendar.EventEditWindow.superclass.initComponent.call(this);
  103. this.formPanel = this.items.items[0];
  104. this.addEvents({
  105. /**
  106. * @event eventadd
  107. * Fires after a new event is added
  108. * @param {Ext.calendar.EventEditWindow} this
  109. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was added
  110. */
  111. eventadd: true,
  112. /**
  113. * @event eventupdate
  114. * Fires after an existing event is updated
  115. * @param {Ext.calendar.EventEditWindow} this
  116. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was updated
  117. */
  118. eventupdate: true,
  119. /**
  120. * @event eventdelete
  121. * Fires after an event is deleted
  122. * @param {Ext.calendar.EventEditWindow} this
  123. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was deleted
  124. */
  125. eventdelete: true,
  126. /**
  127. * @event eventcancel
  128. * Fires after an event add/edit operation is canceled by the user and no store update took place
  129. * @param {Ext.calendar.EventEditWindow} this
  130. * @param {Ext.calendar.EventRecord} rec The new {@link Ext.calendar.EventRecord record} that was canceled
  131. */
  132. eventcancel: true,
  133. /**
  134. * @event editdetails
  135. * Fires when the user selects the option in this window to continue editing in the detailed edit form
  136. * (by default, an instance of {@link Ext.calendar.EventEditForm}. Handling code should hide this window
  137. * and transfer the current event record to the appropriate instance of the detailed form by showing it
  138. * and calling {@link Ext.calendar.EventEditForm#loadRecord loadRecord}.
  139. * @param {Ext.calendar.EventEditWindow} this
  140. * @param {Ext.calendar.EventRecord} rec The {@link Ext.calendar.EventRecord record} that is currently being edited
  141. */
  142. editdetails: true
  143. });
  144. },
  145. // private
  146. afterRender: function() {
  147. Ext.calendar.EventEditWindow.superclass.afterRender.call(this);
  148. this.el.addClass('ext-cal-event-win');
  149. Ext.get('tblink').on('click',
  150. function(e) {
  151. e.stopEvent();
  152. this.updateRecord();
  153. this.fireEvent('editdetails', this, this.activeRecord);
  154. },
  155. this);
  156. },
  157. /**
  158. * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
  159. * @param {Ext.data.Record/Object} o Either a {@link Ext.data.Record} if showing the form
  160. * for an existing event in edit mode, or a plain object containing a StartDate property (and
  161. * optionally an EndDate property) for showing the form in add mode.
  162. * @param {String/Element} animateTarget (optional) The target element or id from which the window should
  163. * animate while opening (defaults to null with no animation)
  164. * @return {Ext.Window} this
  165. */
  166. show: function(o, animateTarget) {
  167. // Work around the CSS day cell height hack needed for initial render in IE8/strict:
  168. var anim = (Ext.isIE8 && Ext.isStrict) ? null: animateTarget;
  169. Ext.calendar.EventEditWindow.superclass.show.call(this, anim,
  170. function() {
  171. Ext.getCmp('title').focus(false, 100);
  172. });
  173. Ext.getCmp('delete-btn')[o.data && o.data[Ext.calendar.EventMappings.EventId.name] ? 'show': 'hide']();
  174. var rec,
  175. f = this.formPanel.form;
  176. if (o.data) {
  177. rec = o;
  178. this.isAdd = !!rec.data[Ext.calendar.EventMappings.IsNew.name];
  179. if (this.isAdd) {
  180. // Enable adding the default record that was passed in
  181. // if it's new even if the user makes no changes
  182. rec.markDirty();
  183. this.setTitle(this.titleTextAdd);
  184. }
  185. else {
  186. this.setTitle(this.titleTextEdit);
  187. }
  188. f.loadRecord(rec);
  189. }
  190. else {
  191. this.isAdd = true;
  192. this.setTitle(this.titleTextAdd);
  193. var M = Ext.calendar.EventMappings,
  194. eventId = M.EventId.name,
  195. start = o[M.StartDate.name],
  196. end = o[M.EndDate.name] || start.add('h', 1);
  197. rec = new Ext.calendar.EventRecord();
  198. rec.data[M.EventId.name] = this.newId++;
  199. rec.data[M.StartDate.name] = start;
  200. rec.data[M.EndDate.name] = end;
  201. rec.data[M.IsAllDay.name] = !!o[M.IsAllDay.name] || start.getDate() != end.clone().add(Date.MILLI, 1).getDate();
  202. rec.data[M.IsNew.name] = true;
  203. f.reset();
  204. f.loadRecord(rec);
  205. }
  206. if (this.calendarStore) {
  207. Ext.getCmp('calendar').setValue(rec.data[Ext.calendar.EventMappings.CalendarId.name]);
  208. }
  209. Ext.getCmp('date-range').setValue(rec.data);
  210. this.activeRecord = rec;
  211. return this;
  212. },
  213. // private
  214. roundTime: function(dt, incr) {
  215. incr = incr || 15;
  216. var m = parseInt(dt.getMinutes(), 10);
  217. return dt.add('mi', incr - (m % incr));
  218. },
  219. // private
  220. onCancel: function() {
  221. this.cleanup(true);
  222. this.fireEvent('eventcancel', this);
  223. },
  224. // private
  225. cleanup: function(hide) {
  226. if (this.activeRecord && this.activeRecord.dirty) {
  227. this.activeRecord.reject();
  228. }
  229. delete this.activeRecord;
  230. if (hide === true) {
  231. // Work around the CSS day cell height hack needed for initial render in IE8/strict:
  232. //var anim = afterDelete || (Ext.isIE8 && Ext.isStrict) ? null : this.animateTarget;
  233. this.hide();
  234. }
  235. },
  236. // private
  237. updateRecord: function() {
  238. var f = this.formPanel.form,
  239. dates = Ext.getCmp('date-range').getValue(),
  240. M = Ext.calendar.EventMappings;
  241. f.updateRecord(this.activeRecord);
  242. this.activeRecord.set(M.StartDate.name, dates[0]);
  243. this.activeRecord.set(M.EndDate.name, dates[1]);
  244. this.activeRecord.set(M.IsAllDay.name, dates[2]);
  245. this.activeRecord.set(M.CalendarId.name, this.formPanel.form.findField('calendar').getValue());
  246. },
  247. // private
  248. onSave: function() {
  249. if (!this.formPanel.form.isValid()) {
  250. return;
  251. }
  252. this.updateRecord();
  253. if (!this.activeRecord.dirty) {
  254. this.onCancel();
  255. return;
  256. }
  257. this.fireEvent(this.isAdd ? 'eventadd': 'eventupdate', this, this.activeRecord);
  258. },
  259. // private
  260. onDelete: function() {
  261. this.fireEvent('eventdelete', this, this.activeRecord);
  262. }
  263. });