diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index ac67f495b..a466ed48f 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -6,6 +6,7 @@ use Icinga\Web\Url; use Icinga\Web\Widget\Tab; use Icinga\Application\Config; use Icinga\Forms\PreferenceForm; +use Icinga\Data\ConfigObject; use Icinga\User\Preferences\PreferencesStore; /** @@ -38,13 +39,16 @@ class PreferenceController extends BasePreferenceController */ public function indexAction() { - $storeConfig = Config::app()->getSection('preferences'); - + $config = Config::app()->getSection('global'); $user = $this->getRequest()->getUser(); + $form = new PreferenceForm(); $form->setPreferences($user->getPreferences()); - if ($storeConfig->get('store', 'ini') !== 'none') { - $form->setStore(PreferencesStore::create($storeConfig, $user)); + if ($config->get('config_backend', 'ini') !== 'none') { + $form->setStore(PreferencesStore::create(new ConfigObject(array( + 'store' => $config->get('config_backend', 'ini'), + 'resource' => $config->config_resource + )), $user)); } $form->handleRequest(); diff --git a/application/forms/Config/General/ApplicationConfigForm.php b/application/forms/Config/General/ApplicationConfigForm.php index 64f8855c8..618178344 100644 --- a/application/forms/Config/General/ApplicationConfigForm.php +++ b/application/forms/Config/General/ApplicationConfigForm.php @@ -7,7 +7,6 @@ use Icinga\Application\Icinga; use Icinga\Data\ResourceFactory; use Icinga\Web\Form; - /** * Form class to modify the general application configuration */ @@ -43,7 +42,7 @@ class ApplicationConfigForm extends Form $this->addElement( 'select', - 'preferences_store', + 'global_config_backend', array( 'required' => true, 'autosubmit' => true, @@ -55,7 +54,7 @@ class ApplicationConfigForm extends Form ) ) ); - if (isset($formData['preferences_store']) && $formData['preferences_store'] === 'db') { + if (isset($formData['global_config_backend']) && $formData['global_config_backend'] === 'db') { $backends = array(); foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) { if ($resource['type'] === 'db') { @@ -65,7 +64,7 @@ class ApplicationConfigForm extends Form $this->addElement( 'select', - 'preferences_resource', + 'global_config_resource', array( 'required' => true, 'multiOptions' => $backends, diff --git a/library/Icinga/Authentication/Manager.php b/library/Icinga/Authentication/Manager.php index fed012ab5..01173330a 100644 --- a/library/Icinga/Authentication/Manager.php +++ b/library/Icinga/Authentication/Manager.php @@ -6,6 +6,7 @@ namespace Icinga\Authentication; use Exception; use Icinga\Authentication\UserGroup\UserGroupBackend; use Icinga\Application\Config; +use Icinga\Data\ConfigObject; use Icinga\Exception\IcingaException; use Icinga\Exception\NotReadableError; use Icinga\Application\Logger; @@ -63,8 +64,11 @@ class Manager ); $config = new Config(); } - if ($config->get('preferences', 'store', 'ini') !== 'none') { - $preferencesConfig = $config->getSection('preferences'); + if ($config->get('global', 'config_backend', 'ini') !== 'none') { + $preferencesConfig = new ConfigObject(array( + 'store' => $config->get('global', 'config_backend', 'ini'), + 'resource' => $config->get('global', 'config_resource') + )); try { $preferencesStore = PreferencesStore::create( $preferencesConfig, diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 679091fde..e2ee66d0a 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -39,26 +39,19 @@ class Form extends Zend_Form const DEFAULT_SUFFIX = '_default'; /** - * The type of the notification for the error + * Identifier for notifications of type error */ - const NOTIFICATION_ERROR = 0; + const NOTIFICATION_ERROR = 0; /** - * The type of the notification for the warning + * Identifier for notifications of type warning */ - const NOTIFICATION_WARNING = 2; + const NOTIFICATION_WARNING = 1; /** - * The type of the notification for the info + * Identifier for notifications of type info */ - const NOTIFICATION_INFO = 4; - - /** - * The notifications of the form - * - * @var array - */ - protected $notifications = array(); + const NOTIFICATION_INFO = 2; /** * Whether this form has been created @@ -160,6 +153,13 @@ class Form extends Zend_Form */ protected $descriptions; + /** + * The notifications of this form + * + * @var array + */ + protected $notifications; + /** * Whether the Autosubmit decorator should be applied to this form * @@ -522,6 +522,50 @@ class Form extends Zend_Form return $this->descriptions; } + /** + * Set the notifications for this form + * + * @param array $notifications + * + * @return $this + */ + public function setNotifications(array $notifications) + { + $this->notifications = $notifications; + return $this; + } + + /** + * Add a notification for this form + * + * If $notification is an array the second value should be + * an array as well containing additional HTML properties. + * + * @param string|array $notification + * @param int $type + * + * @return $this + */ + public function addNotification($notification, $type) + { + $this->notifications[$type][] = $notification; + return $this; + } + + /** + * Return the notifications of this form + * + * @return array + */ + public function getNotifications() + { + if ($this->notifications === null) { + return array(); + } + + return $this->notifications; + } + /** * Set whether the Autosubmit decorator should be applied to this form * @@ -1264,55 +1308,48 @@ class Form extends Zend_Form } /** - * Return all form notifications + * Add a error notification and prevent the form from being successfully validated * - * @return array - */ - public function getNotifications() - { - return $this->notifications; - } - - /** - * Add a typed message to the notifications + * @param string|array $message The notfication's message * - * @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 + * @return $this */ public function error($message) { - $this->addNotification($message, $type = self::NOTIFICATION_ERROR); + $this->addNotification($message, self::NOTIFICATION_ERROR); + $this->markAsError(); + return $this; } /** - * Add a warning message to notifications + * Add a warning notification and prevent the form from being successfully validated * - * @param string $message + * @param string|array $message The notfication's message + * + * @return $this */ public function warning($message) { - $this->addNotification($message, $type = self::NOTIFICATION_WARNING); + $this->addNotification($message, self::NOTIFICATION_WARNING); + $this->markAsError(); + return $this; } /** - * Add a info message to notifications + * Add a info notification * - * @param string $message + * @param string|array $message The notfication's message + * @param bool $markAsError Whether to prevent the form from being successfully validated or not + * + * @return $this */ - public function info($message) + public function info($message, $markAsError = true) { - $this->addNotification($message, $type = self::NOTIFICATION_INFO); + $this->addNotification($message, self::NOTIFICATION_INFO); + if ($markAsError) { + $this->markAsError(); + } + + return $this; } } diff --git a/library/Icinga/Web/Form/Decorator/FormNotifications.php b/library/Icinga/Web/Form/Decorator/FormNotifications.php index ed725e625..935c0ce41 100644 --- a/library/Icinga/Web/Form/Decorator/FormNotifications.php +++ b/library/Icinga/Web/Form/Decorator/FormNotifications.php @@ -4,15 +4,16 @@ namespace Icinga\Web\Form\Decorator; use Zend_Form_Decorator_Abstract; -use Icinga\Web\Form as Form; +use Icinga\Exception\ProgrammingError; +use Icinga\Web\Form; /** - * Decorator to add a list of notifications at the top of a form + * Decorator to add a list of notifications at the top or bottom of a form */ class FormNotifications extends Zend_Form_Decorator_Abstract { /** - * Render form descriptions + * Render form notifications * * @param string $content The html rendered so far * @@ -31,16 +32,27 @@ class FormNotifications extends Zend_Form_Decorator_Abstract } $notifications = $this->recurseForm($form); - if (empty($notifications)) { return $content; } $html = '