BUGFIX Fixed CSV exporting on GridFieldExporter (was calling action via ajax, which doesn't allow HTTP download responses)

This commit is contained in:
Ingo Schommer 2012-03-06 13:36:33 +01:00
parent dca1b0df1c
commit dc83ace928
2 changed files with 24 additions and 1 deletions

View File

@ -47,6 +47,7 @@ class GridFieldExporter implements GridField_HTMLProvider, GridField_ActionProvi
null
);
$button->setButtonIcon('exportlist');
$button->addExtraClass('no-ajax');
return array(
'after' => '<p>' . $button->Field() . '</p>',
);

View File

@ -105,6 +105,28 @@
}
});
/**
* Prevents actions from causing an ajax reload of the field.
* Useful e.g. for actions which rely on HTTP response headers being interpreted nativel
* by the browser, like file download triggers.
*/
$('.ss-gridfield .action.no-ajax').entwine({
onclick: function(e){
var self = this, btn = this.closest(':button'), grid = this.getGridField(),
form = this.closest('form'), data = form.find(':input').serialize();
// Add current button
data += '&' + encodeURIComponent(btn.attr('name')) + '=' + encodeURIComponent(btn.val());
// Include any GET parameters from the current URL, as the view state might depend on it.
// For example, a list prefiltered through external search criteria might be passed to GridField.
if(window.location.search) data = window.location.search.replace(/^\?/, '') + '&' + data;
window.location.href = $.path.makeUrlAbsolute(grid.data('url') + '?' + data, $('base').attr('href'));
return false;
}
});
$('fieldset.ss-gridfield .new-link').entwine({
onclick: function(e) {
this.getGridField().showDetailView($(this).prop('href'));