Merge pull request #253 from wvengen/feature-cleaner_order_details

cleanup show order and add search
This commit is contained in:
wvengen 2014-01-29 08:44:31 -08:00
commit 3f12627aa4
12 changed files with 156 additions and 83 deletions

View file

@ -250,6 +250,11 @@ tr.unavailable {
dd { margin-left: 170px; } dd { margin-left: 170px; }
} }
// get rid of extra bottom margin inside well
.well p:last-child {
margin-bottom: 0;
}
// center table rows vertically (including form elements) // center table rows vertically (including form elements)
table.table { table.table {
td, th { td, th {

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| @partial = case @view
format.html when 'default' then 'articles'
format.js do
@partial = case params[:view]
when 'default' then "articles"
when 'groups'then 'shared/articles_by_groups' when 'groups'then 'shared/articles_by_groups'
when 'articles'then 'shared/articles_by_articles' when 'articles'then 'shared/articles_by_articles'
else 'articles' else 'articles'
end end
respond_to do |format|
format.html
format.js do
render :layout => false render :layout => false
end end
format.pdf do format.pdf do

View file

@ -1,8 +1,10 @@
# encoding: utf-8 # encoding: utf-8
module OrdersHelper module OrdersHelper
def update_articles_link(order, text, view) def update_articles_link(order, text, view, options={})
link_to text, order_path(order, view: view), remote: true 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 end
def order_pdf(order, document, text) def order_pdf(order, document, text)
@ -78,4 +80,23 @@ module OrdersHelper
input_html.html_safe input_html.html_safe
end end
def ordergroup_count(order)
group_orders = order.group_orders.includes(:ordergroup)
txt = "#{group_orders.count} #{Ordergroup.model_name.human count: group_orders.count}"
if group_orders.count == 0
return txt
else
desc = group_orders.all.map {|g| g.ordergroup.name}.join(', ')
content_tag(:abbr, txt, title: desc).html_safe
end
end
def supplier_link(order_or_supplier)
if order_or_supplier.kind_of?(Order) and order_or_supplier.stockit?
link_to(order_or_supplier.name, stock_articles_path).html_safe
else
link_to(@order.supplier.name, supplier_path(@order.supplier)).html_safe
end
end
end end

View file

@ -10,9 +10,9 @@
%th= 'Members' %th= 'Members'
%th= t '.units_full' %th= t '.units_full'
- total_net, total_gross, counter = 0, 0, 0 - total_net, total_gross, counter = 0, 0, 0
%tbody %tbody.list
- order.articles_grouped_by_category.each do |category_name, order_articles| - order.articles_grouped_by_category.each do |category_name, order_articles|
%tr.article-category %tr.list-heading.article-category
%td %td
= category_name = category_name
%i.icon-tag %i.icon-tag
@ -26,7 +26,7 @@
- total_gross += units * unit_quantity * gross_price - total_gross += units * unit_quantity * gross_price
- cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable')) - cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable'))
%tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass} %tr{:class => cycle('even', 'odd', :name => 'articles') + ' ' + cssclass}
%td=h order_article.article.name %td.name=h order_article.article.name
%td= order_article.article.unit %td= order_article.article.unit
%td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}"
- if order.stockit? - if order.stockit?

View file

@ -0,0 +1 @@
$('#orders_table').html('<%= escape_javascript(render('orders')) %>');

View file

@ -1 +0,0 @@
$('#orders_table').html('#{escape_javascript(render('orders'))}');

View file

