allow to preselect order view

This commit is contained in:
wvengen 2014-01-17 15:03:46 +01:00
parent 1129cf4094
commit 65041c78c5
3 changed files with 12 additions and 17 deletions

View File

@ -28,16 +28,17 @@ class OrdersController < ApplicationController
# Renders also the pdf
def show
@order= Order.find(params[:id])
@view = (params[:view] or 'default').gsub(/[^-_a-zA-Z0-9]/, '')
respond_to do |format|
@partial = case @view
when 'default' then "articles"
when 'groups'then 'shared/articles_by_groups'
when 'articles'then 'shared/articles_by_articles'
else 'articles'
end
format.html
format.js do
@partial = case params[:view]
when 'default' then "articles"
when 'groups'then 'shared/articles_by_groups'
when 'articles'then 'shared/articles_by_articles'
else 'articles'
end
render :layout => false
end
format.pdf do

View File

@ -2,7 +2,8 @@
module OrdersHelper
def update_articles_link(order, text, view, options={})
options.merge!({remote: true, id: "view_#{view}_btn"})
options = {remote: true, id: "view_#{view}_btn", class: ''}.merge(options)
options[:class] += ' active' if view.to_s == @view.to_s
link_to text, order_path(order, view: view), options
end

View File

@ -41,7 +41,7 @@
.btn-toolbar
.btn-group.view_buttons
= update_articles_link @order, t('.articles'), :default, class: 'btn active'
= update_articles_link @order, t('.articles'), :default, class: 'btn'
= update_articles_link @order, t('.sort_group'), :groups, class: 'btn'
= update_articles_link @order, t('.sort_article'), :articles, class: 'btn'
@ -69,15 +69,8 @@
class: 'btn btn-danger'
-# unless @order.open?
%ul.nav.nav-pills
%li= update_articles_link(@order, t('.articles'), :default)
%li= update_articles_link(@order, t('.sort_group'), :groups)
%li= update_articles_link(@order, t('.sort_article'), :articles)
%li= link_to t('.comments_link'), '#comments'
%section#articles_table
= render 'articles', order: @order
= render @partial, order: @order
%h2= t '.comments.title'
#comments
@ -103,5 +96,5 @@
$('#query').attr('placeholder', placeholder);
}
$(function() {
activate_search('default', '#{j t('.search_placeholder.default')}');
activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
});