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/site@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
|
* - 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 index() { $this->current(); }
|
||||||
function current() { $this->jqGridSetup('current', 'Current Tenants'); }
|
function current() { $this->jqGridView('current', 'Current Tenants'); }
|
||||||
function past() { $this->jqGridSetup('past', 'Past Tenants'); }
|
function past() { $this->jqGridView('past', 'Past Tenants'); }
|
||||||
function all() { $this->jqGridSetup('all', 'All Tenants'); }
|
function all() { $this->jqGridView('all', 'All Tenants'); }
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
|||||||
@@ -28,114 +28,98 @@ class UnitsController extends AppController {
|
|||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* action: index
|
* action: index / current / past / all
|
||||||
* - Lists all units
|
* - Creates a list of tenants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function index() {
|
function index() { $this->all(); }
|
||||||
$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
|
* virtuals: jqGridData
|
||||||
* - Lists unavailable units
|
* - With the application controller handling the jqGridData action,
|
||||||
|
* these virutal functions ensure that the correct data is passed
|
||||||
|
* to jqGrid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function unavailable() {
|
function jqGridDataSetup(&$params) {
|
||||||
$this->paginate = array_merge
|
parent::jqGridDataSetup($params);
|
||||||
($this->paginate,
|
if (!isset($params['action']))
|
||||||
array('link' =>
|
$params['action'] = 'all';
|
||||||
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 jqGridDataTables(&$params) {
|
||||||
|
$link = array
|
||||||
|
('link' =>
|
||||||
|
array(// Models
|
||||||
|
'UnitSize' => array('fields' => array('name')),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/**************************************************************************
|
if ($params['action'] === 'occupied')
|
||||||
**************************************************************************
|
$link['Lease'] = array('fields' => array(),
|
||||||
**************************************************************************
|
// Models
|
||||||
* action: vacant
|
'Contact' => array('fields' => array('display_name'),
|
||||||
* - Lists vacant units
|
//'type' => 'LEFT',
|
||||||
*/
|
),
|
||||||
|
);
|
||||||
|
|
||||||
function vacant() {
|
return $link;
|
||||||
$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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridDataConditions(&$params) {
|
||||||
|
$conditions = parent::jqGridDataConditions($params);
|
||||||
|
|
||||||
/**************************************************************************
|
if ($params['action'] === 'unavailable') {
|
||||||
**************************************************************************
|
$conditions[] = $this->Unit->conditionUnavailable();
|
||||||
**************************************************************************
|
}
|
||||||
* action: occupied
|
elseif ($params['action'] === 'vacant') {
|
||||||
* - Lists occupied units
|
$conditions[] = $this->Unit->conditionVacant();
|
||||||
*/
|
}
|
||||||
|
elseif ($params['action'] === 'occupied') {
|
||||||
|
$conditions[] = $this->Unit->conditionOccupied();
|
||||||
|
}
|
||||||
|
|
||||||
function occupied() {
|
return $conditions;
|
||||||
$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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function zzjqGridDataRecordCount(&$params, $model, $query) {
|
||||||
|
|
||||||
/**************************************************************************
|
// 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,
|
||||||
* action: all
|
// whether we omit the group by or leave it in.
|
||||||
* - Lists all units
|
// So, build a fresh query for counting.
|
||||||
*/
|
|
||||||
|
|
||||||
function all() {
|
$query['conditions'] = parent::jqGridDataConditions($params);
|
||||||
$this->paginate = array_merge
|
|
||||||
($this->paginate,
|
|
||||||
array('link' =>
|
|
||||||
array(// Models
|
|
||||||
'UnitSize' => array('fields' => array('name')),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
|
|
||||||
$title = 'All Units';
|
$count = $model->find('count',
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
array_merge(array('link' => array_diff_key($query['link'],
|
||||||
$this->set('units', $this->paginate());
|
array('CurrentLease'=>1))),
|
||||||
$this->render('index');
|
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 -*- */
|
<?php /* -*- mode:PHP -*- */
|
||||||
|
|
||||||
if (isset($heading))
|
// Define the table columns
|
||||||
echo $heading;
|
$cols = array();
|
||||||
else
|
$cols['ID'] = array('index' => 'Unit.id', 'width' => '30', 'align' => 'center');
|
||||||
echo '<h2>'.__('Units',true).'</h2>';
|
$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');
|
// Some of the columns should not be sortable
|
||||||
$column_class = array();
|
foreach (array_intersect_key($cols, array('Comment'=>1)) AS $k => $v)
|
||||||
foreach (array_intersect($headers, array('ID')) AS $k => $v) {
|
$cols[$k]['sortable'] = false;
|
||||||
$column_class[$k] = 'id';
|
|
||||||
}
|
|
||||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
|
||||||
$column_class[$k] = 'slack';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($paginator)) {
|
echo $this->element('jqGrid',
|
||||||
echo $paginator->counter(array(
|
array('jqGridColumns' => $cols));
|
||||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
|
||||||
|
|
||||||
$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