@ -1,53 +1,55 @@
- title t('.title', name: @order.name) - title t('.title', name: @order.name)
- if @order.finished? and !@order.closed? .well
%button{type: "button", class: "close", data: {dismiss: 'alert'}}= t('ui.marks.close').html_safe
%p
= raw t '.description1',
state: t("orders.state.#{@order.state}").capitalize,
supplier: supplier_link(@order),
who: show_user_link(@order.created_by),
starts: format_time(@order.starts),
ends: format_time(@order.ends)
%br
= raw t '.description2',
ordergroups: ordergroup_count(@order),
article_count: @order.order_articles.ordered.count,
net_sum: number_to_currency(@order.sum(:net)),
gross_sum: number_to_currency(@order.sum(:gross))
- unless @order.comments.blank?
= link_to t('.comments_link'), '#comments'
- if @note.present?
%p
= heading_helper(Order, :note) + ': '
= @order.note
-# Proposing to remove this warning, since there is a valid period when the order is not settled yet.
-# Perhaps when the pickup day has been, or when the order isn't settled a week after it has been
-# closed, this message could be shown.
-#- if @order.finished? and !@order.closed?
.alert.alert-warning .alert.alert-warning
= t '.warn_not_closed' = t '.warn_not_closed'
// Order summary .well.well-small
.well .btn-toolbar
%dl.dl-horizontal .form-search.pull-right
%dt= heading_helper(Order, :name) + ':' .input-append
%dd= @order.name = text_field_tag :query, params[:query], class: 'search-query delayed-search resettable'
- if @note.present? %button.add-on.btn.reset-search{:type => :button, :title => t('.search_reset')}
%dt= heading_helper(Order, :note) + ':' %i.icon.icon-remove
%dd= @order.note
%dt= heading_helper(Order, :created_by) + ':'
%dd= show_user_link(@order.created_by)
%dt= heading_helper(Order, :starts) + ':'
%dd= format_time(@order.starts)
%dt= heading_helper(Order, :ends) + ':'
%dd= format_time(@order.ends)
%dt= t '.group_orders'
%dd #{@order.group_orders.count} (#{@order.group_orders.includes(:ordergroup).all.map {|g| g.ordergroup.name}.join(', ')})
%dt= t '.amounts'
%dd= "#{number_to_currency(@order.sum(:net))} / #{number_to_currency(@order.sum(:gross))}"
%dt= t '.articles_ordered'
%dd= @order.order_articles.ordered.count
.btn-toolbar
.form-actions .btn-group.view_buttons
- if @order.open? = update_articles_link @order, t('.articles'), :default, class: 'btn'
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn' = update_articles_link @order, t('.sort_group'), :groups, class: 'btn'
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success', = update_articles_link @order, t('.sort_article'), :articles, class: 'btn'
confirm: t('.confirm_end', order: @order.name)
- elsif not @order.closed? and not @order.stockit?
-# TODO btn-success class only if not received before
= link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success'
- unless @order.closed?
= link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete,
class: 'btn btn-danger'
- unless @order.open? - unless @order.open?
%ul.nav.nav-pills .btn-group
%li= update_articles_link(@order, t('.articles'), :default) = link_to '#', class: 'btn dropdown-toggle', data: {toggle: 'dropdown'} do
%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'
%li.dropdown
= link_to '#', class: 'dropdown-toggle', data: {toggle: 'dropdown'} do
= t '.download.title' = t '.download.title'
%b.caret %span.caret
%ul.dropdown-menu %ul.dropdown-menu
%li= order_pdf(@order, :groups, t('.download.group_pdf')) %li= order_pdf(@order, :groups, t('.download.group_pdf'))
%li= order_pdf(@order, :articles, t('.download.article_pdf')) %li= order_pdf(@order, :articles, t('.download.article_pdf'))
@ -55,11 +57,44 @@
%li= order_pdf(@order, :fax, t('.download.fax_pdf')) %li= order_pdf(@order, :fax, t('.download.fax_pdf'))
%li= link_to t('.download.fax_txt'), order_path(@order, format: :txt), {title: t('.download.download_file')} %li= link_to t('.download.fax_txt'), order_path(@order, format: :txt), {title: t('.download.download_file')}
- if @order.open?
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
confirm: t('.confirm_end', order: @order.name)
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
- elsif not @order.closed? and not @order.stockit?
-# TODO btn-success class only if not received before
= link_to t('orders.index.action_receive'), receive_order_path(@order), class: 'btn btn-success'
- unless @order.closed?
= link_to t('ui.delete'), @order, confirm: t('.confirm_delete'), method: :delete,
class: 'btn btn-danger'
%section#articles_table %section#articles_table
= render 'articles', order: @order = render @partial, order: @order
%h2= t '.comments.title' %h2= t '.comments.title'
#comments #comments
= render partial: 'shared/comments', locals: { comments: @order.comments } = render partial: 'shared/comments', locals: { comments: @order.comments }
#new_comment= render partial: 'order_comments/form', locals: { order_comment: @order.comments.build(user: current_user)} #new_comment= render partial: 'order_comments/form', locals: { order_comment: @order.comments.build(user: current_user)}
= link_to_top = link_to_top
- content_for :javascript do
:javascript
function activate_search(view, placeholder) {
new List(document.body, {
valueNames: ['name'],
engine: 'unlist',
plugins: [
['reset', {highlightClass: 'btn-primary'}],
['delay', {delayedSearchTime: 500}],
],
// make large pages work too (as we don't have paging)
page: 10000,
indexAsync: true
});
$('#query').attr('placeholder', placeholder);
}
$(function() {
activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
});

View file

@ -0,0 +1,7 @@
$('#articles_table').html('<%= j render(@partial, order: @order) %>');
$('.view_buttons a').each(function() {
$(this).toggleClass('active', $(this).attr('id') == 'view_<%= j params[:view] %>_btn');
});
activate_search('<%= j params[:view] %>', '<%= j I18n.t("orders.show.search_placeholder.#{params[:view]}") %>');

View file

@ -1,2 +0,0 @@
$('#articles_table').html('#{escape_javascript(render(@partial, order: @order))}');

View file

