Standardized the grid events interface, to ease the burden on the views and ensure that the load functions could be used by the application without wiping out the debug functionality that was built into jqGrid.ctp

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@336 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-15 06:21:55 +00:00
parent 33ba912a7e
commit 69adfd900c
6 changed files with 64 additions and 88 deletions

View File

@@ -130,10 +130,6 @@ echo '<div CLASS="detail supporting">' . "\n";
* Entries
*/
$grid_setup =
array('loadComplete' =>
array('--special' => "function() {url=jQuery('#collected-entries-jqGrid').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#collected-entries-jqGrid').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#collected-entries-jqGrid-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>'); onGridLoadComplete();}"));
echo $this->element('ledger_entries', array
(// Element configuration
'collected_account_id' => $account['id'],
@@ -144,7 +140,7 @@ echo $this->element('ledger_entries', array
(
'grid_div_id' => 'collected-entries',
'grid_div_class' => 'text-below',
'grid_setup' => $grid_setup,
'grid_events' => array('loadComplete' => 'onGridLoadComplete()'),
//'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'caption' => 'Collected ' . Inflector::pluralize($account['name'])
),

View File

@@ -11,9 +11,6 @@ echo $form->create(null, array('id' => 'deposit-form',
'url' => array('controller' => 'accounts',
'action' => 'deposit')));
$grid_setup = array();
$grid_setup['hiddengrid'] = true;
foreach ($tillableAccount AS $acct) {
//$acct = $acct['Account'];
@@ -59,7 +56,7 @@ foreach ($tillableAccount AS $acct) {
'grid_div_id' => $grid_div_id,
'caption' => ('<A HREF="#" ONCLICK="$(\'#'.$grid_div_id.' .HeaderButton\').click();'.
' return false;">Items in '.$acct['Account']['name'].' Ledger</A>'),
'grid_setup' => $grid_setup,
'grid_setup' => array('hiddengrid' => true),
),
));
}

View File

@@ -8,32 +8,9 @@
**********************************************************************
**********************************************************************
**********************************************************************
* Grid Setup / Javascript
* Javascript
*/
$grid_setup = array();
if (isset($customer['id']))
$grid_setup['hiddengrid'] = true;
$grid_setup['onSelectRow'] = array
('--special' =>
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
);
$grid_setup['onHeaderClick'] = array
('--special' =>
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
);
// Customer
// Outstanding balance
// Balance on each lease
// Balance on personal account
// Multiple fields for payments (cash, check, charge, etc)
// How to apply (even split, oldest charges first, etc)
?>
<script type="text/javascript"><!--
@@ -311,7 +288,14 @@ echo $this->element('customers', array
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
' return false;">Select Customer</A>'),
'grid_setup' => $grid_setup,
'grid_setup' => array('hiddengrid' => isset($customer['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'),
'onHeaderClick' =>
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), gridstate)'),
),
'nolinks' => true,
'limit' => 10,
)));

View File

@@ -39,6 +39,9 @@ if (!isset($grid_id))
if (!isset($search_fields))
$search_fields = array();
if (!isset($grid_events))
$grid_events = array();
if (!isset($grid_setup))
$grid_setup = array();
@@ -165,6 +168,29 @@ if (1) { // debug
$caption .= ' :: <span id="'.$grid_id.'-query"></span>';
}
foreach (array_merge(array('loadComplete' => '', 'loadError' => ''),
$grid_events) AS $event => $statement) {
$params = '';
if (is_array($statement)) {
$params = key($statement);
$statement = current($statement);
}
if ($event == 'loadComplete') {
$grid_events[$event] =
array('--special' => "function($params) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>'); $statement;}");
}
elseif ($event == 'loadError') {
$grid_events[$event] =
array('--special' => "function($params) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Error Query</A><BR>'); $statement;}");
}
else {
$grid_events[$event] =
array('--special' => "function($params) { $statement; }");
}
}
// Configure the grid setup, giving priority to user defined parameters
$jqGrid_setup = array_merge
(array('mtype' => 'GET',
@@ -182,11 +208,8 @@ $jqGrid_setup = array_merge
'imgpath' => $imgpath,
'viewrecords' => true,
'pager' => $grid_id.'-pager',
'loadComplete' => array('--special' => "function() {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Query</A><BR>');}"),
'loadError' => array('--special' => "function(xhr,st,err) {url=jQuery('#{$grid_id}').getGridParam('url');url=url.replace(/\/debug.*$/,'?'); pd=jQuery('#{$grid_id}').getPostData();$.each(pd,function(i){ url+=i+'='+escape(pd[i])+'&'; }); jQuery('#{$grid_id}-query').html('<A HREF=\"'+url+'\">Grid Error Query</A><BR>');}"),
),
$grid_events,
$grid_setup
);
//pr(compact('grid_setup', 'jqGrid_setup'));

View File

@@ -8,24 +8,9 @@
**********************************************************************
**********************************************************************
**********************************************************************
* Grid Setup / Javascript
* Javascript
*/
$lease_grid_setup = array();
if (isset($lease['Lease']['id']))
$lease_grid_setup['hiddengrid'] = true;
$lease_grid_setup['onSelectRow'] = array
('--special' =>
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
);
$lease_grid_setup['onHeaderClick'] = array
('--special' =>
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
);
?>
<script type="text/javascript"><!--
@@ -220,7 +205,14 @@ echo $this->element('leases', array
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#leases-list .HeaderButton\').click();'.
' return false;">Select Lease</A>'),
'grid_setup' => $lease_grid_setup,
'grid_setup' => array('hiddengrid' => isset($lease['Lease']['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'),
'onHeaderClick' =>
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), gridstate)'),
),
'nolinks' => true,
'limit' => 10,
)));

View File

@@ -16,39 +16,9 @@ $move_type = preg_replace("/.*_/", "", $this->action);
**********************************************************************
**********************************************************************
**********************************************************************
*
* Javascript
*/
$customer_grid_setup = array();
if (isset($customer['id']))
$customer_grid_setup['hiddengrid'] = true;
$customer_grid_setup['onSelectRow'] = array
('--special' =>
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), "customer", ids); } }'
);
$customer_grid_setup['onHeaderClick'] = array
('--special' =>
'function(gridstate) { onGridState("#"+$(this).attr("id"), "customer", gridstate); }'
);
$unit_grid_setup = array();
if (isset($unit['id']))
$unit_grid_setup['hiddengrid'] = true;
$unit_grid_setup['onSelectRow'] = array
('--special' =>
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), "unit", ids); } }'
);
$unit_grid_setup['onHeaderClick'] = array
('--special' =>
'function(gridstate) { onGridState("#"+$(this).attr("id"), "unit", gridstate); }'
);
?>
<script type="text/javascript"><!--
@@ -109,7 +79,14 @@ if ($move_type !== 'out') {
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
' return false;">Select Customer</A>'),
'grid_setup' => $customer_grid_setup,
'grid_setup' => array('hiddengrid' => isset($customer['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), "customer", ids);}'),
'onHeaderClick' =>
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), "customer", gridstate)'),
),
'nolinks' => true,
'limit' => 10,
)));
@@ -135,7 +112,14 @@ if ($move_type !== 'out') {
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#units-list .HeaderButton\').click();'.
' return false;">Select Unit</A>'),
'grid_setup' => $unit_grid_setup,
'grid_setup' => array('hiddengrid' => isset($unit['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), "unit", ids);}'),
'onHeaderClick' =>
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), "unit", gridstate)'),
),
'action' => 'unoccupied',
'nolinks' => true,
'limit' => 10,