Added mechanism to easily create links in the listing grids. I'm not very keen on how it works, but it's good enough for the moment, unless/until I figure out how to push this to the view. If it should stay in the controller, I'm sure a more sophisticated mechanism will be required.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@128 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -113,6 +113,9 @@ class AppController extends Controller {
|
|||||||
$query['fields'] = $this->jqGridDataFields($params, $model);
|
$query['fields'] = $this->jqGridDataFields($params, $model);
|
||||||
$results = $this->jqGridDataRecords($params, $model, $query);
|
$results = $this->jqGridDataRecords($params, $model, $query);
|
||||||
|
|
||||||
|
// Add in any needed hyperlinks
|
||||||
|
$this->jqGridRecordLinks($params, $model, $results, array());
|
||||||
|
|
||||||
// DEBUG PURPOSES ONLY
|
// DEBUG PURPOSES ONLY
|
||||||
$params['query'] = $query;
|
$params['query'] = $query;
|
||||||
|
|
||||||
@@ -246,6 +249,28 @@ class AppController extends Controller {
|
|||||||
return $model->find('all', $query);
|
return $model->find('all', $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
foreach ($links AS $table => $fields) {
|
||||||
|
$controller = Inflector::pluralize(strtolower($table));
|
||||||
|
$id = 'id';
|
||||||
|
if (isset($fields['id']))
|
||||||
|
$id = $fields['id'];
|
||||||
|
foreach ($records AS &$record) {
|
||||||
|
foreach (array_diff_key($fields, array('id'=>1)) AS $field) {
|
||||||
|
$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
|
||||||
|
$record[$table][$field] =
|
||||||
|
'<A HREF="' .
|
||||||
|
Router::url(array('controller' => $controller,
|
||||||
|
'action' => 'view',
|
||||||
|
$record[$table][$id])) .
|
||||||
|
'">' .
|
||||||
|
$record[$table][$field] .
|
||||||
|
'</A>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function jqGridDataOutputHeader(&$params, &$model) {
|
function jqGridDataOutputHeader(&$params, &$model) {
|
||||||
if ($params['debug']) {
|
if ($params['debug']) {
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -262,7 +287,7 @@ class AppController extends Controller {
|
|||||||
echo " <records>$records</records>\n";
|
echo " <records>$records</records>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataOutputRecords(&$params, &$model, $records) {
|
function jqGridDataOutputRecords(&$params, &$model, &$records) {
|
||||||
$model_alias = $model->alias;
|
$model_alias = $model->alias;
|
||||||
|
|
||||||
foreach ($records AS $record) {
|
foreach ($records AS $record) {
|
||||||
|
|||||||
@@ -122,6 +122,11 @@ class CustomersController extends AppController {
|
|||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Customer'] = array('name');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ class LeasesController extends AppController {
|
|||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
function jqGridDataTables(&$params, &$model) {
|
||||||
return array
|
return array
|
||||||
('link' => array('Unit' => array('fields' => array('Unit.name')),
|
('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')),
|
||||||
'Customer' => array('fields' => array('Customer.name'))));
|
'Customer' => array('fields' => array('Customer.id', 'Customer.name'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
@@ -68,6 +68,12 @@ class LeasesController extends AppController {
|
|||||||
return $conditions;
|
return $conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Lease'] = array('number');
|
||||||
|
$links['Unit'] = array('name');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
function jqGridDataRecords(&$params, &$model, $query) {
|
function jqGridDataRecords(&$params, &$model, $query) {
|
||||||
$leases = parent::jqGridDataRecords($params, $model, $query);
|
$leases = parent::jqGridDataRecords($params, $model, $query);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user