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.

219 lines
6.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js">// private
  19. // This is a support class used internally by the Grid components
  20. Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
  21. maxDragWidth: 120,
  22. constructor : function(grid, hd, hd2){
  23. this.grid = grid;
  24. this.view = grid.getView();
  25. this.ddGroup = &quot;gridHeader&quot; + this.grid.getGridEl().id;
  26. Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
  27. if(hd2){
  28. this.setHandleElId(Ext.id(hd));
  29. this.setOuterHandleElId(Ext.id(hd2));
  30. }
  31. this.scroll = false;
  32. },
  33. getDragData : function(e){
  34. var t = Ext.lib.Event.getTarget(e),
  35. h = this.view.findHeaderCell(t);
  36. if(h){
  37. return {ddel: h.firstChild, header:h};
  38. }
  39. return false;
  40. },
  41. onInitDrag : function(e){
  42. // keep the value here so we can restore it;
  43. this.dragHeadersDisabled = this.view.headersDisabled;
  44. this.view.headersDisabled = true;
  45. var clone = this.dragData.ddel.cloneNode(true);
  46. clone.id = Ext.id();
  47. clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + &quot;px&quot;;
  48. this.proxy.update(clone);
  49. return true;
  50. },
  51. afterValidDrop : function(){
  52. this.completeDrop();
  53. },
  54. afterInvalidDrop : function(){
  55. this.completeDrop();
  56. },
  57. completeDrop: function(){
  58. var v = this.view,
  59. disabled = this.dragHeadersDisabled;
  60. setTimeout(function(){
  61. v.headersDisabled = disabled;
  62. }, 50);
  63. }
  64. });
  65. // private
  66. // This is a support class used internally by the Grid components
  67. Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
  68. proxyOffsets : [-4, -9],
  69. fly: Ext.Element.fly,
  70. constructor : function(grid, hd, hd2){
  71. this.grid = grid;
  72. this.view = grid.getView();
  73. // split the proxies so they don't interfere with mouse events
  74. this.proxyTop = Ext.DomHelper.append(document.body, {
  75. cls:&quot;col-move-top&quot;, html:&quot;&amp;#160;&quot;
  76. }, true);
  77. this.proxyBottom = Ext.DomHelper.append(document.body, {
  78. cls:&quot;col-move-bottom&quot;, html:&quot;&amp;#160;&quot;
  79. }, true);
  80. this.proxyTop.hide = this.proxyBottom.hide = function(){
  81. this.setLeftTop(-100,-100);
  82. this.setStyle(&quot;visibility&quot;, &quot;hidden&quot;);
  83. };
  84. this.ddGroup = &quot;gridHeader&quot; + this.grid.getGridEl().id;
  85. // temporarily disabled
  86. //Ext.dd.ScrollManager.register(this.view.scroller.dom);
  87. Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
  88. },
  89. getTargetFromEvent : function(e){
  90. var t = Ext.lib.Event.getTarget(e),
  91. cindex = this.view.findCellIndex(t);
  92. if(cindex !== false){
  93. return this.view.getHeaderCell(cindex);
  94. }
  95. },
  96. nextVisible : function(h){
  97. var v = this.view, cm = this.grid.colModel;
  98. h = h.nextSibling;
  99. while(h){
  100. if(!cm.isHidden(v.getCellIndex(h))){
  101. return h;
  102. }
  103. h = h.nextSibling;
  104. }
  105. return null;
  106. },
  107. prevVisible : function(h){
  108. var v = this.view, cm = this.grid.colModel;
  109. h = h.prevSibling;
  110. while(h){
  111. if(!cm.isHidden(v.getCellIndex(h))){
  112. return h;
  113. }
  114. h = h.prevSibling;
  115. }
  116. return null;
  117. },
  118. positionIndicator : function(h, n, e){
  119. var x = Ext.lib.Event.getPageX(e),
  120. r = Ext.lib.Dom.getRegion(n.firstChild),
  121. px,
  122. pt,
  123. py = r.top + this.proxyOffsets[1];
  124. if((r.right - x) &lt;= (r.right-r.left)/2){
  125. px = r.right+this.view.borderWidth;
  126. pt = &quot;after&quot;;
  127. }else{
  128. px = r.left;
  129. pt = &quot;before&quot;;
  130. }
  131. if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
  132. return false;
  133. }
  134. px += this.proxyOffsets[0];
  135. this.proxyTop.setLeftTop(px, py);
  136. this.proxyTop.show();
  137. if(!this.bottomOffset){
  138. this.bottomOffset = this.view.mainHd.getHeight();
  139. }
  140. this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
  141. this.proxyBottom.show();
  142. return pt;
  143. },
  144. onNodeEnter : function(n, dd, e, data){
  145. if(data.header != n){
  146. this.positionIndicator(data.header, n, e);
  147. }
  148. },
  149. onNodeOver : function(n, dd, e, data){
  150. var result = false;
  151. if(data.header != n){
  152. result = this.positionIndicator(data.header, n, e);
  153. }
  154. if(!result){
  155. this.proxyTop.hide();
  156. this.proxyBottom.hide();
  157. }
  158. return result ? this.dropAllowed : this.dropNotAllowed;
  159. },
  160. onNodeOut : function(n, dd, e, data){
  161. this.proxyTop.hide();
  162. this.proxyBottom.hide();
  163. },
  164. onNodeDrop : function(n, dd, e, data){
  165. var h = data.header;
  166. if(h != n){
  167. var cm = this.grid.colModel,
  168. x = Ext.lib.Event.getPageX(e),
  169. r = Ext.lib.Dom.getRegion(n.firstChild),
  170. pt = (r.right - x) &lt;= ((r.right-r.left)/2) ? &quot;after&quot; : &quot;before&quot;,
  171. oldIndex = this.view.getCellIndex(h),
  172. newIndex = this.view.getCellIndex(n);
  173. if(pt == &quot;after&quot;){
  174. newIndex++;
  175. }
  176. if(oldIndex &lt; newIndex){
  177. newIndex--;
  178. }
  179. cm.moveColumn(oldIndex, newIndex);
  180. return true;
  181. }
  182. return false;
  183. }
  184. });
  185. Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
  186. constructor : function(grid, hd){
  187. Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
  188. this.proxy.el.addClass('x-grid3-col-dd');
  189. },
  190. handleMouseDown : function(e){
  191. },
  192. callHandleMouseDown : function(e){
  193. Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
  194. }
  195. });</pre>
  196. </body>
  197. </html>