diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index faf77770c..48f7acdb7 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -38,6 +38,28 @@ class Form extends Zend_Form */ const DEFAULT_SUFFIX = '_default'; + /** + * The type of the notification for the error + */ + const NOTIFICATION_ERROR = 0; + + /** + * The type of the notification for the warning + */ + const NOTIFICATION_WARNING = 2; + + /** + * The type of the notification for the info + */ + const NOTIFICATION_INFO = 4; + + /** + * The notifications of the form + * + * @var array + */ + protected $notifications = array(); + /** * Whether this form has been created * @@ -1009,6 +1031,7 @@ class Form extends Zend_Form } $this->addDecorator('FormErrors', array('onlyCustomFormErrors' => true)) + ->addDecorator('FormNotifications') ->addDecorator('FormDescriptions') ->addDecorator('FormElements') //->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')) @@ -1208,4 +1231,57 @@ class Form extends Zend_Form throw new SecurityException('No permission for %s', $permission); } } + + /** + * Return all form notifications + * + * @return array + */ + public function getNotifications() + { + return $this->notifications; + } + + /** + * Add a typed message to the notifications + * + * @param string $message The message which would be displayed to the user + * + * @param int $type The type of the message notification + */ + public function addNotification($message, $type = self::NOTIFICATION_ERROR) + { + $this->notifications[$message] = $type; + $this->markAsError(); + } + + /** + * Add a error message to notifications + * + * @param string $message + */ + public function error($message) + { + $this->addNotification($message, $type = self::NOTIFICATION_ERROR); + } + + /** + * Add a warning message to notifications + * + * @param string $message + */ + public function warning($message) + { + $this->addNotification($message, $type = self::NOTIFICATION_WARNING); + } + + /** + * Add a info message to notifications + * + * @param string $message + */ + public function info($message) + { + $this->addNotification($message, $type = self::NOTIFICATION_INFO); + } }