From 13e4efa2217d380967a7de7990115025db2fa97a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Aug 2013 15:06:07 +0200 Subject: [PATCH 1/4] Make use of the helptext decorator if suitable Refactored some uses of the form element Note so that each one is properly attached to its input element. refs #4566 --- .../forms/Config/AuthenticationForm.php | 13 +- library/Icinga/Web/Form.php | 33 ++++++ .../forms/Command/AcknowledgeForm.php | 111 +++++------------- .../application/forms/Command/CommandForm.php | 50 -------- .../application/forms/Command/CommentForm.php | 44 ++----- .../forms/Command/CustomNotificationForm.php | 67 ++++------- .../forms/Command/DelayNotificationForm.php | 22 +--- .../forms/Command/RescheduleNextCheckForm.php | 46 ++------ .../forms/Command/ScheduleDowntimeForm.php | 105 ++++++----------- .../Command/SubmitPassiveCheckResultForm.php | 63 +++------- .../forms/Config/Backend/EditBackendForm.php | 18 +-- .../Config/Instance/EditInstanceForm.php | 11 +- .../forms/Command/ConfirmationFormTest.php | 15 --- 13 files changed, 172 insertions(+), 426 deletions(-) diff --git a/application/forms/Config/AuthenticationForm.php b/application/forms/Config/AuthenticationForm.php index 2532ebba9..0480fd941 100644 --- a/application/forms/Config/AuthenticationForm.php +++ b/application/forms/Config/AuthenticationForm.php @@ -30,11 +30,8 @@ namespace Icinga\Form\Config; use \Zend_Config; use \Icinga\Application\Config as IcingaConfig; -use \Icinga\Application\Icinga; use \Icinga\Application\Logger; -use \Icinga\Application\DbAdapterFactory; use \Icinga\Web\Form; -use \Icinga\Web\Form\Element\Note; use \Icinga\Web\Form\Decorator\ConditionalHidden; /** @@ -280,15 +277,7 @@ class AuthenticationForm extends Form $order = $this->getAuthenticationOrder(); foreach ($order as $name) { - $this->addElement( - new Note( - array( - 'escape' => false, - 'name' => 'title_backend_' . $name, - 'value' => '

Backend ' . $name . '

