6 <script type="text/javascript" src="/planetlab/tablesort/tablesort.js"></script>
7 <script type="text/javascript" src="/planetlab/tablesort/customsort.js"></script>
8 <script type="text/javascript" src="/planetlab/tablesort/paginate.js"></script>
9 <script type="text/javascript" src="/planetlab/js/plc_tables.js"></script>
10 <link href="/planetlab/css/plc_tables.css" rel="stylesheet" type="text/css" />
13 ////////////////////////////////////////
14 // table_id: <table>'s id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code
15 // headers: an associative array "label"=>"type"
16 // column_sort: the column to sort on at load-time
17 // options : an associative array to override options
18 // - search_area : boolean (default true)
19 // - pagesize_area : boolean (default true)
20 // - notes_area : boolean (default true)
21 // - search_width : size in chars of the search text dialog
22 // - notes : an array of additional notes
23 // - pagesize: the initial pagination size
24 // - pagesize_def: the page size when one clicks the pagesize reset button
25 // - max_pages: the max number of pages to display in the paginator
33 var $search_area; // boolean (default true)
34 var $pagesize_area; // boolean (default true)
35 var $notes_area; // boolean (default true)
36 var $search_width; // size in chars of the search text dialog
37 var $pagesize; // the initial pagination size
38 var $pagesize_def; // the page size when one clicks the pagesize reset button
39 var $max_pages; // the max number of pages to display in the paginator
40 var $notes; // an array of additional notes
43 function PlcTable ($table_id,$headers,$column_sort,$options=NULL) {
44 $this->table_id = $table_id;
45 $this->headers = $headers;
46 $this->column_sort = $column_sort;
48 $this->has_tfoot=false;
50 $this->search_area = true;
51 $this->pagesize_area = true;
52 $this->notes_area = true;
53 $this->search_width = 40;
55 $this->pagesize_def = 999;
56 $this->max_pages = 10;
57 $this->notes = array();
59 $this->set_options ($options);
62 function set_options ($options) {
65 if (array_key_exists('search_area',$options)) $this->search_area=$options['search_area'];
66 if (array_key_exists('pagesize_area',$options)) $this->pagesize_area=$options['pagesize_area'];
67 if (array_key_exists('notes_area',$options)) $this->notes_area=$options['notes_area'];
68 if (array_key_exists('search_width',$options)) $this->search_width=$options['search_width'];
69 if (array_key_exists('pagesize',$options)) $this->pagesize=$options['pagesize'];
70 if (array_key_exists('pagesize_def',$options)) $this->pagesize_def=$options['pagesize_def'];
71 if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages'];
73 if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']);
76 public function columns () {
77 return count ($this->headers);
81 public function start () {
82 $paginator=$this->table_id."_paginator";
83 $classname="paginationcallback-".$paginator;
84 $classname.=" max-pages-" . $this->max_pages;
85 $classname.=" paginate-" . $this->pagesize;
86 // instantiate paginator callback
88 <script type="text/javascript">
89 function $paginator (opts) { plc_table_paginator (opts,"$this->table_id"); }
92 <table id="$this->table_id" cellpadding="0" cellspacing="0" border="0"
93 class="plc_table sortable-onload-$this->column_sort rowstyle-alt colstyle-alt no-arrow $classname">
97 if ($this->pagesize_area)
98 print $this->pagesize_area_html ();
99 if ($this->search_area)
100 print $this->search_area_html ();
103 foreach ($this->headers as $label => $type) {
104 if ($type == "none" ) {
107 if ($type == "string") $type="";
108 if ($type == "int") $type="";
109 if ($type == "float") $type="";
111 if ( ! empty($type)) $class .= "-sort" . $type;
113 printf ('<th class="%s plc_table">%s</th>',$class,$label);
124 // for convenience, the options that apply to the bottom area can be passed here
125 // typically notes will add up to the ones provided so far, and to the default ones
126 // xxx default should be used only if applicable
127 function end ($options=NULL) {
128 $this->set_options($options);
129 print $this->bottom_html();
130 if ($this->notes_area)
131 print $this->notes_area_html();
135 function pagesize_area_html () {
136 $width=count($this->headers);
137 $pagesize_text_id = $this->table_id . "_pagesize";
139 <tr class=pagesize_area><td class=pagesize_area colspan=$width><form class='pagesize'>
140 <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$this->pagesize
141 onkeyup='plc_pagesize_set("$this->table_id","$pagesize_text_id", $this->pagesize);'
142 size=3 maxlength=3 />
143 <label class='pagesize_label'> items/page </label>
144 <img class='table_reset' src="/planetlab/icons/clear.png"
145 onmousedown='plc_pagesize_reset("$this->table_id","$pagesize_text_id",$this->pagesize_def);' />
152 function search_area_html () {
153 $width=count($this->headers);
154 $search_text_id = $this->table_id . "_search";
155 $search_reset_id = $this->table_id . "_search_reset";
156 $search_and_id = $this->table_id . "_search_and";
158 <tr class=search_area><td class=search_area colspan=$width><form class='table_search'>
159 <label class='table_search_label'> Search </label>
160 <input class='table_search_input' type='text' id='$search_text_id'
161 onkeyup='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");'
162 size=$this->search_width maxlength=256 />
164 <input id='$search_and_id' class='table_search_and'
165 type='checkbox' checked='checked'
166 onchange='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");' />
167 <img class='table_reset' src="/planetlab/icons/clear.png"
168 onmousedown='plc_table_filter_reset("$this->table_id","$search_text_id","$search_and_id");'>
174 //////////////////// start a <tfoot> section
175 function tfoot_start () { print $this->tfoot_start_html(); }
176 function tfoot_start_html () {
177 $this->has_tfoot=true;
178 return "</tbody><tfoot>";
181 ////////////////////////////////////////
182 function bottom_html () {
184 if ($this->has_tfoot)
185 $result .= "</tfoot>";
187 $result .= "</tbody>";
188 $result .= "</table>\n";
192 ////////////////////////////////////////
193 function notes_area_html () {
194 $default_notes = array(
195 "Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes",
196 "Hold down the shift key to select multiple columns to sort");
202 $notes=array_merge($notes,$default_notes);
206 $result .= "<p class='plc_table_note'> <span class='plc_table_note_title'>Notes</span>\n";
207 foreach ($notes as $note)
208 $result .= "<br/>$note\n";
213 ////////////////////////////////////////
214 function row_start ($id=NULL,$class=NULL) {
216 if ( $id) print (" id=\"$id\"");
217 if ( $class) print (" class=\"$class\"");
221 function row_end () {
226 public function cell ($text,$colspan=0,$align=NULL) { print $this->cell_html ($text,$colspan,$align); }
227 public function cell_html ($text,$colspan=0,$align=NULL) {
230 if ($colspan) $result .= " colspan=$colspan";
231 if ($align) $result .= " style='text-align:$align'";
232 $result .= ">$text</td>";