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:
@@ -23,6 +23,19 @@ class ContactsController extends AppController {
|
||||
* 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) {
|
||||
$order = parent::gridDataOrder($params, $model, $index, $direction);
|
||||
|
||||
|
||||
@@ -92,19 +92,29 @@ class CustomersController extends AppController {
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function gridDataOrder(&$params, &$model, $index, $direction) {
|
||||
$order = array();
|
||||
$order[] = parent::gridDataOrder($params, $model, $index, $direction);
|
||||
function gridDataFilterTablesConfig(&$params, &$model, $table) {
|
||||
$config = parent::gridDataFilterTablesConfig($params, $model, $table);
|
||||
|
||||
if ($index !== 'PrimaryContact.last_name')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'PrimaryContact.last_name', $direction);
|
||||
if ($index !== 'PrimaryContact.first_name')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'PrimaryContact.first_name', $direction);
|
||||
if ($index !== 'Customer.id')
|
||||
$order[] = parent::gridDataOrder($params, $model,
|
||||
'Customer.id', $direction);
|
||||
// Special case for Contact; We need the Contact/Customer relationship
|
||||
if ($table == 'Contact')
|
||||
$config = array('fields' => array('ContactsCustomer.type',
|
||||
'ContactsCustomer.active'),
|
||||
'conditions' => array('ContactsCustomer.active' => true),
|
||||
);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ echo $this->element('customers', array
|
||||
'config' => array
|
||||
('caption' => 'Related Customers',
|
||||
'filter' => array('Contact.id' => $contact['id']),
|
||||
'include' => array('Relationship'),
|
||||
)));
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ echo $this->element('contacts', array
|
||||
'config' => array
|
||||
('caption' => 'Customer Contacts',
|
||||
'filter' => array('Customer.id' => $customer['Customer']['id']),
|
||||
'include' => array('Type', 'Active'),
|
||||
'include' => array('Relationship'),
|
||||
)));
|
||||
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
// Define the table columns
|
||||
$cols = array();
|
||||
$cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'name');
|
||||
$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'name');
|
||||
$cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum');
|
||||
$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['Type'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum');
|
||||
$cols['Active'] = array('index' => 'ContactsCustomer.active', 'formatter' => 'enum');
|
||||
$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment');
|
||||
|
||||
// Render the grid
|
||||
@@ -16,4 +15,4 @@ $grid
|
||||
->defaultFields(array('Last Name', 'First Name'))
|
||||
->searchFields(array('Last Name', 'First Name', 'Company'))
|
||||
->render($this, isset($config) ? $config : null,
|
||||
array_diff(array_keys($cols), array('Type', 'Active', 'Comment')));
|
||||
array_diff(array_keys($cols), array('Relationship', 'Comment')));
|
||||
|
||||
@@ -10,11 +10,6 @@ $cols['Leases'] = array('index' => 'current_lease_count', 'formatt
|
||||
$cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency');
|
||||
$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
|
||||
$grid
|
||||
->columns($cols)
|
||||
@@ -22,4 +17,4 @@ $grid
|
||||
->defaultFields(array('Name'))
|
||||
->searchFields(array('Name', 'Last Name', 'First Name'))
|
||||
->render($this, isset($config) ? $config : null,
|
||||
array_diff(array_keys($cols), array('Comment')));
|
||||
array_diff(array_keys($cols), array('Relationship', 'Comment')));
|
||||
|
||||
Reference in New Issue
Block a user