$nifty=new PlekitNifty ('','objects-list','big');
$nifty->start();
-$headers = array ();
+$headers = array (); $offset=0;
+if (plc_is_admin()) { $headers["I"]="int"; $offset=1; }
$headers["P"]="string";
$headers["R"]="string";
$headers["Site"]="string";
$headers["IP"]="IPAddress";
$headers["A"]="string";
$headers["S"]='int';
-if (plc_is_admin()) $headers["I"]="int";
$headers["?"]="string";
# initial sort on hostnames
-$table=new PlekitTable ("nodes",$headers,4);
+$table=new PlekitTable ("nodes",$headers,4+$offset);
$table->start();
$peers = new Peers ($api);
$node_type = $node['node_type'];
$table->row_start();
+ if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
$peers->cell ($table,$peer_id);
$table->cell (topdomain($hostname));
$table->cell (l_site_t($site_id,$login_base));
$table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id));
$table->cell ($node['arch'],array('only-if'=> !$peer_id));
$table->cell (count($node['slice_ids']));
- if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
$table->cell (node_status($node));
$table->row_end();
}
$notes=array();
+if (plc_is_admin()) $notes []= "I = node_id";
$notes []= "R = region";
$notes []= "A = arch";
$notes []= "S = number of slivers";
-if (plc_is_admin()) $notes []= "I = node_id";
+$notes []= "? = status";
$table->end(array('notes'=>$notes));
$nifty->end();
$nifty=new PlekitNifty ('','objects-list','big');
$nifty->start();
-$headers = array ("Peer"=>"string",
- "First"=>"string",
- "Last"=>"string",
- "Email"=>"string",
- "Site" => "string",
- "R"=>"string",
- "S" => "int",
- "Status"=>"string",
- );
-
-// initial sort on email
-$table=new PlekitTable("persons",$headers,3);
+$headers=array();
+if (plc_is_admin()) $headers["I"]='int';
+$headers["Peer"]="string";
+$headers["First"]="string";
+$headers["Last"]="string";
+$headers["Email"]="string";
+$headers["Site" ]= "string";
+$headers["R"]="string";
+$headers["S" ]= "int";
+$headers["Status"]="string";
+
+// turn off initial sort as this slows stuff down terribly
+$table=new PlekitTable("persons",$headers,-1,array('debug'=>true));
$table->start();
$peers=new Peers ($api);
$table->row_start();
+ if (plc_is_admin()) $table->cell(href(l_person($person_id),$person_id));
$peers->cell($table,$peer_id);
$table->cell (href(l_person($person_id),$person['first_name']));
$table->cell (href(l_person($person_id),$person['last_name']));
}
$notes = array();
+if (plc_is_admin()) $notes[]= "I = person_id";
$notes []= "R = roles";
$notes []= "S = number of slices";
$table->end(array('notes'=>$notes));
////////////////////////////////////////
// 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 "label"=>"type"
-// sort_column: the column to sort on at load-time
+// 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
// - bullets1 : set to true if you want decorative bullets in column 1 (need white background)
// - stripes : use diferent colors for odd and even rows
// - pagesize_area : boolean (default true)
// - notes_area : boolean (default true)
// - search_width : size in chars of the search text dialog
-// - notes : an array of additional notes
// - 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
+// - notes : an array of additional notes
+// - debug: enables debug callbacks (prints out on console.log)
class PlekitTable {
// mandatory
// options
var $bullets1; // boolean - default false - display decorative bullets in column 1
var $stripes; // boolean - default true - use different colors for odd and even rows
- var $caption;
+ var $caption; // string - never used so far
var $search_area; // boolean (default true)
var $pagesize_area; // boolean (default true)
var $notes_area; // boolean (default true)
var $search_width; // size in chars of the search text dialog
- var $pagesize; // the initial pagination size
+ var $pagesize; // the initial pagination size
var $pagesize_def; // the page size when one clicks the pagesize reset button
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
+
+ // internal
var $has_tfoot;
function PlekitTable ($table_id,$headers,$sort_column,$options=NULL) {
$this->table_id = $table_id;
$this->headers = $headers;
$this->sort_column = $sort_column;
+
$this->bullets1 = true;
$this->stripes=true;
-
- $this->has_tfoot=false;
-
+ $this->caption='';
$this->search_area = true;
$this->pagesize_area = true;
$this->notes_area = true;
$this->pagesize_def = 999;
$this->max_pages = 10;
$this->notes = array();
+ $this->debug = false;
$this->set_options ($options);
+
+ // internal
+ $this->has_tfoot=false;
}
function set_options ($options) {
if (array_key_exists('pagesize',$options)) $this->pagesize=$options['pagesize'];
if (array_key_exists('pagesize_def',$options)) $this->pagesize_def=$options['pagesize_def'];
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'];
}
public function columns () {
$classname.=" paginate-" . $this->pagesize;
if ($this->bullets1) { $classname .= " bullets1"; }
if ($this->stripes) { $classname .= " rowstyle-alt"; }
- // instantiate paginator callback
- print <<< EOF
-<script type="text/javascript">
-function $paginator (opts) { plekit_table_paginator (opts,"$this->table_id"); }
-</script>
-<br/>
-<table id="$this->table_id" cellpadding="0" cellspacing="0" border="0"
-class="plekit_table sortable-onload-$this->sort_column colstyle-alt no-arrow $classname">
-<thead>
-EOF;
+ if ($this->sort_column >= 0) { $classname .= " sortable-onload-$this->sort_column"; }
- if ($this->pagesize_area)
- print $this->pagesize_area_html ();
- if ($this->search_area)
- print $this->search_area_html ();
+ // 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";
+ print "<script type='text/javascript'> function $cb_init () { plc_message ('sorting table $this->table_id'); } </script>\n";
+ $classname .= " sortinitiatedcallback-$cb_init";
+ $cb_comp = $this->table_id."_comp";
+ print "<script type='text/javascript'> function $cb_comp () { plc_message ('table $this->table_id sorted'); } </script>\n";
+ $classname .= " sortcompletecallback-$cb_comp";
+ }
+ // start actual table
+ print "<table id='$this->table_id' class='plekit_table colstyle-alt no-arrow $classname'><thead>\n";
- if ($this->caption)
- print "<caption> $this->caption </caption>";
- print "<tr>";
- foreach ($this->headers as $label => $type) {
- switch ($type) {
- case "none" :
- $class=""; break;
- case "string": case "int": case "float":
- $class="sortable"; break;
- case ( strpos($type,"date-") == 0):
- $class="sortable-" . $type; break;
- default:
- $class="sortable-sort" . $type; break;
+ if ($this->pagesize_area)
+ print $this->pagesize_area_html ();
+ if ($this->search_area)
+ print $this->search_area_html ();
+
+ if ($this->caption)
+ print "<caption> $this->caption </caption>";
+ print "<tr>";
+ foreach ($this->headers as $label => $type) {
+ switch ($type) {
+ case "none" :
+ $class=""; break;
+ case "string": case "int": case "float":
+ $class="sortable"; break;
+ case ( strpos($type,"date-") == 0):
+ $class="sortable-" . $type; break;
+ default:
+ $class="sortable-sort" . $type; break;
+ }
+ printf ('<th class="%s plekit_table">%s</th>',$class,$label);
}
- printf ('<th class="%s plekit_table">%s</th>',$class,$label);
- }
- print <<< EOF
-</tr>
-</thead>
-<tbody>
-EOF;
-}
+ print "</tr></thead><tbody>";
+ }
////////////////////
// for convenience, the options that apply to the bottom area can be passed here
padding: 0;
margin: 0 auto 1.5em auto;
border-collapse:collapse;
+/* this used to be hard-wired in the <table> tag, but looks useless now
+ cellpadding:0;
+ cellspacing:0;
+ border:0;
+ */
}
table.plekit_table>thead>tr, table.plekit_table>tbody>tr {
border-left: 1px solid #C1DAD7;
/* $Id$ */
+var debug=false;
+
+/* for debugging purposes */
+function plc_timestamp () {
+ var now = new Date();
+ return now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() ;
+}
+
+function plc_message (message) {
+ console.log ( plc_timestamp() + ' : ' + message);
+}
+
/* when a table gets paginated, displays context info */
function plekit_table_paginator (opts,table_id) {
}
function plekit_lazy_table_filter (table_id,pattern_id,and_id) {
+
+ if (debug) plc_message ('entering plekit_lazy_table_filter');
+
var table=$(table_id);
var css='#'+table_id+'>tbody';
var rows = $$(css)[0].rows;
return;
}
+ if (debug) plc_message ('inside plekit_lazy_table_filter');
+
var searches=new Array();
var patterns=new Array();
if (pattern_text.length > 0) {
var end=(new Date).getTime();
var match_ms=end-start;
+ if (debug) plc_message ('almost at end of plekit_lazy_table_filter');
+
// optimize useless calls to init, by comparing # of matching entries
var previous_matching=table['previous_matching'];
if (matching_entries == previous_matching) {
tablePaginater.init(table_id);
var end2=(new Date).getTime();
var paginate_ms=end2-end;
-
+
+ if (debug) plc_message ('exiting plekit_lazy_table_filter with paginate_ms=' + paginate_ms);
+
}
function plekit_table_filter_reset (table_id, pattern_id,and_id) {
* Any of these conditions can be waived if you get permission from the copyright holder.
*/
+var debug=false;
+
(function() {
fdTableSort = {
regExp_Currency: /^[£$€¥¤]/,
fdTableSort.init(false);
},
init: function(tableId) {
+ if (debug) plc_message ('entering tablesort.init');
if (!document.getElementsByTagName || !document.createElement || !document.getElementById) return;
var tables = tableId && document.getElementById(tableId) ? [document.getElementById(tableId)] : document.getElementsByTagName("table");
};
fdTableSort.thNode = aclone = a = span = columnNumSortObj = thNode = tbl = allRowArr = rowArr = null;
+ if (debug) plc_message ('exiting tablesort.init');
},
initWrapper: function(e) {
e = e || window.event;
fdTableSort.thNode = null;
},
redraw: function(tableid, identical) {
+ if (debug) plc_message ('entering tablesort.redraw');
if(!tableid || !(tableid in fdTableSort.tableCache)) { return; };
var dataObj = fdTableSort.tableCache[tableid];
var data = dataObj.data;
};
};
tr = tds = hook = null;
+ if (debug) plc_message ('exiting tablesort.redraw');
},
getInnerText: function(el, allowBrTags) {
if (typeof el == "string" || typeof el == "undefined") return el;