4 <script type="text/javascript" src="/planetlab/tablesort/tablesort.js"></script>
5 <script type="text/javascript" src="/planetlab/tablesort/customsort.js"></script>
6 <script type="text/javascript" src="/planetlab/tablesort/paginate.js"></script>
7 <script type="text/javascript" src="/planetlab/js/plc_tables.js"></script>
8 <link href="/planetlab/css/plc_tables.css" rel="stylesheet" type="text/css" />
11 ////////////////////////////////////////
12 // table_id: <table>'s id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code
13 // headers: an associative array "label"=>"type"
14 // column_sort: the column to sort on at load-time
15 // options : an associative array to override options
16 // - search_area : boolean (default true)
17 // - pagesize_area : boolean (default true)
18 // - notes_area : boolean (default true)
19 // - search_width : size in chars of the search text dialog
20 // - notes : an array of additional notes
21 // - pagesize: the initial pagination size
22 // - pagesize_def: the page size when one clicks the pagesize reset button
23 // - max_pages: the max number of pages to display in the paginator
24 // - footers: an array of table rows (<tr> will be added) for building the table's tfoot area
32 var $search_area; // boolean (default true)
33 var $pagesize_area; // boolean (default true)
34 var $notes_area; // boolean (default true)
35 var $search_width; // size in chars of the search text dialog
36 var $pagesize; // the initial pagination size
37 var $pagesize_def; // the page size when one clicks the pagesize reset button
38 var $max_pages; // the max number of pages to display in the paginator
39 var $notes; // an array of additional notes
40 var $footers; // an array of table rows (<tr> will be added) for building the table's tfoot area
42 function PlcTable ($table_id,$headers,$column_sort,$options=NULL) {
43 $this->table_id = $table_id;
44 $this->headers = $headers;
45 $this->column_sort = $column_sort;
47 $this->search_area = true;
48 $this->pagesize_area = true;
49 $this->notes_area = true;
50 $this->search_width = 40;
52 $this->pagesize_def = 999;
53 $this->max_pages = 10;
54 $this->notes = array();
55 $this->footers = array();
57 $this->set_options ($options);
60 function set_options ($options) {
63 if (array_key_exists('search_area',$options)) $this->search_area=$options['search_area'];
64 if (array_key_exists('pagesize_area',$options)) $this->pagesize_area=$options['pagesize_area'];
65 if (array_key_exists('notes_area',$options)) $this->notes_area=$options['notes_area'];
66 if (array_key_exists('search_width',$options)) $this->search_width=$options['search_width'];
67 if (array_key_exists('pagesize',$options)) $this->pagesize=$options['pagesize'];
68 if (array_key_exists('pagesize_def',$options)) $this->pagesize_def=$options['pagesize_def'];
69 if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages'];
71 if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']);
72 if (array_key_exists('footers',$options)) $this->footers=array_merge($this->footers,$options['footers']);
76 public function start () {
77 $paginator=$this->table_id."_paginator";
78 $classname="paginationcallback-".$paginator;
79 $classname.=" max-pages-" . $max_pages;
80 $classname.=" paginate-" . $pagesize;
81 // instantiate paginator callback
83 <script type="text/javascript">
84 function $paginator (opts) { plc_table_paginator (opts,"$this->table_id"); }
87 <table id="$this->table_id" cellpadding="0" cellspacing="0" border="0"
88 class="plc_table sortable-onload-$this->column_sort rowstyle-alt colstyle-alt no-arrow $classname">
92 if ($this->pagesize_area)
93 print $this->pagesize_area_text ();
94 if ($this->search_area)
95 print $this->search_area_text ();
98 foreach ($this->headers as $label => $type) {
99 if ($type == "none" ) {
102 if ($type == "string") $type="";
103 if ($type == "int") $type="";
104 if ($type == "float") $type="";
106 if ( ! empty($type)) $class .= "-sort" . $type;
108 printf ('<th class="%s plc_table">%s</th>',$class,$label);
119 // for convenience, the options that apply to the footer can be passed here
120 // typically footers or notes will add up to the ones provided so far
121 // makes code more readable, as preparing the footer before the table is displayed is confusing
122 function end ($options=NULL) {
123 $this->set_options($options);
124 print $this->foot_text();
125 if ($this->notes_area)
126 print $this->notes_area_text();
130 function pagesize_area_text () {
131 $width=count($this->headers);
132 $pagesize_text_id = $this->table_id . "_pagesize";
134 <tr class=pagesize_area><td class=pagesize_area colspan=$width><form class='pagesize'>
135 <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$this->pagesize
136 onkeyup='plc_pagesize_set("$this->table_id","$this->pagesize_text_id", $this->pagesize);'
137 size=3 maxlength=3 />
138 <label class='pagesize_label'> items/page </label>
139 <img class='table_reset' src="/planetlab/icons/clear.png"
140 onmousedown='plc_pagesize_reset("$this->table_id","$pagesize_text_id",$this->pagesize_def);' />
147 function search_area_text () {
148 $width=count($this->headers);
149 $search_text_id = $this->table_id . "_search";
150 $search_reset_id = $this->table_id . "_search_reset";
151 $search_and_id = $this->table_id . "_search_and";
153 <tr class=search_area><td class=search_area colspan=$width><form class='table_search'>
154 <label class='table_search_label'> Search </label>
155 <input class='table_search_input' type='text' id='$search_text_id'
156 onkeyup='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");'
157 size=$this->search_width maxlength=256 />
159 <input id='$search_and_id' class='table_search_and'
160 type='checkbox' checked='checked'
161 onchange='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");' />
162 <img class='table_reset' src="/planetlab/icons/clear.png"
163 onmousedown='plc_table_filter_reset("$this->table_id","$search_text_id","$search_and_id");'>
169 ////////////////////////////////////////
170 function foot_text () {
172 $result .= "</tbody><tfoot>\n";
174 foreach ($this->footers as $footer)
175 $result .="<tr>$footer</tr>\n";
176 $result .= "</tfoot></table>\n";
180 ////////////////////////////////////////
181 function notes_area_text () {
182 $default_notes = array(
183 "Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes",
184 "Hold down the shift key to select multiple columns to sort");
190 $notes=array_merge($notes,$default_notes);
194 $result .= "<p class='plc_table_note'> <span class='plc_table_note_title'>Notes</span>\n";
195 foreach ($notes as $note)
196 $result .= "<br/>$note\n";
201 ////////////////////////////////////////
202 function row_start ($id=NULL,$class=NULL) {
204 if ( $id) print (" id=\"$id\"");
205 if ( $class) print (" class=\"$class\"");
209 function row_end () {
214 public function cell_text ($cell) {
215 return "<td>$cell</td>";
217 public function cell ($cell) {
218 print $this->cell_text($cell);
221 public static function td_text ($text,$colspan=0,$align=NULL) {
224 if ($colspan) $result .= " colspan=$colspan";
225 if ($align) $result .= " style='text-align:$align'";
226 $result .= ">$text</td>";