Code

Updated folder widget
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 7 Oct 2010 13:55:22 +0000 (13:55 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 7 Oct 2010 13:55:22 +0000 (13:55 +0000)
-It lists now

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19935 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/groupware/personal/groupware/FolderWidget/FolderWidget-filter.xml
gosa-plugins/groupware/personal/groupware/FolderWidget/FolderWidget-list.tpl
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 [new file with mode: 0644]

index 54d213cc4c87be26fa3c71ffb6cd7712950792b9..365a2c7930d68181bc0ebc494f5fe158298ced87 100644 (file)
@@ -6,7 +6,7 @@
     <category>Groupware</category>
     <initial>true</initial>
     <default>default</default>
-    <scope>sub</scope>
+    <scope>auto</scope>
     <attribute>-</attribute>
   </definition>
 
@@ -14,7 +14,7 @@
     <tag>default</tag>
     <label>Default filter</label>
     <query>
-      <backend>LDAP</backend>
+      <backend>FolderWidget</backend>
       <filter>$</filter>
     </query>
     <autocomplete>
index c80f9a2389577f40e56489b37a374fc60e4f18ed..44dcd716e50bf218a27cf1fa3008fabc0c0d5768 100644 (file)
@@ -5,10 +5,8 @@
    <div class="mainlist-nav">
     <table summary="{$HEADLINE}">
      <tr>
-      <td>{$ROOT}</td>
-      <td>{$BACK}</td>
-      <td>{$HOME}</td>
       <td>{$RELOAD}</td>
+      <td class="left-border">{t}Basis{/t}: {$RELEASE}</td>
       <td class="left-border">{$ACTIONS}</td>
       <td class="left-border">{$FILTER}</td>
      </tr>
@@ -20,5 +18,8 @@
 </div>
 
 <div class="clear"></div>
-
-<input type="hidden" name="ignore">
+<hr>
+<div class='plugin-actions'>
+    <button name='FolderWidget_ok'>{msgPool type=okButton}</button>
+    <button name='FolderWidget_cancel'>{msgPool type=cancelButton}</button>
+</div>
index 66937308a2c9b609e1b8503d0862cdd1d84a4aaa..6344097491c0faf0c7431c77fb4f406fb7f7b94e 100644 (file)
@@ -2,9 +2,9 @@
 
 <list>
   <definition>
-    <departmentBrowser>true</departmentBrowser>
-    <departmentRootVisible>true</departmentRootVisible>
-    <baseMode>true</baseMode>
+    <departmentBrowser>false</departmentBrowser>
+    <departmentRootVisible>false</departmentRootVisible>
+    <baseMode>false</baseMode>
     <multiSelect>true</multiSelect>
     <template>../plugins/personal/groupware/FolderWidget/FolderWidget-list.tpl</template>
     <module>users</module>
@@ -22,7 +22,7 @@
   </definition>
 
   <table>
-    <layout>|20px;c|120px||170px;r|</layout>
+    <layout>|20px;c|||170px;r|</layout>
 
     <column>
       <value>%{filter:objectType(dn,objectClass)}</value>
index 899e20916bd5c4d3b5e79f15a7fa25660f77510b..904714ff74997c07458b6087c4cc9ab977a8d6e9 100644 (file)
@@ -7,6 +7,9 @@ class FolderWidget extends plugin
 {
     public $config;
     private $FolderWidgetListing = NULL;
+    private $folderList;
+
+    private $baseEntryMap = array();
 
     function __construct(&$config)
     {
@@ -14,10 +17,77 @@ class FolderWidget extends plugin
     }
 
 
+    /*! \brief  Tell the widget which folders should be displayed.
+     */
+    function setFolderList($arr)
+    {
+        $this->folderList = $this->buildRecursiveList($arr, '/');
+        $this->FolderWidgetListing->setBase('cn=/');
+        $this->FolderWidgetListing->setFolderRoot('cn=/');
+    }
+
+
+    /* \brief   Builds a hierarchical structure which can then be 
+     *           used by the FolderWidgetListing.
+     *
+     * @param   Array   The folder list 
+     * @return  Array   A hierarchical representation of the input array.
+     */
+    function buildRecursiveList($arr, $seperator)
+    {
+        $data = array();
+        $base = &$data;
+        $last = NULL;
+        $ret = array();
+        foreach($arr as $path => $entry){
+            $current = &$base;
+            $pathSteps = preg_split("/".preg_quote($seperator,'/')."/", $path);
+    
+            $entryPath = "";
+            $entryBase = "cn=/";
+            foreach($pathSteps as $name){
+                $entryPath = (empty($entryPath)) ? $name : "{$entryPath}{$seperator}{$name}";
+                $entryBase =  trim("cn={$name},{$entryBase}", ' ,');
+                if(!isset($current[$entryPath])){
+                    $current[$entryPath] = array();
+                    $current[$entryPath]['children'] = array();
+                    $current[$entryPath]['name'] = $name;
+                    $current[$entryPath]['path'] = $path;
+                    $current[$entryPath]['status'] = '';
+                    $current[$entryPath]['type'] = 'manual';
+                    $current[$entryPath]['base'] = $entryBase;
+
+                    $ret['linear'][$entryPath] = &$current[$entryPath];
+
+                    $this->baseEntryMap[$entryBase] = $entryPath;
+                }
+                $last = &$current[$entryPath];
+                $current = &$current[$entryPath]['children'];
+            }
+            $last['acls'] = $entry['acls'];
+            $last['name'] = $entry['name'];
+            $last['type'] = 'real';
+            $last['status'] = $entry['status'];
+    
+            $ret['linear'][$path] = &$last;
+            
+        }
+        $ret['recursive'] = $data;
+        return($ret);
+    }
+
+
     function execute()
     {
+        session::set('FolderWidgetListing::folderList', $this->folderList);
+        $this->FolderWidgetListing->setFolderList($this->folderList);
         return($this->FolderWidgetListing->execute());
     }
+
+    function save_object()
+    {
+        $this->FolderWidgetListing->save_object();
+    }
 }
 
 ?>
index 3712d2b523b12a226c1d7fd61d2e11c9ae4d0318..1d74043dd9da53199d0aaacbb77f024e5e2e6f43 100644 (file)
@@ -2,15 +2,20 @@
 
 class FolderWidgetListing extends management
 {
+   
+    private $folderSelector = NULL; 
+    private $folderList = array();
+
+    private $rootBase = 'cn=/';
+
     function __construct($config,$ui)
     {
         $this->config = $config;
         $this->ui = $ui;
-
         $this->storagePoints = array("");
 
         // Build filter
-        if (session::global_is_set(get_class($this)."_filter")){
+        if (FALSE && session::global_is_set(get_class($this)."_filter")){
             $filter= session::global_get(get_class($this)."_filter");
         } else {
             $filter = new filter(get_template_path("FolderWidget-filter.xml", true, dirname(__FILE__)));
@@ -21,12 +26,77 @@ class FolderWidgetListing extends management
         // Build headpage
         $headpage = new listing(get_template_path("FolderWidget-list.xml", true, dirname(__FILE__)));
         $headpage->setFilter($filter);
+        $headpage->setBase($this->rootBase);
 
+        // Create folderSelector using dummy entries, those will be replaced 
+        //  once setFolderList is called.
+        $this->folderSelector = new ItemSelector(array($this->rootBase => '/'),$this->rootBase,$this->rootBase);
         parent::__construct($config, $ui, "Folder", $headpage);
     }
 
+    
+    function setFolderList($folderList)
+    {
+        $this->folderList = $folderList;
+    }
 
-}
 
+    function getBase()
+    {
+        return($this->base);
+    }
+
+
+    function setBase($base)
+    {
+        $this->base = $base;
+        $this->folderSelector->setBase($this->base);
+        $headpage = $this->getHeadpage();
+        $headpage->setBase($this->base);
+    }
+
+    
+    function setFolderRoot($base)
+    {
+        $this->rootBase = $base;
+        $this->folderSelector->setRootBase($base);
+    }
+   
+    /*! \brief   Overridden render method of class mangement.
+     *            this allows us to add a release selection box.
+     */
+    function renderList()
+    {
+        $this->folderSelector->setBases($this->getSimpleFolderList($this->folderList['recursive']));
+        $this->folderSelector->update(true);
 
+        $headpage = $this->getHeadpage();
+        $headpage->update();
+        $smarty = get_smarty();
+        $smarty->assign("RELEASE", $this->folderSelector->render());
+        $display = $headpage->render();
+        return($this->getHeader().$display);
+    }
+
+
+    function getSimpleFolderList($arr)
+    {
+        $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']));
+            }
+        }
+        return($ret);
+    }
+
+    
+    function save_object()
+    {
+        $this->folderSelector->update();
+        $this->setBase($this->folderSelector->getBase());
+    }
+}
 ?>
