mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge remote-tracking branch 'silverstripe-scienceninjas/pull/SSF-12'
This commit is contained in:
commit
8fcb40cdf0
@ -378,7 +378,130 @@ jQuery.noConflict();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.cms-filter-form').entwine({
|
||||
|
||||
GridField: null,
|
||||
|
||||
/**
|
||||
* Function onmatch
|
||||
*
|
||||
* Try to find the related gridfield by looking up the data-gridfield attribute on this
|
||||
* filter form
|
||||
*/
|
||||
onmatch: function() {
|
||||
var gridfieldName = this.attr('data-gridfield');
|
||||
this.setGridField($('.grid[data-name='+gridfieldName+']'));
|
||||
var self = this;
|
||||
this.getGridField().bind('reload', function(e, gridfield){
|
||||
self.setFilterValues($(gridfield).getState());
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: onsubmit
|
||||
*
|
||||
* Parameters:
|
||||
* (Event) e
|
||||
*/
|
||||
onsubmit: function(e) {
|
||||
this.changeState(jQuery(this).find(':submit:first'));
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Function: setFilterValues
|
||||
*
|
||||
* Parameters:
|
||||
* (JSON) state
|
||||
*
|
||||
*/
|
||||
setFilterValues: function(state){
|
||||
var filterValues = state.GridFieldFilter.Columns;
|
||||
if(jQuery.isEmptyObject(filterValues)){
|
||||
this.resetFilterForm();
|
||||
return;
|
||||
}
|
||||
this.filterFields().each(function(idx, element) {
|
||||
if(typeof filterValues[element.name] !== "undefined") {
|
||||
$(element).val(filterValues[element.name]);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: onreset
|
||||
*
|
||||
* Parameters:
|
||||
* (Event) e
|
||||
*/
|
||||
onreset: function(e) {
|
||||
if(this.resetFilterForm()) {
|
||||
this.changeState(jQuery(this));
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function resetFilterForm
|
||||
*
|
||||
**/
|
||||
resetFilterForm: function() {
|
||||
var needUpdate = false;
|
||||
this.filterFields().each(function(idx, element) {
|
||||
if($(element).val()) {
|
||||
needUpdate = true;
|
||||
$(element).val('');
|
||||
}
|
||||
if($(element).hasClass('chzn-done')){
|
||||
$(element).trigger("liszt:updated");
|
||||
}
|
||||
});
|
||||
return needUpdate;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: changeState
|
||||
*
|
||||
* Change the state of the gridfield, reloads it's and set loading classes on elements
|
||||
*
|
||||
* Parameters:
|
||||
* (Element) element - the element that will get a loading class added / removed
|
||||
*
|
||||
*/
|
||||
changeState: function(element) {
|
||||
element.addClass('loading');
|
||||
this.getGridField().setState('GridFieldFilter', {'Columns': this.filterValues()});
|
||||
this.getGridField().reload(null, function(){
|
||||
element.removeClass('loading');
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Function filterFields
|
||||
* Get all fields that contains filter values
|
||||
*
|
||||
*/
|
||||
filterFields: function() {
|
||||
return this.find(':input').not(".action, .hidden");
|
||||
},
|
||||
|
||||
/**
|
||||
* Function: filterValues
|
||||
*
|
||||
* Returns an key-value array for the filter values set in the filter form
|
||||
*
|
||||
*/
|
||||
filterValues: function() {
|
||||
var filterColumns = {};
|
||||
this.filterFields().each(function(idx,elm){
|
||||
filterColumns[$(elm).attr('name')] = $(elm).val();
|
||||
});
|
||||
return filterColumns;
|
||||
}
|
||||
});
|
||||
}(jQuery));
|
||||
|
||||
// Backwards compatibility
|
||||
|
@ -3,6 +3,7 @@
|
||||
$('.ss-gridfield').entwine({
|
||||
/**
|
||||
* @param {Object} Additional options for jQuery.ajax() call
|
||||
* @param {successCallback} callback to call after reloading succeeded.
|
||||
*/
|
||||
reload: function(ajaxOpts, successCallback) {
|
||||
var self = this, form = this.closest('form'), data = form.find(':input').serializeArray();
|
||||
@ -25,6 +26,7 @@
|
||||
|
||||
form.removeClass('loading');
|
||||
if(successCallback) successCallback.apply(this, arguments);
|
||||
self.trigger('reload', self);
|
||||
},
|
||||
error: function(e) {
|
||||
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user