Code

Updated handling of config items
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Apr 2011 14:41:36 +0000 (14:41 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Apr 2011 14:41:36 +0000 (14:41 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20667 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc

index 08ad944334c86a1a7508a4018a8df3436496de05..5b6365b1fd5f53a702546d728ee2a06acb0ca560 100644 (file)
@@ -428,7 +428,6 @@ class newConfigManagement extends plugin
     function removeEntry($ids)
     {
         $item = $this->dataModel->getItemById($ids[0]);
-
         $release = preg_replace("/^.*\//","",$item['values']['__release']);
         $path = $item['values']['__path'];
         $rpc = $this->config->getRpcHandle();
@@ -475,30 +474,62 @@ class newConfigManagement extends plugin
         $this->currentObject = NULL;
     }
 
+
+    function getItemPath($fullPath)
+    {
+        $fPath = $fullPath.'/';
+        while(preg_match("/\//", $fPath)){
+            $fPath = preg_replace("/\/[^\/]*$/","", $fPath);
+            $item = $this->dataModel->getItemByPath($fPath);
+            if(isset($this->cfgItemMap[$item['type']])){
+                return(preg_replace("/".preg_quote($item['parentPath'],'/')."/", "", $fullPath));
+            }
+        }
+        return(NULL);
+    }
+
+    function getReleasePath($fullPath)
+    {
+        $fullPath.='/';
+        while(preg_match("/\//", $fullPath)){
+            $fullPath = preg_replace("/\/[^\/]*$/","", $fullPath);
+            $item = $this->dataModel->getItemByPath($fullPath);
+            if($item['type'] == 'Release'){
+                return($fullPath);
+            }
+        }
+        return(NULL);
+    }
+    
     function saveItemChanges()
     {
         $item = $this->currentObject;
-
+        
         if($item == NULL){
             $this->TemplateEngine->save_object();
-            $release = preg_replace("/^.*\//","",$this->selectedContainer);
+            $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer));
             $type = $this->TemplateEngine->getItemType();
             $values = array();
             foreach($this->TemplateEngine->getWidgets() as $w){
                 $values[$w->getName()] = $w->getValue();
             }
-            $path = "/".$values['name'];
+            
+            $path = $this->getItemPath($this->selectedContainer)."/".$values['name'];
             $rpc = $this->config->getRpcHandle();
             $res = $rpc->setConfigItem($release, $path, $type, $values);
             if(!$rpc->success()){
                 msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG);
                 return(NULL);
             }else{
-                //$item['values']['itemValues'] = $values;
-                //$this->dataModel->setItemValues($item['path'], $item['values']);
+                $this->dataModel->addItem($type, $this->selectedContainer, $values['name'], 
+                        array(    
+                            '__editable' => TRUE,
+                            '__removeable' => TRUE,
+                            '__path' => $path,
+                            '__release' => $this->getReleasePath($this->selectedContainer)
+                            ), '-' ); 
                 $this->listing->clearDialogObject();
             }
-            print_a(array($release, $path, $type, $values));
         }else{
             $this->TemplateEngine->save_object();
             $values = array();
@@ -511,7 +542,6 @@ class newConfigManagement extends plugin
 
             $rpc = $this->config->getRpcHandle();
             $res = $rpc->setConfigItem($release, $path, $item['type'], $values);
-            print_a(array($release, $path, $item['type'], $values));
             if(!$rpc->success()){
                 msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG);
                 return(NULL);
@@ -523,4 +553,6 @@ class newConfigManagement extends plugin
         }
     }
 }
+
+
 ?>