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; }
}
// get rid of extra bottom margin inside well
.well p:last-child {
margin-bottom: 0;
}
// center table rows vertically (including form elements)
table.table {
td, th {

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]/, '')
@partial = case @view
when 'default' then 'articles'
when 'groups'then 'shared/articles_by_groups'
when 'articles'then 'shared/articles_by_articles'
else 'articles'
end
respond_to do |format|
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

@ -1,8 +1,10 @@
# encoding: utf-8
module OrdersHelper
def update_articles_link(order, text, view)
link_to text, order_path(order, view: view), remote: true
def update_articles_link(order, text, view, options={})
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
def order_pdf(order, document, text)
@ -78,4 +80,23 @@ module OrdersHelper
input_html.html_safe
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

View File

@ -10,9 +10,9 @@
%th= 'Members'
%th= t '.units_full'
- total_net, total_gross, counter = 0, 0, 0
%tbody
%tbody.list
- order.articles_grouped_by_category.each do |category_name, order_articles|
%tr.article-category
%tr.list-heading.article-category
%td
= category_name
%i.icon-tag
@ -26,7 +26,7 @@
- total_gross += units * unit_quantity * gross_price
- cssclass = (units > 0 ? 'used' : (order_article.quantity > 0 ? 'unused' : 'unavailable'))
%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= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}"
- 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,65 +1,100 @@
- 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
= t '.warn_not_closed'
// Order summary
.well
%dl.dl-horizontal
%dt= heading_helper(Order, :name) + ':'
%dd= @order.name
- if @note.present?
%dt= heading_helper(Order, :note) + ':'
%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
.well.well-small
.btn-toolbar
.form-search.pull-right
.input-append
= text_field_tag :query, params[:query], class: 'search-query delayed-search resettable'
%button.add-on.btn.reset-search{:type => :button, :title => t('.search_reset')}
%i.icon.icon-remove
.form-actions
- if @order.open?
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
= link_to t('.action_end'), finish_order_path(@order), method: :post, class: 'btn btn-success',
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'
.btn-toolbar
.btn-group.view_buttons
= 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'
- unless @order.open?
.btn-group
= link_to '#', class: 'btn dropdown-toggle', data: {toggle: 'dropdown'} do
= t '.download.title'
%span.caret
%ul.dropdown-menu
%li= order_pdf(@order, :groups, t('.download.group_pdf'))
%li= order_pdf(@order, :articles, t('.download.article_pdf'))
%li= order_pdf(@order, :matrix, t('.download.matrix_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')}
- 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'
- 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'
%li.dropdown
= link_to '#', class: 'dropdown-toggle', data: {toggle: 'dropdown'} do
= t '.download.title'
%b.caret
%ul.dropdown-menu
%li= order_pdf(@order, :groups, t('.download.group_pdf'))
%li= order_pdf(@order, :articles, t('.download.article_pdf'))
%li= order_pdf(@order, :matrix, t('.download.matrix_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')}
%section#articles_table
= render 'articles', order: @order
= render @partial, order: @order
%h2= t '.comments.title'
#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)}
= 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
%thead
%table.table.table-hover.list
%thead.list-heading
%tr
%th{:style => 'width:70%'}= t '.ordergroup'
%th
@ -9,12 +9,11 @@
%th= t '.price'
- for order_article in order.order_articles.ordered.all(:include => [:article, :article_price])
%thead
%tbody
%tr
%th{:colspan => "4"}
%th.name{:colspan => "4"}
= order_article.article.name
= "(#{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
%tr{:class => [cycle('even', 'odd', :name => 'groups'), if goa.result == 0 then 'unavailable' end]}
%td{:style => "width:70%"}=h goa.group_order.ordergroup.name

View File

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

View File

@ -184,7 +184,9 @@ en:
order: Order
order_article: Order article
order_comment: Order comment
ordergroup: Ordergroup
ordergroup:
one: Ordergroup
other: Ordergroups
stock_article: Stock article
stock_taking: Stock taking
supplier: Supplier
@ -1169,6 +1171,8 @@ en:
confirm_end: ! 'Do you really want to close the order %{order}?
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:
article_pdf: Article PDF
download_file: Download file
@ -1178,6 +1182,11 @@ en:
matrix_pdf: Matrix PDF
title: Download
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_group: Sorted in groups
title: ! 'Order: %{name}'