mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #154 from silverstripe-scienceninjas/pull/gridfield-bugfixes
BUGFIX GridField_Actions did not work in more complex Forms with tabsets...
This commit is contained in:
commit
ce795b6d8a
@ -361,17 +361,31 @@ class Form extends RequestHandler {
|
||||
// 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;
|
||||
} elseif($field = $this->checkFieldsForAction($this->Fields(), $funcName)) {
|
||||
return $field->$funcName($vars, $this, $request);
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
* Uses {@link Form->dataFieldByName()} to find a matching field,
|
||||
|
@ -337,9 +337,11 @@ class GridField extends FormField {
|
||||
'class' => "field CompositeField {$this->extraClass()}"
|
||||
);
|
||||
return
|
||||
$this->createTag('fieldset', array('id'=>$this->ID(),'class'=>'ss-gridfield'),
|
||||
implode("\n", $content['before']) .
|
||||
$this->createTag('table', $attrs, $head."\n".$foot."\n".$body) .
|
||||
implode("\n", $content['after']);
|
||||
implode("\n", $content['after'])
|
||||
);
|
||||
}
|
||||
|
||||
function getColumns() {
|
||||
@ -420,30 +422,32 @@ class GridField extends FormField {
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function gridFieldAlterAction($data, $form, $request) {
|
||||
public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) {
|
||||
$id = $data['StateID'];
|
||||
$stateChange = Session::get($id);
|
||||
$gridName = $stateChange['grid'];
|
||||
$grid = $form->Fields()->dataFieldByName($gridName);
|
||||
|
||||
$state = $this->getState(false);
|
||||
$state = $grid->getState(false);
|
||||
$state->setValue($data['GridState']);
|
||||
|
||||
$gridName = $stateChange['grid'];
|
||||
$grid = $form->Fields()->fieldByName($gridName);
|
||||
$actionName = $stateChange['actionName'];
|
||||
|
||||
$args = $stateChange['args'];
|
||||
$grid->handleAction($actionName, $args, $data);
|
||||
|
||||
// Make the form re-load it's values from the Session after redirect
|
||||
// so the changes we just made above survive the page reload
|
||||
// @todo Form really needs refactoring so we dont have to do this
|
||||
if (Director::is_ajax()) {
|
||||
switch($request->getHeader('X-Get-Fragment')) {
|
||||
case 'CurrentField':
|
||||
return $grid->FieldHolder();
|
||||
break;
|
||||
|
||||
case 'CurrentForm':
|
||||
return $form->forTemplate();
|
||||
} else {
|
||||
$data = $form->getData();
|
||||
Session::set("FormInfo.{$form->FormName()}.errors", array());
|
||||
Session::set("FormInfo.{$form->FormName()}.data", $data);
|
||||
Controller::curr()->redirectBack();
|
||||
break;
|
||||
|
||||
default:
|
||||
return $form->forTemplate();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat
|
||||
if(isset($filterArguments[$columnField])) {
|
||||
$value = $filterArguments[$columnField];
|
||||
}
|
||||
$field = new TextField('filter['.$columnField.']', 'filter['.$columnField.']', $value);
|
||||
$field = new TextField('filter['.$columnField.']', '', $value);
|
||||
$field->addExtraClass('ss-gridfield-sort');
|
||||
} else {
|
||||
$field = new LiteralField('', '');
|
||||
|
@ -68,6 +68,9 @@ class GridState extends HiddenField {
|
||||
|
||||
/** @return string */
|
||||
public function Value() {
|
||||
if(!$this->gridStateData) {
|
||||
return json_encode(array());
|
||||
}
|
||||
return json_encode($this->gridStateData->toArray());
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,21 @@
|
||||
jQuery(function($){
|
||||
|
||||
$('.ss-gridfield .action').entwine({
|
||||
$('fieldset.ss-gridfield .action').entwine({
|
||||
onclick: function(e){
|
||||
button = this;
|
||||
var button = this;
|
||||
e.preventDefault();
|
||||
var form = $(this).closest("form");
|
||||
var field = $(this).closest("fieldset.ss-gridfield");
|
||||
form.addClass('loading');
|
||||
$.ajax({
|
||||
headers: {"X-Get-Fragment" : 'CurrentField'},
|
||||
type: "POST",
|
||||
url: form.attr('action'),
|
||||
data: form.serialize()+'&'+escape(button.attr('name'))+'='+escape(button.val()),
|
||||
dataType: 'html',
|
||||
success: function(data) {
|
||||
form.replaceWith(data);
|
||||
// Replace the grid field with response, not the form.
|
||||
field.replaceWith(data);
|
||||
form.removeClass('loading');
|
||||
},
|
||||
error: function(e) {
|
||||
@ -35,7 +38,7 @@ jQuery(function($){
|
||||
* ToDo ensure filter-button state is maintained after filtering (see resetState param)
|
||||
* 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) {
|
||||
// Dodgy results in IE <=7
|
||||
if($.browser.msie && $.browser.version <= 7) {
|
||||
|
Loading…
Reference in New Issue
Block a user