Author: Leon.van.der.Ree
Date: 2010-04-17 22:03:27 +0200 (Sat, 17 Apr 2010)
New Revision: 29189
Added:
plugins/sfGridJqFlexiPlugin/trunk/
plugins/sfGridJqFlexiPlugin/trunk/lib/
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexi.class.php
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexiRow.class.php
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexi.class.php
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexiRow.class.php
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/sfGridJqFlexi.class.php
plugins/sfGridJqFlexiPlugin/trunk/lib/routing/
plugins/sfGridJqFlexiPlugin/trunk/lib/routing/sfGridJqFlexiRoute.php
plugins/sfGridJqFlexiPlugin/trunk/lib/widget/
plugins/sfGridJqFlexiPlugin/trunk/lib/widget/sfWidgetJqFlexi.class.php
plugins/sfGridJqFlexiPlugin/trunk/modules/
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/actions/
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/actions/actions.class.php
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/templates/
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/templates/indexSuccess.php
Log:
initial commit of Jquery FlexiGrid formatter for sfGrid (POC)
Added:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexi.class.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexi.class.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexi.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,90 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class sfGridFormatterJqFlexi extends sfGridFormatterDynamic
+{
+ /**
+ *
+ * @param sfGridJqFlexi $grid
+ */
+ public function __construct(sfGridJqFlexi $grid)
+ {
+ // grid setup
+ $this->grid = $grid;
+ $this->row = new sfGridFormatterJqFlexiRow($grid, 0);
+ }
+
+ /**
+ * Returns an array of columns, containing Json-arrays with parameters
+ *
+ * @return array
+ */
+ public function getColumnModelConfig()
+ {
+ $columnModelConfig = array();
+
+ foreach ($this->grid->getWidgets() as $column => $widget)
+ {
+ $columnConfig = $widget->getColumnConfig($column);
+ $columnConfig['display'] = $this->grid->getTitleForColumn($column);
+
+ $columnModelConfig[] = $columnConfig;
+ }
+
+ return $columnModelConfig;
+ }
+
+
+ /**
+ * currently does it all... needs to be refactored obviously
+ * @return string
+ */
+ public function render()
+ {
+ $controller = sfContext::getInstance()->getController();
+
+ $p = json_encode(array(
+ 'url' => $controller->genUrl($this->grid->getUri()."?sf_format=json"),
+ 'dataType' => 'json',
+ 'method' => 'GET',
+ 'colModel' => $this->getColumnModelConfig(),
+// buttons : [
+// {name: 'Add', bclass: 'add', onpress : test},
+// {name: 'Delete', bclass: 'delete', onpress : test},
+// {separator: true}
+// ],
+// searchitems : [
+// {display: 'Id', name : 'id'},
+// {display: 'Country', name : 'name', isdefault: true}
+// ],
+ 'sortname' => 'Id', // TODO
+ 'sortorder' => 'desc',
+ 'usepager' => true,
+ 'singleSelect' => true,
+ 'title' => $this->grid->getTitle(),
+ 'useRp' => false,
+ 'rp' => 2,
+ 'showTableToggleBtn' => true,
+ 'width' => 700,
+ 'height' => 200
+ ));
+
+
+ return "
+ (function($){
+ $.fn.".$this->grid->getName()."JqFlexiGrid = function() {
+ return this.flexigrid(".$p.");
+ };
+
+ })(jQuery);
+ ";
+ }
+
+}
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexi.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexiRow.class.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexiRow.class.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexiRow.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * A formatter that renders a row for JqFlexi
+ *
+ * @package symfony
+ * @subpackage grid-jqFlexi
+ * @author Leon van der Ree <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfGridFormatterJqFlexiRow extends sfGridFormatterDynamicRow
+{
+ /**
+ * Renders a row to html
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $source = $this->grid->getDataSource();
+ $source->seek($this->index);
+
+ $data = array();
+
+ foreach ($this->grid->getWidgets() as $column => $widget)
+ {
+ $data[$column] = $source[$column];
+ }
+
+ return $data;
+ }
+}
\ No newline at end of file
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJqFlexiRow.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexi.class.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexi.class.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexi.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class sfGridFormatterJsonJqFlexi extends sfGridFormatterDynamic
+
+{
+ /**
+ * constructor of a Grid Formatter
+ *
+ * @param sfGrid $grid
+ */
+ public function __construct(sfGrid $grid)
+ {
+ parent::__construct($grid, new sfGridFormatterJsonJqFlexiRow($grid, 0));
+ }
+
+ /**
+ * Renders the row in HTML
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $arrJson = array();
+
+ $arrJson['total'] = $this->grid->getPager()->getRecordCount();
+ $arrJson['page'] = $this->grid->getPager()->getPage();
+ $arrJson['rows'] = $this->getData();
+
+ return json_encode($arrJson);
+ }
+
+
+ public function getData()
+ {
+ $arrJson = array();
+ foreach ($this as $row)
+ {
+ $arrJson[] = $row->render();
+ }
+
+ return $arrJson;
+ }
+
+}
+
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexi.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexiRow.class.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexiRow.class.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexiRow.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * A formatter that renders a row as JSON
+ *
+ */
+class sfGridFormatterJsonJqFlexiRow extends sfGridFormatterDynamicRow
+{
+
+ /**
+ * Renders a row to an array
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $source = $this->grid->getDataSource();
+ $source->seek($this->index);
+
+ $arrData = array();
+
+
+ $arrData['cell'] = array();
+
+ $widgets = $this->grid->getWidgets();
+ foreach ($widgets as $column => $widget)
+ {
+ $arrData['cell'][] = $widget->render($column, $source[$column]);
+ }
+ $key = 'Id';
+ $idWidget = $widgets[$key];
+ $arrData['id'] = $idWidget->render($key, $source[$key]);
+
+ return $arrData;
+ }
+
+}
\ No newline at end of file
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/formatter/sfGridFormatterJsonJqFlexiRow.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added: plugins/sfGridJqFlexiPlugin/trunk/lib/grid/sfGridJqFlexi.class.php
===================================================================
--- plugins/sfGridJqFlexiPlugin/trunk/lib/grid/sfGridJqFlexi.class.php
(rev 0)
+++ plugins/sfGridJqFlexiPlugin/trunk/lib/grid/sfGridJqFlexi.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,85 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ * @package symfony
+ * @subpackage grid-JqFlexi
+ * @author Leon van der Ree <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfGridJqFlexi extends sfContextGridJavaScript
+{
+ /**
+ * the name of the JqFlexiGrid-components
+ *
+ * @var string
+ */
+ protected $name;
+
+ /**
+ * Constructor.
+ *
+ * @param string $name the name of the JqFlexi Grid-components
+ * @param mixed $source An array or an instance of sfDataSourceInterface
with
+ * data that should be displayed in the grid.
+ * If an array is given, the array must conform to the
+ * requirements of the constructor of
sfDataSourceArray.
+ */
+ public function __construct($name, $source)
+ {
+ parent::__construct($source);
+
+ $this->name = $name;
+ }
+
+ /**
+ * Configures the grid. This method is called from the constructor. It can
+ * be overridden in child classes to configure the grid.
+ */
+ public function configure()
+ {
+ parent::configure();
+
+ // get the source from the original pager
+ $source = $this->getPager()->getDataSource();
+ // redefine the pager
+// $this->pager = new sfDataSourcePagerJqFlexi($source);
+
+ // define the javascript formatter
+ $this->setJavaScriptFormatter(new sfGridFormatterJqFlexi($this));
+
+ // define the json formatter for JqFlexi
+ $this->setDataFormatter(new sfGridFormatterJsonJqFlexi($this));
+ }
+
+
+ /**
+ * returns the name of the JqFlexiGrid-components
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Returns the default widget
+ *
+ * @return sfWidget
+ */
+ protected function getDefaultWidget()
+ {
+ return new sfWidgetJqFlexi();
+ }
+
+
+}
\ No newline at end of file
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/grid/sfGridJqFlexi.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added: plugins/sfGridJqFlexiPlugin/trunk/lib/routing/sfGridJqFlexiRoute.php
===================================================================
--- plugins/sfGridJqFlexiPlugin/trunk/lib/routing/sfGridJqFlexiRoute.php
(rev 0)
+++ plugins/sfGridJqFlexiPlugin/trunk/lib/routing/sfGridJqFlexiRoute.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,57 @@
+<?php
+/**
+ * sfGridJqFlexiRoute represents a route that is bound to an GridJqFlexi-class.
+ *
+ * A grid route can only represent a single Grid object.
+ *
+ * @package symfony
+ * @subpackage routing
+ * @author Leon van der Ree
+ * @version SVN: $Id: $
+ */
+class sfGridJqFlexiRoute extends sfGridRoute
+{
+ public function __construct($pattern, array $defaults = array(), array
$requirements = array(), array $options = array())
+ {
+
+ if (strpos($pattern,':sf_format') === false)
+ {
+ $pattern .= '.:sf_format';
+ }
+
+ $defaults = array_merge(
+ array(
+ 'module' => 'jqFlexiGrid',
+ 'action' => 'index',
+ 'sf_format' => 'html',
+ ),
+ $defaults
+ );
+
+ if (!isset($requirements['sf_method']))
+ {
+ $requirements['sf_method'] = array('get', 'head', 'post');
+ }
+ else
+ {
+ $requirements['sf_method'] = array_map('strtolower', (array)
$requirements['sf_method']);
+ }
+
+ parent::__construct($pattern, $defaults, $requirements, $options);
+ }
+
+
+ protected function getObjectForParameters($parameters)
+ {
+ $request = sfContext::getInstance()->getRequest();
+ $getParameters = $request->getGetParameters();
+
+ // translate params
+ if (isset($getParameters['page'])) $parameters['page'] =
$getParameters['page'];
+ if (isset($getParameters['sortname'])) $parameters['sort'] =
$getParameters['sortname'];
+ if (isset($getParameters['sortorder'])) $parameters['type'] =
$getParameters['sortorder'];
+
+ return parent::getObjectForParameters($parameters);
+ }
+
+}
\ No newline at end of file
Added: plugins/sfGridJqFlexiPlugin/trunk/lib/widget/sfWidgetJqFlexi.class.php
===================================================================
--- plugins/sfGridJqFlexiPlugin/trunk/lib/widget/sfWidgetJqFlexi.class.php
(rev 0)
+++ plugins/sfGridJqFlexiPlugin/trunk/lib/widget/sfWidgetJqFlexi.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,51 @@
+<?php
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ *
+ * @package symfony
+ * @subpackage grid-JqFlexi
+ * @author Leon van der Ree <[email protected]>
+ * @version SVN: $Id$
+ */
+class sfWidgetJqFlexi extends sfWidget
+{
+ protected $type = 'string';
+
+ /**
+ * renders value (you can extend this class and pre-process this value)
+ *
+ * @see sfWidget#render()
+ */
+ public function render($name, $value = null, $attributes = array(), $errors
= array())
+ {
+ return $value;
+ }
+
+
+ /**
+ * Returns the column-definition for ColumnModel
+ * this is defined in the widget, to allow you to define the type
+ *
+ * @param string $name
+ * @return array
+ */
+ public function getColumnConfig($name)
+ {
+ $arrJs = array(
+ 'name' => $name,
+ 'width' => 140,
+ 'sortable' => true,
+ 'align' => 'center',
+ );
+
+ return $arrJs;
+ }
+
+}
\ No newline at end of file
Property changes on:
plugins/sfGridJqFlexiPlugin/trunk/lib/widget/sfWidgetJqFlexi.class.php
___________________________________________________________________
Added: svn:executable
+ *
Added:
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/actions/actions.class.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/actions/actions.class.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/actions/actions.class.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * jqFlexiGrid actions.
+ *
+ * @package sfGridJqFlexiPlugin
+ * @subpackage jqFlexiGrid
+ * @author Leon van der Ree
+ * @version SVN: $Id: $
+ */
+class jqFlexiGridActions extends sfGridJavaScriptActions
+{
+ /**
+ * Executes index action
+ *
+ * @param sfRequest $request A request object
+ */
+ public function executeIndex(sfWebRequest $request)
+ {
+ }
+}
Added:
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/templates/indexSuccess.php
===================================================================
---
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/templates/indexSuccess.php
(rev 0)
+++
plugins/sfGridJqFlexiPlugin/trunk/modules/jqFlexiGrid/templates/indexSuccess.php
2010-04-17 20:03:27 UTC (rev 29189)
@@ -0,0 +1,10 @@
+<?php $grid = $sf_data->getRaw('grid'); ?>
+<div id="grid-example">
+ <table>
+ <?php echo $grid->render() ?>
+ </table>
+</div>
+
+<script type='text/javascript'>
+ $("#grid-example").<?php echo $grid->getName() ?>JqFlexiGrid();
+</script>
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.