5 require_once 'plc_functions.php';
6 require_once 'plc_forms.php';
9 <link href="/planetlab/css/plc_details.css" rel="stylesheet" type="text/css" />
13 // the basic idea is to define an area for displaying details like
15 // and we add in-line editing capabilities
24 var $input_type="text";
26 function PlcDetails ($editable) {
27 $this->editable=$editable;
29 $this->field_width="";
30 $this->field_height="2";
33 function form() { return $this->form; }
35 // start the details area, with an optional caption
36 function start ($caption="") { print $this->start_html("$caption");}
37 function start_html ($caption="") {
38 $html="<table class=plc_details><thead>";
39 if ($caption) $html .= "<caption>$caption</caption>";
40 $html .= "</thead><tbody>";
44 function end() { print $this->end_html(); }
45 function end_html () {
46 return "</tbody></table>\n";
49 // starts an inner form if the details are editable
50 // accpets same args as PlcForm
51 function form_start ($url,$values,$method="POST") { print $this->form_start_html($url,$values,$method); }
52 function form_start_html ($url,$values,$method="POST") {
53 $this->form = new PlcForm ($url,$values,$method);
54 return $this->form->start_html();
57 function form_end () { print $this->form_end_html(); }
58 function form_end_html () {
59 if ( ! $this->form) return "";
60 $html = $this->form->end_html();
65 // must be embedded in a line or a single
66 // xxx need a way to ask for confirmation
67 function submit_html ($name,$display) {
68 if ( ! $this->form) return "";
69 if ( ! $this->editable) return "";
70 return $this->form->submit_html($name,$display);
73 // give a form_varname if the field can be edited
74 function line ($title,$value,$form_varname="") {
75 print $this->line_html ($title,$value,$form_varname);
77 function line_html ($title,$value,$form_varname="") {
78 if ( ! ($this->editable && $form_varname) ) {
79 return "<tr><th>$title</th><td>$value</td></tr>";
82 $html .= "<tr><th><label for=$form_varname>$title</label></th>";
84 // hack: if input_type is select : user provides the input field verbatim
85 if ( $this->input_type == "select" ) {
87 } else if ($this->input_type == "textarea") {
88 $html .= "<textarea name='$form_varname'";
89 if ($this->field_width) $html .= " cols=$this->field_width";
90 if ($this->field_height) $html .= " rows=$this->field_height";
91 $html .= ">$value</textarea>";
93 $html .= "<input type='$this->input_type' name='$form_varname' value='$value'";
94 if ($this->field_width) $html .= " size=$this->field_width";
97 $html .= "</td></tr>";
102 // same but the values are multiple and displayed in an embedded vertical table (not editable)
103 function lines($title,$list) { print $this->lines_html($title,$list); }
104 function lines_html($title,$list) {
105 return $this->line_html($title,plc_vertical_table($list,"foo"));
109 function single($title,$align=NULL) { print $this->single_html($title,$align);}
110 function single_html($title,$align=NULL) {
111 $result="<tr><td colspan=2";
112 if ($align) $result .= " style='text-align:$align'";
113 $result .=">$title</td></tr>";
117 // a dummy line for getting some air
118 function space () { print $this->space_html(); }
119 function space_html () { return "<tr><td colspan=2> </td></tr>\n"; }
121 function set_field_width ($field_width) {
122 $old=$this->field_width;
123 $this->field_width=$field_width;
126 function set_field_height ($field_height) {
127 $old=$this->field_height;
128 $this->field_height=$field_height;
132 function set_input_type ($input_type) {
133 $old=$this->input_type;
134 $this->input_type=$input_type;