Added a helper to jqGrid, since duplicated code is getting spread through each element. The implementation is nowhere near complete, but the basic idea is there.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@257 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
* @subpackage cake.app
|
* @subpackage cake.app
|
||||||
*/
|
*/
|
||||||
class AppController extends Controller {
|
class AppController extends Controller {
|
||||||
var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time');
|
var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time', 'JqGrid');
|
||||||
var $components = array('DebugKit.Toolbar');
|
var $components = array('DebugKit.Toolbar');
|
||||||
|
|
||||||
function sideMenuLinks() {
|
function sideMenuLinks() {
|
||||||
|
|||||||
97
site/views/helpers/jq_grid.php
Normal file
97
site/views/helpers/jq_grid.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class JqGridHelper extends AppHelper {
|
||||||
|
|
||||||
|
var $jqGrid_options;
|
||||||
|
var $included;
|
||||||
|
var $columns;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
$this->jqGrid_options
|
||||||
|
= array('limit' => 20);
|
||||||
|
|
||||||
|
$this->columns = array();
|
||||||
|
$this->included = array();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to the set of columns for this grid
|
||||||
|
function columns($columns) {
|
||||||
|
if (isset($columns)) {
|
||||||
|
if (is_array($columns))
|
||||||
|
$this->columns += $columns;
|
||||||
|
else
|
||||||
|
array_push($this->columns, $columns);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Included fields will be included unless excluded.
|
||||||
|
function included($fields) {
|
||||||
|
if (isset($fields)) {
|
||||||
|
if (is_array($fields))
|
||||||
|
$this->included = array_merge($this->included, $fields);
|
||||||
|
else
|
||||||
|
array_push($this->included, $fields);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function limit() {
|
||||||
|
$this->jqGrid_options['limit'] = 20;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function id_list($items) {
|
||||||
|
$this->jqGrid_options
|
||||||
|
+= array('custom_ids' =>
|
||||||
|
array_map(create_function('$data',
|
||||||
|
'return $data["id"];'),
|
||||||
|
$items));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function render($included = array(), $excluded = array()) {
|
||||||
|
pr("<H2>jqGrid</H2>");
|
||||||
|
|
||||||
|
$columns = $this->columns;
|
||||||
|
$we_want = $this->included;
|
||||||
|
$they_want = $included;
|
||||||
|
$we_dont_want = array_diff(array_keys($this->columns), $this->included);
|
||||||
|
$they_dont_want = $excluded;
|
||||||
|
|
||||||
|
if (is_bool($included) && $included)
|
||||||
|
$included = array_keys($columns);
|
||||||
|
elseif (is_bool($included) && !$included)
|
||||||
|
$included = array();
|
||||||
|
|
||||||
|
if (is_bool($excluded) && $excluded)
|
||||||
|
$excluded = array_keys($columns);
|
||||||
|
elseif (is_bool($excluded) && !$excluded)
|
||||||
|
$excluded = array();
|
||||||
|
|
||||||
|
$hopefully_wanted = array_merge($this->included, $included);
|
||||||
|
$hopefully_get = array_diff(array_merge($this->included, $included), $excluded);
|
||||||
|
|
||||||
|
$actually_get = array_intersect(array_keys($this->columns), $hopefully_get);
|
||||||
|
$actually_dont_get = array_diff(array_keys($this->columns), $hopefully_get);
|
||||||
|
|
||||||
|
pr(compact('we_want', 'they_want', 'we_dont_want', 'they_dont_want',
|
||||||
|
'hopefully_wanted', 'hopefully_get',
|
||||||
|
'actually_get', 'actually_dont_get'));
|
||||||
|
|
||||||
|
// Since we only have one instance of this class
|
||||||
|
// as a helper, we must assume it could be used
|
||||||
|
// again later to render an entirely different grid.
|
||||||
|
// Reset the variables to prevent contamination.
|
||||||
|
$this->reset();
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user