Code

Allow to set values for widgets
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 27 Sep 2010 09:34:33 +0000 (09:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 27 Sep 2010 09:34:33 +0000 (09:34 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19793 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

index 01d9ecc484e05ce4b70fc30feac0a181ff550eda..61b1209fcbd892382c331a8b55a95fcdcba12b21 100644 (file)
@@ -5,10 +5,12 @@ class DeviceConfig extends plugin
     private $TemplateEngine = NULL;
 
     private $idToName = array();
+    private $currentItemName = "";
 
     function __construct(&$config, $dn)
     {
         $this->TemplateEngine = new TemplateEngine($config);
+        $this->TemplateEngine->setTemplate('puppet.tpl');
         $this->config = $config;
 
         $str = '{
@@ -85,14 +87,15 @@ class DeviceConfig extends plugin
         $this->setCurrentItem('root');
         $this->addItem('PuppetModule','test1',
                 array(
-                    'version' => 1,
-                    'name'  => 'test1',
-                    'description' => 'Test Module')
+                    'dependency' => 'mozilla-2',
+                    'version' => '2.4-f',
+                    'name'  => 'Thundebird',
+                    'description' => 'Mozilla mail client')
                 );
         $this->addItem('PuppetModule','test2',
                 array(
                     'version' => 1,
-                    'name'  => 'test2',
+                    'name'  => 'Firefox',
                     'description' => 'Test Module')
                 );
         $this->setCurrentItem('test1');
@@ -115,6 +118,7 @@ class DeviceConfig extends plugin
         }else{
             $str .= $array['name'];
         }
+        $str .= "&nbsp;<i>(".$array['type'].")</i>";
         $str .= "</a>";
 
         if(count($array['children'])){
@@ -141,10 +145,13 @@ class DeviceConfig extends plugin
 
     function setCurrentItem($item)
     {
+        if($this->currentItemName == $item) return;
         $this->currentItemName = $item;
         $this->currentItem = &$this->currentItemValues[$item];
         $this->currentItemType = $this->currentItem['type'];
         $this->currentItemDescriptor =&$this->itemConfig[$this->currentItem['type']];
+        $this->TemplateEngine->setType($this->currentItemType);
+        $this->TemplateEngine->setValues($this->currentItem['values']);
     }
 
 
@@ -161,15 +168,14 @@ class DeviceConfig extends plugin
         
 
 
-        $this->TemplateEngine->setType($this->currentItemType);
-        $this->TemplateEngine->setValues($this->currentItem);
-        $this->TemplateEngine->setTemplate('puppet.tpl');
         $smarty->assign('template',$this->TemplateEngine->render());
         return($smarty->fetch(get_template_path('goto/Config/DeviceConfig.tpl', TRUE)));
     }
 
     function save_object()
     {
+        $this->TemplateEngine->save_object();
+
         if(isset($_POST['addSubModule']) && isset($_POST['subModule'])){
             $sub = get_post('subModule');
             if(in_array($sub, $this->currentItemDescriptor['container'])){
index f976ed51a33c73d9a54b9e63a4cbd6ddcdf56c28..6d7f3f705ed023489dcb6048a2a47c85ec9174e7 100644 (file)
@@ -13,9 +13,11 @@ class TemplateEngine
         $this->config = &$config;
     }
 
-    function setValues($array)
+    function setValues($values)
     {
-#        print_a($array);
+        foreach($values as $name => $value){
+            $this->widgets[$name]->setValue($value);
+        }
     }
 
     function setType($name)
@@ -23,10 +25,20 @@ class TemplateEngine
         $this->itemType = $name;
         $this->widgets = array();
 
+        if(!isset($this->data[$this->itemType])){
+            trigger_error("Undefined item type '{$name}'!");
+            return;
+        }
         $data = $this->data[$this->itemType];
         if(isset($data['options']) && count($data['options'])){
             foreach($data['options'] as $name => $item){
-                $this->widgets[] = new TemplateWidget($this->config, $name, $item['value']);
+
+                $this->widgets[$name] = new TemplateWidget($this->config, $name, 
+                    $item['value'],
+                    $item['description'],
+                    $item['required'],
+                    $item['type'],
+                    $item['display']);
             }
         }
     }
@@ -50,11 +62,18 @@ class TemplateEngine
     {
         $smarty = get_smarty();
         $smarty->assign("type", $this->itemType);
-        foreach($this->getWidgets() as $widget){
+        foreach($this->widgets as $widget){
             $smarty->assign($widget->getName(), $widget->render());
         }
         return($smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE)));
     }
+
+    function save_object()
+    {
+        foreach($this->widgets as $widget){
+            $widget->save_object();
+        }
+    }
 }
 
 
index d946c3cc15074c1245b2167577c73a2a0db9f736..e48e06a2441811d5f44eb1eb41d57138db8386ae 100644 (file)
@@ -5,25 +5,44 @@ class TemplateWidget
     private $name = "unnamed";
     private $value = "";
 
-    function __construct(&$config, $name, $value)
+    private $description = "";
+    private $required = "";
+    private $type = "";
+    private $display = "";
+
+    function __construct(&$config, $name, $value, $description,$required,$type,$display)
     {
+        $this->config = &$config;
+
+        echo '*';
         $this->name = $name;
         $this->value = $value;
-        $this->config = &$config;
+        $this->description = $description;
+        $this->required = $required;
+        $this->type = $type;
+        $this->display = $display;
     }
 
 
     function render()
     {
-        return("<input type='text' name=\"{$this->name}\" value=\"".set_post($this->value)."\">");
+
+        $class = get_class();
+        return("{$this->display}&nbsp;<input type='text' name=\"{$class}_{$this->name}\" value=\"".set_post($this->value)."\">");
     }
 
     function save_object()
     {
+        $class = get_class();
+        $name = "{$class}_{$this->name}";
+        if(isset($_POST[$name])){
+            $this->value = get_post($name);
+        }
     }
 
     function getValue()
     {
+        return($this->value);
     }
 
     function getName()
@@ -31,8 +50,9 @@ class TemplateWidget
         return($this->name);
     }
 
-    function setValue()
+    function setValue($value)
     {
+        $this->value = $value;
     }
 
 }