cleanup orders and add search

Conflicts:
	app/assets/stylesheets/bootstrap_and_overrides.css.less
	app/views/orders/_articles.html.haml
	app/views/orders/show.html.haml
This commit is contained in:
wvengen 2014-01-17 13:14:49 +01:00
parent bab28d2770
commit 42d622d1b2
11 changed files with 130 additions and 70 deletions

View File

@ -246,6 +246,23 @@ 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 {
vertical-align: middle;
}
select, textarea, input, .uneditable-input,
.input-append, .input-prepend {
margin-bottom: 0;
margin-top: 0;
}
}
.settings {
.settings-group {
margin-bottom: 10px;

View File

@ -1,8 +1,9 @@
# 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.merge!({remote: true, id: "view_#{view}_btn"})
link_to text, order_path(order, view: view), options
end
def order_pdf(order, document, text)

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,59 +1,94 @@
- title t('.title', name: @order.name)
- if @order.finished? and !@order.closed?
- 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('default', '#{j t('.search_placeholder.default')}');
});
.well
%button{type: "button", class: "close", data: {dismiss: 'alert'}}= t('ui.marks.close').html_safe
%p
#{@order.state.capitalize} order from
#{link_to @order.supplier.name, supplier_path(@order.supplier)}
created by #{show_user_link @order.created_by},
open from #{format_time @order.starts} until #{format_time @order.ends}.
%br
%abbr{title: @order.group_orders.includes(:ordergroup).all.map {|g| g.ordergroup.name}.join(', ')}
#{@order.group_orders.count} #{Ordergroup.model_name.human count: @order.group_orders.count}
ordered #{@order.order_articles.ordered.count} articles with a total value of
#{number_to_currency(@order.sum(:net))} / #{number_to_currency(@order.sum(:gross))} (net / gross).
- 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 active'
= update_articles_link @order, t('.sort_group'), :groups, class: 'btn'
= update_articles_link @order, t('.sort_article'), :articles, class: 'btn'
- unless @order.open?
- 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

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

@ -1178,6 +1178,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}'