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:
abijah
2009-06-14 05:33:30 +00:00
parent ddf4d5cb29
commit 67d640b1a0
5 changed files with 100 additions and 153 deletions

View File

@@ -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'); }
/**************************************************************************

View File

@@ -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;
}