Added User email viewing

Improved Table::
This commit is contained in:
Deon George
2011-08-27 16:33:46 +10:00
parent 495da41e0d
commit 6d44e7d5b2
51 changed files with 701 additions and 273 deletions

View File

@@ -25,22 +25,34 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
Block_Sub::add(array(
'title'=>'Invoices Overdue',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_overdue($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id()'=>array('label'=>'ID'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('page'=>TRUE)),
'position'=>1,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Due',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_due($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->name()'=>array('label'),
'account->display("status")'=>array('label'=>'Active'),
'id()'=>array('label'=>'ID'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('show_other'=>'due()')),
'position'=>2,
'order'=>1,
));
@@ -50,11 +62,17 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
Block_Sub::add(array(
'title'=>'Unapplied Payments',
'body'=>Table::limit(
'body'=>Table::display(
$o->list_unapplied(),
30,
array('ID'=>'id','Account'=>'account->name()','Total'=>'display("total_amt")','Balance'=>'balance(TRUE)'),
'balance(TRUE)'),
25,
array(
'id'=>array('label'=>'ID'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
),
array('show_other'=>'balance()')),
'position'=>3,
'order'=>1,
));

View File

@@ -107,7 +107,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
Block::add(array(
'title'=>_('Register'),
'body'=>View::factory('bregister')
'body'=>View::factory('register')
->set('account',$account)
->set('errors',$account->validation()->errors('form/register')),
));

View File

@@ -185,10 +185,13 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
if ($s = $this->_sysmsg() AND (string)$s)
$this->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
# In case there any style sheets or scrpits for this render.
// In case there any style sheets for this render.
$this->response->bodyadd(Style::factory());
# Get the response body
// In case there any javascript for this render.
$this->response->bodyadd(Script::factory());
// Get the response body
$this->response->bodyadd(sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content));
}

View File

