\n";
foreach ($fields AS $field) {
list($tbl, $col) = explode(".", $field);
diff --git a/site/views/elements/customers.ctp b/site/views/elements/customers.ctp
index 844f5e4..c526ef0 100644
--- a/site/views/elements/customers.ctp
+++ b/site/views/elements/customers.ctp
@@ -1,6 +1,16 @@
css('jqGrid/basic/grid', null, null, false);
$html->css('jqGrid/jqModal', null, null, false);
@@ -8,25 +18,22 @@ $javascript->link('jqGrid/jquery.jqGrid.js', false);
$javascript->link('jqGrid/js/jqModal', false);
$javascript->link('jqGrid/js/jqDnR', false);
-/* //echo $html->css('jquery/start/ui.all') . "\n"; */
-/* echo $javascript->link('jquery/jquery') . "\n"; */
-/* //echo $javascript->link('jquery/jquery-ui') . "\n"; */
-/* //echo $javascript->link('jquery.form') . "\n"; */
-/* echo $javascript->link('pmgr') . "\n"; */
-/* echo $html->css('jqGrid/basic/grid') . "\n"; */
-/* //echo $html->css('jqGrid/jqModal') . "\n"; */
-/* echo $javascript->link('jqGrid/jquery.jqGrid.js') . "\n"; */
-/* //echo $javascript->link('jqGrid/js/jqModal') . "\n"; */
-/* //echo $javascript->link('jqGrid/js/jqDnR') . "\n"; */
-
-
+// Define the table columns
$cols = array();
-$cols['ID'] = array('index' => 'Customer.id', 'width' => '50', 'align' => 'center');
-/* $cols['Last Name'] = array('index' => 'Customer.last_name', 'width' => '200', 'align' => 'left'); */
-/* $cols['First Name'] = array('index' => 'Customer.first_name', 'width' => '200', 'align' => 'left'); */
-$cols['Name'] = array('index' => 'Customer.name', 'width' => '200', 'align' => 'left');
-$cols['Unit'] = array('index' => 'Customer.units', 'width' => '200', 'align' => 'left', 'sortable' => false);
+$cols['ID'] = array('index' => 'Customer.id', 'width' => '30', 'align' => 'center');
+if (isset($customers[0]['ContactsCustomer']))
+ $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'width' => '75', 'align' => 'left');
+$cols['Name'] = array('index' => 'Customer.name', 'width' => '150', 'align' => 'left');
+$cols['Last Name'] = array('index' => 'PrimaryContact.last_name', 'width' => '100', 'align' => 'left');
+$cols['First Name'] = array('index' => 'PrimaryContact.first_name', 'width' => '100', 'align' => 'left');
+$cols['Unit(s)'] = array('index' => 'Customer.units', 'width' => '80', 'align' => 'center');
+$cols['Comment'] = array('index' => 'Customer.comment', 'width' => '300', 'align' => 'center');
+// Some of the columns should not be sortable
+foreach (array('Unit(s)') AS $field)
+ $cols[$field]['sortable'] = false;
+
+// Create the javascript code for jqGrid to create each table column
$colModels = array();
foreach ($cols AS $col) {
$col['name'] = $col['index'];
@@ -40,38 +47,24 @@ foreach ($cols AS $col) {
'}';
}
-// URL to fetch data from.
+// Save just the column indices (fields)
+$colFields= array_map(create_function('$col', 'return $col["index"];'), $cols);
+
+// Define the URL to fetch data from.
// To prevent having to keep the controller and the view
// in sync on which fields need to be queried by the
// controller in order to be accessible to the view,
// we'll just pass the desired fields to the controller
// as part of the data fetch.
+
$url = $html->url(array('controller' => 'customers',
- 'action' => 'data',
+ 'action' => 'jqGridData',
'debug' => 0,
- implode(";",
- array_map(create_function
- ('$col',
- 'return $col["index"];'),
- $cols)),
));
-
-/* array_merge(array('Name'), */
-/* isset($customers[0]['ContactsCustomer']) */
-/* ? array('Relationship') */
-/* : array(), */
-/* array('Comment')); */
-
-/* $rows[] = array_merge(array($html->link($customer['name'], */
-/* array('controller' => 'customers', */
-/* 'action' => 'view', */
-/* $customer['id']))), */
-/* isset($contacts_customer) */
-/* ? array($contacts_customer['type']) */
-/* : array(), */
-/* array($customer['comment'])); */
-
+// OK, now that everything is in place, get out of PHP mode,
+// and add the javascript code (along with a touch of HTML)
+// to kick this thing off.
?>
-
-
-'.__('Customers',true).''; */
-
-/* $headers = array_merge(array('Name'), */
-/* isset($customers[0]['ContactsCustomer']) */
-/* ? array('Relationship') */
-/* : array(), */
-/* array('Comment')); */
-/* $column_class = array(); */
-/* foreach (array_intersect($headers, array('Comment')) AS $k => $v) { */
-/* $column_class[$k] = 'comment'; */
-/* } */
-
-
-/* if (isset($paginator)) { */
-/* echo $paginator->counter(array( */
-/* 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); */
-
-/* $headers = array_merge(array($paginator->sort('name')), */
-/* isset($customers[0]['ContactsCustomer']) */
-/* ? array($paginator->sort('Relationship', 'type')) */
-/* : array(), */
-/* array($paginator->sort('comment'))); */
-/* } */
-
-
-
-
-/* $rows = array(); */
-/* foreach ($customers as $customer) { */
-/* $contacts_customer = null; */
-/* if (isset($customer['ContactsCustomer'])) */
-/* $contacts_customer = $customer['ContactsCustomer']; */
-
-/* if (isset($customer['Customer'])) */
-/* $customer = $customer['Customer']; */
-
-/* $rows[] = array_merge(array($html->link($customer['name'], */
-/* array('controller' => 'customers', */
-/* 'action' => 'view', */
-/* $customer['id']))), */
-/* isset($contacts_customer) */
-/* ? array($contacts_customer['type']) */
-/* : array(), */
-/* array($customer['comment'])); */
-/* } */
-
-/* echo $this->element('table', */
-/* array('class' => 'item customer list', */
-/* 'caption' => isset($caption) ? $caption : null, */
-/* 'headers' => $headers, */
-/* 'rows' => $rows, */
-/* 'column_class' => $column_class)); */
-
-/* if (isset($paginator)) { */
-/* echo('' . "\n"); */
-/* echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled')); */
-/* echo(' | '); */
-/* echo $paginator->numbers(); */
-/* echo(' | '); */
-/* echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled')); */
-/* echo('
' . "\n"); */
-/* } */