Changed how tables are layed out (since I was repeatedly duplicating code in many places) by adding a table element to be used wherever we need a table. This could probably have been a helper instead of an element, but it's not clear to me why one should be chosen over the other, and I already know how to quickly add an element (I think the real choice resides in whether you need a collection of helper functions, or you just want to drop in a chunk of html, i.e. a helper element). Also, a major revamp to the style sheets as well, although more work is clearly needed.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@42 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-05-30 15:56:41 +00:00
parent 59398cb3f0
commit b488054106
10 changed files with 452 additions and 535 deletions

View File

@@ -31,87 +31,88 @@ function datefmt($date) {
/**********************************************************************
* Tenant Info
*/
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Tenant Info</CAPTION>' . "\n");
echo $html->tableCells(array(array('Name', $contact['Contact']['display_name']),
array('Company', $contact['Contact']['company_name']),
array('SSN', $contact['Contact']['id_federal']),
array('ID', $contact['Contact']['id_num']
. ($contact['Contact']['id_state']
? " - ".$contact['Contact']['id_state']
: "")),
array('Comment', $contact['Contact']['comment'])),
null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
$rows = array(array('Name', $contact['Contact']['display_name']),
array('Company', $contact['Contact']['company_name']),
array('SSN', $contact['Contact']['id_federal']),
array('ID', ($contact['Contact']['id_num']
. ($contact['Contact']['id_state']
? " - ".$contact['Contact']['id_state']
: ""))),
array('Comment', $contact['Contact']['comment']));
echo $this->element('table',
array('class' => 'item contact detail',
'caption' => 'Tenant Info',
'rows' => $rows,
'column_class' => array('field', 'value')));
/**********************************************************************
* Phones
*/
$headers = array('Location', 'Preference', 'Type', 'Phone', 'Extension', 'Comment');
$headers = array('Preference', 'Phone', 'Comment');
$rows = array();
foreach($contact['ContactPhone'] AS $phone) {
$rows[] = array($phone['ContactsMethod']['type'],
$phone['ContactsMethod']['preference'],
$rows[] = array($phone['ContactsMethod']['preference'] . " / " .
$phone['ContactsMethod']['type'] . " / " .
$phone['type'],
phone($phone['phone']),
$phone['ext'],
phone($phone['phone']) .
($phone['ext'] ? " x".$phone['ext'] : ""),
$phone['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Phone</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
echo $this->element('table',
array('class' => 'item phone list',
'caption' => 'Phone',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
* Emails
*/
$headers = array('Location', 'Preference', 'Email', 'Comment');
$headers = array('Preference', 'Email', 'Comment');
$rows = array();
foreach($contact['ContactEmail'] AS $email) {
$rows[] = array($email['ContactsMethod']['type'],
$email['ContactsMethod']['preference'],
$rows[] = array($email['ContactsMethod']['preference'] . " / " .
$email['ContactsMethod']['type'],
$email['email'],
$email['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Email</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
echo $this->element('table',
array('class' => 'item email list',
'caption' => 'Email',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
* Addresses
*/
$headers = array('Location', 'Preference', 'Address', 'City', 'State', 'Zip', 'Country', 'Comment');
$headers = array('Preference', 'Address', 'Comment');
$rows = array();
foreach($contact['ContactAddress'] AS $address) {
$rows[] = array($address['ContactsMethod']['type'],
$address['ContactsMethod']['preference'],
$address['address'],
$address['city'],
$address['state'],
$address['postcode'],
$address['country'],
$rows[] = array($address['ContactsMethod']['preference'] . " / " .
$address['ContactsMethod']['type'],
preg_replace("/\n/", "<BR>\n", $address['address']) . "<BR>\n" .
$address['city'] . ", " .
$address['state'] . " " .
$address['postcode']
. "<BR>\n" . $address['country']
,
$address['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Address</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
echo $this->element('table',
array('class' => 'item address list',
'caption' => 'Address',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
@@ -133,11 +134,12 @@ foreach($contact['Lease'] AS $lease) {
$lease['comment']);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease History</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
echo $this->element('table',
array('class' => 'item lease list',
'caption' => 'Lease History',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
@@ -149,6 +151,7 @@ foreach($contact['Lease'] AS $lease) {
$headers = array('Date', /*'Through',*/ /*'Charge/Receipt'*/'ID', 'Type', 'Comment', 'Amount', 'Total');
$rows = array();
$row_class = array();
$running_total = 0;
foreach($lease['Charge'] AS $charge) {
$amount = $charge['total'];
@@ -159,6 +162,7 @@ foreach($contact['Lease'] AS $lease) {
$charge['comment'],
currency($amount),
currency($running_total));
$row_class[] = 'charge';
foreach ($charge['Receipt'] AS $receipt) {
$amount = -1 * $receipt['ChargesReceipt']['amount'];
@@ -173,16 +177,18 @@ foreach($contact['Lease'] AS $lease) {
$receipt['comment'],
currency($amount),
currency($running_total));
$row_class[] = 'receipt';
}
}
$grand_total += $running_total;
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease #'.$lease['number'].' ('.$lease['Unit']['name'].')</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
echo $this->element('table',
array('class' => 'item ledger list',
'caption' => 'Lease #'.$lease['number'].' ('.$lease['Unit']['name'].')',
'headers' => $headers,
'rows' => $rows,
'row_class' => $row_class,
'column_class' => $headers));
}
?>

View File

@@ -4,57 +4,52 @@ if (isset($heading))
echo $heading;
else
echo '<h2>'.__('Contacts',true).'</h2>';
?>
<table cellpadding="0" cellspacing="0">
$headers_manual = array('Id', 'Last Name', 'First Name', 'Company', 'Comment');
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
<?php
{
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$rows = array($paginator->sort('id'),
$headers = array($paginator->sort('id'),
$paginator->sort('last_name'),
$paginator->sort('first_name'),
$paginator->sort('company_name'),
//$paginator->sort('unit_id'),
$paginator->sort('comment'));
} else {
$rows = array('Id', 'Last Name', 'First Name', 'Company', 'Comment');
}
echo $html->tableHeaders($rows);
} else {
$headers = $headers_manual;
}
$rows = array();
foreach ($contacts as $contact) {
$rows[] = array($html->link($contact['Contact']['id'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$html->link($contact['Contact']['last_name'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$html->link($contact['Contact']['first_name'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$contact['Contact']['company_name'],
$contact['Contact']['comment']);
}
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
}
?>
</table>
$rows = array();
foreach ($contacts as $contact) {
$rows[] = array($html->link($contact['Contact']['id'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$html->link($contact['Contact']['last_name'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$html->link($contact['Contact']['first_name'],
array('controller' => 'contacts',
'action' => 'view',
$contact['Contact']['id'])),
$contact['Contact']['company_name'],
$contact['Contact']['comment']);
}
<?php
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}
?>
echo $this->element('table',
array('class' => 'item contact list',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers_manual));
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}

View File

@@ -4,55 +4,50 @@ if (isset($heading))
echo $heading;
else
echo '<h2>'.__('Maps',true).'</h2>';
?>
<table cellpadding="0" cellspacing="0">
$headers_manual = array('Id', 'Name', 'Area', 'Width', 'Depth', 'Comment');
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
<?php
{
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$rows = array($paginator->sort('id'),
$headers = array($paginator->sort('id'),
$paginator->sort('name'),
$paginator->sort('site_area_id'),
$paginator->sort('width'),
$paginator->sort('depth'),
$paginator->sort('comment'));
} else {
$rows = array('Id', 'Name', 'Area', 'Width', 'Depth', 'Comment');
}
echo $html->tableHeaders($rows);
} else {
$headers = $headers_manual;
}
$rows = array();
foreach ($maps as $map) {
$rows[] = array($html->link($map['Map']['id'],
array('controller' => 'maps',
'action' => 'view',
$map['Map']['id'])),
$html->link($map['Map']['name'],
array('controller' => 'maps',
'action' => 'view',
$map['Map']['id'])),
$map['SiteArea']['name'],
$map['Map']['width'] / 12,
$map['Map']['depth'] / 12,
$map['Map']['comment']);
}
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
}
?>
</table>
$rows = array();
foreach ($maps as $map) {
$rows[] = array($html->link($map['Map']['id'],
array('controller' => 'maps',
'action' => 'view',
$map['Map']['id'])),
$html->link($map['Map']['name'],
array('controller' => 'maps',
'action' => 'view',
$map['Map']['id'])),
$map['SiteArea']['name'],
$map['Map']['width'] / 12,
$map['Map']['depth'] / 12,
$map['Map']['comment']);
}
<?php
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}
?>
echo $this->element('table',
array('class' => 'item map list',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers_manual));
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}

59
views/elements/table.ctp Normal file
View File

@@ -0,0 +1,59 @@
<?php /* -*- mode:PHP -*- */
/* table.ctp */
/*
*
* @filesource
* @copyright Copyright 2009, Abijah Perkins
* @package pmgr
*/
if (isset($rows) && is_array($rows) && count($rows)) {
echo('<TABLE' . (isset($class) ? ' CLASS="'.$class.'"' : '') . '>' . "\n");
if (isset($caption))
echo(' <CAPTION>' . $caption . '</CAPTION>' . "\n");
if (isset($row_class) && is_array($row_class)) {
foreach ($row_class AS &$rc)
$rc = preg_replace("/ /", "-", strtolower($rc));
}
if (isset($column_class) && is_array($column_class)) {
foreach ($column_class AS &$cc)
$cc = preg_replace("/ /", "-", strtolower($cc));
}
/* if (isset($headers) && is_array($headers)) { */
/* foreach ($headers AS $i => $col) { */
/* if (!isset($column_class[$i])) */
/* continue; */
/* $headers[$i] = array($col, array('class' => $column_class[$i])); */
/* } */
/* } */
// Very kludgy.
// I want the row_class to affix to the <tr> tag.
// tableCells, however, does not have such ability :-/
foreach ($rows AS $r => &$row) {
foreach ($row AS $c => $col) {
$colclass = (isset($column_class) && is_array($column_class)) ? $column_class[$c] : '';;
$rowclass = (isset($row_class) && is_array($row_class)) ? $row_class[$r] : '';
$class = $rowclass . ($colclass ? " " . $colclass : '');
if (!$class)
continue;
$row[$c] = array($col, array('class' => $class));
}
}
echo("\n");
if (isset($headers) && is_array($headers))
echo $html->tableHeaders($headers);
echo("\n");
echo $html->tableCells($rows,
array('class' => "oddrow"),
array('class' => "evnrow"),
false, false);
echo("\n");
echo('</TABLE>' . "\n");
}

View File

@@ -4,53 +4,48 @@ if (isset($heading))
echo $heading;
else
echo '<h2>'.__('Units',true).'</h2>';
?>
<table cellpadding="0" cellspacing="0">
$headers_manual = array('Id', 'Unit', 'Size', 'Status', 'Comment');
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
<?php
{
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$rows = array($paginator->sort('id'),
$headers = array($paginator->sort('id'),
$paginator->sort('Unit', 'name'),
$paginator->sort('unit_size_id'),
$paginator->sort('status'),
$paginator->sort('comment'));
} else {
$rows = array('Id', 'Unit', 'Size', 'Status', 'Comment');
}
echo $html->tableHeaders($rows);
} else {
$headers = $headers_manual;
}
$rows = array();
foreach ($units as $unit) {
$rows[] = array($html->link($unit['Unit']['id'],
array('controller' => 'units',
'action' => 'view',
$unit['Unit']['id'])),
$html->link($unit['Unit']['name'],
array('controller' => 'units',
'action' => 'view',
$unit['Unit']['id'])),
$unit['UnitSize']['name'],
$unit['Unit']['status'],
$unit['Unit']['comment']);
}
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
}
?>
</table>
$rows = array();
foreach ($units as $unit) {
$rows[] = array($html->link($unit['Unit']['id'],
array('controller' => 'units',
'action' => 'view',
$unit['Unit']['id'])),
$html->link($unit['Unit']['name'],
array('controller' => 'units',
'action' => 'view',
$unit['Unit']['id'])),
$unit['UnitSize']['name'],
$unit['Unit']['status'],
$unit['Unit']['comment']);
}
<?php
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}
?>
echo $this->element('table',
array('class' => 'item unit list',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers_manual));
if (isset($paginator)) {
echo('<div class="paging">' . "\n");
echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo(' | ');
echo $paginator->numbers();
echo(' | ');
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));
echo('</div>' . "\n");
}

View File

@@ -30,12 +30,12 @@
Property Manager: <?php echo $title_for_layout; ?>
</title>
<?php
echo $html->meta('icon');
echo $html->css('cake.generic');
echo $scripts_for_layout;
echo $html->meta('icon') . "\n";
echo $html->css('cake.generic') . "\n";
echo $html->css('layout') . "\n";
echo $html->css('sidemenu') . "\n";
echo $scripts_for_layout . "\n";
?>
<LINK REL="stylesheet" TYPE="text/css" HREF="<?php echo $html->url('/webroot/css/sidemenu.css') ?>" />
</head>
<body>

View File

@@ -21,18 +21,16 @@ function datefmt($date) {
/**********************************************************************
* Unit Info
*/
$rows = array();
foreach($unit['Unit'] AS $col => $val) {
$rows[] = array(array($col, 'width=1%'), $val);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Unit Info</CAPTION>' . "\n");
echo $html->tableCells(array(array('Name', $unit['Unit']['name']),
array('Status', $unit['Unit']['status']),
array('Comment', $unit['Unit']['comment'])),
null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
$rows = array(array('Name', $unit['Unit']['name']),
array('Status', $unit['Unit']['status']),
array('Comment', $unit['Unit']['comment']));
echo $this->element('table',
array('class' => 'item unit detail',
'caption' => 'Unit Info',
'rows' => $rows,
'column_class' => array('field', 'value')));
/**********************************************************************
@@ -54,11 +52,12 @@ foreach($unit['Lease'] AS $lease) {
$lease['comment']);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease History</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
echo $this->element('table',
array('class' => 'item lease list',
'caption' => 'Lease History',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
@@ -98,12 +97,12 @@ foreach($unit['Lease'] AS $lease) {
}
$grand_total += $running_total;
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease #'.$lease['number'].' ('.$lease['Contact'][0]['display_name'].')</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
echo $this->element('table',
array('class' => 'item ledger list',
'caption' => 'Lease #'.$lease['number'].' ('.$lease['Contact'][0]['display_name'].')',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
}
?>