make receive delta work when unit_quantity changes

This commit is contained in:
wvengen 2014-01-13 11:37:18 +01:00
parent 45e529b008
commit 3b2d50b47d
3 changed files with 27 additions and 10 deletions

View file

@ -6,6 +6,7 @@
function update_delta(input) {
var units = $(input).val();
var expected = $(input).data('units-expected');
var delta = Math.round((units-expected)*100)/100.0;
var html;
if (units.replace(/\s/g,"")=="") {
@ -13,16 +14,19 @@
html = '';
} else if (isNaN(units)) {
html = '<i class="icon-remove" style="color: red"></i>';
} else if (units == expected) {
} else if (delta == 0) {
// equal value
html = '<i class="icon-ok" style="color: green"></i>';
} else {
if (units < expected) {
html = '<span style="color: red">- '+(expected-units)+'</span>';
if (delta < 0) {
html = '<span style="color: red">- '+(-delta)+'</span>';
} else /*if (units> expected)*/ {
html = '<span style="color: green">+ '+(units-expected)+'</span>';
html = '<span style="color: green">+ '+(delta)+'</span>';
}
// show package icon only if the receive field has one
if ($(input).hasClass('package')) {
html += '#{j pkg_helper_icon}';
}
html += '#{j pkg_helper_icon}';
}
$(input).closest('tr').find('.units_delta').html(html);