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
31 var $search_area; // boolean (default true)
32 var $pagesize_area; // boolean (default true)
33 var $notes_area; // boolean (default true)
34 var $search_width; // size in chars of the search text dialog
35 var $pagesize; // the initial pagination size
36 var $pagesize_def; // the page size when one clicks the pagesize reset button
37 var $max_pages; // the max number of pages to display in the paginator
38 var $notes; // an array of additional notes
41 function PlcTable ($table_id,$headers,$column_sort,$options=NULL) {
42 $this->table_id = $table_id;
43 $this->headers = $headers;
44 $this->column_sort = $column_sort;
46 $this->has_tfoot=false;
48 $this->search_area = true;
49 $this->pagesize_area = true;
50 $this->notes_area = true;
51 $this->search_width = 40;
53 $this->pagesize_def = 999;
54 $this->max_pages = 10;
55 $this->notes = 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']);
74 public function columns () {
75 return count ($this->headers);
79 public function start () {
80 $paginator=$this->table_id."_paginator";
81 $classname="paginationcallback-".$paginator;
82 $classname.=" max-pages-" . $this->max_pages;
83 $classname.=" paginate-" . $this->pagesize;
84 // instantiate paginator callback
86 <script type="text/javascript">
87 function $paginator (opts) { plc_table_paginator (opts,"$this->table_id"); }
90 <table id="$this->table_id" cellpadding="0" cellspacing="0" border="0"
91 class="plc_table sortable-onload-$this->column_sort rowstyle-alt colstyle-alt no-arrow $classname">
95 if ($this->pagesize_area)
96 print $this->pagesize_area_html ();
97 if ($this->search_area)
98 print $this->search_area_html ();
101 foreach ($this->headers as $label => $type) {
102 if ($type == "none" ) {
105 if ($type == "string") $type="";
106 if ($type == "int") $type="";
107 if ($type == "float") $type="";
109 if ( ! empty($type)) $class .= "-sort" . $type;
111 printf ('<th class="%s plc_table">%s</th>',$class,$label);
122 // for convenience, the options that apply to the bottom area can be passed here
123 // typically notes will add up to the ones provided so far, and to the default ones
124 // xxx default should be used only if applicable
125 function end ($options=NULL) {
126 $this->set_options($options);
127 print $this->bottom_html();
128 if ($this->notes_area)
129 print $this->notes_area_html();
133 function pagesize_area_html () {
134 $width=count($this->headers);
135 $pagesize_text_id = $this->table_id . "_pagesize";
137 <tr class=pagesize_area><td class=pagesize_area colspan=$width><form class='pagesize'>
138 <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$this->pagesize
139 onkeyup='plc_pagesize_set("$this->table_id","$pagesize_text_id", $this->pagesize);'
140 size=3 maxlength=3 />
141 <label class='pagesize_label'> items/page </label>
142 <img class='table_reset' src="/planetlab/icons/clear.png"
143 onmousedown='plc_pagesize_reset("$this->table_id","$pagesize_text_id",$this->pagesize_def);' />
150 function search_area_html () {
151 $width=count($this->headers);
152 $search_text_id = $this->table_id . "_search";
153 $search_reset_id = $this->table_id . "_search_reset";
154 $search_and_id = $this->table_id . "_search_and";
156 <tr class=search_area><td class=search_area colspan=$width><form class='table_search'>
157 <label class='table_search_label'> Search </label>
158 <input class='table_search_input' type='text' id='$search_text_id'
159 onkeyup='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");'
160 size=$this->search_width maxlength=256 />
162 <input id='$search_and_id' class='table_search_and'
163 type='checkbox' checked='checked'
164 onchange='plc_table_filter("$this->table_id","$search_text_id","$search_and_id");' />
165 <img class='table_reset' src="/planetlab/icons/clear.png"
166 onmousedown='plc_table_filter_reset("$this->table_id","$search_text_id","$search_and_id");'>
172 //////////////////// start a <tfoot> section
173 function tfoot_start () { print $this->tfoot_start_html(); }
174 function tfoot_start_html () {
175 $this->has_tfoot=true;
176 return "</tbody><tfoot>";
179 ////////////////////////////////////////
180 function bottom_html () {
182 if ($this->has_tfoot)
183 $result .= "</tfoot>";
185 $result .= "</tbody>";
186 $result .= "</table>\n";
190 ////////////////////////////////////////
191 function notes_area_html () {
192 $default_notes = array(
193 "Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes",
194 "Hold down the shift key to select multiple columns to sort");
200 $notes=array_merge($notes,$default_notes);
204 $result .= "<p class='plc_table_note'> <span class='plc_table_note_title'>Notes</span>\n";
205 foreach ($notes as $note)
206 $result .= "<br/>$note\n";
211 ////////////////////////////////////////
212 function row_start ($id=NULL,$class=NULL) {
214 if ( $id) print (" id=\"$id\"");
215 if ( $class) print (" class=\"$class\"");
219 function row_end () {
224 public function cell ($text,$colspan=0,$align=NULL) { print $this->cell_html ($text,$colspan,$align); }
225 public function cell_html ($text,$colspan=0,$align=NULL) {
228 if ($colspan) $result .= " colspan=$colspan";
229 if ($align) $result .= " style='text-align:$align'";
230 $result .= ">$text</td>";