diff --git a/application/forms/BpConfigForm.php b/application/forms/BpConfigForm.php index 8a0bc95d..1abd9872 100644 --- a/application/forms/BpConfigForm.php +++ b/application/forms/BpConfigForm.php @@ -165,7 +165,7 @@ protected function onRequest() $this->bp->clearAppliedChanges(); $this->storage->deleteProcess($name); $this->setSuccessUrl('businessprocess'); - $this->redirectOnSuccess(sprintf('Process %s has been deleted', $name)); + $this->redirectOnSuccess(sprintf($this->translate('Process %s has been deleted'), $name)); } } } @@ -197,10 +197,10 @@ public function onSuccess() array('config' => $name, 'unlocked' => true) ) ); - $this->setSuccessMessage(sprintf('Process %s has been created', $name)); + $this->setSuccessMessage(sprintf($this->translate('Process %s has been created'), $name)); } else { $config = $this->bp; - $this->setSuccessMessage(sprintf('Process %s has been stored', $name)); + $this->setSuccessMessage(sprintf($this->translate('Process %s has been stored'), $name)); } $meta = $config->getMetadata(); foreach ($this->getValues() as $key => $value) { diff --git a/application/forms/BpUploadForm.php b/application/forms/BpUploadForm.php index a7467408..9327981f 100644 --- a/application/forms/BpUploadForm.php +++ b/application/forms/BpUploadForm.php @@ -198,7 +198,7 @@ public function onSuccess() } $this->storage->storeProcess($config); - Notification::success(sprintf('Process %s has been stored', $name)); + Notification::success(sprintf($this->translate('Process %s has been stored'), $name)); $this->getSuccessUrl()->setParam('config', $name); diff --git a/application/forms/CleanupNodeForm.php b/application/forms/CleanupNodeForm.php index c6e53982..cc5f1e20 100644 --- a/application/forms/CleanupNodeForm.php +++ b/application/forms/CleanupNodeForm.php @@ -45,15 +45,28 @@ public function onSuccess() { $changes = ProcessChanges::construct($this->bp, $this->session); + /** @var string[] $nodesToCleanup */ $nodesToCleanup = $this->getValue('cleanup_all') === '1' ? array_keys($this->bp->getMissingChildren()) : $this->getValue('nodes'); + $nodeName = null; foreach ($nodesToCleanup as $nodeName) { $node = $this->bp->getNode($nodeName); $changes->deleteNode($node); } + + $count = count($nodesToCleanup); + $this->setSuccessMessage(sprintf( + $this->translatePlural( + 'Successfully removed missing node %s', + 'Successfully removed %d missing nodes', + $count + ), + $count === 1 ? $nodeName : $count + )); + unset($changes); parent::onSuccess(); diff --git a/application/forms/DeleteNodeForm.php b/application/forms/DeleteNodeForm.php index dba0710c..70215067 100644 --- a/application/forms/DeleteNodeForm.php +++ b/application/forms/DeleteNodeForm.php @@ -98,9 +98,17 @@ public function onSuccess() switch ($confirm) { case 'yes': $changes->deleteNode($this->node, $this->parentNode === null ? null : $this->parentNode->getName()); + $this->setSuccessMessage(sprintf( + $this->translate('Node %s has been deleted'), + $this->node->getAlias() + )); break; case 'all': $changes->deleteNode($this->node); + $this->setSuccessMessage(sprintf( + $this->translate('All occurrences of node %s have been deleted'), + $this->node->getAlias() + )); break; case 'no': $this->setSuccessMessage($this->translate('Well, maybe next time')); diff --git a/application/forms/MoveNodeForm.php b/application/forms/MoveNodeForm.php index 81d15c78..0467e51e 100644 --- a/application/forms/MoveNodeForm.php +++ b/application/forms/MoveNodeForm.php @@ -151,7 +151,7 @@ public function onSuccess() // Trigger session destruction to make sure it get's stored. unset($changes); - $this->notifySuccess($this->getSuccessMessage($this->translate('Node order updated'))); + $this->notifySuccess($this->translate('Node order updated')); $response = $this->getRequest()->getResponse() ->setHeader('X-Icinga-Container', 'ignore') diff --git a/application/forms/ProcessForm.php b/application/forms/ProcessForm.php index 126fe9ba..1fa40ec2 100644 --- a/application/forms/ProcessForm.php +++ b/application/forms/ProcessForm.php @@ -143,7 +143,7 @@ public function onSuccess() Notification::success( sprintf( - 'Process %s has been modified', + $this->translate('Process %s has been modified'), $this->bp->getName() ) ); diff --git a/application/forms/SimulationForm.php b/application/forms/SimulationForm.php index 04a0f569..cabd859e 100644 --- a/application/forms/SimulationForm.php +++ b/application/forms/SimulationForm.php @@ -106,7 +106,7 @@ public function onSuccess() $state = $this->getValue('state'); if ($state !== null && ctype_digit($state)) { - $this->notifySuccess($this->translate('Simulation has been set')); + $this->setSuccessMessage($this->translate('Simulation has been set')); $this->simulation->set($nodeName, (object) array( 'state' => $this->getValue('state'), 'acknowledged' => $this->getValue('acknowledged'), @@ -114,7 +114,7 @@ public function onSuccess() )); } else { if ($this->simulation->remove($nodeName)) { - $this->notifySuccess($this->translate('Simulation has been removed')); + $this->setSuccessMessage($this->translate('Simulation has been removed')); } } diff --git a/library/Businessprocess/Web/Form/QuickBaseForm.php b/library/Businessprocess/Web/Form/QuickBaseForm.php index 36d134fd..2eb0db85 100644 --- a/library/Businessprocess/Web/Form/QuickBaseForm.php +++ b/library/Businessprocess/Web/Form/QuickBaseForm.php @@ -5,10 +5,13 @@ use Icinga\Application\Icinga; use Icinga\Application\Modules\Module; use ipl\Html\ValidHtml; +use ipl\I18n\Translation; use Zend_Form; abstract class QuickBaseForm extends Zend_Form implements ValidHtml { + use Translation; + /** * The Icinga module this form belongs to. Usually only set if the * form is initialized through the FormLoader @@ -154,13 +157,4 @@ protected function valueIsEmpty($value) return strlen($value) === 0; } - - public function translate($string) - { - if ($this->icingaModuleName === null) { - return t($string); - } else { - return mt($this->icingaModuleName, $string); - } - } } diff --git a/phpstan-baseline-standard.neon b/phpstan-baseline-standard.neon index d7aa531d..9a94a54e 100644 --- a/phpstan-baseline-standard.neon +++ b/phpstan-baseline-standard.neon @@ -630,11 +630,6 @@ parameters: count: 1 path: application/forms/BpUploadForm.php - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: application/forms/CleanupNodeForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\CleanupNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" count: 1 @@ -645,11 +640,6 @@ parameters: count: 1 path: application/forms/CleanupNodeForm.php - - - message: "#^Parameter \\#1 \\$name of method Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:getNode\\(\\) expects string, mixed given\\.$#" - count: 1 - path: application/forms/CleanupNodeForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\DeleteNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" count: 1 @@ -3955,16 +3945,6 @@ parameters: count: 1 path: library/Businessprocess/Web/Form/QuickBaseForm.php - - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has no return type specified\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/QuickBaseForm.php - - - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has parameter \\$string with no type specified\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/QuickBaseForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:valueIsEmpty\\(\\) has no return type specified\\.$#" count: 1 diff --git a/public/js/module.js b/public/js/module.js index 4855c9cc..e93accfd 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -122,7 +122,9 @@ ].join('&'); var $container = $source.closest('.container'); - icinga.loader.loadUrl(actionUrl, $container, data, 'POST'); + var icingaLoader = this.module.icinga.loader; + icingaLoader.loadUrl(actionUrl, $container, data, 'POST') + .done((_, __, req) => icingaLoader.processNotificationHeader(req)); } }, @@ -155,7 +157,10 @@ ].join('&'); var $container = $target.closest('.container'); - icinga.loader.loadUrl(actionUrl, $container, data, 'POST'); + var icingaLoader = this.module.icinga.loader; + icingaLoader.loadUrl(actionUrl, $container, data, 'POST') + .done((_, __, req) => icingaLoader.processNotificationHeader(req)); + event.stopPropagation(); } },