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.

140 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"><span id='Ext-grid-GridDragZone'>/**
  19. </span> * @class Ext.grid.GridDragZone
  20. * @extends Ext.dd.DragZone
  21. * &lt;p&gt;A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
  22. * template methods of DragZone to enable dragging of the selected rows of a GridPanel.&lt;/p&gt;
  23. * &lt;p&gt;A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
  24. * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  25. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}&lt;/p&gt; are able
  26. * to process the {@link #getDragData data} which is provided.
  27. */
  28. Ext.grid.GridDragZone = function(grid, config){
  29. this.view = grid.getView();
  30. Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
  31. this.scroll = false;
  32. this.grid = grid;
  33. this.ddel = document.createElement('div');
  34. this.ddel.className = 'x-grid-dd-wrap';
  35. // prevent the default action, but don't stop propagation
  36. this.preventDefault = true;
  37. };
  38. Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
  39. ddGroup : &quot;GridDD&quot;,
  40. <span id='Ext-grid-GridDragZone-method-getDragData'> /**
  41. </span> * &lt;p&gt;The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.&lt;/p&gt;
  42. * &lt;p&gt;This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  43. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.&lt;/p&gt;
  44. * &lt;p&gt;The data object contains the following properties:&lt;ul&gt;
  45. * &lt;li&gt;&lt;b&gt;grid&lt;/b&gt; : Ext.Grid.GridPanel&lt;div class=&quot;sub-desc&quot;&gt;The GridPanel from which the data is being dragged.&lt;/div&gt;&lt;/li&gt;
  46. * &lt;li&gt;&lt;b&gt;ddel&lt;/b&gt; : htmlElement&lt;div class=&quot;sub-desc&quot;&gt;An htmlElement which provides the &quot;picture&quot; of the data being dragged.&lt;/div&gt;&lt;/li&gt;
  47. * &lt;li&gt;&lt;b&gt;rowIndex&lt;/b&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The index of the row which receieved the mousedown gesture which triggered the drag.&lt;/div&gt;&lt;/li&gt;
  48. * &lt;li&gt;&lt;b&gt;selections&lt;/b&gt; : Array&lt;div class=&quot;sub-desc&quot;&gt;Array of the selected Records which are being dragged from the GridPanel.
  49. * Unless a CellSelectionModel is being used and the grid is configured &lt;code&gt;dragCell: true&lt;/code&gt;, in which case, this will be
  50. * an Array containing the single selected cell data as &lt;code&gt;[rowIndex, cellIndex]&lt;/code&gt;.&lt;/div&gt;&lt;/li&gt;
  51. * &lt;/ul&gt;&lt;/p&gt;
  52. */
  53. getDragData : function(e){
  54. var t = Ext.lib.Event.getTarget(e),
  55. sm,
  56. rowIndex = this.view.findRowIndex(t),
  57. cellIndex,
  58. selectedCell,
  59. selection;
  60. if (rowIndex !== false){
  61. sm = this.grid.selModel;
  62. // Handle mousedown on unselected items (depending on what kind of selection we are using)
  63. // Select the mousedowned item
  64. if (sm.getSelectedCell) {
  65. cellIndex = this.view.findCellIndex(t);
  66. selectedCell = sm.getSelectedCell();
  67. if (!selectedCell || selectedCell[0] !== rowIndex || selectedCell[1] !== cellIndex) {
  68. sm.handleMouseDown(this.grid, rowIndex, cellIndex, e);
  69. }
  70. if (this.grid.dragCell) {
  71. // Selection is the cell coordinates
  72. selection = sm.getSelectedCell();
  73. if (!this.grid.hasOwnProperty('ddText')) {
  74. this.grid.ddText = '{0} selected cell{1}';
  75. }
  76. } else {
  77. // Selection is the mousedowned row
  78. selection = [this.grid.store.getAt(rowIndex)];
  79. }
  80. } else {
  81. if(!sm.isSelected(rowIndex) || e.hasModifier()){
  82. sm.handleMouseDown(this.grid, rowIndex, e);
  83. }
  84. selection = sm.getSelections();
  85. }
  86. return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: selection};
  87. }
  88. return false;
  89. },
  90. <span id='Ext-grid-GridDragZone-method-onInitDrag'> /**
  91. </span> * &lt;p&gt;The provided implementation of the onInitDrag method. Sets the &lt;tt&gt;innerHTML&lt;/tt&gt; of the drag proxy which provides the &quot;picture&quot;
  92. * of the data being dragged.&lt;/p&gt;
  93. * &lt;p&gt;The &lt;tt&gt;innerHTML&lt;/tt&gt; data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.&lt;/p&gt;
  94. */
  95. onInitDrag : function(e){
  96. var data = this.dragData;
  97. this.ddel.innerHTML = this.grid.getDragDropText();
  98. this.proxy.update(this.ddel);
  99. // fire start drag?
  100. },
  101. <span id='Ext-grid-GridDragZone-method-afterRepair'> /**
  102. </span> * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
  103. * the selected rows to show that they have not been dragged.
  104. */
  105. afterRepair : function(){
  106. this.dragging = false;
  107. },
  108. <span id='Ext-grid-GridDragZone-method-getRepairXY'> /**
  109. </span> * &lt;p&gt;An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.&lt;/p&gt;
  110. * &lt;p&gt;Called before a repair of an invalid drop to get the XY to animate to.&lt;/p&gt;
  111. * @param {EventObject} e The mouse up event
  112. * @return {Array} The xy location (e.g. [100, 200])
  113. */
  114. getRepairXY : function(e, data){
  115. return false;
  116. },
  117. onEndDrag : function(data, e){
  118. // fire end drag?
  119. },
  120. onValidDrop : function(dd, e, id){
  121. // fire drag drop?
  122. this.hideProxy();
  123. },
  124. beforeInvalidDrop : function(e, id){
  125. }
  126. });
  127. </pre>
  128. </body>
  129. </html>