' - ) - ) - ); + $this->addNote('Backend ' . $name, 4); $this->addRemoveHint($this->filterName($name)); $backend = $this->config->get($name, null); if ($backend === null) { diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 2b7bf738f..54a5816cb 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -33,6 +33,7 @@ use \Zend_View_Interface; use \Icinga\Exception\ProgrammingError; use \Icinga\Web\Form\Decorator\HelpText; use \Icinga\Web\Form\InvalidCSRFTokenException; +use \Icinga\Web\Form\Element\Note; /** * Base class for forms providing CSRF protection, confirmation logic and auto submission @@ -94,6 +95,15 @@ abstract class Form extends Zend_Form */ private $cancelLabel; + /** + * Last used note-id + * + * Helper to generate unique names for note elements + * + * @var int + */ + private $last_note_id = 0; + /** * Getter for the session ID * @@ -259,6 +269,29 @@ abstract class Form extends Zend_Form $this->addElement($submitButton); } + /** + * Add message to form + * + * @param string $message The message to be displayed + * @param int $headingType Whether it should be displayed as heading (1-6) or not (null) + */ + public function addNote($message, $headingType = null) + { + $this->addElement( + new Note( + array( + 'escape' => $headingType === null ? false : true, + 'name' => sprintf('note_%s', $this->last_note_id++), + 'value' => $headingType === null ? $message : sprintf( + '%2$s', + $headingType, + $message + ) + ) + ) + ); + } + /** * Enable automatic form submission on the given elements * diff --git a/modules/monitoring/application/forms/Command/AcknowledgeForm.php b/modules/monitoring/application/forms/Command/AcknowledgeForm.php index 3c55abea7..95e0a8f2e 100644 --- a/modules/monitoring/application/forms/Command/AcknowledgeForm.php +++ b/modules/monitoring/application/forms/Command/AcknowledgeForm.php @@ -29,7 +29,6 @@ namespace Monitoring\Form\Command; use \Icinga\Web\Form\Element\DateTimePicker; -use \Icinga\Web\Form\Element\Note; use \Icinga\Protocol\Commandpipe\Acknowledgement; use \Icinga\Protocol\Commandpipe\Comment; use \Icinga\Util\DateTimeFactory; @@ -44,16 +43,11 @@ class AcknowledgeForm extends CommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t( - 'This command is used to acknowledge host or service problems. When a problem is ' - . 'acknowledged, future notifications about problems are temporarily disabled until the ' - . 'host/service changes from its current state.' - ) - ) + $this->addNote( + t( + 'This command is used to acknowledge host or service problems. When a problem is ' + . 'acknowledged, future notifications about problems are temporarily disabled until the ' + . 'host/service changes from its current state.' ) ); @@ -65,18 +59,11 @@ class AcknowledgeForm extends CommandForm array( 'label' => t('Comment'), 'rows' => 4, - 'required' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'commentnote', - 'value' => t( - ' If you work with other administrators you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) + 'required' => true, + 'helptext' => t( + ' If you work with other administrators you may find it useful to share information ' + . 'about a host or service that is having problems if more than one of you may be working on ' + . 'it. Make sure you enter a brief description of what you are doing.' ) ) ); @@ -85,18 +72,11 @@ class AcknowledgeForm extends CommandForm 'checkbox', 'persistent', array( - 'label' => t('Persistent Comment'), - 'value' => false - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'persistentnote', - 'value' => t( - 'If you would like the comment to remain even when the acknowledgement is removed, ' - . 'check this option.' - ) + 'label' => t('Persistent Comment'), + 'value' => false, + 'helptext' => t( + 'If you would like the comment to remain even when the acknowledgement is removed, ' + . 'check this option.' ) ) ); @@ -105,34 +85,21 @@ class AcknowledgeForm extends CommandForm 'checkbox', 'expire', array( - 'label' => t('Use Expire Time') + 'label' => t('Use Expire Time'), + 'helptext' => t('If the acknowledgement should expire, check this option.') ) ); $this->enableAutoSubmit(array('expire')); - $this->addElement( - new Note( - array( - 'name' => 'expirenote', - 'value' => t('If the acknowledgement should expire, check this option.') - ) - ) - ); + if ($this->getRequest()->getPost('expire', '0') === '1') { $now = DateTimeFactory::create(); $this->addElement( new DateTimePicker( array( - 'name' => 'expiretime', - 'label' => t('Expire Time'), - 'value' => $now->getTimestamp() + 3600 - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'expiretimenote', - 'value' => t( + 'name' => 'expiretime', + 'label' => t('Expire Time'), + 'value' => $now->getTimestamp() + 3600, + 'helptext' => t( 'Enter the expire date/time for this acknowledgement here. Icinga will ' . ' delete the acknowledgement after this date expired.' ) @@ -145,18 +112,11 @@ class AcknowledgeForm extends CommandForm 'checkbox', 'sticky', array( - 'label' => t('Sticky Acknowledgement'), - 'value' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'stickynote', - 'value' => t( - 'If you want the acknowledgement to disable notifications until the host/service ' - . 'recovers, check this option.' - ) + 'label' => t('Sticky Acknowledgement'), + 'value' => true, + 'helptext' => t( + 'If you want the acknowledgement to disable notifications until the host/service ' + . 'recovers, check this option.' ) ) ); @@ -165,18 +125,11 @@ class AcknowledgeForm extends CommandForm 'checkbox', 'notify', array( - 'label' => t('Send Notification'), - 'value' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'sendnotificationnote', - 'value' => t( - 'If you do not want an acknowledgement notification to be sent out to the appropriate ' - . 'contacts, uncheck this option.' - ) + 'label' => t('Send Notification'), + 'value' => true, + 'helptext' => t( + 'If you do not want an acknowledgement notification to be sent out to the appropriate ' + . 'contacts, uncheck this option.' ) ) ); diff --git a/modules/monitoring/application/forms/Command/CommandForm.php b/modules/monitoring/application/forms/Command/CommandForm.php index 3c6004ea3..4d09ac6f0 100644 --- a/modules/monitoring/application/forms/Command/CommandForm.php +++ b/modules/monitoring/application/forms/Command/CommandForm.php @@ -29,51 +29,13 @@ namespace Monitoring\Form\Command; use Icinga\Web\Form; -use Icinga\Web\Form\Element\Note; use \Zend_Form_Element_Hidden; -use \Zend_Validate_Date; /** * Simple confirmation command */ class CommandForm extends Form { - /** - * Array of messages - * - * @var string[] - */ - private $notes = array(); - - /** - * Add message to stack - * - * @param string $message - */ - public function addNote($message) - { - $this->notes[] = $message; - } - - /** - * Purge messages from stack - * - */ - public function clearNotes() - { - $this->notes = array(); - } - - /** - * Getter for notes - * - * @return string[] - */ - public function getNotes() - { - return $this->notes; - } - /** * Create an instance name containing hidden field * @return Zend_Form_Element_Hidden @@ -93,18 +55,6 @@ class CommandForm extends Form */ protected function create() { - if (count($this->getNotes())) { - foreach ($this->getNotes() as $nodeid => $note) { - $element = new Note( - array( - 'name' => 'note_'. $nodeid, - 'value' => $note - ) - ); - $this->addElement($element); - } - } - $this->addElement($this->createInstanceHiddenField()); } diff --git a/modules/monitoring/application/forms/Command/CommentForm.php b/modules/monitoring/application/forms/Command/CommentForm.php index ec9a1a7bf..28f79f444 100644 --- a/modules/monitoring/application/forms/Command/CommentForm.php +++ b/modules/monitoring/application/forms/Command/CommentForm.php @@ -28,7 +28,6 @@ namespace Monitoring\Form\Command; -use \Icinga\Web\Form\Element\Note; use \Icinga\Protocol\Commandpipe\Comment; /** @@ -41,14 +40,7 @@ class CommentForm extends CommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t('This command is used to add a comment to hosts or services.') - ) - ) - ); + $this->addNote(t('This command is used to add a comment to hosts or services.')); $this->addElement($this->createAuthorField()); @@ -58,18 +50,11 @@ class CommentForm extends CommandForm array( 'label' => t('Comment'), 'rows' => 4, - 'required' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'commentnote', - 'value' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) + 'required' => true, + 'helptext' => t( + 'If you work with other administrators, you may find it useful to share information ' + . 'about a host or service that is having problems if more than one of you may be working on ' + . 'it. Make sure you enter a brief description of what you are doing.' ) ) ); @@ -78,18 +63,11 @@ class CommentForm extends CommandForm 'checkbox', 'persistent', array( - 'label' => t('Persistent'), - 'value' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'persistentnote', - 'value' => t( - 'If you uncheck this option, the comment will automatically be deleted the next time ' - . 'Icinga is restarted.' - ) + 'label' => t('Persistent'), + 'value' => true, + 'helptext' => t( + 'If you uncheck this option, the comment will automatically be deleted the next time ' + . 'Icinga is restarted.' ) ) ); diff --git a/modules/monitoring/application/forms/Command/CustomNotificationForm.php b/modules/monitoring/application/forms/Command/CustomNotificationForm.php index a14fad112..44166933f 100644 --- a/modules/monitoring/application/forms/Command/CustomNotificationForm.php +++ b/modules/monitoring/application/forms/Command/CustomNotificationForm.php @@ -28,7 +28,6 @@ namespace Monitoring\Form\Command; -use \Icinga\Web\Form\Element\Note; use \Icinga\Protocol\Commandpipe\CustomNotification; /** @@ -41,16 +40,11 @@ class CustomNotificationForm extends CommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t( - 'This command is used to send a custom notification about hosts or services. Useful in ' - . 'emergencies when you need to notify admins of an issue regarding a monitored system or ' - . 'service.' - ) - ) + $this->addNote( + t( + 'This command is used to send a custom notification about hosts or services. Useful in ' + . 'emergencies when you need to notify admins of an issue regarding a monitored system or ' + . 'service.' ) ); @@ -62,18 +56,11 @@ class CustomNotificationForm extends CommandForm array( 'label' => t('Comment'), 'rows' => 4, - 'required' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'commentnote', - 'value' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) + 'required' => true, + 'helptext' => t( + 'If you work with other administrators, you may find it useful to share information ' + . 'about a host or service that is having problems if more than one of you may be working on ' + . 'it. Make sure you enter a brief description of what you are doing.' ) ) ); @@ -82,18 +69,11 @@ class CustomNotificationForm extends CommandForm 'checkbox', 'forced', array( - 'label' => t('Forced') - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'forcenote', - 'value' => t( - 'Custom notifications normally follow the regular notification logic in Icinga. Selecting this ' - . 'option will force the notification to be sent out, regardless of time restrictions, ' - . 'whether or not notifications are enabled, etc.' - ) + 'label' => t('Forced'), + 'helptext' => t( + 'Custom notifications normally follow the regular notification logic in Icinga. Selecting this ' + . 'option will force the notification to be sent out, regardless of time restrictions, ' + . 'whether or not notifications are enabled, etc.' ) ) ); @@ -102,18 +82,11 @@ class CustomNotificationForm extends CommandForm 'checkbox', 'broadcast', array( - 'label' => t('Broadcast') - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'broadcastnote', - 'value' => t( - 'Selecting this option causes the notification to be sent out to all normal (non-escalated) ' - . ' and escalated contacts. These options allow you to override the normal notification logic ' - . 'if you need to get an important message out.' - ) + 'label' => t('Broadcast'), + 'helptext' => t( + 'Selecting this option causes the notification to be sent out to all normal (non-escalated) ' + . ' and escalated contacts. These options allow you to override the normal notification logic ' + . 'if you need to get an important message out.' ) ) ); diff --git a/modules/monitoring/application/forms/Command/DelayNotificationForm.php b/modules/monitoring/application/forms/Command/DelayNotificationForm.php index b44bbdcf1..acf15b445 100644 --- a/modules/monitoring/application/forms/Command/DelayNotificationForm.php +++ b/modules/monitoring/application/forms/Command/DelayNotificationForm.php @@ -28,8 +28,6 @@ namespace Monitoring\Form\Command; -use \Icinga\Web\Form\Element\Note; - /** * Form for the delay notification command */ @@ -45,14 +43,8 @@ class DelayNotificationForm extends CommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t('This command is used to delay the next problem notification that is sent out.') - ) - ) - ); + $this->addNote(t('This command is used to delay the next problem notification that is sent out.')); + $this->addElement( 'text', 'minutes', @@ -70,15 +62,13 @@ class DelayNotificationForm extends CommandForm 'max' => self::MAX_DELAY ) ) + ), + 'helptext' => t( + 'The notification delay will be disregarded if the host/service changes state before the next ' + . 'notification is scheduled to be sent out.' ) ) ); - $this->addNote( - t( - 'The notification delay will be disregarded if the host/service changes state before the next ' - . 'notification is scheduled to be sent out.' - ) - ); $this->setSubmitLabel(t('Delay Notification')); diff --git a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php index 235124bc2..fd01d7e31 100644 --- a/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php +++ b/modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php @@ -31,7 +31,6 @@ namespace Monitoring\Form\Command; use \Zend_Form_Element_Checkbox; use \Icinga\Web\Form\Element\DateTimePicker; use \Icinga\Util\DateTimeFactory; -use \Icinga\Web\Form\Element\Note; /** * Form for scheduling checks @@ -43,33 +42,21 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t( - 'This command is used to schedule the next check of hosts/services. Icinga will re-queue the ' - . 'check at the time you specify.' - ) - ) + $this->addNote( + t( + 'This command is used to schedule the next check of hosts/services. Icinga will re-queue the ' + . 'check at the time you specify.' ) ); $this->addElement( new DateTimePicker( array( - 'name' => 'checktime', - 'label' => t('Check Time'), - 'value' => DateTimeFactory::create()->getTimestamp(), - 'required' => !$this->getRequest()->getPost('forcecheck') - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'checktimenote', - 'value' => t('Set the date/time when this check should be executed.') + 'name' => 'checktime', + 'label' => t('Check Time'), + 'value' => DateTimeFactory::create()->getTimestamp(), + 'required' => !$this->getRequest()->getPost('forcecheck'), + 'helptext' => t('Set the date/time when this check should be executed.') ) ) ); @@ -77,17 +64,10 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm $this->addElement( new Zend_Form_Element_Checkbox( array( - 'name' => 'forcecheck', - 'label' => t('Force Check'), - 'value' => true - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'forcechecknote', - 'value' => t( + 'name' => 'forcecheck', + 'label' => t('Force Check'), + 'value' => true, + 'helptext' => t( 'If you select this option, Icinga will force a check regardless of both what time the ' . 'scheduled check occurs and whether or not checks are enabled.' ) diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php index 7304ab3e2..d5772a8d9 100644 --- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php +++ b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php @@ -35,7 +35,6 @@ use \Icinga\Web\Form\Element\DateTimePicker; use \Icinga\Protocol\Commandpipe\Downtime; use \Icinga\Protocol\Commandpipe\Comment; use \Icinga\Util\DateTimeFactory; -use \Icinga\Web\Form\Element\Note; /** * Form for scheduling downtimes @@ -78,17 +77,12 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t( - 'This command is used to schedule downtime for hosts/services. During the specified downtime, ' - . 'Icinga will not send notifications out about the affected objects. When the scheduled ' - . 'downtime expires, Icinga will send out notifications as it normally would. Scheduled ' - . 'downtimes are preserved across program shutdowns and restarts.' - ) - ) + $this->addNote( + t( + 'This command is used to schedule downtime for hosts/services. During the specified downtime, ' + . 'Icinga will not send notifications out about the affected objects. When the scheduled ' + . 'downtime expires, Icinga will send out notifications as it normally would. Scheduled ' + . 'downtimes are preserved across program shutdowns and restarts.' ) ); @@ -100,18 +94,11 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm array( 'label' => t('Comment'), 'rows' => 4, - 'required' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'commentnote', - 'value' => t( - 'If you work with other administrators, you may find it useful to share information ' - . 'about a host or service that is having problems if more than one of you may be working on ' - . 'it. Make sure you enter a brief description of what you are doing.' - ) + 'required' => true, + 'helptext' => t( + 'If you work with other administrators, you may find it useful to share information ' + . 'about a host or service that is having problems if more than one of you may be working on ' + . 'it. Make sure you enter a brief description of what you are doing.' ) ) ); @@ -147,34 +134,20 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm $this->addElement( new DateTimePicker( array( - 'name' => 'starttime', - 'label' => t('Start Time'), - 'value' => $now->getTimestamp() - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'stattimenote', - 'value' => t('Set the start date/time for the downtime.') + 'name' => 'starttime', + 'label' => t('Start Time'), + 'value' => $now->getTimestamp(), + 'helptext' => t('Set the start date/time for the downtime.') ) ) ); $this->addElement( new DateTimePicker( array( - 'name' => 'endtime', - 'label' => t('End Time'), - 'value' => $now->getTimestamp() + 3600 - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'endtimenote', - 'value' => t('Set the end date/time for the downtime.') + 'name' => 'endtime', + 'label' => t('End Time'), + 'value' => $now->getTimestamp() + 3600, + 'helptext' => t('Set the end date/time for the downtime.') ) ) ); @@ -183,10 +156,10 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm 'select', 'type', array( - 'label' => t('Downtime Type'), - 'multiOptions' => $this->getDowntimeTypeOptions(), - 'required' => true, - 'validators' => array( + 'label' => t('Downtime Type'), + 'multiOptions' => $this->getDowntimeTypeOptions(), + 'required' => true, + 'validators' => array( array( 'InArray', true, @@ -194,19 +167,12 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm array_keys($this->getDowntimeTypeOptions()) ) ) - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'typenote', - 'value' => t( - 'If you select the fixed option, the downtime will be in effect between the start and end ' - . 'times you specify whereas a flexible downtime starts when the service enters a non-OK state ' - . '(sometime between the start and end times you specified) and lasts as long as the duration ' - . 'of time you enter. The duration fields do not apply for fixed downtime.' - ) + ), + 'helptext' => t( + 'If you select the fixed option, the downtime will be in effect between the start and end ' + . 'times you specify whereas a flexible downtime starts when the service enters a non-OK state ' + . '(sometime between the start and end times you specified) and lasts as long as the duration ' + . 'of time you enter. The duration fields do not apply for fixed downtime.' ) ) ); @@ -242,15 +208,10 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm ) ); $this->addElements(array($hoursText, $minutesText)); - $this->addElement( - new Note( - array( - 'name' => 'flexiblenote', - 'value' => t( - 'Enter here the duration of the downtime. Icinga will automatically delete the downtime ' - . 'after this time expired.' - ) - ) + $this->addNote( + t( + 'Enter here the duration of the downtime. Icinga will automatically delete the downtime ' + . 'after this time expired.' ) ); } diff --git a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php index 418be69ad..68f7317da 100644 --- a/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php +++ b/modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php @@ -29,7 +29,6 @@ namespace Monitoring\Form\Command; use \Icinga\Exception\ProgrammingError; -use \Icinga\Web\Form\Element\Note; /** * Form for submitting passive check results @@ -125,16 +124,11 @@ class SubmitPassiveCheckResultForm extends CommandForm */ protected function create() { - $this->addElement( - new Note( - array( - 'name' => 'commanddescription', - 'value' => t( - 'This command is used to submit a passive check result for particular hosts/services. It is ' - . 'particularly useful for resetting security-related objects to OK states once they have been ' - . 'dealt with.' - ) - ) + $this->addNote( + t( + 'This command is used to submit a passive check result for particular hosts/services. It is ' + . 'particularly useful for resetting security-related objects to OK states once they have been ' + . 'dealt with.' ) ); @@ -142,10 +136,10 @@ class SubmitPassiveCheckResultForm extends CommandForm 'select', 'pluginstate', array( - 'label' => t('Check Result'), - 'multiOptions' => $this->getOptions(), - 'required' => true, - 'validators' => array( + 'label' => t('Check Result'), + 'multiOptions' => $this->getOptions(), + 'required' => true, + 'validators' => array( array( 'Digits', true @@ -157,15 +151,8 @@ class SubmitPassiveCheckResultForm extends CommandForm array_keys($this->getOptions()) ) ) - ) - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'checkresultnote', - 'value' => t('Set the state which should be send to Icinga for this objects.') - ) + ), + 'helptext' => t('Set the state which should be send to Icinga for this objects.') ) ); @@ -173,17 +160,10 @@ class SubmitPassiveCheckResultForm extends CommandForm 'textarea', 'checkoutput', array( - 'label' => t('Check Output'), - 'rows' => 2, - 'required' => true - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'checkoutputnote', - 'value' => t('Fill in the check output string which should be send to Icinga.') - ) + 'label' => t('Check Output'), + 'rows' => 2, + 'required' => true, + 'helptext' => t('Fill in the check output string which should be send to Icinga.') ) ); @@ -191,16 +171,9 @@ class SubmitPassiveCheckResultForm extends CommandForm 'textarea', 'performancedata', array( - 'label' => t('Performance Data'), - 'rows' => 2 - ) - ); - $this->addElement( - new Note( - array( - 'name' => 'performancedatanote', - 'value' => t('Fill in the performance data string which should be send to Icinga.') - ) + 'label' => t('Performance Data'), + 'rows' => 2, + 'helptext' => t('Fill in the performance data string which should be send to Icinga.') ) ); diff --git a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php index da7337c6e..fa66f8104 100644 --- a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php +++ b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php @@ -29,14 +29,9 @@ namespace Monitoring\Form\Config\Backend; use \Zend_Config; - -use \Icinga\Application\Config as IcingaConfig; -use \Icinga\Application\Icinga; -use \Icinga\Application\Logger; -use \Icinga\Application\DbAdapterFactory; - use \Icinga\Web\Form; -use \Icinga\Web\Form\Element\Note; +use \Icinga\Application\Icinga; +use \Icinga\Application\DbAdapterFactory; /** * Form for modifying a monitoring backend @@ -249,14 +244,7 @@ class EditBackendForm extends Form break; default: $this->removeElement('backend_type'); - $this->addElement( - new Note( - array( - 'name' => 'error_note', - 'value' => 'Unknown Backend Type "' . $this->backend->type. '"' - ) - ) - ); + $this->addNote('Unknown Backend Type "' . $this->backend->type. '"'); return; } $this->addDisableButton(); diff --git a/modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php b/modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php index e47268e8d..f04084941 100644 --- a/modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php +++ b/modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php @@ -31,7 +31,6 @@ namespace Monitoring\Form\Config\Instance; use \Zend_Config; use \Icinga\Web\Form; -use \Icinga\Web\Form\Element\Note; /** * Form for editing existing instances @@ -91,14 +90,8 @@ class EditInstanceForm extends Form */ private function addRemoteInstanceForm() { - $this->addElement( - new Note( - array( - 'name' => 'note_ssh_info', - 'value' => 'When configuring a remote host, you need to setup passwordless key authentication' - ) - ) - ); + $this->addNote('When configuring a remote host, you need to setup passwordless key authentication'); + $this->addElement( 'text', 'instance_remote_host', diff --git a/modules/monitoring/test/php/application/forms/Command/ConfirmationFormTest.php b/modules/monitoring/test/php/application/forms/Command/ConfirmationFormTest.php index 53434bb0a..8d003cad0 100644 --- a/modules/monitoring/test/php/application/forms/Command/ConfirmationFormTest.php +++ b/modules/monitoring/test/php/application/forms/Command/ConfirmationFormTest.php @@ -8,7 +8,6 @@ require_once __DIR__. '/../../../../../application/forms/Command/CommandForm.php use \Zend_View; -use \Zend_Test_PHPUnit_ControllerTestCase; use \Test\Icinga\Web\Form\BaseFormTest; use Monitoring\Form\Command\CommandForm; @@ -32,18 +31,4 @@ class CommandFormTest extends BaseFormTest $this->assertContains('444 NOTE 1', $content); $this->assertContains('555 NOTE 2', $content); } - - public function testFormNotes() - { - $form = new CommandForm(); - $form->addNote('test1'); - $form->addNote('test2'); - - $reference = array('test1', 'test2'); - $this->assertCount(2, $form->getNotes()); - $this->assertEquals($reference, $form->getNotes()); - - $form->clearNotes(); - $this->assertCount(0, $form->getNotes()); - } } From 4c79b3d17923f0c3ff483a28a2b6a95a0c6563c4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Aug 2013 15:07:18 +0200 Subject: [PATCH 2/4] Fix use of non-initialised variable --- application/views/helpers/FormDateTime.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/views/helpers/FormDateTime.php b/application/views/helpers/FormDateTime.php index 659f38d35..bc9c5650b 100644 --- a/application/views/helpers/FormDateTime.php +++ b/application/views/helpers/FormDateTime.php @@ -25,7 +25,6 @@ */ // {{{ICINGA_LICENSE_HEADER}}} -use \DateTime; use \Zend_View_Helper_FormElement; /** @@ -63,7 +62,7 @@ class Zend_View_Helper_FormDateTime extends Zend_View_Helper_FormElement // Build the element $xhtml = '
' . '_htmlAttribs($attribs) From 7fab739efd8570ae38c65f1b780dff729f99725a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 28 Aug 2013 09:08:37 +0200 Subject: [PATCH 3/4] Fix styles in Form.php refs #4566 --- library/Icinga/Web/Form.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 54a5816cb..ecb750a7b 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -272,17 +272,17 @@ abstract class Form extends Zend_Form /** * Add message to form * - * @param string $message The message to be displayed - * @param int $headingType Whether it should be displayed as heading (1-6) or not (null) + * @param string $message The message to be displayed + * @param int $headingType Whether it should be displayed as heading (1-6) or not (null) */ public function addNote($message, $headingType = null) { $this->addElement( new Note( array( - 'escape' => $headingType === null ? false : true, - 'name' => sprintf('note_%s', $this->last_note_id++), - 'value' => $headingType === null ? $message : sprintf( + 'escape' => $headingType === null ? false : true, + 'name' => sprintf('note_%s', $this->last_note_id++), + 'value' => $headingType === null ? $message : sprintf( '%2$s', $headingType, $message From 4527aaf57a0322debbc68efaf52e420929138091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Mo=C3=9Fhammer?= Date: Wed, 28 Aug 2013 14:42:31 +0200 Subject: [PATCH 4/4] Smaller fixes in phpdoc style refs #4566 --- library/Icinga/Web/Form.php | 10 +++++----- .../application/forms/Command/CommandForm.php | 4 +++- .../forms/Command/CustomNotificationForm.php | 2 +- .../application/forms/Command/ScheduleDowntimeForm.php | 3 ++- .../forms/Config/Backend/EditBackendForm.php | 1 - 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index ecb750a7b..b530f3a4a 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -297,9 +297,9 @@ abstract class Form extends Zend_Form * * Enables automatic submission of this form once the user edits specific elements * - * @param array $triggerElements The element names which should auto-submit the form + * @param array $triggerElements The element names which should auto-submit the form * - * @throws ProgrammingError When an element is found which does not yet exist + * @throws ProgrammingError When an element is found which does not yet exist */ final public function enableAutoSubmit($triggerElements) { @@ -355,7 +355,7 @@ abstract class Form extends Zend_Form * * This method should be used for testing purposes only * - * @param bool $disabled + * @param bool $disabled Set true in order to disable CSRF tokens in this form (default: true), otherwise false * * @see tokenDisabled */ @@ -388,9 +388,9 @@ abstract class Form extends Zend_Form /** * Test the submitted data for a correct CSRF token * - * @param array $checkData The POST data send by the user + * @param array $checkData The POST data send by the user * - * @throws InvalidCSRFTokenException When CSRF Validation fails + * @throws InvalidCSRFTokenException When CSRF Validation fails */ final public function assertValidCsrfToken(array $checkData) { diff --git a/modules/monitoring/application/forms/Command/CommandForm.php b/modules/monitoring/application/forms/Command/CommandForm.php index 4d09ac6f0..be36ba734 100644 --- a/modules/monitoring/application/forms/Command/CommandForm.php +++ b/modules/monitoring/application/forms/Command/CommandForm.php @@ -38,6 +38,7 @@ class CommandForm extends Form { /** * Create an instance name containing hidden field + * * @return Zend_Form_Element_Hidden */ private function createInstanceHiddenField() @@ -60,7 +61,8 @@ class CommandForm extends Form /** * Get the author name - + * + * @return string */ protected function getAuthorName() { diff --git a/modules/monitoring/application/forms/Command/CustomNotificationForm.php b/modules/monitoring/application/forms/Command/CustomNotificationForm.php index 44166933f..c4c5fbfd9 100644 --- a/modules/monitoring/application/forms/Command/CustomNotificationForm.php +++ b/modules/monitoring/application/forms/Command/CustomNotificationForm.php @@ -99,7 +99,7 @@ class CustomNotificationForm extends CommandForm /** * Create Custom Notification from request data * - * @return \Icinga\Protocol\Commandpipe\CustomNotification + * @return CustomNotification */ public function getCustomNotification() { diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php index d5772a8d9..c7b9c6d65 100644 --- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php +++ b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php @@ -258,8 +258,9 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm /** * Change validators at runtime * + * @param array $data The user provided data that will go into validation + * * @see Form::preValidation - * @param array $data */ protected function preValidation(array $data) { diff --git a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php index fa66f8104..8694c493e 100644 --- a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php +++ b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php @@ -83,7 +83,6 @@ class EditBackendForm extends Form /** * Set a custom array of resources to be used in this form instead of the ones from DbAdapterFactory * (used for testing) - * */ public function setResources($resources) {