From: hickert Date: Mon, 27 Sep 2010 09:34:33 +0000 (+0000) Subject: Allow to set values for widgets X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8f77f4b60ef069944c284333c61f6d5a53283312;p=gosa.git Allow to set values for widgets git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19793 594d385d-05f5-0310-b6e9-bd551577e9d8 --- 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 01d9ecc48..61b1209fc 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc @@ -5,10 +5,12 @@ class DeviceConfig extends plugin private $TemplateEngine = NULL; private $idToName = array(); + private $currentItemName = ""; function __construct(&$config, $dn) { $this->TemplateEngine = new TemplateEngine($config); + $this->TemplateEngine->setTemplate('puppet.tpl'); $this->config = $config; $str = '{ @@ -85,14 +87,15 @@ class DeviceConfig extends plugin $this->setCurrentItem('root'); $this->addItem('PuppetModule','test1', array( - 'version' => 1, - 'name' => 'test1', - 'description' => 'Test Module') + 'dependency' => 'mozilla-2', + 'version' => '2.4-f', + 'name' => 'Thundebird', + 'description' => 'Mozilla mail client') ); $this->addItem('PuppetModule','test2', array( 'version' => 1, - 'name' => 'test2', + 'name' => 'Firefox', 'description' => 'Test Module') ); $this->setCurrentItem('test1'); @@ -115,6 +118,7 @@ class DeviceConfig extends plugin }else{ $str .= $array['name']; } + $str .= " (".$array['type'].")"; $str .= ""; if(count($array['children'])){ @@ -141,10 +145,13 @@ class DeviceConfig extends plugin function setCurrentItem($item) { + if($this->currentItemName == $item) return; $this->currentItemName = $item; $this->currentItem = &$this->currentItemValues[$item]; $this->currentItemType = $this->currentItem['type']; $this->currentItemDescriptor =&$this->itemConfig[$this->currentItem['type']]; + $this->TemplateEngine->setType($this->currentItemType); + $this->TemplateEngine->setValues($this->currentItem['values']); } @@ -161,15 +168,14 @@ class DeviceConfig extends plugin - $this->TemplateEngine->setType($this->currentItemType); - $this->TemplateEngine->setValues($this->currentItem); - $this->TemplateEngine->setTemplate('puppet.tpl'); $smarty->assign('template',$this->TemplateEngine->render()); return($smarty->fetch(get_template_path('goto/Config/DeviceConfig.tpl', TRUE))); } function save_object() { + $this->TemplateEngine->save_object(); + if(isset($_POST['addSubModule']) && isset($_POST['subModule'])){ $sub = get_post('subModule'); if(in_array($sub, $this->currentItemDescriptor['container'])){ diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc index f976ed51a..6d7f3f705 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc @@ -13,9 +13,11 @@ class TemplateEngine $this->config = &$config; } - function setValues($array) + function setValues($values) { -# print_a($array); + foreach($values as $name => $value){ + $this->widgets[$name]->setValue($value); + } } function setType($name) @@ -23,10 +25,20 @@ class TemplateEngine $this->itemType = $name; $this->widgets = array(); + if(!isset($this->data[$this->itemType])){ + trigger_error("Undefined item type '{$name}'!"); + return; + } $data = $this->data[$this->itemType]; if(isset($data['options']) && count($data['options'])){ foreach($data['options'] as $name => $item){ - $this->widgets[] = new TemplateWidget($this->config, $name, $item['value']); + + $this->widgets[$name] = new TemplateWidget($this->config, $name, + $item['value'], + $item['description'], + $item['required'], + $item['type'], + $item['display']); } } } @@ -50,11 +62,18 @@ class TemplateEngine { $smarty = get_smarty(); $smarty->assign("type", $this->itemType); - foreach($this->getWidgets() as $widget){ + foreach($this->widgets as $widget){ $smarty->assign($widget->getName(), $widget->render()); } return($smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE))); } + + function save_object() + { + foreach($this->widgets as $widget){ + $widget->save_object(); + } + } } diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc index d946c3cc1..e48e06a24 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc @@ -5,25 +5,44 @@ class TemplateWidget private $name = "unnamed"; private $value = ""; - function __construct(&$config, $name, $value) + private $description = ""; + private $required = ""; + private $type = ""; + private $display = ""; + + function __construct(&$config, $name, $value, $description,$required,$type,$display) { + $this->config = &$config; + + echo '*'; $this->name = $name; $this->value = $value; - $this->config = &$config; + $this->description = $description; + $this->required = $required; + $this->type = $type; + $this->display = $display; } function render() { - return("name}\" value=\"".set_post($this->value)."\">"); + + $class = get_class(); + return("{$this->display} name}\" value=\"".set_post($this->value)."\">"); } function save_object() { + $class = get_class(); + $name = "{$class}_{$this->name}"; + if(isset($_POST[$name])){ + $this->value = get_post($name); + } } function getValue() { + return($this->value); } function getName() @@ -31,8 +50,9 @@ class TemplateWidget return($this->name); } - function setValue() + function setValue($value) { + $this->value = $value; } }