{% extends 'EPSLayout04Bundle:APY:blocks.html.twig' %} {% block grid_scripts_goto %} function {{ grid.hash }}_goto(url, data, type) { type = type || 'GET'; if (data ) { if( type != 'POST' ) { data = data + '&{{ grid.hash }}_ajax=true'; } else { data = data + '&{{ grid.hash }}[ajax]=true'; } } else { data = '{{ grid.hash }}[ajax]=true'; } $('#{{ grid.hash }}').parent().fadeTo("slow", 0.5); jQuery.ajax({ type: type, dataType : 'html', data: data, error : function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); }, complete : function(XMLHttpRequest, textStatus) { $('#{{ grid.hash }}').parent().fadeTo("slow", 1); }, success : function(data, textStatus) { $('#{{ grid.hash }}').parent().replaceWith(data); {{ grid.hash }}_initGridEvents(url); }, url : url }); return false; } {% endblock grid_scripts_goto %} {% block grid_scripts_submit_form %} function {{ grid.hash }}_submitForm(event, form, force) { key = event.which; if (window.event) { key = window.event.keyCode; //IE } if (force || key == 13 || event.type=="change") { var data = ''; $('.grid-filter-operator select, .grid-filter-input-query-from, .grid-filter-input-query-to, .grid-filter-select-query-from, .grid-filter-select-query-to', form).each(function () { if ($(this).is(':disabled') == false) { var name = $(this).attr('name'); var value = $(this).val(); if (value != null) { if ($(this).attr('multiple') == 'multiple') { for(var i= 0; i < value.length; i++) { data += '&' + name + '=' + value[i]; } } else { data += '&' + name + '=' + value; } } else { data += '&' + name + '='; } } }); {{ grid.hash }}_goto('{{ grid.routeUrl }}', data.substring(1), 'POST'); return false; } } {% endblock grid_scripts_submit_form %} {% block grid_scripts_ajax %} function {{ grid.hash }}_initGridEvents(routeurl) { // Order and pagerfanta links $('.pagination li.disabled a', '#{{ grid.hash }}').click(function (e) { return false; }); $('a.order, nav a, .pagination a', '#{{ grid.hash }}').click(function () { {{ grid.hash }}_goto(this.href); return false; }); // Reset link $('#{{ grid.hash }} a.grid-reset').click(function () { {{ grid.hash }}_reset(); return false; }); // Mass actions submit $('#{{ grid.hash }} input.submit-massaction').click(function () { var selector = $('#{{ grid.hash }} .grid_massactions select'); {{ grid.hash }}_goto('{{ grid.routeUrl }}', selector.attr('name') + '=' + selector.val(), 'POST'); return false; }); // Grid_search submit (load only one time) $('#{{ grid.hash }}_search').one('submit', function (event) { {{ grid.hash }}_submitForm(event, this, true); return false; }); $(window).trigger('grid_{{ grid.hash }}:initialized'); }; {% if ajax is defined and ajax %} {{ grid.hash }}_initGridEvents('{{ grid.routeUrl }}'); {% else %} $(document).ready(function() { {{ grid.hash }}_initGridEvents('{{ grid.routeUrl }}'); }); {% endif %} {% endblock grid_scripts_ajax %}