From 7caac135241163331409a3ed350b71727735e68b Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 30 Sep 2010 08:19:22 +0000 Subject: [PATCH] Updated item config management git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19862 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../systems/goto/Config/AddItemDialog.tpl | 21 ++++ .../systems/goto/Config/DeviceConfig-list.xml | 14 +-- .../goto/Config/class_AddItemDialog.inc | 61 ++++++++++ .../goto/Config/class_DeviceConfig.inc | 105 +++++++++++++++--- 4 files changed, 176 insertions(+), 25 deletions(-) create mode 100644 gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl create mode 100644 gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc diff --git a/gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl b/gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl new file mode 100644 index 000000000..2d9823c07 --- /dev/null +++ b/gosa-plugins/goto/admin/systems/goto/Config/AddItemDialog.tpl @@ -0,0 +1,21 @@ + +

{t}Add item{/t}

+ +{t}Please specify a name for the item to add, this name has to be uniq within the item configuration.{/t} +
+ +
+ +

+ {$itemCfg.name} -  {$itemCfg.description} +

+ +{t}Name{/t}:  + +
+ +
+ + +
+ diff --git a/gosa-plugins/goto/admin/systems/goto/Config/DeviceConfig-list.xml b/gosa-plugins/goto/admin/systems/goto/Config/DeviceConfig-list.xml index e5783ccae..27e6ec474 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/DeviceConfig-list.xml +++ b/gosa-plugins/goto/admin/systems/goto/Config/DeviceConfig-list.xml @@ -21,7 +21,7 @@ - |20px;c||80px|170px;r| + |20px;c|||170px;r| %{filter:objectType(dn,objectClass)} @@ -52,17 +52,7 @@ - - sub - images/lists/element.png[new] - - - remove - entry - images/lists/trash.png - - - + %ITEMS% remove diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc new file mode 100644 index 000000000..461508f5f --- /dev/null +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_AddItemDialog.inc @@ -0,0 +1,61 @@ +config = $config; + $this->itemCfg = $itemCfg; + $this->itemType = $itemType; + } + + function execute() + { + $smarty = get_smarty(); + $smarty->assign('itemCfg', set_post($this->itemCfg)); + $smarty->assign('itemName', set_post($this->itemName)); + return($smarty->fetch(get_template_path('goto/Config/AddItemDialog.tpl', TRUE))); + } + + function getItemCfg() + { + return($this->itemCfg); + } + + function getName() + { + return($this->itemName); + } + + function getItemType() + { + return($this->itemType); + } + + function save_object() + { + if(isset($_POST['itemName'])){ + $this->itemName = get_post('itemName'); + } + } + + function check() + { + $message = array(); + if(empty($this->itemName)){ + $message[] = msgPool::required(_("Name")); + }else + if(!tests::is_uid($this->itemName)){ + $message[] = msgPool::invalid(_("Name")); + } + return($message); + } +} + +?> diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc index 87d317a89..ad89ebb67 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc @@ -23,6 +23,8 @@ class DeviceConfig extends management private $baseToDN = array(); + private $addableContainerItems = array(); + /*! \brief Constructs the device configuration plugin * @param Config The GOsa configuration object. */ @@ -109,13 +111,6 @@ class DeviceConfig extends management } - function cancelItemEdit() - { - $this->closeDialogs(); - $this->dialog = FALSE; - } - - function saveItemChanges() { // Save eventually changed values @@ -125,7 +120,6 @@ class DeviceConfig extends management } } $this->closeDialogs(); - $this->dialog = FALSE; } @@ -203,6 +197,33 @@ class DeviceConfig extends management // Load service xml file and fill in placeholders $contents =file_get_contents(get_template_path("goto/Config/DeviceConfig-list.xml", true)); + + + $items = ""; + foreach($this->addableContainerItems as $item){ + $desc = $this->itemConfig[$item]['description']; + $items .= + "". + " add_{$item}". + " entry". + " images/lists/edit.png". + " ". + ""; + } + + if(!empty($item)){ + $items = + + "". + " sub". + " images/lists/element.png[new]". + " ". + " {$items}". + ""; + } + + $contents = preg_replace("/%ITEMS%/", $items, $contents); + $headpage = new listing($contents,TRUE); $headpage->setBase($this->base); $headpage->setFilter($filter); @@ -215,7 +236,56 @@ class DeviceConfig extends management $this->registerAction("editEntry", "editEntry"); $this->registerAction("saveItemChanges", "saveItemChanges"); - $this->registerAction("cancelItemEdit", "cancelItemEdit"); + $this->registerAction("cancelItemEdit", "closeDialogs"); + $this->registerAction("cancelItemAdd", "closeDialogs"); + $this->registerAction("saveItemAdd", "saveItemAdd"); + foreach($this->itemConfig as $name => $item){ + $this->registerAction("add_{$name}", "newEntry"); + } + } + + + /*! \brief This method intiates the object creation. + * + * @param String 'action' The name of the action which was the used as trigger. + * @param Array 'target' A list of object dns, which should be affected by this method. + * @param Array 'all' A combination of both 'action' and 'target'. + */ + function newEntry($action="",$target=array(),$all=array(), + $altTabClass ="", $altTabType = "", $altAclCategory="") + { + $toAdd = preg_replace("/^add_/", "",$action); + $itemToAdd = $this->itemConfig[$toAdd]; + + $this->dialogObject = new AddItemDialog($this->config,$toAdd,$itemToAdd); + $this->dialog = true; + } + + + function saveItemAdd() + { + if(!$this->dialogObject instanceOf AddItemDialog) return; + + $msgs = $this->dialogObject->save_object(); + $msgs = $this->dialogObject->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + $itemName = $this->dialogObject->getName(); + $itemCfg = $this->dialogObject->getItemCfg(); + $itemType = $this->dialogObject->getItemType(); + + $this->setCurrentItem($this->baseToDN[$this->base]); + + $this->addItem($itemType, $itemName); + $this->closeDialogs(); + +# $this->setCurrentItem($itemName); +# $this->dialogObject = $this->TemplateEngine; +# $this->skipFooter = TRUE; +# $this->dialog = TRUE; + + } } @@ -226,7 +296,7 @@ class DeviceConfig extends management * @param Array values The initial values for this object. * @return */ - function addItem($type,$name, $values) + function addItem($type,$name, $values = array()) { if(!isset($this->itemConfig[$type])){ echo "Invalid type {$type}, skipping item!"; @@ -234,10 +304,9 @@ class DeviceConfig extends management } $allValuesSet = TRUE; - foreach($this->itemConfig[$type]['options'] as $oName => $option){ + foreach($this->itemConfig[$type]['options'] as $oName => $oValue){ if(!isset($values[$oName])){ - echo "Missing value for option {$oName}! Skipping addItem({$type},{$name},array())!
"; - return; + $values[$oName] = $oValue; } } @@ -343,6 +412,7 @@ class DeviceConfig extends management { $this->base = $base; $item = $this->currentItemValues[$this->baseToDN[$base]]; + $this->addableContainerItems = $this->itemConfig[$item['type']]['container']; } @@ -376,7 +446,9 @@ class DeviceConfig extends management { $action = management::detectPostActions(); if(isset($_POST['saveItemEdit'])) $action['action'] = "saveItemChanges"; + if(isset($_POST['saveItemAdd'])) $action['action'] = "saveItemAdd"; if(isset($_POST['cancelItemEdit'])) $action['action'] = "cancelItemEdit"; + if(isset($_POST['cancelItemAdd'])) $action['action'] = "cancelItemAdd"; if($action['action'] == 'remove'){ echo "Löschen geht nicht!"; @@ -384,6 +456,13 @@ class DeviceConfig extends management } return($action); } + + + function closeDialogs() + { + parent::closeDialogs(); + $this->dialog = false; + } function check() -- 2.30.2