Moved the ledger_entries controller/view to jqGrid.

Changed the app controller jqGrid virtual functions for getting the tables for both count and the full query.  The ExtraTables bit was too confusing, and was only intended to allow the user to specify a subset for count and augment it for full query.  This is easily accomplished by having DataTables just call DataCountTables first... one line solution ends the confusion.

Modified linkable behavior to support a %{MODEL_ALIAS} tag, which is replaced in the relationship conditions at runtime with the actual model alias.  This is experimental at best, and certainly will create a problem for any model that ends up using the conditions in 'contain' instead of 'link'.

Broke the LedgerEntry->findInLedgerContext function out into multiple pieces, so those same pieces could be used in the LedgerEntries controller to populate jqGrid.

Changed the ledger_entries element, as a special case, to also allow listing control from ledger_id and account_type, instead of idlist as a mechanism for populating the grid.

Changed the infobox summary css, which will break several pages until I rework them.

Some next steps include fixing the broken infoboxes, and changing the transactions view to use the ledger_entries element.  This also means the ledger_entries element will need to add support for idlist, or if we have any credit/debit issues, perhaps another custom transaction_id instead.



git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@134 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-15 19:41:20 +00:00
parent 3911b3303f
commit 543e2daa43
13 changed files with 282 additions and 170 deletions

View File

@@ -98,8 +98,11 @@ class AppController extends Controller {
// Get the number of records prior to pagination
$count = $this->jqGridDataRecordCount($params, $model, $query);
// Get the rest of the tables.
$this->jqGridDataExtraTables($params, $model, $query);
// Start the query over, this time getting the actual set
// of tables needed, not just those needed for counting.
$query = array_intersect_key($this->jqGridDataTables($params, $model),
array('link'=>1, 'contain'=>1));
$query['conditions'] = $this->jqGridDataConditions($params, $model);
// Verify a few parameters and determine our starting row
$limit = $params['rows'];
@@ -122,7 +125,7 @@ class AppController extends Controller {
// Add in any needed hyperlinks
$this->jqGridRecordLinks($params, $model, $results, array());
// DEBUG PURPOSES ONLY
// DEBUG PURPOSES ONLY!
$params['query'] = $query;
// Finally, dump out the data
@@ -163,36 +166,44 @@ class AppController extends Controller {
Configure::write('debug', '0');
}
// Unserialize our complex structure of fields
// This SHOULD be always set, except when debugging
if (isset($params['fields']))
$fields = unserialize($params['fields']);
else
$fields = array($this->modelClass . '.id');
$params['fields_str'] = $params['fields'];
$params['fields'] = $fields;
// Establish some defaults before extracting params
// Establish some defaults (except for serialized items)
$params = array_merge(array('page' => 1,
'rows' => 20),
$params);
// Unserialize our complex structure of fields
// This SHOULD always be set, except when debugging
if (isset($params['fields']))
$params['fields'] = unserialize($params['fields']);
else
$params['fields'] = array($this->{$this->modelClass}->alias
.'.'.
$this->{$this->modelClass}->primarKey);
// Unserialize the list of ids, if present.
if (isset($params['custom']))
$params['custom'] = unserialize($params['custom']);
else
$params['custom'] = null;
// Unserialize the list of ids, if present.
if (isset($params['idlist']))
$params['idlist'] = unserialize($params['idlist']);
}
function jqGridDataModel(&$params) {
return $this->{$this->modelClass};
}
function jqGridDataTables(&$params, &$model) {
return array('contain' => false);
}
function jqGridDataCountTables(&$params, &$model) {
// For backwards compatibility
// If not overridden, we use the same tables to
// perform our count as we do to for the actual query
return $this->jqGridDataTables($params, $model);
}
function jqGridDataExtraTables(&$params, &$model, &$query) {
function jqGridDataTables(&$params, &$model) {
return array('contain' => false);
}
function jqGridDataConditions(&$params, &$model) {
@@ -237,7 +248,7 @@ class AppController extends Controller {
}
if (isset($params['action']) && $params['action'] === 'idlist') {
$conditions[] = array($model->alias.'.'.$model->primaryKey => unserialize($params['idlist']));
$conditions[] = array($model->alias.'.'.$model->primaryKey => $params['idlist']);
}
return $conditions;
@@ -265,23 +276,31 @@ class AppController extends Controller {
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
$model_alias = $model->alias;
$id = $model->primaryKey;
foreach ($records AS &$record) {
$record['jqGrid_id'] = $record[$model_alias][$id];
// Add the calculated fields (if any), to the model fields
if (isset($record[0]))
if (isset($record[0])) {
$record[$model_alias] += $record[0];
unset($record[0]);
}
}
// DEBUG PURPOSES ONLY!
//$params['records'] = $records;
}
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
foreach ($links AS $table => $fields) {
$controller = Inflector::pluralize(strtolower($table));
$controller = Inflector::pluralize(Inflector::underscore($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');
// DEBUG PURPOSES ONLY!
//$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
$record[$table][$field] =
'<A HREF="' .
Router::url(array('controller' => $controller,
@@ -313,9 +332,10 @@ class AppController extends Controller {
function jqGridDataOutputRecords(&$params, &$model, &$records) {
$model_alias = $model->alias;
$id = 'jqGrid_id';
foreach ($records AS $record) {
echo " <row id='{$record[$model_alias]['id']}'>\n";
echo " <row id='{$record[$id]}'>\n";
foreach ($params['fields'] AS $field) {
if (preg_match("/\./", $field)) {
list($tbl, $col) = explode(".", $field);