Minor updates and enhancements to Table()

This commit is contained in:
Deon George 2013-05-14 23:55:30 +10:00
parent b65ddab2d0
commit 783964ee59
9 changed files with 159 additions and 22 deletions

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Deon George * @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
abstract class lnApp_Controller_Default extends Controller { abstract class lnApp_Controller_Default extends Kohana_Controller {
/** /**
* The variable that our output is stored in * The variable that our output is stored in
*/ */

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Deon George * @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
abstract class lnApp_Controller_TemplateDefault extends Controller_Template { abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Template {
/** /**
* @var object meta object information as per [meta] * @var object meta object information as per [meta]
*/ */
@ -76,7 +76,7 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template {
// Check user auth and role // Check user auth and role
if ($this->_auth_required()) { if ($this->_auth_required()) {
if (Kohana::$is_cli) if (PHP_SAPI === 'cli')
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action())); throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action()));
// If auth is required and the user is logged in, then they dont have access. // If auth is required and the user is logged in, then they dont have access.

View File

@ -48,6 +48,10 @@ abstract class lnApp_Form extends Kohana_Form {
return $output; return $output;
} }
public static function button($name,$body,array $attributes=NULL) {
return sprintf(static::_controlgroup($name,$attributes),parent::button($name,$body,$attributes));
}
/** /**
* Wrap our Form() functions with boostrap HTML * Wrap our Form() functions with boostrap HTML
* *

View File

@ -102,7 +102,7 @@ abstract class lnApp_HTMLRender {
throw new Kohana_Exception('Missing key :key for image',array(':key'=>$key)); throw new Kohana_Exception('Missing key :key for image',array(':key'=>$key));
// Check for unique keys // Check for unique keys
if (static::$_unique_vals) if (isset(static::$_unique_vals) AND static::$_unique_vals)
foreach (static::$_unique_vals as $v=>$u) foreach (static::$_unique_vals as $v=>$u)
foreach (static::$_data as $d) foreach (static::$_data as $d)
if (isset($d[$u]) && $d['data'] == $item['data']) if (isset($d[$u]) && $d['data'] == $item['data'])

View File

@ -12,6 +12,8 @@
abstract class lnApp_Table { abstract class lnApp_Table {
private $data = NULL; private $data = NULL;
private $columns = array(); // Our columns that we need to display 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 $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 = ''; // 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 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 = FALSE; // If we should page the results
private $page_rows = 0; // Number of rows per page private $page_rows = 0; // Number of rows per page
private $prepend = array(); // Our datafomrating that we need to use 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() { public function __toString() {
return (string) $this->render(); return (string) $this->render();
@ -37,6 +41,12 @@ abstract class lnApp_Table {
} }
private function evaluate($d,$key) { 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])) if (is_array($d) AND isset($d[$key]))
$x = $d[$key]; $x = $d[$key];
@ -53,8 +63,18 @@ abstract class lnApp_Table {
if (isset($this->prepend[$key])) { if (isset($this->prepend[$key])) {
foreach ($this->prepend[$key] as $act => $data) { foreach ($this->prepend[$key] as $act => $data) {
switch ($act) { 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); case 'url': $x = HTML::anchor($data.$x,$x);
break; break;
} }
} }
} }
@ -66,8 +86,17 @@ abstract class lnApp_Table {
return new 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; return $this;
} }
@ -92,6 +121,8 @@ abstract class lnApp_Table {
foreach ($this->data as $o) { foreach ($this->data as $o) {
$row++; $row++;
$c = 0; $c = 0;
// So our filters are added for this record.
$this->filters_added = FALSE;
// If we are HTML paging // If we are HTML paging
if ($this->page) { 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 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) { 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 // Otherwise rendering our rows
} else { } else {
@ -118,7 +149,7 @@ abstract class lnApp_Table {
return $result; return $result;
} }
public function render() { private function render() {
$output = ''; $output = '';
// If we need to page the results // 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') $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('other',$this->other)
->set('th',$this->columns) ->set('th',$this->columns)
->set('td',$this->process()); ->set('td',$this->process());
@ -162,7 +196,7 @@ $(document).ready(function() {
odd : "" // even row zebra striping odd : "" // even row zebra striping
}); });
$("#list-table").tablesorter({ $("#list-table'.($this->jssort ? '-'.$this->jssort : '').'").tablesorter({
theme: "bootstrap", theme: "bootstrap",
widthFixed : true, widthFixed : true,
headerTemplate : "{content} {icon}", // Add icon for jui theme; new in v2.7! headerTemplate : "{content} {icon}", // Add icon for jui theme; new in v2.7!
@ -170,7 +204,7 @@ $(document).ready(function() {
}).tablesorterPager({ }).tablesorterPager({
// target the pager markup - see the HTML block below // target the pager markup - see the HTML block below
container : $(".pager"), container : $(".pager'.($this->jssort ? '-'.$this->jssort : '').'"),
output : "{startRow} - {endRow} / {filteredRows} ({totalRows})", output : "{startRow} - {endRow} / {filteredRows} ({totalRows})",
fixedHeight: true, fixedHeight: true,
removeRows : false, removeRows : false,
@ -200,10 +234,27 @@ $(document).ready(function() {
->data('media/vendor/mottie-tablesorter/css/jquery.tablesorter.pager.css'); ->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; 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) { public static function display($data,$rows,array $cols,array $option) {
$prepend = $headers = array(); $prepend = $headers = array();
@ -222,11 +273,6 @@ $(document).ready(function() {
->prepend($prepend); ->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 // This JS is failing, any pressing of select all, unselect all, toggle is propaging up and submitting the form
Script::factory() Script::factory()

31
config/cache.php Normal file
View File

@ -0,0 +1,31 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* lnApp Configuration - Cache Driver
*
* @package lnApp
* @category Configuration
* @author Deon George
* @copyright (c) 2010-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
return array(
'apc' => array(
'driver' => 'apc',
'default_expire' => 3600,
),
'file' => array(
'driver' => 'file',
'cache_dir' => Kohana::$cache_dir ? Kohana::$cache_dir : APPPATH.'cache/',
'default_expire' => 3600,
'ignore_on_delete' => array(
'.gitignore',
'.git',
'.htaccess',
'.svn'
)
),
);
?>

56
config/userguide.php Normal file
View File

@ -0,0 +1,56 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Userguide configuration
*
* @package lnApp
* @category Configuration
* @author Deon George
* @copyright (c) 2010-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
return array
(
// Enable the API browser. TRUE or FALSE
'api_browser' => TRUE,
// Enable these packages in the API browser. TRUE for all packages, or a string of comma seperated packages, using 'None' for a class with no @package
// Example: 'api_packages' => 'Kohana,Kohana/Database,Kohana/ORM,None',
'api_packages' => TRUE,
// Enables Disqus comments on the API and User Guide pages
'show_comments' => Kohana::$environment === Kohana::PRODUCTION,
// Leave this alone
'modules' => array(
'kohana' => array('enabled'=>FALSE),
'auth' => array('enabled'=>FALSE),
'cache' => array('enabled'=>FALSE),
'database' => array('enabled'=>TRUE),
'minion' => array('enabled'=>FALSE),
'orm' => array('enabled'=>FALSE),
'pagination' => array('enabled'=>FALSE),
// This should be the path to this modules userguide pages, without the 'guide/'. Ex: '/guide/modulename/' would be 'modulename'
'userguide' => array(
// Whether this modules userguide pages should be shown
'enabled' => TRUE,
// The name that should show up on the userguide index page
'name' => 'Userguide',
// A short description of this module, shown on the index page
'description' => 'Documentation viewer and api generation.',
// Copyright message, shown in the footer for this module
'copyright' => '&copy; 20082012 Kohana Team',
)
),
// Set transparent class name segments
'transparent_prefixes' => array(
'Kohana' => TRUE,
)
);

View File

@ -1,4 +1,4 @@
<table class="table table-striped table-condensed table-hover" id="list-table"> <table class="table table-striped table-condensed table-hover" id="list-table<?php echo $jssort ? '-'.$jssort : ''; ?>">
<thead><tr><th><?php echo implode('</th><th>',$th); ?></th></tr></thead> <thead><tr><th><?php echo implode('</th><th>',$th); ?></th></tr></thead>
<tbody> <tbody>
<?php foreach ($td as $details) : ?> <?php foreach ($td as $details) : ?>
@ -11,7 +11,7 @@
</table> </table>
<?php if ($jssort) : ?> <?php if ($jssort) : ?>
<div class="pager"> <div class="pager pager<?php echo $jssort ? '-'.$jssort : ''; ?>">
Page: <select class="input-mini gotoPage"></select> Page: <select class="input-mini gotoPage"></select>
<i class="icon-fast-backward first"></i> <i class="icon-fast-backward first"></i>
<i class="icon-step-backward prev"></i> <i class="icon-step-backward prev"></i>

View File

@ -14,7 +14,7 @@
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<?php <?php
if (Kohana::$environment >= Kohana::TESTING) { if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) {
echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css'); echo HTML::style('media/theme/bootstrap/css/bootstrap.min.css');
echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css'); echo HTML::style('media/theme/bootstrap/css/bootstrap-responsive.min.css');
echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css'); echo HTML::style('media/vendor/font-awesome/css/font-awesome.min.css');
@ -97,7 +97,7 @@
</div> <!-- /main --> </div> <!-- /main -->
<?php <?php
if (Kohana::$environment >= Kohana::TESTING) { if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure()) {
echo HTML::script('media/js/jquery/jquery-1.9.1.min.js'); echo HTML::script('media/js/jquery/jquery-1.9.1.min.js');
echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js'); echo HTML::script('media/theme/bootstrap/js/bootstrap.min.js');
// @todo Work out how to delay this loading until required // @todo Work out how to delay this loading until required