silverstripe-framework/javascript/GridField.js
Stig Lindqvist 3c516b7b97 API CHANGE: Refactored GridField modifiers into GridField_ColumnProvider, GridField_HTMLProvider, GridField_ActionProvider, and GridField_DataModifier interfaces, all added as components in the config.
API CHANGE: Simplified state handling so that it's just a key store. Affectors are replaced with GridField_ActionProviders. API CHANGE: Removed GridField state manipulation actions instead opting for GridField_ActionProvider actions.
API CHANGE: Removed support for modifiers that add "body" rows, instead having core support for generating the body rows hardcoded into the GridField.
API CHANGE: Allow modification of columns across the whole GridField with the GridField_ColumnProvider interface.
API CHANGE: Renamed GridField_AlterAction to GridField_Action, and added actionName/args parameters, since it can be used for all actions (including batch actions and row actions)
API CHANGE: Removed GridFieldRow class.
2012-01-09 13:30:34 +13:00

70 lines
2.3 KiB
JavaScript

jQuery(function($){
$('.ss-gridfield .action').entwine({
onclick: function(e){
button = this;
e.preventDefault();
var form = $(this).closest("form");
form.addClass('loading');
$.ajax({
type: "POST",
url: form.attr('action'),
data: form.serialize()+'&'+escape(button.attr('name'))+'='+escape(button.val()),
dataType: 'html',
success: function(data) {
form.replaceWith(data);
form.removeClass('loading');
},
error: function(e) {
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fetching data from the server\n Please try again later.'));
form.removeClass('loading');
}
});
}
});
var removeFilterButtons = function() {
// Remove stuff
$('th').children('div').each(function(i,v) {
$(v).remove();
});
}
/*
* Upon focusing on a filter <input> element, move "filter" and "reset" buttons and display next to the current <input> element
* 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({
onfocusin: function(e) {
// Dodgy results in IE <=7
if($.browser.msie && $.browser.version <= 7) {
return false;
}
var eleInput = $(this);
// Remove existing <div> and <button> elements in-lieu of cloning
removeFilterButtons();
var eleButtonSetFilter = $('#action_filter');
var eleButtonResetFilter = $('#action_reset');
// Retain current widths to ensure <th>'s don't shift widths
var eleButtonWidth = eleButtonSetFilter.width();
// Check <th> doesn't already have an (extra) cloned <button> appended, otherwise clone
if(eleInput.closest('th').children().length == 1) {
var newButtonCss = {
'position':'absolute',
'top':'-23px',
'left':'0',
'border':'#EEE solid 1px',
'padding':'0',
'margin-left':'0'
};
// Append a <div> element used purely for CSS positioning - table elements on their own are untrustworthy to style in this manner
$('<div/>').append(
eleButtonSetFilter.clone().css(newButtonCss),
eleButtonResetFilter.clone().css(newButtonCss).css('left',(eleButtonWidth+4)+'px')
).css({'position':'relative','margin':'0 auto','width':'65%'}).appendTo(eleInput.closest('th'));
}
}
});
});