diff --git a/application/forms/AddNodeForm.php b/application/forms/AddNodeForm.php index 42778ca..2efa1b0 100644 --- a/application/forms/AddNodeForm.php +++ b/application/forms/AddNodeForm.php @@ -122,15 +122,20 @@ class AddNodeForm extends QuickForm ) )); + $display = 1; + if ($this->bp->getMetadata()->isManuallyOrdered() && !$this->bp->isEmpty()) { + $rootNodes = $this->bp->getRootNodes(); + $display = end($rootNodes)->getDisplay() + 1; + } $this->addElement('select', 'display', array( 'label' => $this->translate('Visualization'), 'required' => true, 'description' => $this->translate( 'Where to show this process' ), - 'value' => $this->hasParentNode() ? '0' : '1', + 'value' => $this->hasParentNode() ? '0' : "$display", 'multiOptions' => array( - '1' => $this->translate('Toplevel Process'), + "$display" => $this->translate('Toplevel Process'), '0' => $this->translate('Subprocess only'), ) )); diff --git a/application/forms/EditNodeForm.php b/application/forms/EditNodeForm.php index 5267c12..f1fd29c 100644 --- a/application/forms/EditNodeForm.php +++ b/application/forms/EditNodeForm.php @@ -126,15 +126,16 @@ class EditNodeForm extends QuickForm ) )); + $display = $this->getNode()->getDisplay() ?: 1; $this->addElement('select', 'display', array( 'label' => $this->translate('Visualization'), 'required' => true, 'description' => $this->translate( 'Where to show this process' ), - 'value' => $this->hasParentNode() ? '0' : '1', + 'value' => $display, 'multiOptions' => array( - '1' => $this->translate('Toplevel Process'), + "$display" => $this->translate('Toplevel Process'), '0' => $this->translate('Subprocess only'), ) )); diff --git a/application/forms/ProcessForm.php b/application/forms/ProcessForm.php index 9ee390d..bf233e4 100644 --- a/application/forms/ProcessForm.php +++ b/application/forms/ProcessForm.php @@ -73,14 +73,20 @@ class ProcessForm extends QuickForm ) )); + if ($this->node !== null) { + $display = $this->node->getDisplay() ?: 1; + } else { + $display = 1; + } $this->addElement('select', 'display', array( 'label' => $this->translate('Visualization'), 'required' => true, 'description' => $this->translate( 'Where to show this process' ), + 'value' => $display, 'multiOptions' => array( - '1' => $this->translate('Toplevel Process'), + "$display" => $this->translate('Toplevel Process'), '0' => $this->translate('Subprocess only'), ) )); @@ -97,7 +103,6 @@ class ProcessForm extends QuickForm $this->getElement('alias')->setValue($node->getAlias()); } $this->getElement('operator')->setValue($node->getOperator()); - $this->getElement('display')->setValue($node->getDisplay()); if ($node->hasInfoUrl()) { $this->getElement('url')->setValue($node->getInfoUrl()); } diff --git a/library/Businessprocess/Modification/NodeCreateAction.php b/library/Businessprocess/Modification/NodeCreateAction.php index e33c128..2e0fc6b 100644 --- a/library/Businessprocess/Modification/NodeCreateAction.php +++ b/library/Businessprocess/Modification/NodeCreateAction.php @@ -112,6 +112,15 @@ class NodeCreateAction extends NodeAction $node->$func($val); } + if ($node->getDisplay() > 1) { + $i = $node->getDisplay(); + foreach ($config->getRootNodes() as $_ => $rootNode) { + if ($rootNode->getDisplay() >= $node->getDisplay()) { + $rootNode->setDisplay(++$i); + } + } + } + $config->addNode($name, $node); return $node; diff --git a/library/Businessprocess/Modification/NodeRemoveAction.php b/library/Businessprocess/Modification/NodeRemoveAction.php index fd8aa2b..64d8901 100644 --- a/library/Businessprocess/Modification/NodeRemoveAction.php +++ b/library/Businessprocess/Modification/NodeRemoveAction.php @@ -66,7 +66,18 @@ class NodeRemoveAction extends NodeAction $name = $this->getNodeName(); $parentName = $this->getParentName(); if ($parentName === null) { + $oldDisplay = $config->getBpNode($name)->getDisplay(); $config->removeNode($name); + if ($config->getMetadata()->isManuallyOrdered()) { + foreach ($config->getRootNodes() as $_ => $node) { + $nodeDisplay = $node->getDisplay(); + if ($nodeDisplay > $oldDisplay) { + $node->setDisplay($node->getDisplay() - 1); + } elseif ($nodeDisplay === $oldDisplay) { + break; // Stop immediately to not make things worse ;) + } + } + } } else { $node = $config->getNode($name); $parent = $config->getBpNode($parentName);