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.

305 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Extensible 1.0-beta2
  3. * Copyright(c) 2010-2011 Extensible, LLC
  4. * licensing@ext.ensible.com
  5. * http://ext.ensible.com
  6. */
  7. /**
  8. * @class Ext.ensible.cal.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.ensible.cal.EventEditWindow = Ext.extend(Ext.Window, {
  17. titleTextAdd: 'Add Event',
  18. titleTextEdit: 'Edit Event',
  19. width: 600,
  20. border: true,
  21. closeAction: 'hide',
  22. modal: false,
  23. resizable: false,
  24. buttonAlign: 'left',
  25. labelWidth: 65,
  26. detailsLinkText: 'Edit Details...',
  27. savingMessage: 'Saving changes...',
  28. deletingMessage: 'Deleting event...',
  29. saveButtonText: 'Save',
  30. deleteButtonText: 'Delete',
  31. cancelButtonText: 'Cancel',
  32. titleLabelText: 'Title',
  33. datesLabelText: 'When',
  34. calendarLabelText: 'Calendar',
  35. editDetailsLinkClass: 'edit-dtl-link',
  36. bodyStyle: 'padding:5px 10px;',
  37. // private
  38. initComponent: function(){
  39. this.addEvents({
  40. /**
  41. * @event eventadd
  42. * Fires after a new event is added
  43. * @param {Ext.ensible.cal.EventEditWindow} this
  44. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was added
  45. * @param {Ext.Element} el The target element
  46. */
  47. eventadd: true,
  48. /**
  49. * @event eventupdate
  50. * Fires after an existing event is updated
  51. * @param {Ext.ensible.cal.EventEditWindow} this
  52. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was updated
  53. * @param {Ext.Element} el The target element
  54. */
  55. eventupdate: true,
  56. /**
  57. * @event eventdelete
  58. * Fires after an event is deleted
  59. * @param {Ext.ensible.cal.EventEditWindow} this
  60. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was deleted
  61. * @param {Ext.Element} el The target element
  62. */
  63. eventdelete: true,
  64. /**
  65. * @event eventcancel
  66. * Fires after an event add/edit operation is canceled by the user and no store update took place
  67. * @param {Ext.ensible.cal.EventEditWindow} this
  68. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was canceled
  69. * @param {Ext.Element} el The target element
  70. */
  71. eventcancel: true,
  72. /**
  73. * @event editdetails
  74. * Fires when the user selects the option in this window to continue editing in the detailed edit form
  75. * (by default, an instance of {@link Ext.ensible.cal.EventEditForm}. Handling code should hide this window
  76. * and transfer the current event record to the appropriate instance of the detailed form by showing it
  77. * and calling {@link Ext.ensible.cal.EventEditForm#loadRecord loadRecord}.
  78. * @param {Ext.ensible.cal.EventEditWindow} this
  79. * @param {Ext.ensible.cal.EventRecord} rec The {@link Ext.ensible.cal.EventRecord record} that is currently being edited
  80. * @param {Ext.Element} el The target element
  81. */
  82. editdetails: true
  83. });
  84. this.fbar = [{
  85. xtype: 'tbtext', text: '<a href="#" class="'+this.editDetailsLinkClass+'">'+this.detailsLinkText+'</a>'
  86. },'->',{
  87. text:this.saveButtonText, disabled:false, handler:this.onSave, scope:this
  88. },{
  89. id:this.id+'-delete-btn', text:this.deleteButtonText, disabled:false, handler:this.onDelete, scope:this, hideMode:'offsets'
  90. },{
  91. text:this.cancelButtonText, disabled:false, handler:this.onCancel, scope:this
  92. }];
  93. Ext.ensible.cal.EventEditWindow.superclass.initComponent.call(this);
  94. },
  95. // private
  96. onRender : function(ct, position){
  97. this.deleteBtn = Ext.getCmp(this.id+'-delete-btn');
  98. this.titleField = new Ext.form.TextField({
  99. name: Ext.ensible.cal.EventMappings.Title.name,
  100. fieldLabel: this.titleLabelText,
  101. anchor: '100%'
  102. });
  103. this.dateRangeField = new Ext.ensible.cal.DateRangeField({
  104. anchor: '95%',
  105. fieldLabel: this.datesLabelText
  106. });
  107. var items = [this.titleField, this.dateRangeField];
  108. if(this.calendarStore){
  109. this.calendarField = new Ext.ensible.cal.CalendarCombo({
  110. name: Ext.ensible.cal.EventMappings.CalendarId.name,
  111. anchor: '100%',
  112. fieldLabel: this.calendarLabelText,
  113. store: this.calendarStore
  114. });
  115. items.push(this.calendarField);
  116. }
  117. this.formPanel = new Ext.FormPanel({
  118. labelWidth: this.labelWidth,
  119. frame: false,
  120. bodyBorder: false,
  121. border: false,
  122. items: items
  123. });
  124. this.add(this.formPanel);
  125. Ext.ensible.cal.EventEditWindow.superclass.onRender.call(this, ct, position);
  126. },
  127. // private
  128. afterRender: function(){
  129. Ext.ensible.cal.EventEditWindow.superclass.afterRender.call(this);
  130. this.el.addClass('ext-cal-event-win');
  131. this.el.select('.'+this.editDetailsLinkClass).on('click', this.onEditDetailsClick, this);
  132. },
  133. // private
  134. onEditDetailsClick: function(e){
  135. e.stopEvent();
  136. this.updateRecord();
  137. this.fireEvent('editdetails', this, this.activeRecord, this.animateTarget);
  138. },
  139. /**
  140. * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
  141. * @param {Ext.data.Record/Object} o Either a {@link Ext.data.Record} if showing the form
  142. * for an existing event in edit mode, or a plain object containing a StartDate property (and
  143. * optionally an EndDate property) for showing the form in add mode.
  144. * @param {String/Element} animateTarget (optional) The target element or id from which the window should
  145. * animate while opening (defaults to null with no animation)
  146. * @return {Ext.Window} this
  147. */
  148. show: function(o, animateTarget){
  149. // Work around the CSS day cell height hack needed for initial render in IE8/strict:
  150. var anim = (Ext.isIE8 && Ext.isStrict) ? null : animateTarget;
  151. Ext.ensible.cal.EventEditWindow.superclass.show.call(this, anim, function(){
  152. this.titleField.focus(false, 100);
  153. });
  154. this.deleteBtn[o.data && o.data[Ext.ensible.cal.EventMappings.EventId.name] ? 'show' : 'hide']();
  155. var rec, f = this.formPanel.form;
  156. if(o.data){
  157. rec = o;
  158. //this.isAdd = !!rec.data[Ext.ensible.cal.EventMappings.IsNew.name];
  159. if(rec.phantom){
  160. // Enable adding the default record that was passed in
  161. // if it's new even if the user makes no changes
  162. //rec.markDirty();
  163. this.setTitle(this.titleTextAdd);
  164. }
  165. else{
  166. this.setTitle(this.titleTextEdit);
  167. }
  168. f.loadRecord(rec);
  169. }
  170. else{
  171. //this.isAdd = true;
  172. this.setTitle(this.titleTextAdd);
  173. var M = Ext.ensible.cal.EventMappings,
  174. start = o[M.StartDate.name],
  175. end = o[M.EndDate.name] || start.add('h', 1);
  176. rec = new Ext.ensible.cal.EventRecord();
  177. //rec.data[M.EventId.name] = this.newId++;
  178. rec.data[M.StartDate.name] = start;
  179. rec.data[M.EndDate.name] = end;
  180. rec.data[M.IsAllDay.name] = !!o[M.IsAllDay.name] || start.getDate() != end.clone().add(Date.MILLI, 1).getDate();
  181. f.reset();
  182. f.loadRecord(rec);
  183. }
  184. if(this.calendarStore){
  185. this.calendarField.setValue(rec.data[Ext.ensible.cal.EventMappings.CalendarId.name]);
  186. }
  187. this.dateRangeField.setValue(rec.data);
  188. this.activeRecord = rec;
  189. this.el.setStyle('z-index', 12000);
  190. return this;
  191. },
  192. // private
  193. roundTime: function(dt, incr){
  194. incr = incr || 15;
  195. var m = parseInt(dt.getMinutes());
  196. return dt.add('mi', incr - (m % incr));
  197. },
  198. // private
  199. onCancel: function(){
  200. this.cleanup(true);
  201. this.fireEvent('eventcancel', this, this.animateTarget);
  202. },
  203. // private
  204. cleanup: function(hide){
  205. if(this.activeRecord){
  206. this.activeRecord.reject();
  207. }
  208. delete this.activeRecord;
  209. if(hide===true){
  210. // Work around the CSS day cell height hack needed for initial render in IE8/strict:
  211. //var anim = afterDelete || (Ext.isIE8 && Ext.isStrict) ? null : this.animateTarget;
  212. this.hide();
  213. }
  214. },
  215. // private
  216. updateRecord: function(){
  217. var dates = this.dateRangeField.getValue(),
  218. M = Ext.ensible.cal.EventMappings,
  219. rec = this.activeRecord,
  220. form = this.formPanel.form,
  221. fs = rec.fields,
  222. dirty = false;
  223. rec.beginEdit();
  224. //TODO: This block is copied directly from BasicForm.updateRecord.
  225. // Unfortunately since that method internally calls begin/endEdit all
  226. // updates happen and the record dirty status is reset internally to
  227. // that call. We need the dirty status, plus currently the DateRangeField
  228. // does not map directly to the record values, so for now we'll duplicate
  229. // the setter logic here (we need to be able to pick up any custom-added
  230. // fields generically). Need to revisit this later and come up with a better solution.
  231. fs.each(function(f){
  232. var field = form.findField(f.name);
  233. if(field){
  234. var value = field.getValue();
  235. if (value.getGroupValue) {
  236. value = value.getGroupValue();
  237. }
  238. else if (field.eachItem) {
  239. value = [];
  240. field.eachItem(function(item){
  241. value.push(item.getValue());
  242. });
  243. }
  244. rec.set(f.name, value);
  245. }
  246. }, this);
  247. rec.set(M.StartDate.name, dates[0]);
  248. rec.set(M.EndDate.name, dates[1]);
  249. rec.set(M.IsAllDay.name, dates[2]);
  250. dirty = rec.dirty;
  251. rec.endEdit();
  252. return dirty;
  253. },
  254. // private
  255. onSave: function(){
  256. if(!this.formPanel.form.isValid()){
  257. return;
  258. }
  259. if(!this.updateRecord()){
  260. this.onCancel();
  261. return;
  262. }
  263. this.fireEvent(this.activeRecord.phantom ? 'eventadd' : 'eventupdate', this, this.activeRecord, this.animateTarget);
  264. },
  265. // private
  266. onDelete: function(){
  267. this.fireEvent('eventdelete', this, this.activeRecord, this.animateTarget);
  268. }
  269. });
  270. Ext.reg('extensible.eventeditwindow', Ext.ensible.cal.EventEditWindow);