Project

General

Profile

Patch #7594 » proper-pagination-1.1.0.patch

bugfix1 - Brian Lindahl, 2011-02-09 22:00

View differences:

redmine-1.1.0-proper-pagination/app/helpers/application_helper.rb 2011-02-09 12:42:19.711990100 -0700
327 327

  
328 328
    html = ''
329 329
    if paginator.current.previous
330
      html << link_to_remote_content_update('&#171; ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
330
      html << pagination_link('&#171; ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
331 331
    end
332 332

  
333 333
    html << (pagination_links_each(paginator, options) do |n|
334
      link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
334
      pagination_link(n.to_s, url_param.merge(page_param => n))
335 335
    end || '')
336 336
    
337 337
    if paginator.current.next
338
      html << ' ' + link_to_remote_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
338
      html << ' ' + pagination_link((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
339 339
    end
340 340

  
341 341
    unless count.nil?
......
353 353
    url_param.clear if url_param.has_key?(:set_filter)
354 354

  
355 355
    links = Setting.per_page_options_array.collect do |n|
356
      n == selected ? n : link_to_remote(n, {:update => "content",
357
                                             :url => params.dup.merge(:per_page => n),
358
                                             :method => :get},
359
                                            {:href => url_for(url_param.merge(:per_page => n))})
356
      n == selected ? n : pagination_link(n, url_param.merge(:per_page => n))
360 357
    end
361 358
    links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
362 359
  end
363 360
  
361
  def pagination_link(text, url_params)
362
    # !!!HACK!!!
363
    # To use direct link pagination for improved browser history and bookmarking, we want to 
364
    # trim the number of paramters down to the normal ones you'd see in an non-Ajax update link. 
365
    # However, this causes problems with some controllers, as parameters can be lost. Use a hash 
366
    # to isolate these parameters and controllers rather than implementing a real pagination fix.
367
    controller_keep_params = { "all"   => ["action", "project_id", "query_id", "page", "per_page", "controller"],
368
                               "users" => ["status", "name"] }
369
    #logger.error("#{url_params.inspect}") # peek at URL parameters for improving the above hash
370
    keep_params = (controller_keep_params['all'] << controller_keep_params[url_params['controller']]).flatten
371
    url_params.delete_if {|p, v| !keep_params.include?(p)}
372
    link_to(text, url_params)
373
  end
374
  
364 375
  def reorder_links(name, url)
365 376
    link_to(image_tag('2uparrow.png',   :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
366 377
    link_to(image_tag('1uparrow.png',   :alt => l(:label_sort_higher)),  url.merge({"#{name}[move_to]" => 'higher'}),  :method => :post, :title => l(:label_sort_higher)) +
(2-2/2)