Files
pmgr/site/views/elements/jqGrid.ctp
abijah 543e2daa43 Moved the ledger_entries controller/view to jqGrid.
Changed the app controller jqGrid virtual functions for getting the tables for both count and the full query.  The ExtraTables bit was too confusing, and was only intended to allow the user to specify a subset for count and augment it for full query.  This is easily accomplished by having DataTables just call DataCountTables first... one line solution ends the confusion.

Modified linkable behavior to support a %{MODEL_ALIAS} tag, which is replaced in the relationship conditions at runtime with the actual model alias.  This is experimental at best, and certainly will create a problem for any model that ends up using the conditions in 'contain' instead of 'link'.

Broke the LedgerEntry->findInLedgerContext function out into multiple pieces, so those same pieces could be used in the LedgerEntries controller to populate jqGrid.

Changed the ledger_entries element, as a special case, to also allow listing control from ledger_id and account_type, instead of idlist as a mechanism for populating the grid.

Changed the infobox summary css, which will break several pages until I rework them.

Some next steps include fixing the broken infoboxes, and changing the transactions view to use the ledger_entries element.  This also means the ledger_entries element will need to add support for idlist, or if we have any credit/debit issues, perhaps another custom transaction_id instead.



git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@134 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-15 19:41:20 +00:00

253 lines
8.3 KiB
PHP

