Permalink
Browse files

API CHANGE: Refactored GridField modifiers into GridField_ColumnProvi…

…der, GridField_HTMLProvider, GridField_ActionProvider, and GridField_DataModifier interfaces, all added as components in the config.

API CHANGE: Simplified state handling so that it's just a key store. Affectors are replaced with GridField_ActionProviders. API CHANGE: Removed GridField state manipulation actions instead opting for GridField_ActionProvider actions.
API CHANGE: Removed support for modifiers that add "body" rows, instead having core support for generating the body rows hardcoded into the GridField.
API CHANGE: Allow modification of columns across the whole GridField with the GridField_ColumnProvider interface.
API CHANGE: Renamed GridField_AlterAction to GridField_Action, and added actionName/args parameters, since it can be used for all actions (including batch actions and row actions)
API CHANGE: Removed GridFieldRow class.
  • Loading branch information...
stojg committed Dec 6, 2011
1 parent 7f9ced2 commit 3c516b7b976728076f3b095c7562cd4aeebae43a
Showing with 1,687 additions and 1,354 deletions.
  1. +32 −17 css/GridField.css
  2. +16 −2 filesystem/Folder.php
  3. +1 −1 filesystem/Upload.php
  4. +23 −0 forms/Form.php
  5. +0 −174 forms/GridField.php
  6. +0 −277 forms/GridFieldPaginator.php
  7. +0 −417 forms/GridFieldPresenter.php
  8. +589 −0 forms/gridfield/GridField.php
  9. +44 −0 forms/gridfield/GridFieldComponent.php
  10. +88 −0 forms/gridfield/GridFieldConfig.php
  11. +120 −0 forms/gridfield/GridFieldDefaultColumns.php
  12. +105 −0 forms/gridfield/GridFieldFilter.php
  13. +90 −0 forms/gridfield/GridFieldPaginator.php
  14. +82 −0 forms/gridfield/GridFieldSortableHeader.php
  15. +148 −0 forms/gridfield/GridState.php
  16. +70 −0 javascript/GridField.js
  17. +0 −30 javascript/GridFieldPaginator.js
  18. +3 −1 javascript/lang/en_US.js
  19. +2 −1 javascript/lang/fr_FR.js
  20. +14 −1 model/DataList.php
  21. +184 −95 scss/GridField.scss
  22. 0 scss/newfile
  23. +0 −25 templates/GridField.ss
  24. +0 −29 templates/GridFieldPaginator.ss
  25. +0 −29 templates/GridFieldPresenter.ss
  26. +5 −0 templates/Includes/GridFieldFilter_Row.ss
  27. +7 −0 templates/Includes/GridFieldPaginator_Row.ss
  28. +5 −0 templates/Includes/GridFieldSortableHeader_Row.ss
  29. +10 −3 templates/Includes/GridField_Item.ss
  30. +40 −0 tests/control/RequestHandlingTest.php
  31. +1 −1 tests/filesystem/FileTest.php
  32. +8 −8 tests/filesystem/FolderTest.php
  33. +0 −45 tests/forms/GridFieldFunctionalTest.php
  34. +0 −38 tests/forms/GridFieldPaginatorTest.php
  35. +0 −61 tests/forms/GridFieldPresenterTest.php
  36. +0 −94 tests/forms/GridFieldTest.php
  37. +0 −5 tests/forms/GridFieldTest.yml
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -25,12 +25,26 @@ class Folder extends File {
static $default_sort = "\"Sort\"";
- function populateDefaults() {
+ /**
+ *
+ */
+ public function populateDefaults() {
parent::populateDefaults();
if(!$this->Name) $this->Name = _t('AssetAdmin.NEWFOLDER',"NewFolder");
}
+ /**
+ * @param $folderPath string Absolute or relative path to the file.
+ * If path is relative, its interpreted relative to the "assets/" directory.
+ * @return Folder
+ * @deprecated in favor of the correct name find_or_make
+ */
+ public static function findOrMake($folderPath) {
+ Deprecation::notice('3.0', "Folder::findOrMake() is deprecated in favor of Folder::find_or_make()");
+ return self::find_or_make($folderPath);
+ }
+
/**
* Find the given folder or create it both as {@link Folder} database records
* and on the filesystem. If necessary, creates parent folders as well.
@@ -39,7 +53,7 @@ function populateDefaults() {
* If path is relative, its interpreted relative to the "assets/" directory.
* @return Folder
*/
- static function findOrMake($folderPath) {
+ public static function find_or_make($folderPath) {
// Create assets directory, if it is missing
if(!file_exists(ASSETS_PATH)) Filesystem::makeFolder(ASSETS_PATH);
View
@@ -120,7 +120,7 @@ function load($tmpFile, $folderPath = false) {
// @TODO This puts a HUGE limitation on files especially when lots
// have been uploaded.
$base = Director::baseFolder();
- $parentFolder = Folder::findOrMake($folderPath);
+ $parentFolder = Folder::find_or_make($folderPath);
// Create a folder for uploading.
if(!file_exists(ASSETS_PATH)){
View
@@ -302,6 +302,23 @@ function httpSubmission($request) {
sprintf('Action "%s" not allowed on form (Name: "%s")', $funcName, $this->Name())
);
}
+ // TODO : Once we switch to a stricter policy regarding allowed_actions (meaning actions must be set explicitly in allowed_actions in order to run)
+ // Uncomment the following for checking security against running actions on form fields
+ /* else {
+ // Try to find a field that has the action, and allows it
+ $fieldsHaveMethod = false;
+ foreach ($this->Fields() as $field){
+ if ($field->hasMethod($funcName) && $field->checkAccessAction($funcName)) {
+ $fieldsHaveMethod = true;
+ }
+ }
+ if (!$fieldsHaveMethod) {
+ return $this->httpError(
+ 403,
+ sprintf('Action "%s" not allowed on any fields of form (Name: "%s")', $funcName, $this->Name())
+ );
+ }
+ }*/
// Validate the form
if(!$this->validate()) {
@@ -344,6 +361,12 @@ function httpSubmission($request) {
// Otherwise, try a handler method on the form object.
} elseif($this->hasMethod($funcName)) {
return $this->$funcName($vars, $this, $request);
+ } else {
+ // Finally try to find a field that could handle that action, ie GridField
+ foreach ($this->Fields() as $field){
+ if (!$field->hasMethod($funcName)) continue;
+ return $field->$funcName($vars, $this, $request);
+ }
}
return $this->httpError(404);
View
@@ -1,174 +0,0 @@
-<?php
-/**
- * Displays a {@link SS_List} in a grid format.
- *
- * GridFIeld is a field that takes an SS_List and displays it in an table with rows
- * and columns. It reminds of the old TableFields but works with SS_List types
- * and only loads the necessary rows from the list.
- *
- * The minimum configuration is to pass in name and title of the field and a
- * SS_List.
- *
- * <code>
- * $gridField = new GridField('ExampleGrid', 'Example grid', new DataList('Page'));
- * </code>
- *
- * If you want to modify the output of the grid you can attach a customised
- * DataGridPresenter that are the actual Renderer of the data. Sapphire provides
- * a default one if you chooses not to.
- *
- * @see GridFieldPresenter
- * @see SS_List
- *
- * @package sapphire
- * @subpackage forms
- */
-class GridField extends FormField {
-
- /**
- * @var SS_List
- */
- protected $list = 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 = '';
-
- /**
- * Url handlers
- *
- * @var array
- */
- public static $url_handlers = array(
- '$Action' => '$Action',
- );
-
- /**
- * Creates a new GridField field
- *
- * @param string $name
- * @param string $title
- * @param SS_List $dataList
- * @param Form $form
- * @param string|GridFieldPresenter $dataPresenterClassName - can either pass in a string or an instance of a GridFieldPresenter
- */
- public function __construct($name, $title = null, SS_List $dataList = null, Form $form = null, $dataPresenterClassName = 'GridFieldPresenter') {
- parent::__construct($name, $title, null, $form);
-
- if ($dataList) {
- $this->setList($dataList);
- }
-
- $this->setPresenter($dataPresenterClassName);
- }
-
- /**
- *
- * @return string - HTML
- */
- public function index() {
- return $this->FieldHolder();
- }
-
- /**
- * @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->list->dataClass) {
- return $this->list->dataClass;
- }
-
- throw new LogicException(get_class($this).' does not have a modelClassName');
- }
-
- /**
- * @param string|GridFieldPresenter
- *
- * @throws Exception
- */
- public function setPresenter($presenter) {
- if(!$presenter){
- throw new InvalidArgumentException('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 InvalidArgumentException('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.');
- }
-
- if($presenter !='GridFieldPresenter' && !is_subclass_of($presenter, 'GridFieldPresenter')) {
- throw new InvalidArgumentException(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 $list
- */
- public function setList(SS_List $list) {
- $this->list = $list;
- return $this;
- }
-
- /**
- * Get the datasource
- *
- * @return SS_List
- */
- public function getList() {
- return $this->list;
- }
-
- /**
- * @return string - html for the form
- */
- function FieldHolder() {
- return $this->getPresenter()->render();
- }
-}
-
Oops, something went wrong.

0 comments on commit 3c516b7

Please sign in to comment.