js: Don't permit to create loops

This commit is contained in:
Johannes Meyer 2019-01-16 13:38:30 +01:00
parent 493328ff20
commit fe8f4d8c15
2 changed files with 16 additions and 6 deletions

View file

@ -111,10 +111,11 @@ class TreeRenderer extends Renderer
*/
public function renderNode(BpConfig $bp, Node $node, $path = array())
{
$htmlId = $this->getId($node, $path);
$table = Html::tag(
'li',
[
'id' => $this->getId($node, $path),
'id' => $htmlId,
'class' => ['bp', 'movable', $node->getObjectClassName()],
'data-node-name' => $node->getName()
]
@ -169,7 +170,7 @@ class TreeRenderer extends Renderer
'data-sortable-draggable' => '.movable',
'data-sortable-direction' => 'vertical',
'data-sortable-group' => json_encode([
'name' => 'branch',
'name' => $htmlId, // Unique, so that the function below is the only deciding factor
'put' => 'function:rowPutAllowed'
]),
'data-csrf-token' => CsrfToken::generate(),

View file

@ -151,15 +151,24 @@
* @param from
* @param item
* @param event
* @returns {*}
* @returns boolean
*/
rowPutAllowed: function(to, from, item, event) {
if (from.options.group.name === 'root') {
return true;
}
if (to.options.group.name === 'root') {
return $(item).is('.process');
}
// Otherwise we're facing a nesting error next
var $item = $(item),
childrenNames = $item.find('.process').map(function () {
return $(this).data('nodeName');
}).get();
childrenNames.push($item.data('nodeName'));
var loopDetected = $(to.el).parents('.process').toArray().some(function (parent) {
return childrenNames.indexOf($(parent).data('nodeName')) !== -1;
});
return !loopDetected;
},
/**