checkpoint
[plewww.git] / planetlab / includes / plc_tables.php
index 95e23be..7bdcf51 100644 (file)
@@ -1,20 +1,55 @@
 <?php
-  /* table_id */
-function plc_table_header ($table_id,$size_init,$size_def) {
-  $tablesize_text_id = $table_id . "_tablesize";
+
+drupal_set_html_head('
+<script type="text/javascript" src="/planetlab/tablesort/tablesort.js"></script>
+<script type="text/javascript" src="/planetlab/tablesort/customsort.js"></script>
+<script type="text/javascript" src="/planetlab/tablesort/paginate.js"></script>
+<script type="text/javascript" src="/planetlab/js/plc_tables.js"></script>
+<link href="/planetlab/css/plc_tables.css" rel="stylesheet" type="text/css" />
+');
+
+
+////////////////////////////////////////
+function plc_table_cell($cell) {
+  printf ('<td class="plc_table"> %s </td>',$cell);
+}
+
+////////////////////////////////////////
+// table_id: <table>'s id tag
+// headers: an associative array "label"=>"type" 
+// column_sort: the column to sort on at load-time
+// search_area : boolean
+// pagesize: the initial pagination size
+// pagesize_def: the page size when one clicks the pagesize reset button
+// max_pages: the max number of pages to display in the paginator
+function plc_table_start ($table_id, $headers, $column_sort,
+                         $search_area=true,$max_pages="10",$pagesize="25",$pagesize_def="999") {
+  if ($search_area) {
+    plc_table_search_area($table_id,$pagesize,$pagesize_def);
+  }
+  plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize);
+}
+
+function plc_table_end () {
+  plc_table_foot();
+}
+                   
+////////////////////
+function plc_table_search_area ($table_id,$pagesize,$pagesize_def) {
+  $pagesize_text_id = $table_id . "_pagesize";
   $search_text_id = $table_id . "_search";
   $search_reset_id = $table_id . "_search_reset";
   $search_and_id = $table_id . "_search_and";
   print <<< EOF
 <table class='table_dialogs'> <tr>
 <td class='table_flushleft'>
-<form class='table_size'>
-   <input class='table_size_input' type='text' id="$tablesize_text_id" value=$size_init 
-      onkeyup='plc_table_setsize("$table_id","$tablesize_text_id", $size_init);' 
+<form class='pagesize'>
+   <input class='pagesize_input' type='text' id="$pagesize_text_id" value=$pagesize 
+      onkeyup='plc_pagesize_set("$table_id","$pagesize_text_id", $pagesize);' 
       size=3 maxlength=3 /> 
-  <label class='table_size_label'> items/page </label>   
+  <label class='pagesize_label'> items/page </label>   
   <img class='table_reset' src="/planetlab/icons/clear.png" 
-      onmousedown='plc_table_size_reset("$table_id","$tablesize_text_id",$size_def);'>
+      onmousedown='plc_pagesize_reset("$table_id","$pagesize_text_id",$pagesize_def);'>
 </form>
 </td>
 
@@ -35,5 +70,62 @@ function plc_table_header ($table_id,$size_init,$size_def) {
 </tr></table>
 EOF;
 }
+
+////////////////////////////////////////
+function plc_table_head ($table_id,$headers,$column_sort,$max_pages,$pagesize) {
+  $paginator=$table_id."_paginator";
+  $classname="paginationcallback-".$paginator;
+  $classname.=" max-pages-" . $max_pages;
+  $classname.=" paginate-" . $pagesize;
+  print <<< EOF
+<!-- instantiate paginator callback -->
+<script type"text/javascript"> 
+function $paginator (opts) { plc_table_paginator (opts,"$table_id"); }
+</script>
+<br/>
+<table id="$table_id" cellpadding="0" cellspacing="0" border="0" 
+class="plc_table sortable-onload-$column_sort rowstyle-alt colstyle-alt no-arrow $classname">
+<thead>
+<tr>
+EOF;
+
+  foreach ($headers as $label => $type) {
+    if ($type == "string") $type="";
+    if ($type == "int") $type="";
+    if ($type == "float") $type="";
+    $class="sortable";
+    if ( ! empty($type)) $class .= "-" . $type;
+    print '<th class="' . $class . ' plc_table">' . $label . "</th>\n";
+  }
+
+  print <<< EOF
+</tr>
+</thead>
+<tbody>
+EOF;
+}
+
+////////////////////////////////////////
+function plc_table_foot () {
+  print <<< EOF
+</tbody>
+<tfoot>
+</tfoot>
+</table>
+EOF;
+}
+
+////////////////////////////////////////
+function plc_table_notes () {
+  print <<< EOF
+<p class='plc_filter_note'> 
+Notes: Enter & or | in the search area to alternate between <bold>AND</bold> and <bold>OR</bold> search modes
+<br/> 
+Hold down the shift key to select multiple columns to sort 
+</p>
+EOF;
+}
+
+
 ?>