de77b6eb1718aa9832ae0f449a06c724217a3982
[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / TemplateEngine / class_TemplateWidget_list.inc
1 <?php
3 class TemplateWidget_list extends TemplateWidget
4 {
5 function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
6 {
7 if(!$value) $value =array();
8 parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
10 $this->listWidget= new sortableListing($this->value);
11 $this->listWidget->setEditable(false);
12 $this->listWidget->setDeleteable(true);
13 $this->listWidget->setColspecs(array('*'));
14 $this->listWidget->setWidth("100%");
15 $this->listWidget->setHeight("70px");
16 $this->listWidget->setAcl("");
17 }
20 function render()
21 {
22 $str = "";
23 $this->listWidget->setDeleteable($this->enabled);
24 $this->listWidget->setListData($this->value);
25 $this->listWidget->update();
26 $str .= $this->listWidget->render();
27 $disabled = (!$this->enabled || !$this->writeable)? "disabled" : "";
28 $name = (!$this->enabled || !$this->writeable)? "dummy".rand(0,10000) : $this->postName;
30 $acls = "";
31 $acls.= ($this->writeable && $this->enabled) ? 'w' : '';
32 $acls.= ($this->readable) ? 'r' : '';
33 $this->listWidget->setAcl($acls);
35 $str .= "<input type='text' name='{$name}_Input' {$disabled}>";
36 $str .= "<button name='{$name}_Add' {$disabled}>".msgPool::addButton()."</button>";
37 return($str);
38 }
40 function save_object()
41 {
42 $this->listWidget->save_object();
43 $action = $this->listWidget->getAction();
44 if($action['action'] == 'delete'){
45 $id = $this->listWidget->getKey($action['targets'][0]);
46 unset($this->value[$id]);
47 $this->value = array_values($this->value);
48 }
50 if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){
51 $input = get_post("{$this->postName}_Input");
53 if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){
54 msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/")));
55 }elseif(!empty($input)){
56 $this->value[] = $input;
57 }
58 }
59 }
61 /*! \brief Check the value entry using the provieded syntax.
62 * @return Array Returns a list of errors
63 */
64 function check()
65 {
66 if($this->required && empty($this->value)){
67 return(array(msgPool::required($this->display)));
68 }
69 return(array());
70 }
71 }
74 ?>