Command forms: make the defaults of some checkboxes configurable

refs #11952
This commit is contained in:
Alexander A. Klimov 2016-12-07 16:53:53 +01:00
parent 4eb61c2bcf
commit 7253fbcfa4
5 changed files with 19 additions and 7 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Monitoring\Forms\Command\Object;
use DateTime; use DateTime;
use DateInterval; use DateInterval;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\AcknowledgeProblemCommand; use Icinga\Module\Monitoring\Command\Object\AcknowledgeProblemCommand;
use Icinga\Web\Notification; use Icinga\Web\Notification;
@ -40,6 +41,8 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
*/ */
public function createElements(array $formData = array()) public function createElements(array $formData = array())
{ {
$config = Config::module('monitoring');
$this->addElements(array( $this->addElements(array(
array( array(
'textarea', 'textarea',
@ -59,6 +62,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'persistent', 'persistent',
array( array(
'label' => $this->translate('Persistent Comment'), 'label' => $this->translate('Persistent Comment'),
'value' => (bool) $config->get('settings', 'acknowledge_persistent', false),
'description' => $this->translate( 'description' => $this->translate(
'If you would like the comment to remain even when the acknowledgement is removed, check this' 'If you would like the comment to remain even when the acknowledgement is removed, check this'
. ' option.' . ' option.'
@ -70,6 +74,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'expire', 'expire',
array( array(
'label' => $this->translate('Use Expire Time'), 'label' => $this->translate('Use Expire Time'),
'value' => (bool) $config->get('settings', 'acknowledge_expire', false),
'description' => $this->translate( 'description' => $this->translate(
'If the acknowledgement should expire, check this option.' 'If the acknowledgement should expire, check this option.'
), ),
@ -109,7 +114,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'sticky', 'sticky',
array( array(
'label' => $this->translate('Sticky Acknowledgement'), 'label' => $this->translate('Sticky Acknowledgement'),
'value' => false, 'value' => (bool) $config->get('settings', 'acknowledge_sticky', false),
'description' => $this->translate( 'description' => $this->translate(
'If you want the acknowledgement to remain until the host or service recovers even if the host' 'If you want the acknowledgement to remain until the host or service recovers even if the host'
. ' or service changes state, check this option.' . ' or service changes state, check this option.'
@ -121,7 +126,7 @@ class AcknowledgeProblemCommandForm extends ObjectsCommandForm
'notify', 'notify',
array( array(
'label' => $this->translate('Send Notification'), 'label' => $this->translate('Send Notification'),
'value' => true, 'value' => (bool) $config->get('settings', 'acknowledge_notify', true),
'description' => $this->translate( 'description' => $this->translate(
'If you do not want an acknowledgement notification to be sent out to the appropriate contacts,' 'If you do not want an acknowledgement notification to be sent out to the appropriate contacts,'
. ' uncheck this option.' . ' uncheck this option.'

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object; namespace Icinga\Module\Monitoring\Forms\Command\Object;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\AddCommentCommand; use Icinga\Module\Monitoring\Command\Object\AddCommentCommand;
use Icinga\Web\Notification; use Icinga\Web\Notification;
@ -53,7 +54,7 @@ class AddCommentCommandForm extends ObjectsCommandForm
'persistent', 'persistent',
array( array(
'label' => $this->translate('Persistent'), 'label' => $this->translate('Persistent'),
'value' => true, 'value' => (bool) Config::module('monitoring')->get('settings', 'comment_persistent', true),
'description' => $this->translate( 'description' => $this->translate(
'If you uncheck this option, the comment will automatically be deleted the next time Icinga is' 'If you uncheck this option, the comment will automatically be deleted the next time Icinga is'
. ' restarted.' . ' restarted.'

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object; namespace Icinga\Module\Monitoring\Forms\Command\Object;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\ScheduleHostCheckCommand; use Icinga\Module\Monitoring\Command\Object\ScheduleHostCheckCommand;
use Icinga\Web\Notification; use Icinga\Web\Notification;
@ -17,6 +18,8 @@ class ScheduleHostCheckCommandForm extends ScheduleServiceCheckCommandForm
*/ */
public function createElements(array $formData = array()) public function createElements(array $formData = array())
{ {
$config = Config::module('monitoring');
parent::createElements($formData); parent::createElements($formData);
$this->addElements(array( $this->addElements(array(
array( array(
@ -24,6 +27,7 @@ class ScheduleHostCheckCommandForm extends ScheduleServiceCheckCommandForm
'all_services', 'all_services',
array( array(
'label' => $this->translate('All Services'), 'label' => $this->translate('All Services'),
'value' => (bool) $config->get('settings', 'hostcheck_all_services', false),
'description' => $this->translate( 'description' => $this->translate(
'Schedule check for all services on the hosts and the hosts themselves.' 'Schedule check for all services on the hosts and the hosts themselves.'
) )

View File

@ -29,8 +29,7 @@ class ScheduleHostDowntimeCommandForm extends ScheduleServiceDowntimeCommandForm
'description' => $this->translate( 'description' => $this->translate(
'Schedule downtime for all services on the hosts and the hosts themselves.' 'Schedule downtime for all services on the hosts and the hosts themselves.'
), ),
'label' => $this->translate('All Services'), 'label' => $this->translate('All Services')
'value' => false
) )
); );

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object; namespace Icinga\Module\Monitoring\Forms\Command\Object;
use Icinga\Application\Config;
use Icinga\Module\Monitoring\Command\Object\SendCustomNotificationCommand; use Icinga\Module\Monitoring\Command\Object\SendCustomNotificationCommand;
use Icinga\Web\Notification; use Icinga\Web\Notification;
@ -34,6 +35,8 @@ class SendCustomNotificationCommandForm extends ObjectsCommandForm
*/ */
public function createElements(array $formData = array()) public function createElements(array $formData = array())
{ {
$config = Config::module('monitoring');
$this->addElements(array( $this->addElements(array(
array( array(
'textarea', 'textarea',
@ -53,7 +56,7 @@ class SendCustomNotificationCommandForm extends ObjectsCommandForm
'forced', 'forced',
array( array(
'label' => $this->translate('Forced'), 'label' => $this->translate('Forced'),
'value' => false, 'value' => (bool) $config->get('settings', 'custom_notification_forced', false),
'description' => $this->translate( 'description' => $this->translate(
'If you check this option, the notification is sent out regardless of time restrictions and' 'If you check this option, the notification is sent out regardless of time restrictions and'
. ' whether or not notifications are enabled.' . ' whether or not notifications are enabled.'
@ -68,7 +71,7 @@ class SendCustomNotificationCommandForm extends ObjectsCommandForm
'broadcast', 'broadcast',
array( array(
'label' => $this->translate('Broadcast'), 'label' => $this->translate('Broadcast'),
'value' => false, 'value' => (bool) $config->get('settings', 'custom_notification_broadcast', false),
'description' => $this->translate( 'description' => $this->translate(
'If you check this option, the notification is sent out to all normal and escalated contacts.' 'If you check this option, the notification is sent out to all normal and escalated contacts.'
) )