mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-26 06:29:24 +02:00
BUGFIX GridField_Actions did not work in more complex Forms with tabsets (i.e SecurityAdmin) when using GridField_Action
BUGFIX Empty GridState data causes isset error BUGFIX Last field of GridFieldFilter outputs wrong label
This commit is contained in:
parent
1e1e3a2d80
commit
39372497df
|
@ -361,17 +361,31 @@ class Form extends RequestHandler {
|
||||||
// Otherwise, try a handler method on the form object.
|
// Otherwise, try a handler method on the form object.
|
||||||
} elseif($this->hasMethod($funcName)) {
|
} elseif($this->hasMethod($funcName)) {
|
||||||
return $this->$funcName($vars, $this, $request);
|
return $this->$funcName($vars, $this, $request);
|
||||||
} else {
|
} elseif($field = $this->checkFieldsForAction($this->Fields(), $funcName)) {
|
||||||
// Finally try to find a field that could handle that action, ie GridField
|
return $field->$funcName($vars, $this, $request);
|
||||||
foreach ($this->Fields() as $field){
|
|
||||||
if (!$field->hasMethod($funcName)) continue;
|
|
||||||
return $field->$funcName($vars, $this, $request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->httpError(404);
|
return $this->httpError(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fields can have action to, let's check if anyone of the responds to $funcname them
|
||||||
|
*
|
||||||
|
* @return FormField
|
||||||
|
*/
|
||||||
|
protected function checkFieldsForAction($fields, $funcName) {
|
||||||
|
foreach($fields as $field){
|
||||||
|
if(method_exists($field, 'FieldList')) {
|
||||||
|
if($field = $this->checkFieldsForAction($field->FieldList(), $funcName)) {
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
} elseif (!$field->hasMethod($funcName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a field request.
|
* Handle a field request.
|
||||||
* Uses {@link Form->dataFieldByName()} to find a matching field,
|
* Uses {@link Form->dataFieldByName()} to find a matching field,
|
||||||
|
|
|
@ -337,9 +337,11 @@ class GridField extends FormField {
|
||||||
'class' => "field CompositeField {$this->extraClass()}"
|
'class' => "field CompositeField {$this->extraClass()}"
|
||||||
);
|
);
|
||||||
return
|
return
|
||||||
implode("\n", $content['before']) .
|
$this->createTag('fieldset', array('id'=>$this->ID(),'class'=>'ss-gridfield'),
|
||||||
$this->createTag('table', $attrs, $head."\n".$foot."\n".$body) .
|
implode("\n", $content['before']) .
|
||||||
implode("\n", $content['after']);
|
$this->createTag('table', $attrs, $head."\n".$foot."\n".$body) .
|
||||||
|
implode("\n", $content['after'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColumns() {
|
function getColumns() {
|
||||||
|
@ -420,30 +422,32 @@ class GridField extends FormField {
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function gridFieldAlterAction($data, $form, $request) {
|
public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) {
|
||||||
$id = $data['StateID'];
|
$id = $data['StateID'];
|
||||||
$stateChange = Session::get($id);
|
$stateChange = Session::get($id);
|
||||||
|
$gridName = $stateChange['grid'];
|
||||||
|
$grid = $form->Fields()->dataFieldByName($gridName);
|
||||||
|
|
||||||
$state = $this->getState(false);
|
$state = $grid->getState(false);
|
||||||
$state->setValue($data['GridState']);
|
$state->setValue($data['GridState']);
|
||||||
|
|
||||||
$gridName = $stateChange['grid'];
|
|
||||||
$grid = $form->Fields()->fieldByName($gridName);
|
|
||||||
$actionName = $stateChange['actionName'];
|
$actionName = $stateChange['actionName'];
|
||||||
|
|
||||||
$args = $stateChange['args'];
|
$args = $stateChange['args'];
|
||||||
$grid->handleAction($actionName, $args, $data);
|
$grid->handleAction($actionName, $args, $data);
|
||||||
|
|
||||||
// Make the form re-load it's values from the Session after redirect
|
switch($request->getHeader('X-Get-Fragment')) {
|
||||||
// so the changes we just made above survive the page reload
|
case 'CurrentField':
|
||||||
// @todo Form really needs refactoring so we dont have to do this
|
return $grid->FieldHolder();
|
||||||
if (Director::is_ajax()) {
|
break;
|
||||||
return $form->forTemplate();
|
|
||||||
} else {
|
case 'CurrentForm':
|
||||||
$data = $form->getData();
|
return $form->forTemplate();
|
||||||
Session::set("FormInfo.{$form->FormName()}.errors", array());
|
break;
|
||||||
Session::set("FormInfo.{$form->FormName()}.data", $data);
|
|
||||||
Controller::curr()->redirectBack();
|
default:
|
||||||
|
return $form->forTemplate();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat
|
||||||
if(isset($filterArguments[$columnField])) {
|
if(isset($filterArguments[$columnField])) {
|
||||||
$value = $filterArguments[$columnField];
|
$value = $filterArguments[$columnField];
|
||||||
}
|
}
|
||||||
$field = new TextField('filter['.$columnField.']', 'filter['.$columnField.']', $value);
|
$field = new TextField('filter['.$columnField.']', '', $value);
|
||||||
$field->addExtraClass('ss-gridfield-sort');
|
$field->addExtraClass('ss-gridfield-sort');
|
||||||
} else {
|
} else {
|
||||||
$field = new LiteralField('', '');
|
$field = new LiteralField('', '');
|
||||||
|
|
|
@ -68,6 +68,9 @@ class GridState extends HiddenField {
|
||||||
|
|
||||||
/** @return string */
|
/** @return string */
|
||||||
public function Value() {
|
public function Value() {
|
||||||
|
if(!$this->gridStateData) {
|
||||||
|
return json_encode(array());
|
||||||
|
}
|
||||||
return json_encode($this->gridStateData->toArray());
|
return json_encode($this->gridStateData->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
jQuery(function($){
|
jQuery(function($){
|
||||||
|
|
||||||
$('.ss-gridfield .action').entwine({
|
$('fieldset.ss-gridfield .action').entwine({
|
||||||
onclick: function(e){
|
onclick: function(e){
|
||||||
button = this;
|
var button = this;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var form = $(this).closest("form");
|
var form = $(this).closest("form");
|
||||||
|
var field = $(this).closest("fieldset.ss-gridfield");
|
||||||
form.addClass('loading');
|
form.addClass('loading');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
headers: {"X-Get-Fragment" : 'CurrentField'},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: form.attr('action'),
|
url: form.attr('action'),
|
||||||
data: form.serialize()+'&'+escape(button.attr('name'))+'='+escape(button.val()),
|
data: form.serialize()+'&'+escape(button.attr('name'))+'='+escape(button.val()),
|
||||||
dataType: 'html',
|
dataType: 'html',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
form.replaceWith(data);
|
// Replace the grid field with response, not the form.
|
||||||
|
field.replaceWith(data);
|
||||||
form.removeClass('loading');
|
form.removeClass('loading');
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
|
@ -35,7 +38,7 @@ jQuery(function($){
|
||||||
* ToDo ensure filter-button state is maintained after filtering (see resetState param)
|
* ToDo ensure filter-button state is maintained after filtering (see resetState param)
|
||||||
* ToDo get working in IE 6-7
|
* ToDo get working in IE 6-7
|
||||||
*/
|
*/
|
||||||
$('.ss-gridfield input.ss-gridfield-sort').entwine({
|
$('fieldset.ss-gridfield input.ss-gridfield-sort').entwine({
|
||||||
onfocusin: function(e) {
|
onfocusin: function(e) {
|
||||||
// Dodgy results in IE <=7
|
// Dodgy results in IE <=7
|
||||||
if($.browser.msie && $.browser.version <= 7) {
|
if($.browser.msie && $.browser.version <= 7) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user