Check in aother snapshot, since I can now pass complex structures from the view back to the jqGrid data provider
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@105 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class CustomersController extends AppController {
|
class CustomersController extends AppController {
|
||||||
var $paginate = array('limit' => 100,
|
|
||||||
'group' => 'Customer.id',
|
|
||||||
'order' => array('Customer.name' => 'ASC'));
|
|
||||||
|
|
||||||
var $sidemenu_links =
|
var $sidemenu_links =
|
||||||
array(array('name' => 'Tenants', 'header' => true),
|
array(array('name' => 'Tenants', 'header' => true),
|
||||||
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
||||||
@@ -12,7 +8,7 @@ class CustomersController extends AppController {
|
|||||||
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
||||||
);
|
);
|
||||||
|
|
||||||
var $components = array('RequestHandler');
|
//var $components = array('RequestHandler');
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@@ -102,6 +98,7 @@ class CustomersController extends AppController {
|
|||||||
function all() {
|
function all() {
|
||||||
$title = 'All Customers';
|
$title = 'All Customers';
|
||||||
$this->set('title', $title); $this->set('heading', $title);
|
$this->set('title', $title); $this->set('heading', $title);
|
||||||
|
$this->set('params', $this->params);
|
||||||
$this->render('index');
|
$this->render('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,11 +110,19 @@ class CustomersController extends AppController {
|
|||||||
* -
|
* -
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function data($fields_str) {
|
function jqGridData($debug = true) {
|
||||||
/* pr(array('fields' => $fields, */
|
/* pr(array('fields' => $fields, */
|
||||||
/* 'explode' => explode(";", $fields_str))); */
|
/* 'explode' => explode(";", $fields_str))); */
|
||||||
|
|
||||||
$fields = explode(";", $fields_str);
|
/* $debug=true; */
|
||||||
|
|
||||||
|
/* $tf = unserialize($fields); */
|
||||||
|
/* $tp = unserialize($params); */
|
||||||
|
|
||||||
|
/* $fields = array('Customer.id'); */
|
||||||
|
|
||||||
|
//$action_params = unserialize($action_params);
|
||||||
|
//$fields = explode(";", $fields_str);
|
||||||
|
|
||||||
//$fields=array();
|
//$fields=array();
|
||||||
/* foreach (explode(";", $fields_str) AS $i => $field) { */
|
/* foreach (explode(";", $fields_str) AS $i => $field) { */
|
||||||
@@ -130,6 +135,7 @@ class CustomersController extends AppController {
|
|||||||
|
|
||||||
//pr(array('fields' => $fields));
|
//pr(array('fields' => $fields));
|
||||||
|
|
||||||
|
|
||||||
$debug = true;
|
$debug = true;
|
||||||
if (isset($this->passedArgs['debug']))
|
if (isset($this->passedArgs['debug']))
|
||||||
$debug = $this->passedArgs['debug'];
|
$debug = $this->passedArgs['debug'];
|
||||||
@@ -146,9 +152,21 @@ class CustomersController extends AppController {
|
|||||||
$rows = 20; // rows in the grid - rowNum parameter
|
$rows = 20; // rows in the grid - rowNum parameter
|
||||||
$sidx = 'Customer.id'; // sort column - index from colModel
|
$sidx = 'Customer.id'; // sort column - index from colModel
|
||||||
$sord = 'ASC'; // sort order
|
$sord = 'ASC'; // sort order
|
||||||
|
|
||||||
|
$fields = array('Customer.id');
|
||||||
|
|
||||||
if (isset($this->params['url']) && is_array($this->params['url']))
|
if (isset($this->params['url']) && is_array($this->params['url']))
|
||||||
extract($this->params['url']);
|
extract($this->params['url']);
|
||||||
|
|
||||||
|
if (isset($fields))
|
||||||
|
$fields = unserialize($fields);
|
||||||
|
else
|
||||||
|
$fields = array('Customer.id');
|
||||||
|
|
||||||
|
if (isset($params))
|
||||||
|
$params = unserialize($params);
|
||||||
|
else
|
||||||
|
$params = array('action' => 'all');
|
||||||
|
|
||||||
// calculate the number of rows for the query. We need this for paging the result
|
// calculate the number of rows for the query. We need this for paging the result
|
||||||
$row = $this->Customer->findCount();
|
$row = $this->Customer->findCount();
|
||||||
@@ -172,12 +190,22 @@ class CustomersController extends AppController {
|
|||||||
// typical case is that the user type 0 for the requested page
|
// typical case is that the user type 0 for the requested page
|
||||||
if($start <0) $start = 0;
|
if($start <0) $start = 0;
|
||||||
|
|
||||||
|
$cond = array();
|
||||||
|
if ($params['action'] == 'current') {
|
||||||
|
|
||||||
|
} elseif ($params['action'] == 'past') {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// the actual query for the grid data
|
// the actual query for the grid data
|
||||||
$customers = $this->Customer->find
|
$customers = $this->Customer->find
|
||||||
('all',
|
('all',
|
||||||
array('contain' => array
|
array('contain' => array
|
||||||
(// Models
|
(// Models
|
||||||
/* 'Contact' => */
|
'PrimaryContact',
|
||||||
/* array(// Models */
|
/* array(// Models */
|
||||||
/* 'ContactPhone', */
|
/* 'ContactPhone', */
|
||||||
/* 'ContactEmail', */
|
/* 'ContactEmail', */
|
||||||
@@ -221,6 +249,8 @@ class CustomersController extends AppController {
|
|||||||
/* echo " <d><![CDATA[{$d}]]></d>\n"; */
|
/* echo " <d><![CDATA[{$d}]]></d>\n"; */
|
||||||
/* echo " <named><![CDATA[" . print_r($this->params, true) . "]]></named>\n"; */
|
/* echo " <named><![CDATA[" . print_r($this->params, true) . "]]></named>\n"; */
|
||||||
/* echo " <passed><![CDATA[" . print_r($this->passedArgs, true) . "]]></passed>\n"; */
|
/* echo " <passed><![CDATA[" . print_r($this->passedArgs, true) . "]]></passed>\n"; */
|
||||||
|
/* echo " <params><![CDATA[" . print_r($params, true) . "]]></params>\n"; */
|
||||||
|
/* echo " <tp><![CDATA[" . print_r($tp, true) . "]]></tp>\n"; */
|
||||||
/* echo " </parms>\n"; */
|
/* echo " </parms>\n"; */
|
||||||
echo " <page>".$page."</page>\n";
|
echo " <page>".$page."</page>\n";
|
||||||
echo " <total>".$total_pages."</total>\n";
|
echo " <total>".$total_pages."</total>\n";
|
||||||
@@ -234,6 +264,7 @@ class CustomersController extends AppController {
|
|||||||
('$lease', 'return $lease["Unit"]["name"];'),
|
('$lease', 'return $lease["Unit"]["name"];'),
|
||||||
$customer['CurrentLease']));
|
$customer['CurrentLease']));
|
||||||
|
|
||||||
|
|
||||||
echo " <row id='{$customer['Customer']['id']}'>\n";
|
echo " <row id='{$customer['Customer']['id']}'>\n";
|
||||||
foreach ($fields AS $field) {
|
foreach ($fields AS $field) {
|
||||||
list($tbl, $col) = explode(".", $field);
|
list($tbl, $col) = explode(".", $field);
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
<?php /* -*- mode:PHP -*- */
|
<?php /* -*- mode:PHP -*- */
|
||||||
|
|
||||||
//$imgpath = 'jqGrid/basic/images';
|
//unset($caption);
|
||||||
|
if (!isset($limit))
|
||||||
|
$limit = 20;
|
||||||
|
|
||||||
|
if (!isset($limitOptions))
|
||||||
|
$limitOptions = array(10, 20, 50, 200);
|
||||||
|
|
||||||
|
if (!isset($height))
|
||||||
|
$height = '80%';
|
||||||
|
|
||||||
|
// Do some prework to bring in the appropriate libraries
|
||||||
$imgpath = '/pmgr/site/css/jqGrid/basic/images';
|
$imgpath = '/pmgr/site/css/jqGrid/basic/images';
|
||||||
$html->css('jqGrid/basic/grid', null, null, false);
|
$html->css('jqGrid/basic/grid', null, null, false);
|
||||||
$html->css('jqGrid/jqModal', 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/jqModal', false);
|
||||||
$javascript->link('jqGrid/js/jqDnR', false);
|
$javascript->link('jqGrid/js/jqDnR', false);
|
||||||
|
|
||||||
/* //echo $html->css('jquery/start/ui.all') . "\n"; */
|
// Define the table columns
|
||||||
/* 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"; */
|
|
||||||
|
|
||||||
|
|
||||||
$cols = array();
|
$cols = array();
|
||||||
$cols['ID'] = array('index' => 'Customer.id', 'width' => '50', 'align' => 'center');
|
$cols['ID'] = array('index' => 'Customer.id', 'width' => '30', 'align' => 'center');
|
||||||
/* $cols['Last Name'] = array('index' => 'Customer.last_name', 'width' => '200', 'align' => 'left'); */
|
if (isset($customers[0]['ContactsCustomer']))
|
||||||
/* $cols['First Name'] = array('index' => 'Customer.first_name', 'width' => '200', 'align' => 'left'); */
|
$cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'width' => '75', 'align' => 'left');
|
||||||
$cols['Name'] = array('index' => 'Customer.name', 'width' => '200', 'align' => 'left');
|
$cols['Name'] = array('index' => 'Customer.name', 'width' => '150', 'align' => 'left');
|
||||||
$cols['Unit'] = array('index' => 'Customer.units', 'width' => '200', 'align' => 'left', 'sortable' => false);
|
$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();
|
$colModels = array();
|
||||||
foreach ($cols AS $col) {
|
foreach ($cols AS $col) {
|
||||||
$col['name'] = $col['index'];
|
$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
|
// To prevent having to keep the controller and the view
|
||||||
// in sync on which fields need to be queried by the
|
// in sync on which fields need to be queried by the
|
||||||
// controller in order to be accessible to the view,
|
// controller in order to be accessible to the view,
|
||||||
// we'll just pass the desired fields to the controller
|
// we'll just pass the desired fields to the controller
|
||||||
// as part of the data fetch.
|
// as part of the data fetch.
|
||||||
|
|
||||||
$url = $html->url(array('controller' => 'customers',
|
$url = $html->url(array('controller' => 'customers',
|
||||||
'action' => 'data',
|
'action' => 'jqGridData',
|
||||||
'debug' => 0,
|
'debug' => 0,
|
||||||
implode(";",
|
|
||||||
array_map(create_function
|
|
||||||
('$col',
|
|
||||||
'return $col["index"];'),
|
|
||||||
$cols)),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// OK, now that everything is in place, get out of PHP mode,
|
||||||
/* array_merge(array('Name'), */
|
// and add the javascript code (along with a touch of HTML)
|
||||||
/* isset($customers[0]['ContactsCustomer']) */
|
// to kick this thing off.
|
||||||
/* ? 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'])); */
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
@@ -81,95 +74,25 @@ jQuery(document).ready(function(){
|
|||||||
url: '<?php echo $url; ?>',
|
url: '<?php echo $url; ?>',
|
||||||
datatype: 'xml',
|
datatype: 'xml',
|
||||||
mtype: 'GET',
|
mtype: 'GET',
|
||||||
colNames:[ '<?php echo implode("', '", array_keys($cols)); ?>' ],
|
postData: { params: '<?php echo serialize($params); ?>',
|
||||||
colModel :[ <?php echo "\n " . implode(",\n ", $colModels); ?> ],
|
fields: '<?php echo serialize($colFields); ?>' },
|
||||||
|
colNames: [ '<?php echo implode("', '", array_keys($cols)); ?>' ],
|
||||||
|
colModel: [ <?php echo "\n " . implode(",\n ", $colModels); ?> ],
|
||||||
pager: jQuery('#customer-pager'),
|
pager: jQuery('#customer-pager'),
|
||||||
rowNum:10,
|
height: '100%',
|
||||||
rowList:[10,20,30],
|
//height: 'auto',
|
||||||
|
rowNum: <?php echo $limit; ?>,
|
||||||
|
rowList: [<?php echo implode(",",$limitOptions); ?>],
|
||||||
sortname: 'Customer.id',
|
sortname: 'Customer.id',
|
||||||
sortorder: "ASC",
|
sortorder: "ASC",
|
||||||
viewrecords: true,
|
viewrecords: true,
|
||||||
imgpath: '<?php echo $imgpath; ?>',
|
imgpath: '<?php echo $imgpath; ?>',
|
||||||
caption: 'My first grid'
|
caption: <?php echo isset($caption) ? "'$caption'" : "null"; ?>,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getText() {
|
|
||||||
$("#debug").html(htmlEncode($("#customer-list").html()));
|
|
||||||
}
|
|
||||||
|
|
||||||
--></script>
|
--></script>
|
||||||
|
|
||||||
<table id="customer-list" class="scroll"></table>
|
<table id="customer-list" class="scroll"></table>
|
||||||
<div id="customer-pager" class="scroll" style="text-align:center;"></div>
|
<div id="customer-pager" class="scroll" style="text-align:center;"></div>
|
||||||
<div><a href="#" onClick="getText(); return false;">Get Table Code</a>
|
|
||||||
</div>
|
|
||||||
<div id="debug"></div>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/* if (isset($heading)) */
|
|
||||||
/* echo $heading; */
|
|
||||||
/* elseif (!isset($caption)) */
|
|
||||||
/* echo '<h2>'.__('Customers',true).'</h2>'; */
|
|
||||||
|
|
||||||
/* $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('<div class="paging">' . "\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('</div>' . "\n"); */
|
|
||||||
/* } */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user