Skip to content

Commit

Permalink
[BUGFIX] Move page correctly when droping page before another one
Browse files Browse the repository at this point in the history
Fixes an issue where drag and dropping page before a another one didn't
detect the previous page correctly. DataHandler always expect
us to put a node AFTER. So when we want to place a page before, we need
to find previous page and put the new on after it.

Now it correctly compares depth of the node mouse is over with a previous
node. Before it took a dragged node depth for a comparison, which was wrong.

Releases: master
Resolves: #84008
Change-Id: Ic43be1147a5bb0fc1e15943a5d9e235d10727a07
Reviewed-on: https://review.typo3.org/57809
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Kummer <typo3@enobe.de>
Tested-by: Joerg Kummer <typo3@enobe.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
  • Loading branch information
Progowi authored and tmotyl committed Aug 5, 2018
1 parent 932cf61 commit 96e3bbe
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ define([
)
) {
var options = _this.changeNodePosition({droppedNode: droppedNode});

var modalText = options.position === 'in' ? TYPO3.lang['mess.move_into'] : TYPO3.lang['mess.move_after'];
modalText = modalText.replace('%s', options.node.name).replace('%s', options.target.name);

Expand Down Expand Up @@ -673,10 +672,8 @@ define([
return;
}

tree.nodes.indexOf(tree.settings.nodeOver.node);

if (position === 'before') {
var positionAndTarget = this.setNodePositionAndTarget(tree.settings.nodeDrag.depth, index);
var positionAndTarget = this.setNodePositionAndTarget(index);
position = positionAndTarget[0];
target = positionAndTarget[1];
}
Expand All @@ -697,27 +694,30 @@ define([
/**
* Returns Array of position and target node
*
* @param {Integer} nodeDepth
* @param {Integer} index
* @param {Integer} index of node which is over mouse
* @returns {Array} [position, target]
*/
setNodePositionAndTarget: function(nodeDepth, index) {
setNodePositionAndTarget: function(index) {
var nodes = this.tree.nodes;
var nodeOver = nodes[index];
var nodeOverDepth = nodeOver.depth;
if (index > 0) {
index--;
}

var nodeBefore = nodes[index];
var nodeBeforeDepth = nodeBefore.depth;
var target = this.tree.nodes[index];

if (this.tree.nodes[index].depth === nodeDepth) {
if (nodeBeforeDepth === nodeOverDepth) {
return ['after', target];
} else if (this.tree.nodes[index].depth < nodeDepth) {
} else if (nodeBeforeDepth < nodeOverDepth) {
return ['in', target];
} else {
for (var i = index; i >= 0; i--) {
if (this.tree.nodes[i].depth === nodeDepth) {
if (nodes[i].depth === nodeOverDepth) {
return ['after', this.tree.nodes[i]];
} else if (this.tree.nodes[i].depth < nodeDepth) {
return ['in', this.tree.nodes[i]];
} else if (nodes[i].depth < nodeOverDepth) {
return ['in', nodes[i]];
}
}
}
Expand Down Expand Up @@ -778,7 +778,7 @@ define([
}

if (newNode.position === 'before') {
var positionAndTarget = this.setNodePositionAndTarget(this.tree.nodes[index].depth, index);
var positionAndTarget = this.setNodePositionAndTarget(index);
newNode.position = positionAndTarget[0];
newNode.target = positionAndTarget[1];
}
Expand Down

0 comments on commit 96e3bbe

Please sign in to comment.