From 9a21d76aad7e35cd62c38147db3c92f94cd50121 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 4 Nov 2010 15:38:03 -0600 Subject: [PATCH] Better error handling when updating prefs. --- framework/Core/lib/Horde/Core/Prefs/Ui.php | 29 +++++++++++++++++++++++++---- horde/templates/prefs/error_end.html | 5 +++++ horde/templates/prefs/error_start.html | 2 ++ horde/themes/screen.css | 12 ++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 horde/templates/prefs/error_end.html create mode 100644 horde/templates/prefs/error_start.html diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui.php b/framework/Core/lib/Horde/Core/Prefs/Ui.php index 1a1fab01b..d160bc4d7 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui.php @@ -91,6 +91,13 @@ class Horde_Core_Prefs_Ui public $nobuttons = false; /** + * List of update errors. + * + * @var array + */ + protected $_errors = array(); + + /** * Constructor. * * @param Horde_Variables $vars Form variables. @@ -254,7 +261,7 @@ class Horde_Core_Prefs_Ui if (isset($enum[$this->vars->$pref])) { $updated |= $save->setValue($pref, $this->vars->$pref); } else { - $notification->push(Horde_Core_Translation::t("An illegal value was specified."), 'horde.error'); + $this->_errors[$pref] = Horde_Core_Translation::t("An illegal value was specified."); } break; @@ -270,7 +277,7 @@ class Horde_Core_Prefs_Ui if (isset($enum[$val])) { $set[] = $val; } else { - $notification->push(Horde_Core_Translation::t("An illegal value was specified."), 'horde.error'); + $this->_errors[$pref] = Horde_Core_Translation::t("An illegal value was specified."); break 2; } } @@ -282,9 +289,9 @@ class Horde_Core_Prefs_Ui case 'number': $num = $this->vars->$pref; if ((string)(double)$num !== $num) { - $notification->push(Horde_Core_Translation::t("This value must be a number."), 'horde.error'); + $this->_errors[$pref] = Horde_Core_Translation::t("This value must be a number."); } elseif (empty($num)) { - $notification->push(Horde_Core_Translation::t("This number must be non-zero."), 'horde.error'); + $this->_errors[$pref] = Horde_Core_Translation::t("This value must be non-zero."); } else { $updated |= $save->setValue($pref, $num); } @@ -307,6 +314,10 @@ class Horde_Core_Prefs_Ui } } + if (count($this->_errors)) { + $notification->push(Horde_Core_Translation::t("There were errors encountered while updating your preferences."), 'horde.error'); + } + if ($updated) { if ($save instanceof Horde_Prefs_Identity) { // Throws Exception caught in _identitiesUpdate(). @@ -419,6 +430,11 @@ class Horde_Core_Prefs_Ui } $t = clone $base; + + if (isset($this->_errors[$pref])) { + echo $t->fetch(HORDE_TEMPLATES . '/prefs/error_start.html'); + } + if (isset($this->prefs[$pref]['desc'])) { $t->set('desc', Horde::label($pref, $this->prefs[$pref]['desc'])); } @@ -506,6 +522,11 @@ class Horde_Core_Prefs_Ui } echo $t->fetch(HORDE_TEMPLATES . '/prefs/' . $type . '.html'); + + if (isset($this->_errors[$pref])) { + $t->set('error', htmlspecialchars($this->_errors[$pref])); + echo $t->fetch(HORDE_TEMPLATES . '/prefs/error_end.html'); + } } $t = clone $base; diff --git a/horde/templates/prefs/error_end.html b/horde/templates/prefs/error_end.html new file mode 100644 index 000000000..0353ce3a9 --- /dev/null +++ b/horde/templates/prefs/error_end.html @@ -0,0 +1,5 @@ + +
+ +
+ diff --git a/horde/templates/prefs/error_start.html b/horde/templates/prefs/error_start.html new file mode 100644 index 000000000..8bbf4a627 --- /dev/null +++ b/horde/templates/prefs/error_start.html @@ -0,0 +1,2 @@ +
+
diff --git a/horde/themes/screen.css b/horde/themes/screen.css index 3d09f1f92..3c58cd378 100644 --- a/horde/themes/screen.css +++ b/horde/themes/screen.css @@ -699,6 +699,18 @@ span.prefsAdvanced { font-size: 80%; } +div.prefsErrorDiv { + border: 1px solid red; + display: inline-block; + padding: 2px; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; +} + +div.prefsError { + color: red; +} + /* Block styles. */ .currentBlock { border: 2px solid red; -- 2.11.0