mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-02-10 22:43:04 -05:00
js: Don't permit to create loops
This commit is contained in:
parent
493328ff20
commit
fe8f4d8c15
2 changed files with 16 additions and 6 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue