Permalink
Browse files

ENHANCEMENT Renamed DataGrid to GridField

  • Loading branch information...
1 parent a2c7175 commit b229c17e1d5039bb972802df0560849baf615c60 @stojg stojg committed with Hamish Friedlander Sep 29, 2011
View
@@ -1,2 +1,2 @@
.sass-cache
-.DS_Store
+.DS_Store
View
@@ -1,17 +0,0 @@
-/** Core styles for the basic DataGrid form field without any specific style. @package sapphire @subpackage scss */
-.ss-datagrid { border: none; }
-.ss-datagrid table { width: 100%; border-collapse: collapse; border-spacing: 0; background: #fff; border: 1px solid #c1c1c1; }
-.ss-datagrid thead { color: #5a5a5a; background: #dadada; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f3f3f3), color-stop(100%, #dadada)); background-image: -webkit-linear-gradient(#f3f3f3, #dadada); background-image: -moz-linear-gradient(#f3f3f3, #dadada); background-image: -o-linear-gradient(#f3f3f3, #dadada); background-image: -ms-linear-gradient(#f3f3f3, #dadada); background-image: linear-gradient(#f3f3f3, #dadada); }
-.ss-datagrid thead th { font-weight: bold; padding: 8px 24px 8px 8px; position: relative; border: 1px solid #c1c1c1; border-width: 0 1px 1px 0; }
-.ss-datagrid thead th.ss-datagrid-sortable.hover { color: #747474; cursor: pointer; background: #f3f3f3; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff), color-stop(100%, #e7e7e7)); background-image: -webkit-linear-gradient(#ffffff, #e7e7e7); background-image: -moz-linear-gradient(#ffffff, #e7e7e7); background-image: -o-linear-gradient(#ffffff, #e7e7e7); background-image: -ms-linear-gradient(#ffffff, #e7e7e7); background-image: linear-gradient(#ffffff, #e7e7e7); }
-.ss-datagrid thead th.ss-datagrid-sorted { background: #e7e7e7; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dadada), color-stop(100%, #f3f3f3)); background-image: -webkit-linear-gradient(#dadada, #f3f3f3); background-image: -moz-linear-gradient(#dadada, #f3f3f3); background-image: -o-linear-gradient(#dadada, #f3f3f3); background-image: -ms-linear-gradient(#dadada, #f3f3f3); background-image: linear-gradient(#dadada, #f3f3f3); }
-.ss-datagrid thead th.ss-datagrid-sorted.hover { background: #f3f3f3; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #e7e7e7), color-stop(100%, #ffffff)); background-image: -webkit-linear-gradient(#e7e7e7, #ffffff); background-image: -moz-linear-gradient(#e7e7e7, #ffffff); background-image: -o-linear-gradient(#e7e7e7, #ffffff); background-image: -ms-linear-gradient(#e7e7e7, #ffffff); background-image: linear-gradient(#e7e7e7, #ffffff); }
-.ss-datagrid thead th .ui-icon { position: absolute; top: 5px; right: 0; }
-.ss-datagrid thead th.ss-datagrid-desc .ui-icon { background-position: 0 -48px; }
-.ss-datagrid thead th.ss-datagrid-asc .ui-icon { background-position: -64px -48px; }
-.ss-datagrid td { padding: 8px; border-right: 1px solid #f3f3f3; }
-.ss-datagrid td.ss-datagrid-last { border-right: none; }
-.ss-datagrid tr.ss-datagrid-even { border: 1px solid #c6e5f6; border-width: 1px 0; background: #f2f9fd; }
-.ss-datagrid tr.ss-datagrid-even.ss-datagrid-last { border-bottom: none; }
-.ss-datagrid tr.ss-datagrid-even td { border-right: 1px solid #dceffa; }
-.ss-datagrid tr.ss-datagrid-even td.ss-datagrid-last { border-right: none; }
View
@@ -0,0 +1,17 @@
+/** Core styles for the basic GridField form field without any specific style. @package sapphire @subpackage scss */
+.ss-gridfield { border: none; }
+.ss-gridfield table { width: 100%; border-collapse: collapse; border-spacing: 0; background: #fff; border: 1px solid #c1c1c1; }
+.ss-gridfield thead { color: #5a5a5a; background: #dadada; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #f3f3f3), color-stop(100%, #dadada)); background-image: -webkit-linear-gradient(#f3f3f3, #dadada); background-image: -moz-linear-gradient(#f3f3f3, #dadada); background-image: -o-linear-gradient(#f3f3f3, #dadada); background-image: -ms-linear-gradient(#f3f3f3, #dadada); background-image: linear-gradient(#f3f3f3, #dadada); }
+.ss-gridfield thead th { font-weight: bold; padding: 8px 24px 8px 8px; position: relative; border: 1px solid #c1c1c1; border-width: 0 1px 1px 0; }
+.ss-gridfield thead th.ss-gridfield-sortable.hover { color: #747474; cursor: pointer; background: #f3f3f3; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffffff), color-stop(100%, #e7e7e7)); background-image: -webkit-linear-gradient(#ffffff, #e7e7e7); background-image: -moz-linear-gradient(#ffffff, #e7e7e7); background-image: -o-linear-gradient(#ffffff, #e7e7e7); background-image: -ms-linear-gradient(#ffffff, #e7e7e7); background-image: linear-gradient(#ffffff, #e7e7e7); }
+.ss-gridfield thead th.ss-gridfield-sorted { background: #e7e7e7; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dadada), color-stop(100%, #f3f3f3)); background-image: -webkit-linear-gradient(#dadada, #f3f3f3); background-image: -moz-linear-gradient(#dadada, #f3f3f3); background-image: -o-linear-gradient(#dadada, #f3f3f3); background-image: -ms-linear-gradient(#dadada, #f3f3f3); background-image: linear-gradient(#dadada, #f3f3f3); }
+.ss-gridfield thead th.ss-gridfield-sorted.hover { background: #f3f3f3; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #e7e7e7), color-stop(100%, #f9f9f9)); background-image: -webkit-linear-gradient(#e7e7e7, #f9f9f9); background-image: -moz-linear-gradient(#e7e7e7, #f9f9f9); background-image: -o-linear-gradient(#e7e7e7, #f9f9f9); background-image: -ms-linear-gradient(#e7e7e7, #f9f9f9); background-image: linear-gradient(#e7e7e7, #f9f9f9); }
+.ss-gridfield thead th .ui-icon { position: absolute; top: 5px; right: 0; }
+.ss-gridfield thead th.ss-gridfield-desc .ui-icon { background-position: 0 -48px; }
+.ss-gridfield thead th.ss-gridfield-asc .ui-icon { background-position: -64px -48px; }
+.ss-gridfield td { padding: 8px; border-right: 1px solid #f3f3f3; }
+.ss-gridfield td.ss-gridfield-last { border-right: none; }
+.ss-gridfield tr.ss-gridfield-even { border: 1px solid #c6e5f6; border-width: 1px 0; background: #f2f9fd; }
+.ss-gridfield tr.ss-gridfield-even.ss-gridfield-last { border-bottom: none; }
+.ss-gridfield tr.ss-gridfield-even td { border-right: 1px solid #dceffa; }
+.ss-gridfield tr.ss-gridfield-even td.ss-gridfield-last { border-right: none; }
View
@@ -1,129 +0,0 @@
-<?php
-/**
- * Datagrid
- *
- * This field takes care of displaying a table of a list of data
- *
- */
-class Datagrid extends FormField {
-
- /**
- *
- * @var SS_list
- */
- protected $datasource = null;
-
- /**
- *
- * @var string
- */
- protected $dataPresenterClassName = "DatagridPresenter";
-
- /**
- *
- * @var DatagridPresenter
- */
- protected $datagridPresenter = null;
-
- /**
- * @var string - the name of the DataObject that the Datagrid will display
- */
- protected $modelClassName = '';
-
- /**
- * Creates a new datagrid field
- *
- * @param string $name
- * @param string $title
- * @param SS_list $datasource
- * @param Form $form
- * @param string $dataPresenterClassName
- */
- function __construct($name, $title = null, SS_list $datasource = null, Form $form = null, $dataPresenterClassName = null) {
- parent::__construct($name, $title, null, $form);
- if ($datasource) $this->setDatasource($datasource);
- if ($dataPresenterClassName) $this->setDataPresenter($dataPresenterClassName);
- }
-
- /**
- *
- * @param string $modelClassName
- */
- function setModelClass($modelClassName) {
- $this->modelClassName = $modelClassName;
- return $this;
- }
-
- /**
- *
- * @param string $dataPresenterClassName
- * @throws Exception
- */
- function setDataPresenter($dataPresenterClassName) {
- if(!$dataPresenterClassName){
- throw new Exception('Datapresenter for Datagrid must be set with a class');
- }
- if(!class_exists($dataPresenterClassName)){
- throw new Exception('Datapresenter for Datagrid must be set with an existing class');
- }
-
- if($dataPresenterClassName !='DatagridPresenter' && !ClassInfo::is_subclass_of($dataPresenterClassName, 'DatagridPresenter')){
- throw new Exception('Datapresenter "$dataPresenterClassName" must inherit DatagridPresenter' );
- }
- $this->dataPresenterClassName = $dataPresenterClassName;
- return $this;
- }
-
- /**
- *
- * @return type
- */
- function getModelClass() {
- if ($this->modelClassName) {
- return $this->modelClassName;
- }
- if ($this->datasource->dataClass) {
- return $this->datasource->dataClass;
- }
- throw new Exception(get_class($this).' does not have a modelClassName');
- }
-
- /**
- * Set the datasource
- *
- * @param SS_List $datasource
- */
- public function setDatasource(SS_List $datasource) {
- $this->datasource = $datasource;
- return $this;
- }
-
- /**
- * Get the datasource
- *
- * @return SS_list
- */
- public function getDatasource() {
- return $this->datasource;
- }
-
- /**
- *
- * @return DatagridPresenter
- */
- public function getDatagridPresenter(){
- if(!$this->datagridPresenter) {
- $this->datagridPresenter = new $this->dataPresenterClassName();
- $this->datagridPresenter->setDatagrid($this);
- }
- return $this->datagridPresenter;
- }
-
- /**
- *
- * @return string - html for the form
- */
- function FieldHolder() {
- return $this->getDatagridPresenter()->render();
- }
-}
View
@@ -0,0 +1,140 @@
+<?php
+/**
+ * Displays a {@link SS_List} in a grid format.
+ *
+ * @package sapphire
+ * @subpackage forms
+ */
+class GridField extends FormField {
+
+ /**
+ * @var SS_List
+ */
+ protected $dataSource = null;
+
+ /**
+ * @var string
+ */
+ protected $presenterClassName = "GridFieldPresenter";
+
+ /**
+ * @var GridFieldPresenter
+ */
+ protected $presenter = null;
+
+ /**
+ * @var string - the classname of the DataObject that the GridField will display
+ */
+ protected $modelClassName = '';
+
+ /**
+ * Creates a new GridField field
+ *
+ * @param string $name
+ * @param string $title
+ * @param SS_List $datasource
+ * @param Form $form
+ * @param string $dataPresenterClassName
+ */
+ public function __construct($name, $title = null, SS_List $datasource = null, Form $form = null, $dataPresenterClassName = 'GridFieldPresenter') {
+ parent::__construct($name, $title, null, $form);
+
+ if ($datasource) {
+ $this->setDatasource($datasource);
+ }
+
+ $this->setPresenter($dataPresenterClassName);
+ }
+
+ /**
+ * @param string $modelClassName
+ */
+ public function setModelClass($modelClassName) {
+ $this->modelClassName = $modelClassName;
+
+ return $this;
+ }
+
+ /**
+ * @throws Exception
+ * @return string
+ */
+ public function getModelClass() {
+ if ($this->modelClassName) {
+ return $this->modelClassName;
+ }
+ if ($this->datasource->dataClass) {
+ return $this->datasource->dataClass;
+ }
+
+ throw new Exception(get_class($this).' does not have a modelClassName');
+ }
+
+ /**
+ * @param string|GridFieldPresenter
+ *
+ * @throws Exception
+ */
+ public function setPresenter($presenter) {
+ if(!$presenter){
+ throw new Exception('setPresenter() for GridField must be set with a class');
+ }
+
+ if(is_object($presenter)) {
+ $this->presenter = $presenter;
+ $this->presenter->setGridField($this);
+
+ return;
+ }
+
+ if(!class_exists($presenter)){
+ throw new Exception('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.');
+ }
+
+ if($presenter !='GridFieldPresenter' && !ClassInfo::is_subclass_of($presenter, 'GridFieldPresenter')) {
+ throw new Exception(sprintf(
+ 'DataPresenter "%s" must subclass GridFieldPresenter', $presenter
+ ));
+ }
+
+ $this->presenter = new $presenter;
+ $this->presenter->setGridField($this);
+
+ return $this;
+ }
+
+ /**
+ * @return GridFieldPresenter
+ */
+ public function getPresenter(){
+ return $this->presenter;
+ }
+
+ /**
+ * Set the datasource
+ *
+ * @param SS_List $datasource
+ */
+ public function setDataSource(SS_List $datasource) {
+ $this->datasource = $datasource;
+
+ return $this;
+ }
+
+ /**
+ * Get the datasource
+ *
+ * @return SS_List
+ */
+ public function getDataSource() {
+ return $this->datasource;
+ }
+
+ /**
+ * @return string - html for the form
+ */
+ function FieldHolder() {
+ return $this->getPresenter()->render();
+ }
+}
+
Oops, something went wrong. Retry.

0 comments on commit b229c17

Please sign in to comment.