foodsoft/app/views/orders/_edit_amounts.html.haml

97 lines
3.5 KiB
Text
Raw Normal View History

- new_articles = (@order.supplier.articles rescue @order.articles)
- new_article_data = articles_for_select2(new_articles, @order_articles.map(&:article_id)) {|a| "#{a.name} (#{a.unit_quantity}#{a.unit})"}
- content_for :javascript do
:javascript
function update_delta(input) {
var units = $(input).val();
var expected = $(input).data('units-expected');
var html;
if (units.replace(/\s/g,"")=="") {
// no value
html = '';
} else if (isNaN(units)) {
html = '<i class="icon-remove" style="color: red"></i>';
} else if (units == expected) {
// equal value
html = '<i class="icon-ok" style="color: green"></i>';
} else {
if (units < expected) {
html = '<span style="color: red">- '+(expected-units)+'</span>';
} else /*if (units> expected)*/ {
html = '<span style="color: green">+ '+(units-expected)+'</span>';
}
html += '#{j pkg_helper_icon}';
}
$(input).closest('tr').find('.units_delta').html(html);
}
2014-01-08 19:28:39 +01:00
$(document).on('change keyup', 'input[data-units-expected]', function() {
update_delta(this);
});
$(document).on('click', '#order_articles .unlocker', unlock_receive_input_field);
$(function() {
$('input[data-units-expected]').each(function() {
update_delta(this);
});
init_add_article('#add_article');
});
function init_add_article(sel) {
$(sel).removeAttr('disabled').select2({
2014-01-06 23:48:39 +01:00
placeholder: '#{j t('orders.receive.add_article')}',
formatNoMatches: function(term) { return '#{j t('.no_articles_available')}';}
// TODO implement adding a new article, like in deliveries
}).on('change', function(e) {
var selectedArticle = $(e.currentTarget).select2('data');
if(!selectedArticle) {
return false;
}
$.ajax({
url: '#{order_order_articles_path(@order)}',
type: 'post',
data: JSON.stringify({order_article: {article_id: selectedArticle.id}}),
contentType: 'application/json; charset=UTF-8'
});
$('#add_article').select2('data', null);
}).select2('data', null);
}
function unlock_receive_input_field() {
$('.units_received', $(this).closest('tr')).prop('disabled', false).focus();
2014-01-09 13:01:10 +01:00
$(this).closest('.input-prepend').prop('title', I18n.t('orders.edit_amount.field_unlocked_title'));
$(this).replaceWith('<i class="icon icon-warning-sign add-on"></i>');
}
2014-01-06 23:48:39 +01:00
%table#order_articles.ordered-articles.table.table-striped.stupidtable{style: 'margin-bottom: 0'}
%thead
%tr
2013-12-18 21:06:05 +01:00
%th.sort{:data => {:sort => 'string'}}= heading_helper Article, :order_number, short: true
%th.default-sort.sort{:data => {:sort => 'string'}}= heading_helper Article, :name
%th= heading_helper Article, :unit
2014-01-02 22:30:04 +01:00
%th= heading_helper Article, :price
%th= heading_helper OrderArticle, :quantity, short: true
2014-01-08 12:52:29 +01:00
%th= heading_helper OrderArticle, :units_to_order, short: true
2013-12-18 21:53:31 +01:00
-#%th Invoice # TODO implement invoice screen
%th= heading_helper OrderArticle, :units_received, short: true
%th
%th= t 'ui.actions'
%tfoot
%tr
%th{:colspan => 10}
%select#add_article{:style => 'width: 500px;'}
- new_article_data.each do |option|
%option{id: "add_article_#{option[:id]}", value: option[:id]}= option[:text]
2014-01-06 23:48:39 +01:00
%tbody#result_table
- @order_articles.each do |order_article|
2013-12-18 21:06:05 +01:00
= render :partial => 'edit_amount', :locals => {:order_article => order_article}