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.

296 lines
10 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.EventEditForm
  9. * @extends Ext.form.FormPanel
  10. * <p>A custom form used for detailed editing of events.</p>
  11. * <p>This is pretty much a standard form that is simply pre-configured for the options needed by the
  12. * calendar components. It is also configured to automatically bind records of type {@link Ext.ensible.cal.EventRecord}
  13. * to and from the form.</p>
  14. * <p>This form also provides custom events specific to the calendar so that other calendar components can be easily
  15. * notified when an event has been edited via this component.</p>
  16. * <p>The default configs are as follows:</p><pre><code>
  17. labelWidth: 65,
  18. title: 'Event Form',
  19. titleTextAdd: 'Add Event',
  20. titleTextEdit: 'Edit Event',
  21. bodyStyle: 'background:transparent;padding:20px 20px 10px;',
  22. border: false,
  23. buttonAlign: 'center',
  24. autoHeight: true, // to allow for the notes field to autogrow
  25. cls: 'ext-evt-edit-form',
  26. </code></pre>
  27. * @constructor
  28. * @param {Object} config The config object
  29. */
  30. Ext.ensible.cal.EventEditForm = Ext.extend(Ext.form.FormPanel, {
  31. labelWidth: 65,
  32. labelWidthRightCol: 65,
  33. colWidthLeft: .6,
  34. colWidthRight: .4,
  35. title: 'Event Form',
  36. titleTextAdd: 'Add Event',
  37. titleTextEdit: 'Edit Event',
  38. titleLabelText: 'Title',
  39. datesLabelText: 'When',
  40. reminderLabelText: 'Reminder',
  41. notesLabelText: 'Notes',
  42. locationLabelText: 'Location',
  43. webLinkLabelText: 'Web Link',
  44. calendarLabelText: 'Calendar',
  45. repeatsLabelText: 'Repeats',
  46. saveButtonText: 'Save',
  47. deleteButtonText: 'Delete',
  48. cancelButtonText: 'Cancel',
  49. bodyStyle: 'padding:20px 20px 10px;',
  50. border: false,
  51. buttonAlign: 'center',
  52. autoHeight: true, // to allow for the notes field to autogrow
  53. cls: 'ext-evt-edit-form',
  54. /**
  55. * @cfg {Boolean} enableRecurrence
  56. * True to show the recurrence field, false to hide it (default). Note that recurrence requires
  57. * something on the server-side that can parse the iCal RRULE format in order to generate the
  58. * instances of recurring events to display on the calendar, so this field should only be enabled
  59. * if the server supports it.
  60. */
  61. enableRecurrence: false,
  62. // private properties:
  63. layout: 'column',
  64. // private
  65. initComponent: function(){
  66. this.addEvents({
  67. /**
  68. * @event eventadd
  69. * Fires after a new event is added
  70. * @param {Ext.ensible.cal.EventEditForm} this
  71. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was added
  72. */
  73. eventadd: true,
  74. /**
  75. * @event eventupdate
  76. * Fires after an existing event is updated
  77. * @param {Ext.ensible.cal.EventEditForm} this
  78. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was updated
  79. */
  80. eventupdate: true,
  81. /**
  82. * @event eventdelete
  83. * Fires after an event is deleted
  84. * @param {Ext.ensible.cal.EventEditForm} this
  85. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was deleted
  86. */
  87. eventdelete: true,
  88. /**
  89. * @event eventcancel
  90. * Fires after an event add/edit operation is canceled by the user and no store update took place
  91. * @param {Ext.ensible.cal.EventEditForm} this
  92. * @param {Ext.ensible.cal.EventRecord} rec The new {@link Ext.ensible.cal.EventRecord record} that was canceled
  93. */
  94. eventcancel: true
  95. });
  96. this.titleField = new Ext.form.TextField({
  97. fieldLabel: this.titleLabelText,
  98. name: Ext.ensible.cal.EventMappings.Title.name,
  99. anchor: '90%'
  100. });
  101. this.dateRangeField = new Ext.ensible.cal.DateRangeField({
  102. fieldLabel: this.datesLabelText,
  103. singleLine: false,
  104. anchor: '90%',
  105. listeners: {
  106. 'change': this.onDateChange.createDelegate(this)
  107. }
  108. });
  109. this.reminderField = new Ext.ensible.cal.ReminderField({
  110. name: Ext.ensible.cal.EventMappings.Reminder.name,
  111. fieldLabel: this.reminderLabelText
  112. });
  113. this.notesField = new Ext.form.TextArea({
  114. fieldLabel: this.notesLabelText,
  115. name: Ext.ensible.cal.EventMappings.Notes.name,
  116. grow: true,
  117. growMax: 150,
  118. anchor: '100%'
  119. });
  120. this.locationField = new Ext.form.TextField({
  121. fieldLabel: this.locationLabelText,
  122. name: Ext.ensible.cal.EventMappings.Location.name,
  123. anchor: '100%'
  124. });
  125. this.urlField = new Ext.form.TextField({
  126. fieldLabel: this.webLinkLabelText,
  127. name: Ext.ensible.cal.EventMappings.Url.name,
  128. anchor: '100%'
  129. });
  130. var leftFields = [this.titleField, this.dateRangeField, this.reminderField],
  131. rightFields = [this.notesField, this.locationField, this.urlField];
  132. if(this.enableRecurrence){
  133. this.recurrenceField = new Ext.ensible.cal.RecurrenceField({
  134. name: Ext.ensible.cal.EventMappings.RRule.name,
  135. fieldLabel: this.repeatsLabelText,
  136. anchor: '100%'
  137. });
  138. leftFields.splice(2, 0, this.recurrenceField);
  139. }
  140. if(this.calendarStore){
  141. this.calendarField = new Ext.ensible.cal.CalendarCombo({
  142. store: this.calendarStore,
  143. fieldLabel: this.calendarLabelText,
  144. name: Ext.ensible.cal.EventMappings.CalendarId.name
  145. });
  146. leftFields.splice(2, 0, this.calendarField);
  147. };
  148. this.items = [{
  149. id: this.id+'-left-col',
  150. columnWidth: this.colWidthLeft,
  151. layout: 'form',
  152. border: false,
  153. items: leftFields
  154. },{
  155. id: this.id+'-right-col',
  156. columnWidth: this.colWidthRight,
  157. layout: 'form',
  158. labelWidth: this.labelWidthRightCol || this.labelWidth,
  159. border: false,
  160. items: rightFields
  161. }];
  162. this.fbar = [{
  163. text:this.saveButtonText, scope: this, handler: this.onSave
  164. },{
  165. cls:'ext-del-btn', text:this.deleteButtonText, scope:this, handler:this.onDelete
  166. },{
  167. text:this.cancelButtonText, scope: this, handler: this.onCancel
  168. }];
  169. Ext.ensible.cal.EventEditForm.superclass.initComponent.call(this);
  170. },
  171. // private
  172. onDateChange: function(dateRangeField, val){
  173. if(this.recurrenceField){
  174. this.recurrenceField.setStartDate(val[0]);
  175. }
  176. },
  177. // inherited docs
  178. loadRecord: function(rec){
  179. this.form.reset().loadRecord.apply(this.form, arguments);
  180. this.activeRecord = rec;
  181. this.dateRangeField.setValue(rec.data);
  182. if(this.recurrenceField){
  183. this.recurrenceField.setStartDate(rec.data[Ext.ensible.cal.EventMappings.StartDate.name]);
  184. }
  185. if(this.calendarStore){
  186. this.form.setValues({'calendar': rec.data[Ext.ensible.cal.EventMappings.CalendarId.name]});
  187. }
  188. //this.isAdd = !!rec.data[Ext.ensible.cal.EventMappings.IsNew.name];
  189. if(rec.phantom){
  190. //rec.markDirty();
  191. this.setTitle(this.titleTextAdd);
  192. Ext.select('.ext-del-btn').setDisplayed(false);
  193. }
  194. else {
  195. this.setTitle(this.titleTextEdit);
  196. Ext.select('.ext-del-btn').setDisplayed(true);
  197. }
  198. this.titleField.focus();
  199. },
  200. // inherited docs
  201. updateRecord: function(){
  202. var dates = this.dateRangeField.getValue(),
  203. M = Ext.ensible.cal.EventMappings,
  204. rec = this.activeRecord,
  205. fs = rec.fields,
  206. dirty = false;
  207. rec.beginEdit();
  208. //TODO: This block is copied directly from BasicForm.updateRecord.
  209. // Unfortunately since that method internally calls begin/endEdit all
  210. // updates happen and the record dirty status is reset internally to
  211. // that call. We need the dirty status, plus currently the DateRangeField
  212. // does not map directly to the record values, so for now we'll duplicate
  213. // the setter logic here (we need to be able to pick up any custom-added
  214. // fields generically). Need to revisit this later and come up with a better solution.
  215. fs.each(function(f){
  216. var field = this.form.findField(f.name);
  217. if(field){
  218. var value = field.getValue();
  219. if (value.getGroupValue) {
  220. value = value.getGroupValue();
  221. }
  222. else if (field.eachItem) {
  223. value = [];
  224. field.eachItem(function(item){
  225. value.push(item.getValue());
  226. });
  227. }
  228. rec.set(f.name, value);
  229. }
  230. }, this);
  231. rec.set(M.StartDate.name, dates[0]);
  232. rec.set(M.EndDate.name, dates[1]);
  233. rec.set(M.IsAllDay.name, dates[2]);
  234. dirty = rec.dirty;
  235. rec.endEdit();
  236. return dirty;
  237. },
  238. // private
  239. onCancel: function(){
  240. this.cleanup(true);
  241. this.fireEvent('eventcancel', this, this.activeRecord);
  242. },
  243. // private
  244. cleanup: function(hide){
  245. if(this.activeRecord){
  246. this.activeRecord.reject();
  247. }
  248. delete this.activeRecord;
  249. if(this.form.isDirty()){
  250. this.form.reset();
  251. }
  252. },
  253. // private
  254. onSave: function(){
  255. if(!this.form.isValid()){
  256. return;
  257. }
  258. if(!this.updateRecord()){
  259. this.onCancel();
  260. return;
  261. }
  262. this.fireEvent(this.activeRecord.phantom ? 'eventadd' : 'eventupdate', this, this.activeRecord);
  263. },
  264. // private
  265. onDelete: function(){
  266. this.fireEvent('eventdelete', this, this.activeRecord);
  267. }
  268. });
  269. Ext.reg('extensible.eventeditform', Ext.ensible.cal.EventEditForm);