Fixed the relationship field for customer and contact grids.

git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@750 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-23 19:23:49 +00:00
parent 89d7f22e4a
commit 5ad28c809b
6 changed files with 44 additions and 26 deletions

View File

@@ -23,6 +23,19 @@ class ContactsController extends AppController {
* to jqGrid. * to jqGrid.
*/ */
function gridDataFilterTablesConfig(&$params, &$model, $table) {
$config = parent::gridDataFilterTablesConfig($params, $model, $table);
// Special case for Customer; We need the Contact/Customer relationship
if ($table == 'Customer')
$config = array('fields' => array('ContactsCustomer.type',
'ContactsCustomer.active'),
'conditions' => array('ContactsCustomer.active' => true),
);
return $config;
}
function gridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
$order = parent::gridDataOrder($params, $model, $index, $direction); $order = parent::gridDataOrder($params, $model, $index, $direction);

View File

@@ -92,19 +92,29 @@ class CustomersController extends AppController {
return $conditions; return $conditions;
} }
function gridDataOrder(&$params, &$model, $index, $direction) { function gridDataFilterTablesConfig(&$params, &$model, $table) {
$order = array(); $config = parent::gridDataFilterTablesConfig($params, $model, $table);
$order[] = parent::gridDataOrder($params, $model, $index, $direction);
if ($index !== 'PrimaryContact.last_name') // Special case for Contact; We need the Contact/Customer relationship
$order[] = parent::gridDataOrder($params, $model, if ($table == 'Contact')
'PrimaryContact.last_name', $direction); $config = array('fields' => array('ContactsCustomer.type',
if ($index !== 'PrimaryContact.first_name') 'ContactsCustomer.active'),
$order[] = parent::gridDataOrder($params, $model, 'conditions' => array('ContactsCustomer.active' => true),
'PrimaryContact.first_name', $direction); );
if ($index !== 'Customer.id')
$order[] = parent::gridDataOrder($params, $model, return $config;
'Customer.id', $direction); }
function gridDataOrder(&$params, &$model, $index, $direction) {
$order = parent::gridDataOrder($params, $model, $index, $direction);
// After sorting by whatever the user wants, add these
// defaults into the sort mechanism. If we're already
// sorting by one of them, it will only be redundant,
// and should cause no harm (possible a longer query?)
$order[] = 'PrimaryContact.last_name ' . $direction;
$order[] = 'PrimaryContact.first_name ' . $direction;
$order[] = 'Customer.id ' . $direction;
return $order; return $order;
} }

View File

@@ -135,6 +135,7 @@ echo $this->element('customers', array
'config' => array 'config' => array
('caption' => 'Related Customers', ('caption' => 'Related Customers',
'filter' => array('Contact.id' => $contact['id']), 'filter' => array('Contact.id' => $contact['id']),
'include' => array('Relationship'),
))); )));

View File

@@ -61,7 +61,7 @@ echo $this->element('contacts', array
'config' => array 'config' => array
('caption' => 'Customer Contacts', ('caption' => 'Customer Contacts',
'filter' => array('Customer.id' => $customer['Customer']['id']), 'filter' => array('Customer.id' => $customer['Customer']['id']),
'include' => array('Type', 'Active'), 'include' => array('Relationship'),
))); )));

View File

@@ -2,11 +2,10 @@
// Define the table columns // Define the table columns
$cols = array(); $cols = array();
$cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'name'); $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum');
$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'name'); $cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'longname');
$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'longname');
$cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname'); $cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname');
$cols['Type'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum');
$cols['Active'] = array('index' => 'ContactsCustomer.active', 'formatter' => 'enum');
$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment'); $cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment');
// Render the grid // Render the grid
@@ -16,4 +15,4 @@ $grid
->defaultFields(array('Last Name', 'First Name')) ->defaultFields(array('Last Name', 'First Name'))
->searchFields(array('Last Name', 'First Name', 'Company')) ->searchFields(array('Last Name', 'First Name', 'Company'))
->render($this, isset($config) ? $config : null, ->render($this, isset($config) ? $config : null,
array_diff(array_keys($cols), array('Type', 'Active', 'Comment'))); array_diff(array_keys($cols), array('Relationship', 'Comment')));

View File

@@ -10,11 +10,6 @@ $cols['Leases'] = array('index' => 'current_lease_count', 'formatt
$cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency'); $cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency');
$cols['Comment'] = array('index' => 'Customer.comment', 'formatter' => 'comment'); $cols['Comment'] = array('index' => 'Customer.comment', 'formatter' => 'comment');
// Certain fields are only valid with a particular context
if (!isset($config['filter']['Contact.id']))
$grid->invalidFields('Relationship');
// Render the grid // Render the grid
$grid $grid
->columns($cols) ->columns($cols)
@@ -22,4 +17,4 @@ $grid
->defaultFields(array('Name')) ->defaultFields(array('Name'))
->searchFields(array('Name', 'Last Name', 'First Name')) ->searchFields(array('Name', 'Last Name', 'First Name'))
->render($this, isset($config) ? $config : null, ->render($this, isset($config) ? $config : null,
array_diff(array_keys($cols), array('Comment'))); array_diff(array_keys($cols), array('Relationship', 'Comment')));