1 <?php
3 class TemplateWidget_list extends TemplateWidget
4 {
5 function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
6 {
7 parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
9 $this->listWidget= new sortableListing($this->value);
10 $this->listWidget->setEditable(false);
11 $this->listWidget->setDeleteable(true);
12 $this->listWidget->setColspecs(array('*'));
13 $this->listWidget->setWidth("100%");
14 $this->listWidget->setHeight("70px");
15 $this->listWidget->setAcl("rwcdm");
16 }
19 function render()
20 {
21 $str = "";
22 $this->listWidget->setListData($this->value);
23 $this->listWidget->update();
24 $str .= $this->listWidget->render();
25 $str .= "<input type='text' name='{$this->postName}_Input'>";
26 $str .= "<button name='{$this->postName}_Add'>".msgPool::addButton()."</button>";
27 return($str);
28 }
30 function save_object()
31 {
32 $this->listWidget->save_object();
33 $action = $this->listWidget->getAction();
34 if($action['action'] == 'delete'){
35 $id = $this->listWidget->getKey($action['targets'][0]);
36 unset($this->value[$id]);
37 $this->value = array_values($this->value);
38 }
40 if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){
41 $input = get_post("{$this->postName}_Input");
43 if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){
44 msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/")));
45 }elseif(!empty($input)){
46 $this->value[] = $input;
47 }
48 }
49 }
51 /*! \brief Check the value entry using the provieded syntax.
52 * @return Array Returns a list of errors
53 */
54 function check()
55 {
56 if($this->required && empty($this->value)){
57 return(array(msgPool::required($this->display)));
58 }
59 return(array());
60 }
61 }
64 ?>