|
|
|
@@ -12,6 +12,8 @@
|
|
|
|
|
abstract class lnApp_Table {
|
|
|
|
|
private $data = NULL;
|
|
|
|
|
private $columns = array(); // Our columns that we need to display
|
|
|
|
|
private $filters = array(); // Our datafomrating that we need to use
|
|
|
|
|
private $filters_added = FALSE;
|
|
|
|
|
private $jssort = FALSE; // Use the JS pager and sorter
|
|
|
|
|
private $other = ''; // If we are only listing x items, this will be the other summary line
|
|
|
|
|
private $other_col = NULL; // If we are only listing x items, this will be the other summary line
|
|
|
|
@@ -19,6 +21,8 @@ abstract class lnApp_Table {
|
|
|
|
|
private $page = FALSE; // If we should page the results
|
|
|
|
|
private $page_rows = 0; // Number of rows per page
|
|
|
|
|
private $prepend = array(); // Our datafomrating that we need to use
|
|
|
|
|
private $prepend_vals = array(); // Our datafomrating that we need to use
|
|
|
|
|
private $select = array(); // Our select form details
|
|
|
|
|
|
|
|
|
|
public function __toString() {
|
|
|
|
|
return (string) $this->render();
|
|
|
|
@@ -37,6 +41,12 @@ abstract class lnApp_Table {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function evaluate($d,$key) {
|
|
|
|
|
if (count($this->filters) AND ! $this->filters_added) {
|
|
|
|
|
$d->display_filters($this->filters);
|
|
|
|
|
// So we dont keep extending our display_filters
|
|
|
|
|
$this->filters_added = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_array($d) AND isset($d[$key]))
|
|
|
|
|
$x = $d[$key];
|
|
|
|
|
|
|
|
|
@@ -53,8 +63,18 @@ abstract class lnApp_Table {
|
|
|
|
|
if (isset($this->prepend[$key])) {
|
|
|
|
|
foreach ($this->prepend[$key] as $act => $data) {
|
|
|
|
|
switch ($act) {
|
|
|
|
|
case 'checkbox': $x = sprintf('<label class="checkbox">%s %s</label>',Form::checkbox($data,$x,FALSE,array('nocg'=>TRUE)),$x); // @todo Check those not yet checked
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'input':
|
|
|
|
|
if (preg_match('/__VALUE__/',$data['key']))
|
|
|
|
|
$data['key'] = preg_replace('/__VALUE__/',$x,$data['key']);
|
|
|
|
|
|
|
|
|
|
$x = Form::input($data['key'],isset($data['values'][$x]) ? $data['values'][$x] : '',array('placeholder'=>$x,'label'=>$x));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'url': $x = HTML::anchor($data.$x,$x);
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -66,8 +86,17 @@ abstract class lnApp_Table {
|
|
|
|
|
return new Table;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function jssort($bool) {
|
|
|
|
|
$this->jssort = $bool;
|
|
|
|
|
/**
|
|
|
|
|
* Apply additional display filters to the results
|
|
|
|
|
*/
|
|
|
|
|
public function filters($cols) {
|
|
|
|
|
$this->filters = $cols;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function jssort($table) {
|
|
|
|
|
$this->jssort = $table;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
@@ -92,6 +121,8 @@ abstract class lnApp_Table {
|
|
|
|
|
foreach ($this->data as $o) {
|
|
|
|
|
$row++;
|
|
|
|
|
$c = 0;
|
|
|
|
|
// So our filters are added for this record.
|
|
|
|
|
$this->filters_added = FALSE;
|
|
|
|
|
|
|
|
|
|
// If we are HTML paging
|
|
|
|
|
if ($this->page) {
|
|
|
|
@@ -103,7 +134,7 @@ abstract class lnApp_Table {
|
|
|
|
|
|
|
|
|
|
// If we are just listing page_rows items and a summary line as a result of exceeding that
|
|
|
|
|
if ($this->other_col AND $row>$this->page_rows) {
|
|
|
|
|
$this->other += Table::resolve($o,$this->other_col);
|
|
|
|
|
$this->other += $this->evaluate($o,$this->other_col);
|
|
|
|
|
|
|
|
|
|
// Otherwise rendering our rows
|
|
|
|
|
} else {
|
|
|
|
@@ -118,7 +149,7 @@ abstract class lnApp_Table {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
|
private function render() {
|
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
|
|
// If we need to page the results
|
|
|
|
@@ -132,8 +163,11 @@ abstract class lnApp_Table {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->select)
|
|
|
|
|
$output .= Form::open($this->select['form']);
|
|
|
|
|
|
|
|
|
|
$output .= View::factory('table')
|
|
|
|
|
->set('jssort',$this->jssort AND ! $this->page)
|
|
|
|
|
->set('jssort',($this->jssort AND ! $this->page) ? $this->jssort : FALSE)
|
|
|
|
|
->set('other',$this->other)
|
|
|
|
|
->set('th',$this->columns)
|
|
|
|
|
->set('td',$this->process());
|
|
|
|
@@ -162,7 +196,7 @@ $(document).ready(function() {
|
|
|
|
|
odd : "" // even row zebra striping
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#list-table").tablesorter({
|
|
|
|
|
$("#list-table'.($this->jssort ? '-'.$this->jssort : '').'").tablesorter({
|
|
|
|
|
theme: "bootstrap",
|
|
|
|
|
widthFixed : true,
|
|
|
|
|
headerTemplate : "{content} {icon}", // Add icon for jui theme; new in v2.7!
|
|
|
|
@@ -170,7 +204,7 @@ $(document).ready(function() {
|
|
|
|
|
|
|
|
|
|
}).tablesorterPager({
|
|
|
|
|
// target the pager markup - see the HTML block below
|
|
|
|
|
container : $(".pager"),
|
|
|
|
|
container : $(".pager'.($this->jssort ? '-'.$this->jssort : '').'"),
|
|
|
|
|
output : "{startRow} - {endRow} / {filteredRows} ({totalRows})",
|
|
|
|
|
fixedHeight: true,
|
|
|
|
|
removeRows : false,
|
|
|
|
@@ -200,10 +234,27 @@ $(document).ready(function() {
|
|
|
|
|
->data('media/vendor/mottie-tablesorter/css/jquery.tablesorter.pager.css');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->select) {
|
|
|
|
|
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary','value'=>$this->select['submit']));
|
|
|
|
|
|
|
|
|
|
foreach ($this->select['hidden'] as $k=>$v)
|
|
|
|
|
$output .= Form::hidden($k,$v);
|
|
|
|
|
|
|
|
|
|
$output .= Form::close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ZZ
|
|
|
|
|
public function select($form,$submit='',array $hidden=array()) {
|
|
|
|
|
$this->select['form'] = $form;
|
|
|
|
|
$this->select['submit'] = $submit;
|
|
|
|
|
$this->select['hidden'] = $hidden;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @deprecated
|
|
|
|
|
public static function display($data,$rows,array $cols,array $option) {
|
|
|
|
|
$prepend = $headers = array();
|
|
|
|
|
|
|
|
|
@@ -222,11 +273,6 @@ $(document).ready(function() {
|
|
|
|
|
->prepend($prepend);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (! empty($option['button']))
|
|
|
|
|
$button = implode('',$option['button']);
|
|
|
|
|
else
|
|
|
|
|
$button = Form::button('Submit','View/Edit',array('class'=>'form_button','type'=>'submit'));
|
|
|
|
|
|
|
|
|
|
// This JS is failing, any pressing of select all, unselect all, toggle is propaging up and submitting the form
|
|
|
|
|
|
|
|
|
|
Script::factory()
|
|
|
|
|