Merge pull request #234 from foodcoop-adam/article-dialog

introduce new layout in balancing article screen as well
This commit is contained in:
wvengen 2014-01-03 05:16:03 -08:00
commit 436ebc0190
4 changed files with 51 additions and 45 deletions

View file

@ -7,35 +7,14 @@
.modal-body .modal-body
= f.input :availability = f.input :availability
= f.input :name = f.input :name
.fold-line
= f.input :unit_quantity, label: Article.human_attribute_name(:unit), = render partial: 'shared/article_fields_units', locals: {f: f}
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit_quantity)}
= f.input :unit, label: '×'.html_safe,
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit)}
= f.input :note = f.input :note
= f.association :article_category = f.association :article_category
/ TODO labels / TODO labels
.fold-line = render partial: 'shared/article_fields_price', locals: {f: f}
= f.input :price do
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :price, class: 'input-mini'
= f.input :tax do
.input-append
= f.input_field :tax, class: 'input-mini'
%span.add-on %
.fold-line
= f.input :deposit do
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :deposit, class: 'input-mini'
.control-group
%label.control-label{for: 'article_fc_price'}
= Article.human_attribute_name(:fc_price)
.controls.control-text#article_fc_price
= number_to_currency(@article.fc_price) rescue nil
= f.input :origin = f.input :origin
= f.input :manufacturer = f.input :manufacturer
@ -44,14 +23,3 @@
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary' = f.submit class: 'btn btn-primary'
:javascript
var form = $('form.edit_article, form.new_article');
$('#article_price, #article_tax, #article_deposit', form).on('change keyup', function() {
var price = parseFloat($('#article_price', form).val());
var tax = parseFloat($('#article_tax', form).val());
var deposit = parseFloat($('#article_deposit', form).val());
// Article#gross_price and Article#fc_price
var gross_price = (price + deposit) * (tax / 100 + 1);
var fc_price = gross_price * (#{FoodsoftConfig[:price_markup].to_f} / 100 + 1);
$('#article_fc_price').html($.isNumeric(fc_price) ? I18n.l("currency", fc_price) : '…');
});

View file

@ -7,18 +7,16 @@
= simple_fields_for :article, @order_article.article do |f| = simple_fields_for :article, @order_article.article do |f|
= f.input :name = f.input :name
= f.input :order_number
= f.input :unit
- if @order_article.article.is_a?(StockArticle) - if @order_article.article.is_a?(StockArticle)
%div.alert= t '.stock_alert' %div.alert= t '.stock_alert'
- else - else
= simple_fields_for :article_price, @order_article.article_price do |f| = simple_fields_for :article_price, @order_article.article_price do |fprice|
= f.input :unit_quantity = render partial: 'shared/article_fields_units', locals: {f_unit: f, f_uq: fprice}
= f.input :price = render partial: 'shared/article_fields_price', locals: {f: fprice}
= f.input :tax
= f.input :deposit
= form.input :update_current_price, as: :boolean = form.input :update_current_price, as: :boolean
= f.input :order_number
.modal-footer .modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= form.submit class: 'btn btn-primary' = form.submit class: 'btn btn-primary'

View file

@ -0,0 +1,34 @@
.fold-line
= f.input :price do
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :price, class: 'input-mini'
= f.input :tax do
.input-append
= f.input_field :tax, class: 'input-mini'
%span.add-on %
.fold-line
= f.input :deposit do
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :deposit, class: 'input-mini'
.control-group
%label.control-label{for: 'article_fc_price'}
= Article.human_attribute_name(:fc_price)
.controls.control-text#article_fc_price
= number_to_currency(f.object.fc_price) rescue nil
-# do this inline, since it's being used in ajax forms only
- field = f.object.class.model_name.underscore
:javascript
var form = $('#article_fc_price').closest('form');
$('##{field}_price, ##{field}_tax, ##{field}_deposit', form).on('change keyup', function() {
var price = parseFloat($('##{field}_price', form).val());
var tax = parseFloat($('##{field}_tax', form).val());
var deposit = parseFloat($('##{field}_deposit', form).val());
// Article#gross_price and Article#fc_price
var gross_price = (price + deposit) * (tax / 100 + 1);
var fc_price = gross_price * (#{FoodsoftConfig[:price_markup].to_f} / 100 + 1);
$('#article_fc_price').html($.isNumeric(fc_price) ? I18n.l("currency", fc_price) : '…');
});

View file

@ -0,0 +1,6 @@
-# use the local 'f', or supply 'f_uq' and 'f_unit' for more control (like in balancing)
.fold-line
= (f_uq rescue f).input :unit_quantity, label: Article.human_attribute_name(:unit),
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit_quantity)}
= (f_unit rescue f).input :unit, label: '×'.html_safe,
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit)}