mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Update to work with Silverstripe 3.1
This commit is contained in:
parent
712c5070e9
commit
bdb395a468
3
.htaccess
Normal file
3
.htaccess
Normal 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
4
code/GridFieldAddExistingSearchButton.php
Executable file → Normal file
@ -7,10 +7,6 @@ class GridFieldAddExistingSearchButton implements
|
||||
GridField_HTMLProvider,
|
||||
GridField_URLHandler {
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'handleSearch'
|
||||
);
|
||||
|
||||
protected $title;
|
||||
protected $fragment;
|
||||
protected $searchList;
|
||||
|
@ -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
0
code/GridFieldAddNewInlineButton.php
Executable file → Normal file
4
code/GridFieldAddNewMultiClass.php
Executable file → Normal file
4
code/GridFieldAddNewMultiClass.php
Executable file → Normal file
@ -7,10 +7,6 @@
|
||||
*/
|
||||
class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URLHandler {
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'handleAdd'
|
||||
);
|
||||
|
||||
private $fragment;
|
||||
|
||||
private $title;
|
||||
|
@ -14,10 +14,6 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
|
||||
GridField_SaveHandler,
|
||||
GridField_URLHandler {
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'handleForm'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var Form[]
|
||||
*/
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
32
code/GridFieldOrderableRows.php
Executable file → Normal file
32
code/GridFieldOrderableRows.php
Executable file → Normal file
@ -140,6 +140,14 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$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();
|
||||
}
|
||||
@ -177,6 +185,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;
|
||||
$order = array();
|
||||
@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,6 @@
|
||||
*/
|
||||
abstract class GridFieldRequestHandler extends RequestHandler {
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'Form'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var GridField
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user