From af2d5c38f37becfc2bef6c6139ab20de65840eeb Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 14 Jun 2009 05:04:41 +0000 Subject: [PATCH] Moved all the jqGrid logic into a separate element, in anticipation of moving all lists to jqGrid git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@115 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/elements/customers.ctp | 182 +------------------------- site/views/elements/jqGrid.ctp | 210 ++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 179 deletions(-) create mode 100644 site/views/elements/jqGrid.ctp diff --git a/site/views/elements/customers.ctp b/site/views/elements/customers.ctp index c3f501e..faeb05a 100644 --- a/site/views/elements/customers.ctp +++ b/site/views/elements/customers.ctp @@ -1,25 +1,5 @@ '.$this->pageTitle.''; - -if (!isset($limit)) - $limit = 20; - -if (!isset($limitOptions)) - $limitOptions = array(10, 20, 50, 200); - -if (!isset($height)) - $height = 'auto'; - -// 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); - // Define the table columns $cols = array(); $cols['ID'] = array('index' => 'Customer.id', 'width' => '30', 'align' => 'center'); @@ -39,99 +19,13 @@ foreach (array_intersect_key($cols, array('Comment'=>1)) AS $k => $v) foreach (array_intersect_key($cols, array('Last Name'=>1, 'First Name'=>1)) AS $k => $v) $cols[$k]['search'] = true; -// Create the javascript code for jqGrid to create each table column -$colModels = array(); -foreach ($cols AS $col) { - $col['name'] = $col['index']; - $colModels[] = - '{ ' . implode(", ", - array_map(create_function - ('$k, $v', - 'return "$k:".($v===false?"false":($v===true?"true":"\'$v\'"));'), - array_keys($col), - array_values($col))) . - '}'; -} +echo $this->element('jqGrid', + array('jqGridColumns' => $cols)); -// 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' => 'jqGridData', - 'debug' => 0, - )); - -// 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. ?> - - -
-
-
Search By:
-Enable Autosearch
+Enable Autosearch
Last Name
@@ -147,73 +41,3 @@ First Name
-
- - - diff --git a/site/views/elements/jqGrid.ctp b/site/views/elements/jqGrid.ctp new file mode 100644 index 0000000..b12aae3 --- /dev/null +++ b/site/views/elements/jqGrid.ctp @@ -0,0 +1,210 @@ +'.$this->pageTitle.''; + +if (!isset($limit)) + $limit = 20; + +if (!isset($limitOptions)) + $limitOptions = array(10, 20, 50, 200); + +if (!isset($height)) + $height = 'auto'; + +if (!isset($gridId)) + $gridId = $this->params['controller'] . '-jqGrid'; + +// 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); + +// Create the javascript code for jqGrid to create each table column +$colModels = array(); +foreach ($jqGridColumns AS $col) { + $col['name'] = $col['index']; + $colModels[] = + '{ ' . implode(", ", + array_map(create_function + ('$k, $v', + 'return "$k:".($v===false?"false":($v===true?"true":"\'$v\'"));'), + array_keys($col), + array_values($col))) . + '}'; +} + +// Save just the column indices (fields) +$colFields= array_map(create_function('$col', 'return $col["index"];'), $jqGridColumns); + +// 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('action' => 'jqGridData', + 'debug' => 0, + )); + +// 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. +?> + + + +
+
+ + +