From 5147b37a3285a231d8c938c3baf2f216a3b7f197 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 17 Oct 2011 10:04:44 +0200 Subject: model sorting for endpoints| pager for models --- views/models_navigation_bottom.haml | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 views/models_navigation_bottom.haml (limited to 'views/models_navigation_bottom.haml') diff --git a/views/models_navigation_bottom.haml b/views/models_navigation_bottom.haml new file mode 100644 index 0000000..abea2d4 --- /dev/null +++ b/views/models_navigation_bottom.haml @@ -0,0 +1,47 @@ +.models_navigation + - js = "" + %form{:name => "nav_bottom", :action => url_for('/models'), :method => "get", :id => "nav"} + %input{:type => :hidden, :name => :sort_by, :id => "sort_by", :value => params[:sort_by]} + %input{:type => :hidden, :name => :order, :id => "order", :value => params[:order]} + %input{:type => :hidden, :name => :page, :id => "page", :value => params[:page]} + + - if @models.size > 5 + Models: + - if @models.size < 5*@page+5 + - last = @models.size + - else + - last = 5*@page+5 + = "#{5*@page+1}-#{last} / #{@models.size}" + | Page: + - unless @page.to_i == 0 + #prevbot{:class => "link"} + %img{:src => "arrow_left.png", :alt => 'previous', :title => 'previous'}/ + -else + %img{:src => "arrow_left_inactive.png", :alt => '', :title => ''}/ + + - (0..(@models.size/5).to_f.ceil-1).each do |p| + -if p != @page.to_f + %a{:href => '#', :id => "page_linkbot_#{p}", :class => "page page_link"} #{p+1} + - js += "$('#page_linkbot_#{p}').click(function() \{ \n" + - js += " $('#page').val('#{p}');\n" + - js += " $('#nav').submit();\n" + - js += "});\n" + -else + %span{:class => "page page_active"} #{p+1} + + - unless 5*@page.to_i+5 >= @models.size + #nextbot{:class => "link"} + %img{:src => "arrow_right.png", :alt => 'next', :title => 'next'}/ + -else + %img{:src => "arrow_right_inactive.png", :alt => '', :title => ''}/ + + :javascript + $("#prevbot").click(function() { + $("#page").val(#{@page-1}); + $("#nav").submit(); + }); + $("#nextbot").click(function() { + $("#page").val(#{@page+1}); + $("#nav").submit(); + }); + #{js} \ No newline at end of file -- cgit v1.2.3 From f60f559c98343b36ed50cfba1a365f2738f59a68 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 17 Oct 2011 12:32:27 +0200 Subject: clean code for navigation --- views/models_navigation_bottom.haml | 77 +++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 41 deletions(-) (limited to 'views/models_navigation_bottom.haml') diff --git a/views/models_navigation_bottom.haml b/views/models_navigation_bottom.haml index abea2d4..b2425fa 100644 --- a/views/models_navigation_bottom.haml +++ b/views/models_navigation_bottom.haml @@ -1,47 +1,42 @@ .models_navigation - js = "" - %form{:name => "nav_bottom", :action => url_for('/models'), :method => "get", :id => "nav"} - %input{:type => :hidden, :name => :sort_by, :id => "sort_by", :value => params[:sort_by]} - %input{:type => :hidden, :name => :order, :id => "order", :value => params[:order]} - %input{:type => :hidden, :name => :page, :id => "page", :value => params[:page]} + - if @models.size > 5 + Models: + - if @models.size < 5*@page+5 + - last = @models.size + - else + - last = 5*@page+5 + = "#{5*@page+1}-#{last} / #{@models.size}" + | Page: + - unless @page.to_i == 0 + #prevbot{:class => "link"} + %img{:src => "arrow_left.png", :alt => 'previous', :title => 'previous'}/ + -else + %img{:src => "arrow_left_inactive.png", :alt => '', :title => ''}/ - - if @models.size > 5 - Models: - - if @models.size < 5*@page+5 - - last = @models.size - - else - - last = 5*@page+5 - = "#{5*@page+1}-#{last} / #{@models.size}" - | Page: - - unless @page.to_i == 0 - #prevbot{:class => "link"} - %img{:src => "arrow_left.png", :alt => 'previous', :title => 'previous'}/ + - (0..(@models.size/5).to_f.ceil-1).each do |p| + -if p != @page.to_f + %a{:href => '#', :id => "page_linkbot_#{p}", :class => "page page_link"} #{p+1} + - js += "$('#page_linkbot_#{p}').click(function() \{ \n" + - js += " $('#page').val('#{p}');\n" + - js += " $('#nav').submit();\n" + - js += "});\n" -else - %img{:src => "arrow_left_inactive.png", :alt => '', :title => ''}/ + %span{:class => "page page_active"} #{p+1} - - (0..(@models.size/5).to_f.ceil-1).each do |p| - -if p != @page.to_f - %a{:href => '#', :id => "page_linkbot_#{p}", :class => "page page_link"} #{p+1} - - js += "$('#page_linkbot_#{p}').click(function() \{ \n" - - js += " $('#page').val('#{p}');\n" - - js += " $('#nav').submit();\n" - - js += "});\n" - -else - %span{:class => "page page_active"} #{p+1} + - unless 5*@page.to_i+5 >= @models.size + #nextbot{:class => "link"} + %img{:src => "arrow_right.png", :alt => 'next', :title => 'next'}/ + -else + %img{:src => "arrow_right_inactive.png", :alt => '', :title => ''}/ - - unless 5*@page.to_i+5 >= @models.size - #nextbot{:class => "link"} - %img{:src => "arrow_right.png", :alt => 'next', :title => 'next'}/ - -else - %img{:src => "arrow_right_inactive.png", :alt => '', :title => ''}/ - - :javascript - $("#prevbot").click(function() { - $("#page").val(#{@page-1}); - $("#nav").submit(); - }); - $("#nextbot").click(function() { - $("#page").val(#{@page+1}); - $("#nav").submit(); - }); - #{js} \ No newline at end of file + :javascript + $("#prevbot").click(function() { + $("#page").val(#{@page-1}); + $("#nav").submit(); + }); + $("#nextbot").click(function() { + $("#page").val(#{@page+1}); + $("#nav").submit(); + }); + #{js} \ No newline at end of file -- cgit v1.2.3