From b7344a11f093e98b1ebb06c8ce1cf30a0d701e30 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 14 Apr 2011 12:11:37 +0000 Subject: [PATCH] Enabled item movement git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20729 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../class_ConfigManagementDataModel.inc | 26 ++++++ .../class_newConfigManagement.inc | 79 +++++++++---------- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagementDataModel.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagementDataModel.inc index 16dd8fcc0..d742056f1 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagementDataModel.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/class_ConfigManagementDataModel.inc @@ -19,6 +19,32 @@ class ConfigManagementDataModel return($this->data); } + function moveItem($from, $to) + { + // Get source entries + $itemFrom = &$this->data['linear'][$from]; + $parentFrom = &$this->data['linear'][$itemFrom['parentPath']]; + + // Extract 'to' informations out of the path. + $name = preg_replace("/^.*\//","", $to); + $toParentPath = preg_replace("/\/[^\/]*$/","", $to); + $parentTo = &$this->data['linear'][$toParentPath]; + $parentToDn = $parentTo['dn']; + + // Append the 'from' entry to the 'to' parent children. + $parentTo['children'][$to] = $parentFrom['children'][$from]; + $parentTo['children'][$to]['path']= $to; + $parentTo['children'][$to]['name']= $name; + $parentTo['children'][$to]['dn']= rtrim("cn={$name},{$parentToDn}",','); + + // Unset the source path + unset($parentFrom['children'][$from]); + unset($this->data['linear'][$from]); + + // Append the linear entry. + $this->data['linear'][$to] = &$parentTo['children'][$to]; + } + function removeItem($path) { $item = &$this->data['linear'][$path]; diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc index faa9f1e93..1d6f9a023 100644 --- a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc +++ b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc @@ -557,61 +557,60 @@ class newConfigManagement extends plugin return; } - // Null means a new object has to be added. - if($item == NULL){ + if($this->cfgItemMap[$type] != 'root'){ // Save template engine modifications $this->TemplateEngine->save_object(); $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer)); - // Collect modified values + // Get values to be saved $values = array(); foreach($this->TemplateEngine->getWidgets() as $w){ $values[$w->getName()] = $w->getValue(); } - // Create the elements target path - $path = $this->getItemPath($this->selectedContainer)."/".$values['name']; - - // Add the new item - $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{ + // Get paths + $newPath = $this->selectedContainer."/".$values['name']; + $newItemPath = $this->getItemPath($this->selectedContainer)."/".$values['name']; + if($item){ + $oldPath = $item['path']; + $oldItemPath = $this->getItemPath($item['path']); + } - // We've successfully added the item, now add it to the tree. - $this->dataModel->addItem($type, $this->selectedContainer, $values['name'],array(), '-' ); + // If this is a new item, then create it now. + if($item == NULL){ - // Finally - close the dialog. - $this->listing->clearDialogObject(); - } - }else{ + // Add the new item + $rpc = $this->config->getRpcHandle(); + $res = $rpc->setConfigItem($release, $newItemPath, $type, $values); + if(!$rpc->success()){ + msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG); + return(NULL); + }else{ - // Collect modified values. - $this->TemplateEngine->save_object(); - $values = array(); - foreach($this->TemplateEngine->getWidgets() as $w){ - $values[$w->getName()] = $w->getValue(); - } + // We've successfully added the item, now add it to the tree. + $this->dataModel->addItem($type, $this->selectedContainer, $values['name'],array(), '-' ); - // Get the items release & path info - $release = preg_replace("/^.*\//","", $this->getReleasePath($item['path'])); - $path = $this->getItemPath($item['path']); - - // Write the modifications back to the server. - $rpc = $this->config->getRpcHandle(); - $res = $rpc->setConfigItem($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); + // Finally - close the dialog. + $this->listing->clearDialogObject(); + } }else{ - - // Update the data model - $item['values'] = $values; - $this->dataModel->setItemValues($item['path'], $item['values']); - $this->listing->clearDialogObject(); + + // Write the modifications back to the server. + $rpc = $this->config->getRpcHandle(); + $res = $rpc->setConfigItem($release, $oldItemPath, $type, $values); + if(!$rpc->success()){ + msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG); + return(NULL); + }else{ + + // Update the data model + $item['values'] = $values; + + $this->dataModel->setItemValues($item['path'], $item['values']); + $this->dataModel->moveItem($oldPath, $newPath); + $this->listing->clearDialogObject(); + } } } } -- 2.30.2