Code

Allow to add new entries
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Oct 2010 13:58:38 +0000 (13:58 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 8 Oct 2010 13:58:38 +0000 (13:58 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19958 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/groupware/personal/groupware/FolderWidget/FolderEditDialog.tpl
gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderEditDialog.inc
gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc
gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc

index 56152b86e3d69010641df8da073145d2c618108a..d7270b94e681ac907f8148edb22c80a14b4c0d6f 100644 (file)
@@ -1,5 +1,17 @@
-<h3>{t}Folder{/t}</h3>
 
+{if $isNew}
+
+<h3>{t}Create folder{/t}</h3>
+<table>
+    <tr>
+        <td>{t}Name{/t}:&nbsp;</td>
+        <td><input name='folderName' value="{$folderItem.name}" type="text"></td>
+    </tr>
+</table>
+
+{else}
+
+<h3>{t}Edit folder{/t}</h3>
 <table>
     <tr>
         <td>{t}Name{/t}:&nbsp;</td>
@@ -10,6 +22,7 @@
         <td>{$folderItem.path}</td>
     </tr>
 </table>
+{/if}
 
 <hr>
 
index 4af753839a76199c46fd65403265d10ec86ffe04..e4e3ab87e29509dd4e9b5cf37df44e79a00ba47e 100644 (file)
@@ -5,10 +5,19 @@ class FolderEditDialog extends plugin
     private $folderItem = NULL;    
     private $permissions = array();
 
-    function __construct($config, $folderItem)
+    function __construct($config, $folderItem, $isNew = FALSE)
     {
         $this->config = $config;
         $this->folderItem = $folderItem;
+        $this->isNew = $isNew;
+
+        // Prepare new item
+        if($this->isNew){
+            $entry = array();
+            $entry['name'] = "";
+            $entry['acls'] = array();
+            $this->folderItem = $entry;
+        }
     }
 
     function setPermissions($perms)
@@ -22,12 +31,20 @@ class FolderEditDialog extends plugin
         $smarty->assign('folderItem', $this->folderItem);
         $smarty->assign('permissions', $this->permissions);
         $smarty->assign('permissionCnt', count($this->permissions));
+        $smarty->assign('isNew', $this->isNew);
         return($smarty->fetch(get_template_path("FolderEditDialog.tpl", TRUE, dirname(__FILE__))));
     }
 
 
     function save_object()
     {
+        // Get folder name 
+        if($this->is_new){
+            if(isset($_POST['folderName'])){
+                $this->folderItem['name'] = get_post('folderName');
+            }
+        }
+
         // Get all posted value modifications
         foreach($this->folderItem['acls'] as $id => $aclEntry){
 
@@ -52,6 +69,11 @@ class FolderEditDialog extends plugin
         $this->folderItem['acls'] = array_values($this->folderItem['acls']);
     }
 
+    function isNew()
+    {
+        return($this->isNew);
+    }
+
     function save()
     {
         return($this->folderItem);
index ae3c5f9e6cc0ac867fa8e454312c226bb69cebc4..4307d73055bb81f5f57f9468b3c6d301380c65e2 100644 (file)
@@ -24,7 +24,7 @@ class FolderWidget extends plugin
         //  effect on the results.
         $this->rootBase = $this->fakeCnAttr.$this->rootName;
 
-        $this->accountPrefix = (empty($accountPrefix)) ? "" : rtrim($accountPrefix,$pathSeparator).$pathSeparator;
+        $this->accountPrefix = (empty($accountPrefix)) ? "" : rtrim($accountPrefix,$this->pathSeparator).$this->pathSeparator;
         $this->rootBase = $this->pathToDn($accountPrefix);
 
         // Update the folder list, initially.
@@ -80,11 +80,12 @@ class FolderWidget extends plugin
         $data[$this->accountPrefix]['name'] = $this->rootName;
         $data[$this->accountPrefix]['status'] = '';
         $data[$this->accountPrefix]['acls'] = array();
-        $data[$this->accountPrefix]['path'] = $this->rootName;
+        $data[$this->accountPrefix]['path'] = $this->accountPrefix;
         $data[$this->accountPrefix]['type'] = 'manual';
         $data[$this->accountPrefix]['base'] = $this->rootBase;
         $data[$this->accountPrefix]['parentPath'] = "";
         $data[$this->accountPrefix]['children'] = array();
+        $this->baseEntryMap[$this->rootBase] = $this->accountPrefix;
         $ret['linear'][$this->accountPrefix] = &$data[$this->accountPrefix];
 
         $base = &$data[$this->accountPrefix]['children'];
@@ -161,6 +162,15 @@ class FolderWidget extends plugin
         $this->FolderWidgetListing->setFolderList($this->folderList);
     }
 
+
+    function addFolder()
+    {
+            $this->currentlyEditedItem = NULL;
+            $this->dialog = new FolderEditDialog($this->config, array(), TRUE);
+            $this->dialog->setPermissions($this->permissions);
+    }
+
+
     function _recursiveRemoveByBase(&$arr, $base)
     {
         $ret = array();
@@ -227,16 +237,38 @@ class FolderWidget extends plugin
         $this->FolderWidgetListing->save_object();
 
         // Handle dialogs 
-        if(isset($_POST['FolderEditDialog_ok'])){
+        if(isset($_POST['FolderEditDialog_ok']) && is_object($this->dialog)){
     
             $this->dialog->save_object();
             $msgs = $this->dialog->check();
             if(count($msgs)){
                 msg_dialog::displayChecks($msgs);
             }else{
-                $newItem = $this->dialog->save();
-                $path = $this->currentlyEditedItem['path'];
-                $this->folderList['linear'][$path]['acls'] = $newItem['acls']; 
+                if($this->dialog->isNew()){
+                    // Detect the current entry
+                    $base = $this->FolderWidgetListing->getBase();
+   
+                    if(isset($this->baseEntryMap[$base])){
+                        $entry = $this->folderList['linear'][$this->baseEntryMap[$base]];
+                        $path = $entry['path'];
+                        $newItem = $this->dialog->save();
+                        $name = $newItem['name'];
+                        $newPath = "{$path}{$this->pathSeparator}{$name}";
+                        $newItem['status'] = 'added';
+                        $newItem['type'] = 'real';
+                        $newItem['children'] = array();
+                        $newItem['path'] = $newPath;
+                        $newItem['parentPath'] = $entry['path'];
+                        $newItem['folderType'] = $this->getFolderType($newItem);
+                        $newItem['base'] = $this->pathToDn($newPath);
+                        $this->folderList['linear'][$path]['children'][$newPath] = $newItem;
+                        $this->baseEntryMap[$newItem['base']] = $newPath;
+                    }
+                }else{
+                    $newItem = $this->dialog->save();
+                    $path = $this->currentlyEditedItem['path'];
+                    $this->folderList['linear'][$path]['acls'] = $newItem['acls']; 
+                }
                 $this->dialog = NULL;
             }
         }
index fbbf7a2dbf249e8823bb3ac5253b09c3ec910d23..c1c114656987e52d1a739c9831eef6cb46d90b54 100644 (file)
@@ -52,6 +52,11 @@ class FolderWidgetListing extends management
         $this->parent->editByBase($target[0]);
     }
 
+    function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
+    {
+        $this->parent->addFolder();
+    }
+
     protected function removeEntryRequested($action="",$target=array(),$all=array())
     {   
         foreach($target as $tar){