Web UI for ARGUS server
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.

285 lines
9.4 KiB

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