Better error handling when updating prefs.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 4 Nov 2010 21:38:03 +0000 (15:38 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Nov 2010 16:19:11 +0000 (10:19 -0600)
framework/Core/lib/Horde/Core/Prefs/Ui.php
horde/templates/prefs/error_end.html [new file with mode: 0644]
horde/templates/prefs/error_start.html [new file with mode: 0644]
horde/themes/screen.css

index 1a1fab0..d160bc4 100644 (file)
@@ -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 (file)
index 0000000..0353ce3
--- /dev/null
@@ -0,0 +1,5 @@
+ </div>
+ <div class="prefsError">
+  <tag:error />
+ </div>
+</div>
diff --git a/horde/templates/prefs/error_start.html b/horde/templates/prefs/error_start.html
new file mode 100644 (file)
index 0000000..8bbf4a6
--- /dev/null
@@ -0,0 +1,2 @@
+<div class="prefsErrorDiv">
+ <div>
index 3d09f1f..3c58cd3 100644 (file)
@@ -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;