From cc894450a323e66ccc8566a781c9748df7cfb14c Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 8 Oct 2010 13:58:38 +0000 Subject: [PATCH] Allow to add new entries git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19958 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../FolderWidget/FolderEditDialog.tpl | 15 ++++++- .../FolderWidget/class_FolderEditDialog.inc | 24 +++++++++- .../FolderWidget/class_FolderWidget.inc | 44 ++++++++++++++++--- .../class_FolderWidgetListing.inc | 5 +++ 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/gosa-plugins/groupware/personal/groupware/FolderWidget/FolderEditDialog.tpl b/gosa-plugins/groupware/personal/groupware/FolderWidget/FolderEditDialog.tpl index 56152b86e..d7270b94e 100644 --- a/gosa-plugins/groupware/personal/groupware/FolderWidget/FolderEditDialog.tpl +++ b/gosa-plugins/groupware/personal/groupware/FolderWidget/FolderEditDialog.tpl @@ -1,5 +1,17 @@ -

{t}Folder{/t}

+{if $isNew} + +

{t}Create folder{/t}

+ + + + + +
{t}Name{/t}: 
+ +{else} + +

{t}Edit folder{/t}

@@ -10,6 +22,7 @@
{t}Name{/t}: {$folderItem.path}
+{/if}
diff --git a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderEditDialog.inc b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderEditDialog.inc index 4af753839..e4e3ab87e 100644 --- a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderEditDialog.inc +++ b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderEditDialog.inc @@ -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); diff --git a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc index ae3c5f9e6..4307d7305 100644 --- a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc +++ b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidget.inc @@ -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; } } diff --git a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc index fbbf7a2db..c1c114656 100644 --- a/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc +++ b/gosa-plugins/groupware/personal/groupware/FolderWidget/class_FolderWidgetListing.inc @@ -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){ -- 2.30.2