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.

269 lines
8.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. /*
  16. * Internal drag zone implementation for the calendar components. This provides base functionality
  17. * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
  18. */
  19. Ext.calendar.DragZone = Ext.extend(Ext.dd.DragZone, {
  20. ddGroup: 'CalendarDD',
  21. eventSelector: '.ext-cal-evt',
  22. constructor: function(el, config) {
  23. if (!Ext.calendar._statusProxyInstance) {
  24. Ext.calendar._statusProxyInstance = new Ext.calendar.StatusProxy();
  25. }
  26. this.proxy = Ext.calendar._statusProxyInstance;
  27. Ext.calendar.DragZone.superclass.constructor.call(this, el, config);
  28. },
  29. getDragData: function(e) {
  30. // Check whether we are dragging on an event first
  31. var t = e.getTarget(this.eventSelector, 3);
  32. if (t) {
  33. var rec = this.view.getEventRecordFromEl(t);
  34. return {
  35. type: 'eventdrag',
  36. ddel: t,
  37. eventStart: rec.data[Ext.calendar.EventMappings.StartDate.name],
  38. eventEnd: rec.data[Ext.calendar.EventMappings.EndDate.name],
  39. proxy: this.proxy
  40. };
  41. }
  42. // If not dragging an event then we are dragging on
  43. // the calendar to add a new event
  44. t = this.view.getDayAt(e.getPageX(), e.getPageY());
  45. if (t.el) {
  46. return {
  47. type: 'caldrag',
  48. start: t.date,
  49. proxy: this.proxy
  50. };
  51. }
  52. return null;
  53. },
  54. onInitDrag: function(x, y) {
  55. if (this.dragData.ddel) {
  56. var ghost = this.dragData.ddel.cloneNode(true),
  57. child = Ext.fly(ghost).child('dl');
  58. Ext.fly(ghost).setWidth('auto');
  59. if (child) {
  60. // for IE/Opera
  61. child.setHeight('auto');
  62. }
  63. this.proxy.update(ghost);
  64. this.onStartDrag(x, y);
  65. }
  66. else if (this.dragData.start) {
  67. this.onStartDrag(x, y);
  68. }
  69. this.view.onInitDrag();
  70. return true;
  71. },
  72. afterRepair: function() {
  73. if (Ext.enableFx && this.dragData.ddel) {
  74. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || 'c3daf9');
  75. }
  76. this.dragging = false;
  77. },
  78. getRepairXY: function(e) {
  79. if (this.dragData.ddel) {
  80. return Ext.Element.fly(this.dragData.ddel).getXY();
  81. }
  82. },
  83. afterInvalidDrop: function(e, id) {
  84. Ext.select('.ext-dd-shim').hide();
  85. }
  86. });
  87. /*
  88. * Internal drop zone implementation for the calendar components. This provides base functionality
  89. * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
  90. */
  91. Ext.calendar.DropZone = Ext.extend(Ext.dd.DropZone, {
  92. ddGroup: 'CalendarDD',
  93. eventSelector: '.ext-cal-evt',
  94. // private
  95. shims: [],
  96. getTargetFromEvent: function(e) {
  97. var dragOffset = this.dragOffset || 0,
  98. y = e.getPageY() - dragOffset,
  99. d = this.view.getDayAt(e.getPageX(), y);
  100. return d.el ? d: null;
  101. },
  102. onNodeOver: function(n, dd, e, data) {
  103. var D = Ext.calendar.Date,
  104. start = data.type == 'eventdrag' ? n.date: D.min(data.start, n.date),
  105. end = data.type == 'eventdrag' ? n.date.add(Date.DAY, D.diffDays(data.eventStart, data.eventEnd)) :
  106. D.max(data.start, n.date);
  107. if (!this.dragStartDate || !this.dragEndDate || (D.diffDays(start, this.dragStartDate) != 0) || (D.diffDays(end, this.dragEndDate) != 0)) {
  108. this.dragStartDate = start;
  109. this.dragEndDate = end.clearTime().add(Date.DAY, 1).add(Date.MILLI, -1);
  110. this.shim(start, end);
  111. var range = start.format('n/j');
  112. if (D.diffDays(start, end) > 0) {
  113. range += '-' + end.format('n/j');
  114. }
  115. var msg = String.format(data.type == 'eventdrag' ? this.moveText: this.createText, range);
  116. data.proxy.updateMsg(msg);
  117. }
  118. return this.dropAllowed;
  119. },
  120. shim: function(start, end) {
  121. this.currWeek = -1;
  122. var dt = start.clone(),
  123. i = 0,
  124. shim,
  125. box,
  126. cnt = Ext.calendar.Date.diffDays(dt, end) + 1;
  127. Ext.each(this.shims,
  128. function(shim) {
  129. if (shim) {
  130. shim.isActive = false;
  131. }
  132. }
  133. );
  134. while (i++<cnt) {
  135. var dayEl = this.view.getDayEl(dt);
  136. // if the date is not in the current view ignore it (this
  137. // can happen when an event is dragged to the end of the
  138. // month so that it ends outside the view)
  139. if (dayEl) {
  140. var wk = this.view.getWeekIndex(dt);
  141. shim = this.shims[wk];
  142. if (!shim) {
  143. shim = this.createShim();
  144. this.shims[wk] = shim;
  145. }
  146. if (wk != this.currWeek) {
  147. shim.boxInfo = dayEl.getBox();
  148. this.currWeek = wk;
  149. }
  150. else {
  151. box = dayEl.getBox();
  152. shim.boxInfo.right = box.right;
  153. shim.boxInfo.width = box.right - shim.boxInfo.x;
  154. }
  155. shim.isActive = true;
  156. }
  157. dt = dt.add(Date.DAY, 1);
  158. }
  159. Ext.each(this.shims,
  160. function(shim) {
  161. if (shim) {
  162. if (shim.isActive) {
  163. shim.show();
  164. shim.setBox(shim.boxInfo);
  165. }
  166. else if (shim.isVisible()) {
  167. shim.hide();
  168. }
  169. }
  170. });
  171. },
  172. createShim: function() {
  173. if (!this.shimCt) {
  174. this.shimCt = Ext.get('ext-dd-shim-ct');
  175. if (!this.shimCt) {
  176. this.shimCt = document.createElement('div');
  177. this.shimCt.id = 'ext-dd-shim-ct';
  178. Ext.getBody().appendChild(this.shimCt);
  179. }
  180. }
  181. var el = document.createElement('div');
  182. el.className = 'ext-dd-shim';
  183. this.shimCt.appendChild(el);
  184. return new Ext.Layer({
  185. shadow: false,
  186. useDisplay: true,
  187. constrain: false
  188. },
  189. el);
  190. },
  191. clearShims: function() {
  192. Ext.each(this.shims,
  193. function(shim) {
  194. if (shim) {
  195. shim.hide();
  196. }
  197. });
  198. },
  199. onContainerOver: function(dd, e, data) {
  200. return this.dropAllowed;
  201. },
  202. onCalendarDragComplete: function() {
  203. delete this.dragStartDate;
  204. delete this.dragEndDate;
  205. this.clearShims();
  206. },
  207. onNodeDrop: function(n, dd, e, data) {
  208. if (n && data) {
  209. if (data.type == 'eventdrag') {
  210. var rec = this.view.getEventRecordFromEl(data.ddel),
  211. dt = Ext.calendar.Date.copyTime(rec.data[Ext.calendar.EventMappings.StartDate.name], n.date);
  212. this.view.onEventDrop(rec, dt);
  213. this.onCalendarDragComplete();
  214. return true;
  215. }
  216. if (data.type == 'caldrag') {
  217. this.view.onCalendarEndDrag(this.dragStartDate, this.dragEndDate,
  218. this.onCalendarDragComplete.createDelegate(this));
  219. //shims are NOT cleared here -- they stay visible until the handling
  220. //code calls the onCalendarDragComplete callback which hides them.
  221. return true;
  222. }
  223. }
  224. this.onCalendarDragComplete();
  225. return false;
  226. },
  227. onContainerDrop: function(dd, e, data) {
  228. this.onCalendarDragComplete();
  229. return false;
  230. },
  231. destroy: function() {
  232. Ext.calendar.DropZone.superclass.destroy.call(this);
  233. Ext.destroy(this.shimCt);
  234. }
  235. });
  236. </pre>
  237. </body>
  238. </html>