<?php
- // $Id: table.php 15752 2009-11-15 22:28:05Z thierry $
+ // $Id$
require_once 'prototype.php';
-// Get session and API handles
-require_once 'plc_session.php';
-global $plc, $api;
-
-
drupal_set_html_head('
<script type="text/javascript" src="/plekit/tablesort/tablesort.js"></script>
<script type="text/javascript" src="/plekit/tablesort/customsort.js"></script>
////////////////////////////////////////
// table_id: <table>'s id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code
// headers: an associative array; the values can take several forms
-// simple/legacy form is "label"=>"type"
+// simple/legacy form is "label"=>"type"
// more advanced form is "label"=>options, it self a dict with the following known keys
// (*) 'type': the type for sorting; this is passed to the javascript layer for custom sorting
// default is to use 'text', custom sort functions can be specified with e.g. 'type'=>'sortAlphaNumericBottom'
// setting type to 'none' gives an non-sortable column
// (*) 'title': if set, this is used in the "Sort on ``<title>''" bubble
// sort_column: the column to sort on at load-time - set to negative number for no onload- sorting
-// options : an associative array to override options
+// options : an associative array to override options
// - bullets1 : set to true if you want decorative bullets in column 1 (need white background)
// - stripes : use diferent colors for odd and even rows
// - caption : a caption for the table -- never used I'm afraid
// - notes : an array of additional notes
// - debug: enables debug callbacks (prints out on console.log)
-class PlekitTable2 {
+class PlekitTable {
// mandatory
var $table_id;
var $headers;
var $max_pages; // the max number of pages to display in the paginator
var $notes; // an array of additional notes
var $debug; // set to true for enabling various log messages on console.log
- var $headersToShow;
-
+ var $configurable; // boolen (whether the column configuration option is set or not)
// internal
var $has_tfoot;
- function PlekitTable2 ($table_id,$headers,$sort_column,$headersToShow=NULL,$options=NULL) {
+ function __construct ($table_id,$headers,$sort_column,$options=NULL) {
$this->table_id = $table_id;
$this->headers = $headers;
$this->sort_column = $sort_column;
$this->max_pages = 10;
$this->notes = array();
$this->debug = false;
+ $this->configurable = false;
+
$this->set_options ($options);
- //$this->headersToShow=array();
- $this->headersToShow = $headersToShow;
+
// internal
$this->has_tfoot=false;
-
-//print_r ($this->headersToShow);
-
-
}
function set_options ($options) {
if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages'];
if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']);
if (array_key_exists('debug',$options)) $this->debug=$options['debug'];
+ if (array_key_exists('configurable',$options)) $this->configurable=$options['configurable'];
}
public function columns () {
// instantiate paginator callback
print "<script type='text/javascript'> function $paginator (opts) { plekit_table_paginator (opts,'$this->table_id'); } </script>\n";
-
+
// instantiate debug hooks if needed
if ($this->debug) {
$cb_init = $this->table_id."_init";
if ($this->pagesize_area)
print $this->pagesize_area_html ();
- if ($this->search_area)
+ if ($this->search_area)
print $this->search_area_html ();
-
- if ($this->caption)
+
+ if ($this->caption)
print "<caption> $this->caption </caption>";
print "<tr>";
+//a hidden column to store the node_id (used for the dynamic update of column data but not sure if
+//it is necessary)
+if ($this->configurable)
+ print ("<th class=\"plekit_table\" style=\"display:none\">hiddenID</th>\n");
-
-//panos: hidden column for the node_id
-print ("<th class=\"plekit_table\" name=\"nid\" style=\"display:none\">nid</th>\n");
-////DON'T FORGET!
-
- foreach ($this->headers as $hkey => $colspec) {
- //print $label;
+ foreach ($this->headers as $label => $colspec) {
// which form is being used
if (is_array($colspec)) {
$type=$colspec['type'];
- $title=$colspec['title'];
-//panos some additional attributes
- $visible=$colspec['visible'];
- $header = $colspec['header'];
- $label=$colspec['label'];
+ $title=ucfirst($colspec['title']);
+ if ($this->configurable) {
+ $visible=$colspec['visible'];
+ $header = $colspec['header'];
+ $tlabel=$colspec['label'];
+ }
} else {
// simple/legacy form
$type=$colspec;
$title=NULL;
- $visible = true;
- $label=$hkey;
- $header=$hkey;
+ if ($this->configurable) {
+ $visible = true;
+ $tlabel=$label;
+ $header=$hkey;
+ }
}
switch ($type) {
- case "none" :
+ case "none" :
$class=""; break;
case "string": case "int": case "float":
$class="sortable"; break;
}
$title_part=$title ? "title=\"$title\"" : "";
-
- if ($visible) print ("<th class=\"$class plekit_table\" $title_part name=\"$header\" style=\"display:table-cell\">".$label."</th>\n");
- else print ("<th class=\"$class plekit_table\" $title_part name=\"$header\" style=\"display:none\">".$label."</th>\n");
-
+ if ($this->configurable) {
+ if ($visible) print ("<th class=\"$class plekit_table\" $title_part name=\"$header\" style=\"display:table-cell\">".$tlabel."</th>\n");
+ else print ("<th class=\"$class plekit_table\" $title_part name=\"$header\" style=\"display:none\">".$tlabel."</th>\n");
+ }
+ else
+ print ("<th class=\"$class plekit_table\" $title_part name=\"$label\" style=\"display:table-cell\">$label</th>\n");
+ //print ("<th class=\"$class plekit_table\" $title_part>$label</th>\n");
}
print "</tr></thead><tbody>";
////////////////////
// for convenience, the options that apply to the bottom area can be passed here
- // typically notes will add up to the ones provided so far, and to the default ones
+ // typically notes will add up to the ones provided so far, and to the default ones
// xxx default should be used only if applicable
function end ($options=NULL) {
$this->set_options($options);
print $this->bottom_html();
- if ($this->notes_area)
+ if ($this->notes_area)
print $this->notes_area_html();
}
-
+
////////////////////
function pagesize_area_html () {
$width=count($this->headers);
<tr class='pagesize_area'><td class='pagesize_area' colspan='$width'>
<form class='pagesize' action='satisfy_xhtml_validator'><fieldset>
<input class='pagesize_input' type='text' id="$pagesize_text_id" value='$this->pagesize'
- onkeyup='plekit_pagesize_set("$this->table_id","$pagesize_text_id", $this->pagesize);'
- size='3' maxlength='4' />
- <label class='pagesize_label'> items/page </label>
+ onkeyup='plekit_pagesize_set("$this->table_id","$pagesize_text_id", $this->pagesize);'
+ size='3' maxlength='4' />
+ <label class='pagesize_label'> items/page </label>
<img class='reset' src="/planetlab/icons/clear.png" alt="reset visible size"
onmousedown='plekit_pagesize_reset("$this->table_id","$pagesize_text_id",$this->pagesize_def);' />
</fieldset></form></td></tr>
$result = <<< EOF
<tr class='search_area'><td class='search_area' colspan='$width'>
<div class='search'><fieldset>
- <label class='search_label'> Search </label>
+ <label class='search_label'> Search </label>
<input class='search_input' type='text' id='$search_text_id'
onkeyup='plekit_table_filter("$this->table_id","$search_text_id","$search_and_id");'
size='$this->search_width' maxlength='256' />
<label>and</label>
- <input id='$search_and_id' class='search_and'
- type='checkbox' checked='checked'
+ <input id='$search_and_id' class='search_and'
+ type='checkbox' checked='checked'
onchange='plekit_table_filter("$this->table_id","$search_text_id","$search_and_id");' />
<img class='reset' src="/planetlab/icons/clear.png" alt="reset search"
onmousedown='plekit_table_filter_reset("$this->table_id","$search_text_id","$search_and_id");' />
////////////////////////////////////////
function notes_area_html () {
-// $search_notes =
-// array("Enter & or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes");
-// $sort_notes =
-// array ("Hold down the shift key to select multiple columns to sort");
+ $search_notes =
+ array("Enter & or | in the search area to switch between <span class='bold'>AND</span> and <span class='bold'>OR</span> search modes");
+ $sort_notes =
+ array ("Hold down the shift key to select multiple columns to sort");
if ($this->notes)
$notes=$this->notes;
else
$notes=array();
-// $notes=array_merge($notes,$sort_notes);
-// if ($this->search_area)
-// $notes=array_merge($notes,$search_notes);
+ $notes=array_merge($notes,$sort_notes);
+ if ($this->search_area)
+ $notes=array_merge($notes,$search_notes);
if (! $notes)
return "";
$result = "";
-// $result .= "<p class='table_note'> <span class='table_note_title'>Notes</span>\n";
-// foreach ($notes as $note)
-// $result .= "<br/><div id='test' style=\"display:none; width:160px; height:80px; background:#ccc;\">$note</div>";
- // $result .= "</p>";
+ $result .= "<p class='table_note'> <span class='table_note_title'>Notes</span>\n";
+ foreach ($notes as $note)
+ $result .= "<br/>$note\n";
+ $result .= "</p>";
return $result;
}
$text="n/a";
$html="";
$html .= "<td";
- $option=$options['class']; if ($option) $html .= " class='$option'";
- $option=$options['columns'];if ($option) $html .= " colspan='$option'";
- $option=$options['hfill']; if ($option) $html .= " colspan='" . $this->columns() . "'";
- $option=$options['align']; if ($option) $html .= " style='text-align:$option'";
- $option=$options['color']; if ($option) $html .= " style='color:$option'";
- $option=$options['display']; if ($option) $html .= " style='display: $option'";
- $option=$options['name']; if ($option) $html .= " name='$option'";
+ $option=get_array($options, 'class');
+ if ($option) $html .= " class='$option'";
+ $option=get_array($options, 'columns');
+ if ($option) $html .= " colspan='$option'";
+ $option=get_array($options, 'hfill');
+ if ($option) $html .= " colspan='" . $this->columns() . "'";
+ $option=get_array($options, 'align');
+ if ($option) $html .= " style='text-align:$option'";
+ $option=get_array($options, 'color');
+ if ($option) $html .= " style='color:$option'";
+ $option=get_array($options, 'display');
+ if ($option) $html .= " style='display: $option'";
+ $option=get_array($options, 'name');
+ if ($option) $html .= " name='$option'";
$html .= ">$text</td>";
return $html;
}