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 # Renders also the pdf
def show def show
@order= Order.find(params[:id]) @order= Order.find(params[:id])
@view = (params[:view] or 'default').gsub(/[^-_a-zA-Z0-9]/, '')
respond_to do |format| 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.html
format.js do 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 render :layout => false
end end
format.pdf do format.pdf do

View file

@ -2,7 +2,8 @@
module OrdersHelper module OrdersHelper
def update_articles_link(order, text, view, options={}) 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 link_to text, order_path(order, view: view), options
end end

View file

@ -41,7 +41,7 @@
.btn-toolbar .btn-toolbar
.btn-group.view_buttons .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_group'), :groups, class: 'btn'
= update_articles_link @order, t('.sort_article'), :articles, class: 'btn' = update_articles_link @order, t('.sort_article'), :articles, class: 'btn'
@ -69,15 +69,8 @@
class: 'btn btn-danger' 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 %section#articles_table
= render 'articles', order: @order = render @partial, order: @order
%h2= t '.comments.title' %h2= t '.comments.title'
#comments #comments
@ -103,5 +96,5 @@
$('#query').attr('placeholder', placeholder); $('#query').attr('placeholder', placeholder);
} }
$(function() { $(function() {
activate_search('default', '#{j t('.search_placeholder.default')}'); activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
}); });