Code

Added syntax checking
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 1 Oct 2010 08:04:17 +0000 (08:04 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 1 Oct 2010 08:04:17 +0000 (08:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19880 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_list.inc
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_string.inc

index 99379cd9a7368d6839282b71a18dc209789e3f91..03a2a075ab90dda4441211609df6e28d380cde80 100644 (file)
@@ -220,11 +220,18 @@ class DeviceConfig extends management
     {
         // Save eventually changed values
         if($this->currentItem){
-            foreach($this->TemplateEngine->getWidgets() as $widget){
-                $this->currentItem['values'][$widget->getName()] = $widget->getValue();
+
+            // Check if everything is fine.
+            $msgs = $this->TemplateEngine->check();
+            if(count($msgs)){
+                msg_dialog::displayChecks($msgs);
+            }else{
+                foreach($this->TemplateEngine->getWidgets() as $widget){
+                    $this->currentItem['values'][$widget->getName()] = $widget->getValue();
+                }
+                $this->closeDialogs();
             }
         }
-        $this->closeDialogs();
     }
 
 
index 0723bc4fd0437fdb8905868bd215c7a081b49551..484b701f38241fb5948229ab8d4b01f62aee0ed6 100644 (file)
@@ -85,11 +85,13 @@ class TemplateEngine
 
                 // Prepare the value for the widget 
                 $value = $values[$name];
-
+                $syntax = (isset($item['syntax']))? $item['syntax']: "";
+    
                 // Create the new widget.
                 $this->widgets[$name] = new $widgetClassName($this->config, $name, 
                         $value,
                         $item['description'],
+                        $syntax,
                         $item['required'],
                         $item['type'],
                         $item['display']);
@@ -132,6 +134,18 @@ class TemplateEngine
             $widget->save_object();
         }
     }
+
+
+    /*! \brief  Check widget values and return a list of errors.
+     */
+    function check()
+    {
+        $msgs = array();
+        foreach($this->widgets as $widget){
+            $msgs = array_merge($msgs, $widget->check());
+        }
+        return($msgs);
+    }
 }
 
 
index ef4ff99d68dd32a694f65e716f8a1bd5c6dfbb99..670fbed18c22070e680251d35c09cd421fb5ac19 100644 (file)
@@ -12,6 +12,7 @@ class TemplateWidget
     protected $required = "";
     protected $type = "";
     protected $display = "";
+    protected $syntax = "";
 
     /*! \brief  Constructs the template widget and sets the default values.
      *  @param  Config  The GOsa configuration object.
@@ -22,7 +23,7 @@ class TemplateWidget
      *  @param  String  The widget type. 
      *  @param  String  A display name for the widget.
      */
-    function __construct(&$config, $name, $value, $description,$required,$type,$display)
+    function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display)
     {
         $this->config = &$config;
         $this->name = $name;
@@ -42,7 +43,16 @@ class TemplateWidget
      */
     function getDisplayName()
     {
-        return($this->display);
+        $must = ($this->required)?"<span class='required'>*</span>":"";
+        return($this->display.$must);
+    }
+
+
+    /*! \brief  Returns the description for the widget.
+     */
+    function getDescription()
+    {
+        return($this->description);
     }
 
 
@@ -90,5 +100,14 @@ class TemplateWidget
     {
         $this->value = $value;
     }
+
+
+    /*! \brief  Check the value entry using the provieded syntax.
+     * @return  Array   Returns a list of errors
+     */
+    function check()
+    {
+        return(array());
+    }
 }
 ?>
index 3f1f457efafe1f77e6c76aa08ec0e86d54279f7f..0d21145d8422da581de5b5d65717667489030c96 100644 (file)
@@ -2,9 +2,9 @@
 
 class TemplateWidget_list extends TemplateWidget
 {
-    function __construct(&$config, $name, $value, $description,$required,$type,$display)
+    function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display)
     {
-        parent:: __construct($config, $name, $value, $description,$required,$type,$display);
+        parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display);
 
         $this->listWidget= new sortableListing($this->value);
         $this->listWidget->setEditable(false);
index 1ff9520a5e47d44ca366d3db3863fae56db0dc5a..2bf3ccca030331d374800e93af72e4cf2b3957f3 100644 (file)
@@ -4,7 +4,14 @@ class TemplateWidget_string extends TemplateWidget
 {
     function render()
     {
-        return("<input type='text' name=\"{$this->postName}\" value=\"".set_post($this->value)."\">");
+        $desc = set_post($this->description);
+        $value = set_post($this->value);
+
+        $name = " name=\"{$this->postName}\" ";
+        $value = " value=\"{$value}\" ";
+        $title = (empty($this->description))?"": " title=\"{$desc}\"";
+
+        return("<input type='text' {$title} {$name} {$value }>");
     }
 }