From 1018cf8223d36aa903df9e97d2dfbbcef9fde157 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 17 May 2011 09:28:34 +0000 Subject: [PATCH] Fixed saving of DeviceConfig git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20842 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../systems/goto/Device/DeviceConfig.tpl | 57 ++++++++------ .../goto/Device/class_DeviceConfig.inc | 75 +++++++++++++++++-- 2 files changed, 104 insertions(+), 28 deletions(-) diff --git a/gosa-plugins/goto/admin/systems/goto/Device/DeviceConfig.tpl b/gosa-plugins/goto/admin/systems/goto/Device/DeviceConfig.tpl index 21e889b22..f5439f66e 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/DeviceConfig.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Device/DeviceConfig.tpl @@ -1,23 +1,34 @@ - - - - - - - - - - - -
-

{t}Assignable items{/t}

- {$assignableElementsList} -
-

{t}Assigned items{/t}

- {$usedElementsList} -
-
-
-

{t}Parameters{/t}

- {$parameterList} -
+{if $error} + +

+ {$errorMsg} +

+ + +{else} + + + + + + + + + + + + +
+

{t}Assignable items{/t}

+ {$assignableElementsList} +
+

{t}Assigned items{/t}

+ {$usedElementsList} +
+
+
+

{t}Parameters{/t}

+ {$parameterList} +
+ +{/if} diff --git a/gosa-plugins/goto/admin/systems/goto/Device/class_DeviceConfig.inc b/gosa-plugins/goto/admin/systems/goto/Device/class_DeviceConfig.inc index b064c1cfe..006a2b91b 100644 --- a/gosa-plugins/goto/admin/systems/goto/Device/class_DeviceConfig.inc +++ b/gosa-plugins/goto/admin/systems/goto/Device/class_DeviceConfig.inc @@ -16,6 +16,10 @@ class DeviceConfig extends plugin public $usedElements = array(); public $assignableElements = array(); + public $parameterValues = array(); + public $parameterWidgets = array(); + + public $initialized = FALSE; /*! \brief Initialize the plugin and its widgets. * Finally call init() to load values from the backend. @@ -54,7 +58,7 @@ class DeviceConfig extends plugin $this->parameterList = new sortableListing(); $this->parameterList->setDeleteable(TRUE); $this->parameterList->setInstantDelete(FALSE); - $this->parameterList->setEditable(TRUE); + $this->parameterList->setEditable(FALSE); $this->parameterList->setWidth("100%"); $this->parameterList->setHeight("200px"); $this->parameterList->setHeader(array(_("Type"))); @@ -70,6 +74,25 @@ class DeviceConfig extends plugin function execute() { + // Initialize to plugin + if(!$this->initialized){ + $rpc = $this->config->getRpcHandle(); + $res = $rpc->systemGetConfigParameters($this->deviceUUID); + if(!$rpc->success()){ + $smarty = get_smarty(); + $smarty->assign("error", TRUE); + $smarty->assign("errorMsg", msgPool::rpcError($this->rpcErrorMessage)); + return($display.$smarty->fetch(get_template_path('goto/Device/DeviceConfig.tpl', TRUE))); + }else{ + $this->initialized = TRUE; + $this->is_account = $this->initially_was_account = isset($res['item']); + + if(isset($res['var'])) $this->parameterValues = $res['var']; + if(isset($res['item'])) $this->usedElements = $res['item']; + } + } + + // Log account access if($this->is_account && !$this->view_logged){ $this->view_logged = TRUE; @@ -133,14 +156,19 @@ class DeviceConfig extends plugin foreach($parameter as $param => $desc){ $data[$param] = NULL; } - $value = (isset($this->parameterValues[$param])) ? $this->parameterValues[$param] : ""._('unset').""; - $lData[$param] = array('data' => array($name, $param, $value)); + $value = (isset($this->parameterValues[$param])) ? $this->parameterValues[$param] : ""; + + if(!isset($this->parameterWidgets[$param])){ + $this->parameterWidgets[$param] = new TemplateWidget_string($this->config, $param, $value, + $desc, '', FALSE, 'string', $param); + } + $w = $this->parameterWidgets[$param]; + $lData[$param] = array('data' => array($w->getDisplayName(), $w->render())); } $this->parameterList->setListData($data, $lData); - - $smarty = get_smarty(); + $smarty->assign("error", FALSE); $smarty->assign("assignableElementsList", $this->assignableElementsList->render()); $smarty->assign("usedElementsList", $this->usedElementsList->render()); $smarty->assign("parameterList", $this->parameterList->render()); @@ -151,6 +179,12 @@ class DeviceConfig extends plugin function save_object() { + // Get posted parameter values + foreach($this->parameterWidgets as $name => $w){ + $w->save_object(); + $this->parameterValues[$name] = $w->getValue(); + } + // Act on Add-Element actions $this->assignableElementsList->save_object(); $action = $this->assignableElementsList->getAction(); @@ -171,11 +205,42 @@ class DeviceConfig extends plugin function save() { + + // Collect paramter list. + $params = array(); + foreach($this->usedElements as $name){ + $params = array_merge($this->assignableElements[$name]['parameter']); + } + + // Decide whoch parameter has to be saved and which has to be removed. + $save = array(); + foreach($this->parameterValues as $name => $value){ + if(isset($params[$name])){ + $save[$name] = $value; + } + } + + // Save changes back to server. + $rpc = $this->config->getRpcHandle(); + $rpc->systemSetConfigParameters($this->deviceUUID, array('method' => 'puppet', 'var' => $save, 'item' => $this->usedElements)); + if(!$rpc->success()){ + $this->rpcErrorMessage = $rpc->get_error(); + msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG); + return(NULL); + } } function remove_from_parent() { + // Save changes back to server. + $rpc = $this->config->getRpcHandle(); + $rpc->removeConfigParameters($this->deviceUUID); + if(!$rpc->success()){ + $this->rpcErrorMessage = $rpc->get_error(); + msg_dialog::display(_("Error"), msgPool::rpcError($this->rpcErrorMessage), ERROR_DIALOG); + return(NULL); + } } -- 2.30.2