From 53e5ec70cdf96ace415dc0059fa62e4265fa711b Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 1 Oct 2010 08:04:17 +0000 Subject: [PATCH] Added syntax checking git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19880 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../goto/Config/class_DeviceConfig.inc | 13 ++++++++--- .../goto/Config/class_TemplateEngine.inc | 16 ++++++++++++- .../goto/Config/class_TemplateWidget.inc | 23 +++++++++++++++++-- .../goto/Config/class_TemplateWidget_list.inc | 4 ++-- .../Config/class_TemplateWidget_string.inc | 9 +++++++- 5 files changed, 56 insertions(+), 9 deletions(-) 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 99379cd9a..03a2a075a 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc @@ -220,11 +220,18 @@ class DeviceConfig extends management { // Save eventually changed values if($this->currentItem){ - foreach($this->TemplateEngine->getWidgets() as $widget){ - $this->currentItem['values'][$widget->getName()] = $widget->getValue(); + + // Check if everything is fine. + $msgs = $this->TemplateEngine->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + foreach($this->TemplateEngine->getWidgets() as $widget){ + $this->currentItem['values'][$widget->getName()] = $widget->getValue(); + } + $this->closeDialogs(); } } - $this->closeDialogs(); } 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 0723bc4fd..484b701f3 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc @@ -85,11 +85,13 @@ class TemplateEngine // Prepare the value for the widget $value = $values[$name]; - + $syntax = (isset($item['syntax']))? $item['syntax']: ""; + // Create the new widget. $this->widgets[$name] = new $widgetClassName($this->config, $name, $value, $item['description'], + $syntax, $item['required'], $item['type'], $item['display']); @@ -132,6 +134,18 @@ class TemplateEngine $widget->save_object(); } } + + + /*! \brief Check widget values and return a list of errors. + */ + function check() + { + $msgs = array(); + foreach($this->widgets as $widget){ + $msgs = array_merge($msgs, $widget->check()); + } + return($msgs); + } } 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 ef4ff99d6..670fbed18 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget.inc @@ -12,6 +12,7 @@ class TemplateWidget protected $required = ""; protected $type = ""; protected $display = ""; + protected $syntax = ""; /*! \brief Constructs the template widget and sets the default values. * @param Config The GOsa configuration object. @@ -22,7 +23,7 @@ class TemplateWidget * @param String The widget type. * @param String A display name for the widget. */ - function __construct(&$config, $name, $value, $description,$required,$type,$display) + function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display) { $this->config = &$config; $this->name = $name; @@ -42,7 +43,16 @@ class TemplateWidget */ function getDisplayName() { - return($this->display); + $must = ($this->required)?"*":""; + return($this->display.$must); + } + + + /*! \brief Returns the description for the widget. + */ + function getDescription() + { + return($this->description); } @@ -90,5 +100,14 @@ class TemplateWidget { $this->value = $value; } + + + /*! \brief Check the value entry using the provieded syntax. + * @return Array Returns a list of errors + */ + function check() + { + return(array()); + } } ?> diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_list.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_list.inc index 3f1f457ef..0d21145d8 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_list.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_list.inc @@ -2,9 +2,9 @@ class TemplateWidget_list extends TemplateWidget { - function __construct(&$config, $name, $value, $description,$required,$type,$display) + function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display) { - parent:: __construct($config, $name, $value, $description,$required,$type,$display); + parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display); $this->listWidget= new sortableListing($this->value); $this->listWidget->setEditable(false); diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_string.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_string.inc index 1ff9520a5..2bf3ccca0 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_string.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateWidget_string.inc @@ -4,7 +4,14 @@ class TemplateWidget_string extends TemplateWidget { function render() { - return("postName}\" value=\"".set_post($this->value)."\">"); + $desc = set_post($this->description); + $value = set_post($this->value); + + $name = " name=\"{$this->postName}\" "; + $value = " value=\"{$value}\" "; + $title = (empty($this->description))?"": " title=\"{$desc}\""; + + return(""); } } -- 2.30.2