Code

Allow to remove folder entries in the new folder widget
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Oct 2010 09:02:31 +0000 (09:02 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Oct 2010 09:02:31 +0000 (09:02 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19949 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/groupware/personal/groupware/FolderWidget/FolderWidget-list.xml
gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc
gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc
gosa-plugins/groupware/personal/groupware/FolderWidget/class_filterFolderWidget.inc

index 52335f43d77ce0088cdc5ee2d19525affc038f30..10d9e60781945f61713c089f9043f99acc75ed2d 100644 (file)
     </action>
 
     <action>
-      <name>edit</name>
+      <name>editEntry</name>
       <type>entry</type>
       <image>images/lists/edit.png</image>
       <label>Edit Sudo role</label>
index 65c4875e162667f45ef2b2f612e18e5ba1da1449..fc94f2818b8c1fa2e8a6ced252926499ec8403ef 100644 (file)
@@ -20,7 +20,7 @@ class FolderWidget extends plugin
     function __construct(&$config)
     {
         $this->rootBase = $this->fakeCnAttr.$this->rootName;
-        $this->FolderWidgetListing = new FolderWidgetListing($this->config, get_userinfo(), $this->rootBase);
+        $this->FolderWidgetListing = new FolderWidgetListing($this->config, get_userinfo(), $this->rootBase, $this);
         $this->FolderWidgetListing->setBase($this->rootBase);
         $this->FolderWidgetListing->setFolderRoot($this->rootBase);
     }
@@ -104,6 +104,35 @@ class FolderWidget extends plugin
     }
 
 
+    function removeByBase($base)
+    {
+        $this->_recursiveRemoveByBase($this->folderList['recursive'], $base);
+        $this->_recursiveRemoveByBase($this->folderList['linear'], $base);
+        $this->FolderWidgetListing->setFolderList($this->folderList);
+    }
+
+    function _recursiveRemoveByBase(&$arr, $base)
+    {
+        $ret = array();
+        foreach($arr as $path => $item){
+            if($item['base'] == $base){
+
+                // remove all children too
+                if(isset($item['children']) && count($item['children'])){
+                    foreach($item['children'] as $child){
+                        $this->_recursiveRemoveByBase($this->folderList['recursive'], $child['base']);
+                    }
+                }
+
+                $arr[$path]['status'] = 'removed';
+            }elseif(isset($item['children']) && count($item['children'])){
+                $ret = array_merge($ret, $this->_recursiveRemoveByBase($arr[$path]['children'], $base));
+            }
+        }
+        return($ret);
+        
+    }
+
     function _saveRecursive($arr)
     {
         $ret = array();
@@ -130,6 +159,7 @@ class FolderWidget extends plugin
     function execute()
     {
         session::set('FolderWidgetListing::folderList', $this->folderList);
+
         $this->FolderWidgetListing->setFolderList($this->folderList);
         return($this->FolderWidgetListing->execute());
     }
index 14bdf17fe8f40a62b0613d399ac99a8f6b5f6e58..cafff0943bb480391d14b826e9b3c5a0312cbbcf 100644 (file)
@@ -7,13 +7,15 @@ class FolderWidgetListing extends management
     private $folderList = array();
 
     private $rootBase = '';
+    private $parent;
 
-    function __construct($config,$ui, $rootBase)
+    function __construct($config,$ui, $rootBase, $parent)
     {
         $this->config = $config;
         $this->ui = $ui;
         $this->storagePoints = array("");
         $this->rootBase = $rootBase;
+        $this->parent = &$parent;
 
         // Build filter
         if (FALSE && session::global_is_set(get_class($this)."_filter")){
@@ -44,7 +46,19 @@ class FolderWidgetListing extends management
     {
         $this->setBase($targets[0]);
     }
-    
+
+    function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
+    {
+        print_a($all);
+    }
+
+    protected function removeEntryRequested($action="",$target=array(),$all=array())
+    {   
+        foreach($target as $tar){
+            $this->parent->removeByBase($tar);
+            if($tar == $this->base) $this->setBase($this->rootBase);
+        }
+    }
     
     function setFolderList($folderList)
     {
@@ -95,9 +109,11 @@ class FolderWidgetListing extends management
     {
         $ret = array($this->rootBase => '/');
         foreach($arr as $path => $entry){
-            $ret[$entry['base']] = $entry['name'];
-            if(isset($entry['children'])){
-                $ret = array_merge($ret, $this->getSimpleFolderList($entry['children']));
+            if($entry['status'] != 'removed'){
+                $ret[$entry['base']] = $entry['name'];
+                if(isset($entry['children'])){
+                    $ret = array_merge($ret, $this->getSimpleFolderList($entry['children']));
+                }
             }
         }
         return($ret);
index f6f82a114d76db5e867ed852ad9ee3220fd56c29..6d51669080980355da3de7cc84b7ac1dba012c87 100644 (file)
@@ -38,7 +38,7 @@ class filterFolderWidget {
 
     static function addEntry(&$ret, $item, $recursive = FALSE, $filter)
     {
-        if(preg_match("/".$filter."/",$item['name'])){
+        if(preg_match("/".$filter."/",$item['name']) && $item['status'] != 'removed'){
             $entry = array();
             $entry['dn'] = $item['base'];
             $entry[] = 'dn';