BUGFIX Checks if movedNode is in allowedChildren of newParent node before moving in tree (fixes #6578)

This commit is contained in:
Frank Mullenger 2011-04-06 09:50:20 +12:00 committed by Ingo Schommer
parent fcca1d454d
commit bde2696ff5

View File

@ -17,7 +17,6 @@
* @todo Automatic load of full subtree via ajax on node checkbox selection (minNodeCount = 0)
* to avoid doing partial selection with "hidden nodes" (unloaded markup)
* @todo Add siteTreeHints to field (as "data-hints" attribute with serialized JSON instead of javascript global variable)
* @todo Disallow drag'n'drop when not matching "allowedChildren" or "allowedParents" (see siteTreeHints)
* @todo Disallow drag'n'drop when node has "noChildren" set (see siteTreeHints)
* @todo Disallow moving of pages marked as deleted
* @todo Enforce sitetreeHints rules on page creation ("allowedChildren", "noChildren") -
@ -50,18 +49,26 @@
'initially_select': [this.find('.current').attr('id')]
},
"crrm": {
'move': {
'move': {
// Check if a node is allowed to be moved.
// Caution: Runs on every drag over a new node
'check_move': function(data) {
var movedNode = $(data.o), newParent = $(data.np),
isMovedOntoContainer = data.ot.get_container()[0] == data.np[0];
isMovedOntoContainer = data.ot.get_container()[0] == data.np[0],
movedNodeClass = movedNode.getClassname(),
newParentClass = newParent.getClassname(),
// Check allowedChildren of newParent or against root node rules
allowedChildren = siteTreeHints[newParentClass ? newParentClass : 'Root'].allowedChildren || [];
var isAllowed = (
// Don't allow moving the root node
movedNode.data('id') != 0
// Only allow moving node inside the root container, not before/after it
&& (!isMovedOntoContainer || data.p == 'inside')
// movedNode is allowed as a child
&& ($.inArray(movedNodeClass, allowedChildren) != -1)
);
return isAllowed;
}
}
@ -273,7 +280,7 @@
*/
getSelectedIDs: function() {
return $.map($(this).jstree('get_checked'), function(el, i) {return $(el).data('id');});
},
}
});
$('#sitetree_ul li').entwine({
@ -288,6 +295,16 @@
this.toggleClass('disabled', !(bool));
},
/**
* Function: getClassname
*
* Returns PHP class for this element. Useful to check business rules like valid drag'n'drop targets.
*/
getClassname: function() {
var matches = this.attr('class').match(/class-([^\s]*)/i);
return matches ? matches[1] : '';
},
/**
* Function: getID
*