Code

Updated widgets to allow disabling items
[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / TemplateEngine / class_TemplateWidget_fixedList.inc
1 <?php
3 class TemplateWidget_fixedList extends TemplateWidget
4 {
5     protected $value = array();
6     
7     function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
8     {
9         parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
11         $this->listWidget= new sortableListing($this->value);
12         $this->listWidget->setEditable(false);
13         $this->listWidget->setDeleteable(true);
14         $this->listWidget->setColspecs(array('*'));
15         $this->listWidget->setWidth("100%");
16         $this->listWidget->setHeight("70px");
17         $this->listWidget->setAcl("rwcdm");
18     }
20     function getAvailableOptions()
21     {
22         $tmp = array();
23         foreach($this->values as $key => $name){
24             if(!in_array($key, $this->value)){
25                 $tmp[$key]=$name;
26             }
27         }
28         return($tmp);
29     }
31     function render()
32     {
33         $str = "";
35         // Build up list data
36         $this->listWidget->setDeleteable($this->enabled);
37         $disabled = (!$this->enabled)? "disabled" : "";
38         $data = $this->value;
39         foreach($this->value as $key => $name){
40             $lData[$key] = array('data' => array($this->values[$name]));
41         }
42         $this->listWidget->setListData($data, $lData);
43         $this->listWidget->update();
44         $str .= $this->listWidget->render();
45         $str .= "<select size='1' name='{$this->postName}_Input' {$disabled}>";
46         foreach($this->getAvailableOptions() as $name => $value){
47             $str .= "<option value=\"{$name}\">{$value}</option>\n";
48         }
49         $str .= "</select>";
50         $str .= "<button name='{$this->postName}_Add' {$disabled}>".msgPool::addButton()."</button>";
51         return($str);
52     }
54     function save_object()
55     {
56         $this->listWidget->save_object();
57         $action = $this->listWidget->getAction();
58         if($action['action'] == 'delete'){
59             $id = $this->listWidget->getKey($action['targets'][0]);
60             unset($this->value[$id]);
61             $this->value = array_values($this->value);
62         }
64         if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){
65             $input = get_post("{$this->postName}_Input");
67             if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){
68                 msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/")));
69             }elseif(!empty($input)){
70                 $this->value[] = $input;
71             }
72         }
73     }
75     /*! \brief  Check the value entry using the provieded syntax.
76      * @return  Array   Returns a list of errors
77      */
78     function check()
79     {
80         if($this->required && empty($this->value)){
81             return(array(msgPool::required($this->display)));
82         }
83         return(array());
84     }
85 }
88 ?>