@@ -17,10 +17,10 @@ class Controller_lnApp_Tree extends Controller_Default {
protected static $jsmediaroute = 'default/media';
public function after() {
parent::after();
$this->response->headers('Content-Type','application/json');
$this->response->body(sprintf('[%s]',json_encode($this->output)));
parent::after();
}
public static function js() {

View File

@@ -86,7 +86,7 @@ class lnApp_Block_Sub extends HTMLRender {
// Render our output.
$output .= '<table class="subblockhead">';
foreach ($o as $k => $v)
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',round(100/$y,0),implode('</td><td>',$v));
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',$x=round(100/$y,0),implode(sprintf('</td><td style="width: %s%%;">',$x),$v));
$output .= '</table>';
return $output;

View File

@@ -12,52 +12,242 @@
* @uses Style
*/
class lnApp_Table {
public static function limit($data,$rows,array $cols,$other) {
public static function resolve($d,$key) {
if (is_array($d) AND isset($d[$key]))
$x = $d[$key];
// If the key is a method, we need to eval it
elseif (preg_match('/\(/',$key))
eval("\$x = \$d->$key;");
elseif (preg_match('/^__VALUE__$/',$key))
$x = $d;
else
$x = $d->display($key);
return $x;
}
public static function display($data,$rows,array $cols,array $option) {
if (! (array)$data)
return '';
$output = '';
$pag = NULL;
$view = $output = '';
$other = $i = 0;
$output = '<table border="0">';
$output .= '<tr><th>'.implode('</th><th>',array_keys($cols)).'</th></tr>';
foreach ($data as $do) {
if ($i++ < $rows) {
$output .= '<tr>';
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {
case 'select':
$view = 'table/select';
foreach (array_values($cols) as $col) {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$output .= sprintf('<td>%s</td>',$x);
Script::add(array(
'type'=>'stdin',
'data'=>'
(function($) {
// Enable Range Selection
$.fn.enableCheckboxRangeSelection = function() {
var lastCheckbox = null;
var followOn = 0;
var $spec = this;
$spec.bind("click", function(e) {
if (lastCheckbox != null && e.shiftKey) {
x = y = 0;
if (followOn != 0) {
if ($spec.index(lastCheckbox) < $spec.index(e.target)) {
x = 1 - ((followOn == 1) ? 1 : 0);
} else {
y = 1 - ((followOn == -1) ? 1 : 0);
}
}
$output .= '</tr>';
$spec.slice(
Math.min($spec.index(lastCheckbox) - x, $spec.index(e.target)) + 1,
Math.max($spec.index(lastCheckbox), $spec.index(e.target)) + y
).attr("checked",function() { return ! this.checked; })
.parent().parent().toggleClass("selected");
followOn = ($spec.index(lastCheckbox) < $spec.index(e.target)) ? 1 : -1;
} else {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
followOn = 0;
}
lastCheckbox = e.target;
});
$other += $x;
return $spec;
};
// Enable Toggle, (De)Select All
$.fn.check = function(mode) {
// if mode is undefined, use "on" as default
var mode = mode || "on";
switch(mode) {
case "on":
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:not(checked))")
.toggleClass("selected")
break;
case "off":
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:checked)")
.toggleClass("selected")
break;
case "toggle":
$("#select-table tr:not(.head)")
.toggleClass("selected");
break;
}
return this.each(function(e) {
switch(mode) {
case "on":
this.checked = true;
break;
case "off":
this.checked = false;
break;
case "toggle":
this.checked = !this.checked;
break;
}
});
};
})(jQuery);
// Bind our actions
$(document).ready(function() {
$("#select-table :checkbox").enableCheckboxRangeSelection();
$("#select-menu > #toggle").bind("click",function() {
$("#select-table :checkbox").check("toggle");
});
$("#select-menu > #all_on").bind("click",function() {
$("#select-table :checkbox").check("on");
});
$("#select-menu > #all_off").bind("click",function() {
$("#select-table :checkbox").check("off");
});
// Our mouse over row highlight
$("#select-table tr:not(.head)").hover(function() {
$(this).children().toggleClass("highlight");
},
function() {
$(this).children().toggleClass("highlight");
});
// Click to select Row
$("#select-table tr:not(.head)")
.filter(":has(:checkbox:checked)")
.addClass("selected")
.end()
.click(function(e) {
$(this).toggleClass("selected");
if (e.target.type !== "checkbox") {
$(":checkbox", this).attr("checked", function() {
return !this.checked;
});
}
});
});
'));
$output .= Form::open((isset($option['form']) ? $option['form'] : ''));
break;
case 'list':
default:
Script::add(array(
'type'=>'stdin',
'data'=>'
// Bind our actions
$(document).ready(function() {
// Our mouse over row highlight
$("#list-table tr:not(.head)").hover(function() {
$(this).children().toggleClass("highlight");
},
function() {
$(this).children().toggleClass("highlight");
});
});
'));
}
If (! $view)
$view = 'table/list';
if (isset($option['page']) AND $option['page']) {
$pag = new Pagination(array(
'total_items'=>count($data),
'items_per_page'=>$rows,
));
$output .= (string)$pag;
}
$other = $i = 0;
$td = $th = array();
foreach ($cols as $col => $details) {
$th[$col] = isset($details['label']) ? $details['label'] : '';
$td[$col]['class'] = isset($details['class']) ? $details['class'] : '';
$td[$col]['url'] = isset($details['url']) ? $details['url'] : '';
}
$output .= View::factory($view.'_head')
->set('th',array_values($th));
foreach ($data as $do) {
if ($pag) {
if (++$i < $pag->current_first_item())
continue;
elseif ($i > $pag->current_last_item())
break;
}
if ($pag OR ($i++ < $rows)) {
foreach (array_keys($cols) as $col)
$td[$col]['value'] = Table::resolve($do,$col);
$output .= View::factory($view.'_body')
->set('td',$td)
->set('trc',$i%2 ? 'odd' : 'even');
} elseif (isset($option['show_other']) AND ($col=$option['show_other'])) {
$other += Table::resolve($do,$col);
}
}
if ($other)
$output .= sprintf('<tr><td>Other</td><td colspan="%s">(%s) %s</td></tr>',count($cols)-1,$i-$rows,$other);
$output .= View::factory($view.'_xtra')
->set('td',array_values($cols))
->set('count',$i-$rows)
->set('other',$other);
$output .= '</table>';
$output .= View::factory($view.'_foot');
if (isset($option['type']) AND $option['type'])
switch ($option['type']) {
case 'select':
$output .= Form::close();
}
return $output;
}
public static function post($key,$i='id') {
if (isset($_POST[$i]))
Session::instance()->set('page_table_view'.$key,$_POST[$i]);
}
public static function page($key) {
if ($ids = Session::instance()->get('page_table_view'.$key)) {
$pag = new Pagination(array(
'total_items'=>count($ids),
'items_per_page'=>1,
));
return array($ids[$pag->current_first_item()-1],(string)$pag);
// If we get here, then there is no previous data to retrieve.
} else
return array(NULL,'');
}
}
?>

View File

@@ -27,8 +27,13 @@ class Model_Module extends ORMOSB {
'name'=>'ASC',
);
protected $_formats = array(
'status'=>array('StaticList_YesNo::display'=>array()),
protected $_display_filters = array(
'name'=>array(
array('strtoupper',array(':value')),
),
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
}
?>