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.

214 lines
6.0 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. Ext.ux.Portal = Ext.extend(Ext.Panel, {
  16. layout : 'column',
  17. autoScroll : true,
  18. cls : 'x-portal',
  19. defaultType : 'portalcolumn',
  20. initComponent : function(){
  21. Ext.ux.Portal.superclass.initComponent.call(this);
  22. this.addEvents({
  23. validatedrop:true,
  24. beforedragover:true,
  25. dragover:true,
  26. beforedrop:true,
  27. drop:true
  28. });
  29. },
  30. initEvents : function(){
  31. Ext.ux.Portal.superclass.initEvents.call(this);
  32. this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
  33. },
  34. beforeDestroy : function() {
  35. if(this.dd){
  36. this.dd.unreg();
  37. }
  38. Ext.ux.Portal.superclass.beforeDestroy.call(this);
  39. }
  40. });
  41. Ext.reg('portal', Ext.ux.Portal);
  42. Ext.ux.Portal.DropZone = Ext.extend(Ext.dd.DropTarget, {
  43. constructor : function(portal, cfg){
  44. this.portal = portal;
  45. Ext.dd.ScrollManager.register(portal.body);
  46. Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
  47. portal.body.ddScrollConfig = this.ddScrollConfig;
  48. },
  49. ddScrollConfig : {
  50. vthresh: 50,
  51. hthresh: -1,
  52. animate: true,
  53. increment: 200
  54. },
  55. createEvent : function(dd, e, data, col, c, pos){
  56. return {
  57. portal: this.portal,
  58. panel: data.panel,
  59. columnIndex: col,
  60. column: c,
  61. position: pos,
  62. data: data,
  63. source: dd,
  64. rawEvent: e,
  65. status: this.dropAllowed
  66. };
  67. },
  68. notifyOver : function(dd, e, data){
  69. var xy = e.getXY(), portal = this.portal, px = dd.proxy;
  70. // case column widths
  71. if(!this.grid){
  72. this.grid = this.getGrid();
  73. }
  74. // handle case scroll where scrollbars appear during drag
  75. var cw = portal.body.dom.clientWidth;
  76. if(!this.lastCW){
  77. this.lastCW = cw;
  78. }else if(this.lastCW != cw){
  79. this.lastCW = cw;
  80. portal.doLayout();
  81. this.grid = this.getGrid();
  82. }
  83. // determine column
  84. var col = 0, xs = this.grid.columnX, cmatch = false;
  85. for(var len = xs.length; col < len; col++){
  86. if(xy[0] < (xs[col].x + xs[col].w)){
  87. cmatch = true;
  88. break;
  89. }
  90. }
  91. // no match, fix last index
  92. if(!cmatch){
  93. col--;
  94. }
  95. // find insert position
  96. var p, match = false, pos = 0,
  97. c = portal.items.itemAt(col),
  98. items = c.items.items, overSelf = false;
  99. for(var len = items.length; pos < len; pos++){
  100. p = items[pos];
  101. var h = p.el.getHeight();
  102. if(h === 0){
  103. overSelf = true;
  104. }
  105. else if((p.el.getY()+(h/2)) > xy[1]){
  106. match = true;
  107. break;
  108. }
  109. }
  110. pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
  111. var overEvent = this.createEvent(dd, e, data, col, c, pos);
  112. if(portal.fireEvent('validatedrop', overEvent) !== false &&
  113. portal.fireEvent('beforedragover', overEvent) !== false){
  114. // make sure proxy width is fluid
  115. px.getProxy().setWidth('auto');
  116. if(p){
  117. px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
  118. }else{
  119. px.moveProxy(c.el.dom, null);
  120. }
  121. this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
  122. this.scrollPos = portal.body.getScroll();
  123. portal.fireEvent('dragover', overEvent);
  124. return overEvent.status;
  125. }else{
  126. return overEvent.status;
  127. }
  128. },
  129. notifyOut : function(){
  130. delete this.grid;
  131. },
  132. notifyDrop : function(dd, e, data){
  133. delete this.grid;
  134. if(!this.lastPos){
  135. return;
  136. }
  137. var c = this.lastPos.c,
  138. col = this.lastPos.col,
  139. pos = this.lastPos.p,
  140. panel = dd.panel,
  141. dropEvent = this.createEvent(dd, e, data, col, c,
  142. pos !== false ? pos : c.items.getCount());
  143. if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
  144. this.portal.fireEvent('beforedrop', dropEvent) !== false){
  145. dd.proxy.getProxy().remove();
  146. panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
  147. if(pos !== false){
  148. c.insert(pos, panel);
  149. }else{
  150. c.add(panel);
  151. }
  152. c.doLayout();
  153. this.portal.fireEvent('drop', dropEvent);
  154. // scroll position is lost on drop, fix it
  155. var st = this.scrollPos.top;
  156. if(st){
  157. var d = this.portal.body.dom;
  158. setTimeout(function(){
  159. d.scrollTop = st;
  160. }, 10);
  161. }
  162. }
  163. delete this.lastPos;
  164. },
  165. // internal cache of body and column coords
  166. getGrid : function(){
  167. var box = this.portal.bwrap.getBox();
  168. box.columnX = [];
  169. this.portal.items.each(function(c){
  170. box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
  171. });
  172. return box;
  173. },
  174. // unregister the dropzone from ScrollManager
  175. unreg: function() {
  176. Ext.dd.ScrollManager.unregister(this.portal.body);
  177. Ext.ux.Portal.DropZone.superclass.unreg.call(this);
  178. }
  179. });
  180. </pre>
  181. </body>
  182. </html>