Allow to edit OrderArticle in Order#receive form

This commit is contained in:
Julius 2013-12-30 14:34:26 +01:00 committed by wvengen
parent 81dfe8110c
commit cf1e68f11d
6 changed files with 66 additions and 3 deletions

View file

@ -127,6 +127,12 @@ class OrdersController < ApplicationController
end end
end end
def receive_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
protected protected
# Renders the fax-text-file # Renders the fax-text-file

View file

@ -1,21 +1,28 @@
# NOTE: if you modify tiny details here you must also change them in `receive_on_order_article_update.js.erb`
= fields_for 'order_articles', order_article, index: order_article.id do |form| = fields_for 'order_articles', order_article, index: order_article.id do |form|
%tr{class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"} %tr{id: "order_article_#{order_article.id}", class: "#{cycle('even', 'odd', name: 'articles')} order-article", valign: "top"}
- order_title = [] - order_title = []
- order_title.append Article.human_attribute_name(:manufacturer)+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty? - order_title.append Article.human_attribute_name(:manufacturer)+': ' + order_article.article.manufacturer unless order_article.article.manufacturer.to_s.empty?
- order_title.append Article.human_attribute_name(:note)+': ' + order_article.article.note unless order_article.article.note.to_s.empty? - order_title.append Article.human_attribute_name(:note)+': ' + order_article.article.note unless order_article.article.note.to_s.empty?
- units_expected = (order_article.units_billed or order_article.units_to_order) - units_expected = (order_article.units_billed or order_article.units_to_order)
%td= order_article.article.order_number %td= order_article.article.order_number
%td.name{title: order_title.join("\n")}= order_article.article.name %td.name{title: order_title.join("\n")}= order_article.article.name
%td #{order_article.article.unit_quantity} &times; #{order_article.article.unit} %td.unit= order_article.article.unit
%td #{order_article.quantity} + #{order_article.tolerance} %td #{order_article.quantity} + #{order_article.tolerance}
%td %td
= order_article.units_to_order = order_article.units_to_order
%i.package pkg %i.package pkg
%span.article_unit_quantity (&times; #{order_article.article.unit_quantity})
%td.article_price= number_to_currency order_article.article.price
-#%td # TODO implement invoice screen -#%td # TODO implement invoice screen
- unless order_article.units_billed.nil? - unless order_article.units_billed.nil?
= order_article.units_billed = order_article.units_billed
%i.package pkg %i.package pkg
%td %td
= form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected} = form.text_field :units_received, class: 'input-nano package', data: {'units-expected' => units_expected}
%span.article_price_unit_quantity (&times; #{order_article.article_price.unit_quantity})
/ TODO add almost invisible text_field for entering single units / TODO add almost invisible text_field for entering single units
%td.article_price_price= number_to_currency order_article.article_price.price
%td.units_delta %td.units_delta
%td
= link_to t('ui.edit'), edit_finance_order_order_article_path(order_article.order, order_article), remote: true, class: 'btn btn-mini'

View file

@ -74,12 +74,15 @@
%tr %tr
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name %th.sort{:data => {:sort => 'string'}}= heading_helper Article, :name
%th= heading_helper GroupOrderArticle, :units %th= heading_helper Article, :unit
%th Members %th Members
%th Ordered %th Ordered
%th= heading_helper Article, :price
-#%th Invoice # TODO implement invoice screen -#%th Invoice # TODO implement invoice screen
%th Received %th Received
%th= heading_helper ArticlePrice, :price
%th %th
%th= t 'ui.actions'
%tbody#result_table %tbody#result_table
- @order_articles.each do |order_article| - @order_articles.each do |order_article|
= render :partial => 'edit_amount', :locals => {:order_article => order_article} = render :partial => 'edit_amount', :locals => {:order_article => order_article}

View file

@ -1,3 +1,18 @@
- content_for :javascript do
:javascript
$(function() {
// Subscribe to database changes.
// See publish/subscribe design pattern in /doc.
$(document).on('OrderArticle#update', function(e) {
$.ajax({
url: '#{receive_on_order_article_update_order_path(@order)}',
type: 'get',
data: {order_article_id: e.order_article_id},
contentType: 'application/json; charset=UTF-8'
});
});
});
- title "Receiving #{@order.name}" - title "Receiving #{@order.name}"
= form_tag(receive_order_path(@order)) do = form_tag(receive_order_path(@order)) do

View file

@ -0,0 +1,30 @@
// Handle more advanced DOM update after AJAX database manipulation.
// See publish/subscribe design pattern in /doc.
(function(w) {
var order_article_entry = $('#order_article_<%= @order_article.id %>');
$('.name', order_article_entry).text(
'<%= j @order_article.article.name %>'
);
$('.unit', order_article_entry).text(
'<%= j @order_article.article.unit %>'
);
$('.article_unit_quantity', order_article_entry).text(
'(× <%= @order_article.article.unit_quantity %>)'
);
$('.article_price', order_article_entry).text(
'<%= j number_to_currency @order_article.article.price %>'
);
$('.article_price_unit_quantity', order_article_entry).text(
'(× <%= @order_article.article_price.unit_quantity %>)'
);
$('.article_price_price', order_article_entry).text(
'<%= j number_to_currency @order_article.article_price.price %>'
);
})(window);

View file

@ -42,6 +42,8 @@ Foodsoft::Application.routes.draw do
get :receive get :receive
post :receive post :receive
get :add_article get :add_article
get :receive_on_order_article_update
end end
end end