Moved units onto jqGrid. Also generalized the jqGridSetup (now jqGridView) function and moved it into the app controller.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@117 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -56,6 +56,21 @@ class AppController extends Controller {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* helper: jqGridView
|
||||
* - called by function to create an index listing
|
||||
*/
|
||||
|
||||
function jqGridView($action, $title) {
|
||||
$this->set('title', $title);
|
||||
// The resulting page will contain a jqGrid, which will
|
||||
// use ajax to obtain the actual data for this action
|
||||
$this->set('action', $action);
|
||||
$this->render('/elements/' . $this->params['controller']);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -29,18 +29,10 @@ class CustomersController extends AppController {
|
||||
* - Creates a list of tenants
|
||||
*/
|
||||
|
||||
function jqGridSetup($action, $title) {
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
// The resulting page will contain a jqGrid, which will
|
||||
// use ajax to obtain the actual data for this action
|
||||
$this->set('action', $action);
|
||||
$this->render('/elements/customers');
|
||||
}
|
||||
|
||||
function index() { $this->current(); }
|
||||
function current() { $this->jqGridSetup('current', 'Current Tenants'); }
|
||||
function past() { $this->jqGridSetup('past', 'Past Tenants'); }
|
||||
function all() { $this->jqGridSetup('all', 'All Tenants'); }
|
||||
function current() { $this->jqGridView('current', 'Current Tenants'); }
|
||||
function past() { $this->jqGridView('past', 'Past Tenants'); }
|
||||
function all() { $this->jqGridView('all', 'All Tenants'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
@@ -28,114 +28,98 @@ class UnitsController extends AppController {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: index
|
||||
* - Lists all units
|
||||
* action: index / current / past / all
|
||||
* - Creates a list of tenants
|
||||
*/
|
||||
|
||||
function index() {
|
||||
$this->all();
|
||||
}
|
||||
function index() { $this->all(); }
|
||||
function unavailable() { $this->jqGridView('unavailable', 'Unavailable Units'); }
|
||||
function vacant() { $this->jqGridView('vacant', 'Vacant Units'); }
|
||||
function occupied() { $this->jqGridView('occupied', 'Occupied Units'); }
|
||||
function all() { $this->jqGridView('all', 'All Units'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: unavailable
|
||||
* - Lists unavailable units
|
||||
* virtuals: jqGridData
|
||||
* - With the application controller handling the jqGridData action,
|
||||
* these virutal functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function unavailable() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'UnitSize' => array('fields' => array('name')),
|
||||
),
|
||||
'conditions' => $this->Unit->conditionUnavailable()
|
||||
));
|
||||
|
||||
$title = 'Unavailable Units';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('units', $this->paginate());
|
||||
$this->render('index');
|
||||
function jqGridDataSetup(&$params) {
|
||||
parent::jqGridDataSetup($params);
|
||||
if (!isset($params['action']))
|
||||
$params['action'] = 'all';
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params) {
|
||||
$link = array
|
||||
('link' =>
|
||||
array(// Models
|
||||
'UnitSize' => array('fields' => array('name')),
|
||||
),
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: vacant
|
||||
* - Lists vacant units
|
||||
*/
|
||||
if ($params['action'] === 'occupied')
|
||||
$link['Lease'] = array('fields' => array(),
|
||||
// Models
|
||||
'Contact' => array('fields' => array('display_name'),
|
||||
//'type' => 'LEFT',
|
||||
),
|
||||
);
|
||||
|
||||
function vacant() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'UnitSize' => array('fields' => array('name')),
|
||||
),
|
||||
'conditions' => $this->Unit->conditionVacant()
|
||||
));
|
||||
|
||||
$title = 'Vacant Units';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('units', $this->paginate());
|
||||
$this->render('index');
|
||||
return $link;
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params) {
|
||||
$conditions = parent::jqGridDataConditions($params);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: occupied
|
||||
* - Lists occupied units
|
||||
*/
|
||||
if ($params['action'] === 'unavailable') {
|
||||
$conditions[] = $this->Unit->conditionUnavailable();
|
||||
}
|
||||
elseif ($params['action'] === 'vacant') {
|
||||
$conditions[] = $this->Unit->conditionVacant();
|
||||
}
|
||||
elseif ($params['action'] === 'occupied') {
|
||||
$conditions[] = $this->Unit->conditionOccupied();
|
||||
}
|
||||
|
||||
function occupied() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'UnitSize' => array('fields' => array('name')),
|
||||
'Lease' => array('fields' => array(),
|
||||
|
||||
// Models
|
||||
'Contact' => array('fields' => array('display_name'),
|
||||
//'type' => 'LEFT',
|
||||
),
|
||||
),
|
||||
),
|
||||
'conditions' => $this->Unit->conditionOccupied()
|
||||
));
|
||||
|
||||
$title = 'Occupied Units';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('units', $this->paginate());
|
||||
$this->render('index');
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function zzjqGridDataRecordCount(&$params, $model, $query) {
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: all
|
||||
* - Lists all units
|
||||
*/
|
||||
// We don't have a good way to use the query to obtain
|
||||
// our count. The problem is that we're relying on the
|
||||
// group by for the query, which will destroy the count,
|
||||
// whether we omit the group by or leave it in.
|
||||
// So, build a fresh query for counting.
|
||||
|
||||
function all() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'UnitSize' => array('fields' => array('name')),
|
||||
),
|
||||
));
|
||||
$query['conditions'] = parent::jqGridDataConditions($params);
|
||||
|
||||
$title = 'All Units';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('units', $this->paginate());
|
||||
$this->render('index');
|
||||
$count = $model->find('count',
|
||||
array_merge(array('link' => array_diff_key($query['link'],
|
||||
array('CurrentLease'=>1))),
|
||||
array_diff_key($query, array('link'=>1))));
|
||||
|
||||
if ($params['action'] === 'all')
|
||||
return $count;
|
||||
|
||||
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
||||
$count_past = $model->find('count', $query);
|
||||
|
||||
// Since we can't easily count 'current' directly, we
|
||||
// can quickly derive it since 'current' customers
|
||||
// are mutually exclusive to 'past' customers.
|
||||
if ($params['action'] == 'current')
|
||||
$count = $count - $count_past;
|
||||
elseif ($params['action'] == 'past') {
|
||||
$count = $count_past;
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,58 +1,17 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Units',true).'</h2>';
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['ID'] = array('index' => 'Unit.id', 'width' => '30', 'align' => 'center');
|
||||
$cols['Unit'] = array('index' => 'Unit.name', 'width' => '50', 'align' => 'left');
|
||||
$cols['Size'] = array('index' => 'UnitSize.name', 'width' => '75', 'align' => 'left');
|
||||
$cols['Status'] = array('index' => 'Unit.status', 'width' => '75', 'align' => 'left');
|
||||
$cols['Comment'] = array('index' => 'Unit.comment', 'width' => '400', 'align' => 'left');
|
||||
|
||||
$headers = array('ID', 'Unit', 'Size', 'Status', 'Comment');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('ID')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'slack';
|
||||
}
|
||||
// Some of the columns should not be sortable
|
||||
foreach (array_intersect_key($cols, array('Comment'=>1)) AS $k => $v)
|
||||
$cols[$k]['sortable'] = false;
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
echo $this->element('jqGrid',
|
||||
array('jqGridColumns' => $cols));
|
||||
|
||||
$headers = array($paginator->sort('id'),
|
||||
$paginator->sort('Unit', 'name'),
|
||||
$paginator->sort('unit_size_id'),
|
||||
$paginator->sort('status'),
|
||||
$paginator->sort('comment'));
|
||||
}
|
||||
|
||||
$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 $this->element('table',
|
||||
array('class' => 'item unit list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<div class="units index">
|
||||
<?php echo $this->element('units', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||
</div>
|
||||
Reference in New Issue
Block a user