<?php /* -*- mode:PHP -*- */
if (!isset($caption))
$caption = '<H2>'.$this->pageTitle.'</H2>';
if (!isset($limit))
$limit = 20;
if (!isset($limitOptions)) {
$limitOptions = array($limit);
if ($limit < 10)
array_push($limitOptions, 2, 5);
if ($limit < 30)
array_push($limitOptions, 10, 25);
if ($limit > 10)
array_push($limitOptions, 25, 50, 200);
if ($limit > 20)
array_push($limitOptions, 500);
}
sort($limitOptions, SORT_NUMERIC);
$limitOptions = array_unique($limitOptions, SORT_NUMERIC);
if (!isset($height))
$height = 'auto';
if (!isset($controller))
$controller = $this->params['controller'];
if (!isset($grid_div_class))
$grid_div_class = '';
$grid_div_class = 'item grid list' . ($grid_div_class ? ' '.$grid_div_class : '');
if (!isset($grid_div_id))
$grid_div_id = $controller . '-list';
if (!isset($grid_id))
$grid_id = $grid_div_id . '-jqGrid';
if (!isset($search_fields))
$search_fields = array();
// Do some prework to bring in the appropriate libraries
$imgpath = '/pmgr/site/css/jqGrid/basic/images';
$html->css('jqGrid/basic/grid', null, null, false);
$html->css('jqGrid/jqModal', null, null, false);
$javascript->link('jqGrid/jquery.jqGrid.js', false);
$javascript->link('jqGrid/js/jqModal', false);
$javascript->link('jqGrid/js/jqDnR', false);
$javascript->link('pmgr_jqGrid', false);
// 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' => $controller,
'action' => 'jqGridData',
'debug' => 0,
));
// Create extra parameters that jqGrid will pass to our
// controller whenever data is requested.
// 'fields' will allow the controller to return only the
// requested fields, and in the right order. Since fields
// is a complex structure (an array), we'll need to
// serialize it first for transport over HTTP.
$postData = array();
$postData['fields'] = serialize(array_map(create_function('$col',
'return $col["index"];'),
array_values($jqGridColumns)));
// Determine if we're to be using a custom list, or if
// the data will simply be action based.
if (isset($custom_ids)) {
$action = 'idlist';
$postData['idlist'] = serialize($custom_ids);
}
elseif (!isset($action)) {
$action = null;
}
if (isset($custom_post_data)) {
$postData['custom'] = serialize($custom_post_data);
}
// 'action' will ensure that the controller provides the
// correct subset of data
$postData['action'] = $action;
// Perform column customizations.
// This will largely be based off of the 'formatter' parameter,
// but could be on any pertinent condition.
foreach ($jqGridColumns AS &$col) {
$default = array();
// Make sure every column has a name
$default['name'] = preg_replace("/\./", '-', $col['index']);
// Perform customization based on formatter
if (isset($col['formatter'])) {
if ($col['formatter'] === 'id') {
// Switch currency over to our own custom formatting
$col['formatter'] = array('--special' => 'idFormatter');
$default['width'] = 50;
$default['align'] = 'center';
}
elseif ($col['formatter'] === 'currency') {
// Switch currency over to our own custom formatting
$col['formatter'] = array('--special' => 'currencyFormatter');
$default['width'] = 80;
$default['align'] = 'right';
}
elseif ($col['formatter'] === 'date') {
$default['formatoptions'] = array('newformat' => 'm/d/Y');
$default['width'] = 90;
$default['align'] = 'center';
}
elseif ($col['formatter'] === 'name' || $col['formatter'] === 'longname') {
$default['width'] = 100;
if ($col['formatter'] === 'longname')
$default['width'] *= 1.5;
// No special formatting for name
unset($col['formatter']);
}
elseif ($col['formatter'] === 'comment') {
$default['width'] = 300;
$default['sortable'] = false;
}
}
$col = array_merge($default, $col);
}
reset($jqGridColumns);
$sortname = current($jqGridColumns);
$sortname = $sortname['index'];
// 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.
?>
<DIV ID="<?php echo $grid_div_id; ?>" CLASS="<?php echo $grid_div_class; ?>">
<table id="<?php echo $grid_id; ?>" class="scroll"></table>
<div id="<?php echo $grid_id; ?>-pager" class="scroll" style="text-align:right"></div>
<div id="<?php echo $grid_id; ?>-query"></div>
<script type="text/javascript"><!--
jQuery(document).ready(function(){
currencyFormatter = function(el, cellval, opts) {
$(el).html(fmtCurrency(cellval));
}
idFormatter = function(el, cellval, opts) {
$(el).html('#'+cellval);
}
jQuery('#<?php echo $grid_id; ?>').jqGrid(
<?php
echo FormatHelper::phpVarToJavascript
(array('mtype' => 'GET',
'datatype' => 'xml',
'url' => $url,
'postData' => $postData,
'colNames' => array_keys($jqGridColumns),
'colModel' => array('--special' => $jqGridColumns),
'height' => $height,
'rowNum' => $limit,
'rowList' => $limitOptions,
'sortname' => $sortname,
'caption' => $caption,
'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>'+url);}"),
'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>'+url);}"),
//'toolbar' => array(true,"bottom"),
)); ?>
);
<?php
/* jQuery('#t_<?php echo $grid_id; ?>').height(25).hide() */
/* .filterGrid('#<?php echo $grid_id; ?>', { */
/* gridModel:true, */
/* gridToolbar:true, */
/* autosearch:true, */
/* }); */
/* jQuery('#<?php echo $grid_id; ?>').navGrid('#<?php echo $grid_id; ?>-pager', */
/* { view:false, */
/* edit:false, */
/* add:false, */
/* del:false, */
/* search:false, */
/* refresh:false}) */
/* .navButtonAdd('#<?php echo $grid_id; ?>-pager',{ */
/* caption:"Search", */
/* title:"Toggle Search", */
/* buttonimg:'<?php echo $imgpath; ?>' + '/find.gif', */
/* onClickButton:function(){ */
/* if(jQuery('#t_<?php echo $grid_id; ?>').css("display")=="none") { */
/* jQuery('#t_<?php echo $grid_id; ?>').css("display",""); */
/* } else { */
/* jQuery('#t_<?php echo $grid_id; ?>').css("display","none"); */
/* } */
/* } */
/* }); */
?>
});
--></script>
<?php
if (count($search_fields) > 0) {
echo('<div>Search By:<BR>' . "\n");
echo('<input type="checkbox" CLASS="filt-autosearch"'.
' onclick="enableAutosubmit(this.checked)" CHECKED>'.
'Enable Autosearch' .
'<BR>' . "\n");
foreach ($search_fields AS $field) {
echo($field . "<BR>\n");
echo('<input type="text" CLASS="filt-text filt-text-'.$grid_id.'"' .
' id="filt_'.$jqGridColumns[$field]['name'].'"' .
' filt-grid="'.$grid_id.'"' .
' filt-index="'.$jqGridColumns[$field]['index'].'"' .
'/>' . "\n");
echo('<button CLASS="filt-submit filt-submit-'.$grid_id.'"' .
' id="submit_'.$jqGridColumns[$field]['name'].'"' .
' style="margin-left:30px;">' .
'Search' .
'</button><BR>' . "\n");
}
echo('<div>' . "\n");
echo('<button CLASS="filt-clear" ONCLICK="'."gridRestore('$grid_id')".'">' .
'Clear' .
'</button>' . "\n");
echo('</div>' . "\n");
echo('</div>' . "\n");
}
// Finally, back to HTML mode, and end the grid DIV we created
?>
</DIV>