diff --git a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_filterFolderWidget.inc b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_filterFolderWidget.inc
new file mode 100644 (file)
index 0000000..17af6b5
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+class filterFolderWidget {
+
+    static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
+    {
+        $data = session::get('FolderWidgetListing::folderList');
+
+        // Prepare filter, strip out regex regex related chars, except for *
+        $filter = preg_replace('/\*/','____STAR____', $filter);
+        $filter = preg_quote($filter,'/');
+        $filter = preg_replace('/____STAR____/','.*', $filter);
+
+        // Detect starting position in folder tree.
+        $items = $data['recursive'];
+        foreach($data['linear'] as $item){
+            if($item['base'] == $base){
+                $items = $item['children'];
+            }
+        }
+
+        // Add entries
+        $ret = array();
+        foreach($items as $item){
+            filterFolderWidget::addEntry($ret, $item, $scope == 'sub', $filter);
+        }
+        return($ret);
+    }
+
+    static function addEntry(&$ret, $item, $recursive = FALSE, $filter)
+    {
+        if(preg_match("/".$filter."/",$item['name'])){
+            $entry = array();
+            $entry['dn'] = $item['base'];
+            $entry[] = 'dn';
+            $entry['cn'] = array($item['name'], 'count' => 1);
+            $entry[] = 'cn';
+            $entry['objectClass'] = array('FAKE_OC_GroupwareFolder','count' => 1);
+            $entry[] = 'objectClass';
+            $entry['count'] = 3;
+            $ret[] = $entry;
+        }
+
+        if($recursive && isset($item['children']) && count($item['children'])){
+            foreach($item['children'] as $item){
+                filterFolderWidget::addEntry($ret, $item, $recursive,$filter);
+            }
+        }
+    }
+}
+?>