(function($){ $('fieldset.ss-gridfield').entwine({ /** * @param {Object} Additional options for jQuery.ajax() call */ reload: function(ajaxOpts, successCallback) { var self = this, form = this.closest('form'), data = form.find(':input').serializeArray(); if(!ajaxOpts) ajaxOpts = {}; if(!ajaxOpts.data) ajaxOpts.data = []; ajaxOpts.data = ajaxOpts.data.concat(data); form.addClass('loading'); $.ajax($.extend({}, { headers: {"X-Get-Fragment" : 'CurrentField'}, type: "POST", url: this.data('url'), dataType: 'html', success: function(data) { // Replace the grid field with response, not the form. self.replaceWith(data); form.removeClass('loading'); if(successCallback) successCallback.apply(this, arguments); }, 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'); } }, ajaxOpts)); }, getItems: function() { return this.find('.ss-gridfield-item'); }, /** * @param {String} * @param {Mixed} */ setState: function(k, v) { var state = this.getState(); state[k] = v; this.find(':input[name="' + this.data('name') + '[GridState]"]').val(JSON.stringify(state)); }, /** * @return {Object} */ getState: function() { return JSON.parse(this.find(':input[name="' + this.data('name') + '[GridState]"]').val()); } }); $('fieldset.ss-gridfield *').entwine({ getGridField: function() { return this.parents('fieldset.ss-gridfield:first'); } }); $('fieldset.ss-gridfield .action').entwine({ onclick: function(e){ this.getGridField().reload({data: [{name: this.attr('name'), value: this.val()}]}); e.preventDefault(); } }); /* * Upon focusing on a filter element, move "filter" and "reset" buttons and display next to the current element * ToDo ensure filter-button state is maintained after filtering (see resetState param) * ToDo get working in IE 6-7 */ $('fieldset.ss-gridfield input.ss-gridfield-sort').entwine({ onfocusin: function(e) { // Dodgy results in IE <=7 & ignore if only one filter-field countfields = $('fieldset.ss-gridfield input.ss-gridfield-sort').length; if(($.browser.msie && $.browser.version <= 7) || countfields == 1) { return false; } var eleInput = $(this); // Remove existing
and