Update to work with Silverstripe 3.1

This commit is contained in:
andrelohmann 2013-10-03 14:06:17 +02:00
parent 712c5070e9
commit bdb395a468
17 changed files with 35 additions and 37 deletions

3
.htaccess Normal file
View File

@ -0,0 +1,3 @@
<FilesMatch "\.(php|php3|php4|php5|phtml|inc|yml|md)$">
Deny from all
</FilesMatch>

4
code/GridFieldAddExistingSearchButton.php Executable file → Normal file
View File

@ -7,10 +7,6 @@ class GridFieldAddExistingSearchButton implements
GridField_HTMLProvider,
GridField_URLHandler {
private static $allowed_actions = array(
'handleSearch'
);
protected $title;
protected $fragment;
protected $searchList;

View File

@ -5,7 +5,7 @@
*/
class GridFieldAddExistingSearchHandler extends RequestHandler {
private static $allowed_actions = array(
public static $allowed_actions = array(
'index',
'add',
'SearchForm'

0
code/GridFieldAddNewInlineButton.php Executable file → Normal file
View File

4
code/GridFieldAddNewMultiClass.php Executable file → Normal file
View File

@ -7,10 +7,6 @@
*/
class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URLHandler {
private static $allowed_actions = array(
'handleAdd'
);
private $fragment;
private $title;

View File

@ -14,10 +14,6 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
GridField_SaveHandler,
GridField_URLHandler {
private static $allowed_actions = array(
'handleForm'
);
/**
* @var Form[]
*/

View File

@ -5,13 +5,8 @@
class GridFieldExtensions {
public static function include_requirements() {
$moduleDir = self::get_module_dir();
Requirements::css($moduleDir.'/css/GridFieldExtensions.css');
Requirements::javascript($moduleDir.'/javascript/GridFieldExtensions.js');
}
public static function get_module_dir() {
return basename(dirname(__DIR__));
Requirements::css('gridfieldextensions/css/GridFieldExtensions.css');
Requirements::javascript('gridfieldextensions/javascript/GridFieldExtensions.js');
}
}

42
code/GridFieldOrderableRows.php Executable file → Normal file
View File

@ -11,11 +11,11 @@ class GridFieldOrderableRows extends RequestHandler implements
GridField_DataManipulator,
GridField_HTMLProvider,
GridField_URLHandler {
private static $allowed_actions = array(
'handleReorder',
'handleMoveToPage'
);
private static $allowed_actions = array(
'handleReorder',
'handleMoveToPage'
);
/**
* The database field which specifies the sort, defaults to "Sort".
@ -139,6 +139,14 @@ class GridFieldOrderableRows extends RequestHandler implements
$ids = $request->postVar('order');
$list = $grid->getList();
$field = $this->getSortField();
if($list instanceof ManyManyList){
$owner = $grid->Form->getRecord();
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($grid->getName());
$many_many = ' AND "' . $parentField . '" = ' . $owner->ID;
}else{
$many_many = '';
}
if(!is_array($ids)) {
$this->httpError(400);
@ -152,13 +160,13 @@ class GridFieldOrderableRows extends RequestHandler implements
}
// Populate each object we are sorting with a sort value.
$this->populateSortValues($items);
$this->populateSortValues($items, $many_many);
// Generate the current sort values.
$current = $items->map('ID', $field)->toArray();
// Perform the actual re-ordering.
$this->reorderItems($list, $current, $ids);
$this->reorderItems($list, $current, $ids, $many_many);
return $grid->FieldHolder();
}
@ -176,6 +184,14 @@ class GridFieldOrderableRows extends RequestHandler implements
$list = $grid->getList();
$manip = $grid->getManipulatedList();
if($list instanceof ManyManyList){
$owner = $grid->Form->getRecord();
list($parentClass, $componentClass, $parentField, $componentField, $table) = $owner->many_many($grid->getName());
$many_many = ' AND "' . $parentField . '" = ' . $owner->ID;
}else{
$many_many = '';
}
$existing = $manip->map('ID', $field)->toArray();
$values = $existing;
@ -188,7 +204,7 @@ class GridFieldOrderableRows extends RequestHandler implements
$this->httpError(400, 'Invalid item ID');
}
$this->populateSortValues($list);
$this->populateSortValues($list, $many_many);
$page = ((int) $grid->getState()->GridFieldPaginator->currentPage) ?: 1;
$per = $paginator->getItemsPerPage();
@ -217,12 +233,12 @@ class GridFieldOrderableRows extends RequestHandler implements
$this->httpError(400, 'Invalid page target');
}
$this->reorderItems($list, $values, $order);
$this->reorderItems($list, $values, $order, $many_many);
return $grid->FieldHolder();
}
protected function reorderItems($list, array $values, array $order) {
protected function reorderItems($list, array $values, array $order, $many_many) {
// Get a list of sort values that can be used.
$pool = array_values($values);
sort($pool);
@ -236,13 +252,13 @@ class GridFieldOrderableRows extends RequestHandler implements
$this->getSortTable($list),
$this->getSortField(),
$pool[$pos],
$this->getSortTableClauseForIds($list, $id)
$this->getSortTableClauseForIds($list, $id).$many_many
));
}
}
}
protected function populateSortValues(DataList $list) {
protected function populateSortValues(DataList $list, $many_many) {
$list = clone $list;
$field = $this->getSortField();
$table = $this->getSortTable($list);
@ -257,7 +273,7 @@ class GridFieldOrderableRows extends RequestHandler implements
$table,
$field,
$max,
$this->getSortTableClauseForIds($list, $id)
$this->getSortTableClauseForIds($list, $id).$many_many
));
}
}

View File

@ -9,10 +9,6 @@
*/
abstract class GridFieldRequestHandler extends RequestHandler {
private static $allowed_actions = array(
'Form'
);
/**
* @var GridField
*/