@ -1,5 +1,5 @@
%table.table.table-hover %table.table.table-hover.list
%thead %thead.list-heading
%tr %tr
%th{:style => 'width:70%'}= t '.ordergroup' %th{:style => 'width:70%'}= t '.ordergroup'
%th %th
@ -9,12 +9,11 @@
%th= t '.price' %th= t '.price'
- for order_article in order.order_articles.ordered.all(:include => [:article, :article_price]) - for order_article in order.order_articles.ordered.all(:include => [:article, :article_price])
%thead %tbody
%tr %tr
%th{:colspan => "4"} %th.name{:colspan => "4"}
= order_article.article.name = order_article.article.name
= "(#{order_article.article.unit} | #{order_article.price.unit_quantity} | #{number_to_currency(order_article.price.gross_price)})" = "(#{order_article.article.unit} | #{order_article.price.unit_quantity} | #{number_to_currency(order_article.price.gross_price)})"
%tbody
- for goa in order_article.group_order_articles.ordered - for goa in order_article.group_order_articles.ordered
%tr{:class => [cycle('even', 'odd', :name => 'groups'), if goa.result == 0 then 'unavailable' end]} %tr{:class => [cycle('even', 'odd', :name => 'groups'), if goa.result == 0 then 'unavailable' end]}
%td{:style => "width:70%"}=h goa.group_order.ordergroup.name %td{:style => "width:70%"}=h goa.group_order.ordergroup.name

View file

@ -1,5 +1,5 @@
%table.table.table-hover %table.table.table-hover.list
%thead %thead.list-heading
%tr %tr
%th{:style => "width:40%"}= heading_helper Article, :name %th{:style => "width:40%"}= heading_helper Article, :name
%th %th
@ -14,18 +14,17 @@
%th= t '.price' %th= t '.price'
- for group_order in order.group_orders.ordered - for group_order in order.group_orders.ordered
%thead %tbody
%tr %tr
%th{:colspan => "7"} %th{:colspan => "7"}
%h4= group_order.ordergroup.name %h4.name= group_order.ordergroup.name
%tbody
- total = 0 - total = 0
- for goa in group_order.group_order_articles.ordered.all(:include => :order_article) - for goa in group_order.group_order_articles.ordered.all(:include => :order_article)
- fc_price = goa.order_article.price.fc_price - fc_price = goa.order_article.price.fc_price
- subTotal = fc_price * goa.result - subTotal = fc_price * goa.result
- total += subTotal - total += subTotal
%tr{:class => [cycle('even', 'odd', :name => 'articles'), if goa.result == 0 then 'unavailable' end]} %tr{:class => [cycle('even', 'odd', :name => 'articles'), if goa.result == 0 then 'unavailable' end]}
%td{:style => "width:40%"}=h goa.order_article.article.name %td.name{:style => "width:40%"}=h goa.order_article.article.name
%td= "#{goa.quantity} + #{goa.tolerance}" %td= "#{goa.quantity} + #{goa.tolerance}"
%td %td
%b= goa.result %b= goa.result
@ -33,7 +32,6 @@
%td= goa.order_article.price.unit_quantity %td= goa.order_article.price.unit_quantity
%td= goa.order_article.article.unit %td= goa.order_article.article.unit
%td= number_to_currency(subTotal) %td= number_to_currency(subTotal)
%tr{:class => cycle('even', 'odd', :name => 'articles')} %tr{:class => cycle('even', 'odd', :name => 'articles')}
%th{:colspan => "6"} Summe %th{:colspan => "6"} Summe
%th= number_to_currency(total) %th= number_to_currency(total)

View file

@ -184,7 +184,9 @@ en:
order: Order order: Order
order_article: Order article order_article: Order article
order_comment: Order comment order_comment: Order comment
ordergroup: Ordergroup ordergroup:
one: Ordergroup
other: Ordergroups
stock_article: Stock article stock_article: Stock article
stock_taking: Stock taking stock_taking: Stock taking
supplier: Supplier supplier: Supplier
@ -1169,6 +1171,8 @@ en:
confirm_end: ! 'Do you really want to close the order %{order}? confirm_end: ! 'Do you really want to close the order %{order}?
There is no going back.' There is no going back.'
description1: ! '%{state} order from %{supplier} created by %{who}, open from %{starts} until %{ends}.'
description2: ! '%{ordergroups} ordered %{article_count} articles, with a total value of %{net_sum} / %{gross_sum} (net / gross).'
download: download:
article_pdf: Article PDF article_pdf: Article PDF
download_file: Download file download_file: Download file
@ -1178,6 +1182,11 @@ en:
matrix_pdf: Matrix PDF matrix_pdf: Matrix PDF
title: Download title: Download
group_orders: ! 'Group orders:' group_orders: ! 'Group orders:'
search_placeholder:
default: Search for articles...
groups: Search for ordergroups...
articles: Search for articles...
search_reset: Reset search
sort_article: Sorted in articles sort_article: Sorted in articles
sort_group: Sorted in groups sort_group: Sorted in groups
title: ! 'Order: %{name}' title: ! 'Order: %{name}'