Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Generate proper URLs server side instead of munging them entirely wit…

…h javascript
  • Loading branch information...
commit 037a29a131b3922c70ca18e081a6350624bc7f65 1 parent 43c53b2
@rmg authored
View
4 lib/assets/javascripts/magic_grid.js
@@ -48,7 +48,7 @@ $(function () {
if (this.is("[data-searcher]")) {
params[this.attr('id') + '_q'] = $("#" + this.data("searcher")).val();
}
- return $.extend({}, this.find('thead').data("params"), params);
+ return $.extend({}, params);
}
// Default handler for ajax events that displays 'Loading...' in
@@ -61,7 +61,7 @@ $(function () {
$(".magic_grid[data-remote=true]").on( "click", ".pagination a, .sorter a", function (e) {
var $grid = $(e.delegateTarget),
- url = this.href + "&" + $.param($grid.getGridParams());
+ url = this.href;
$grid.trigger("magic_grid:loading");
$grid.load(url + ' #' + $grid.attr('id') + " > *");
return false;
View
4 lib/magic_grid/definition.rb
@@ -178,6 +178,10 @@ def param(key, default=nil)
@params.fetch(param_key(key), default)
end
+ def base_params
+ @params.select { |k,_| accepted.include? k.to_sym }.merge :magic_grid_id => @magic_id
+ end
+
def order(something)
case something
when 1, "1", :desc, :DESC, "desc", "DESC"
View
22 lib/magic_grid/helpers.rb
@@ -21,7 +21,7 @@ def magic_collection(collection, cols, opts = {})
def magic_grid(collection = nil, cols = nil, opts = {}, &block)
grid = normalize_magic(collection, cols, opts)
- passed_params = params.select { |k,_| grid.accepted.include? k.to_sym }
+ base_params = grid.base_params
data = {
:searcher => grid.options[:searcher],
:current => url_for,
@@ -29,7 +29,7 @@ def magic_grid(collection = nil, cols = nil, opts = {}, &block)
:listeners => (grid.options[:listeners] unless grid.options[:listeners].empty?),
:remote => grid.options[:remote],
:default_ajax_handler => grid.options[:default_ajax_handler],
- :params => passed_params,
+ :params => base_params,
}
classes = ['magic_grid'] << grid.options[:class]
content_tag('table',
@@ -37,7 +37,7 @@ def magic_grid(collection = nil, cols = nil, opts = {}, &block)
:id => grid.magic_id,
:data => data.select {|_,v| v }
) do
- table = content_tag('thead', :data => {:params => passed_params}
+ table = content_tag('thead', :data => {:params => base_params}
) do
thead = ''.html_safe
has_spinner = false
@@ -71,7 +71,8 @@ def magic_grid(collection = nil, cols = nil, opts = {}, &block)
content_tag('td', :class => 'full-width ui-widget-header',
:colspan => grid.columns.count) do
pager = will_paginate(grid.collection,
- :param_name => grid.param_key(:page)
+ :param_name => grid.param_key(:page),
+ :params => base_params
)
unless has_spinner
has_spinner = true
@@ -104,7 +105,8 @@ def magic_grid(collection = nil, cols = nil, opts = {}, &block)
content_tag('td', :class => 'full-width ui-widget-header',
:colspan => grid.columns.count) do
will_paginate(grid.collection,
- :param_name => grid.param_key(:page)
+ :param_name => grid.param_key(:page),
+ :params => base_params
)
end
end
@@ -207,13 +209,9 @@ def sortable_header(grid, col, opts = {})
id = col[:id]
label = col[:label] || id.titleize
default_sort_order = opts.fetch(:default_order, grid.order(grid.default_order))
- my_params = params.select do |k,v|
- grid.accepted.include? k.to_sym
- end
- my_params = my_params.merge({grid.param_key(:col) => id})
- if grid.options[:remote]
- my_params[:magic_grid_id] = grid.magic_id
- end
+ my_params = grid.base_params.merge({
+ grid.param_key(:col) => id,
+ })
my_params = HashWithIndifferentAccess.new(my_params)
order = nil
classes = ['sorter ui-state-default'] << col[:class]
Please sign in to comment.
Something went wrong with that request. Please try again.