From 998838ca3ee6e7125c7f9a652110df8b24a13403 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 30 Mar 2017 13:31:16 -0300 Subject: [PATCH] Add update button --- kfet/static/kfet/css/index.css | 9 +++++ kfet/templates/kfet/inventory_create.html | 48 ++++++++++++++++++----- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/kfet/static/kfet/css/index.css b/kfet/static/kfet/css/index.css index fa404b5f..643cd52f 100644 --- a/kfet/static/kfet/css/index.css +++ b/kfet/static/kfet/css/index.css @@ -555,3 +555,12 @@ thead .tooltip { .inventory_modified { background:rgba(236,100,0,0.15); } + +.stock_diff { + padding-left: 5px; + color:#C8102E; +} + +.inventory_update { + display:none; +} diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 80f9d4c0..e88612c7 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -58,6 +58,7 @@
{{ form.stock_new }}
+
@@ -99,16 +100,30 @@ $(document).ready(function() { }); /* - * Remove warning if .finished is unchecked + * Remove warning and update stock */ + function update_stock($line) { + $line.removeClass('inventory_modified'); + $line.find('.inventory_update').hide(); + + var old_stock = +$line.find('.current_stock').text() + var stock_diff = +$line.find('.stock_diff').text(); + $line.find('.current_stock').text(old_stock + stock_diff); + $line.find('.stock_diff').text(''); + + var id = $line.find('input[type="hidden"]').val(); + conflicts = conflicts.filter(item => item != id); + } + $('.finished input').change(function() { - if (!$(this).is(":checked")) { - var $line = $(this).closest('tr'); - var id = $line.find('input[type="hidden"]').val(); - $(this).closest('tr').removeClass('inventory_modified'); - conflicts = conflicts.filter(item => item != id); - } + var $line = $(this).closest('tr'); + update_stock($line); + }); + + $('.inventory_update button').click(function() { + var $line = $(this).closest('tr'); + update_stock($line); }); @@ -127,9 +142,20 @@ $(document).ready(function() { var data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); for (let article of data['articles']) { var $line = $('input[value="'+article.id+'"]').parent(); - if ($line.find('.finished input').prop("checked")) { + if ($line.find('.finished input').is(":checked")) { conflicts.push(article.id); + //Display warning $line.addClass('inventory_modified'); + + //Realigning input and displaying update button + $line.find('.inventory_update').show(); + + //Displaying stock changes + var stock = $line.find('.current_stock').text(); + $line.find('.stock_diff').text(article.stock - stock); + } else { + // If we haven't counted the article yet, we simply update the expected stock + $line.find('.current_stock').text(article.stock); } } } @@ -144,8 +170,10 @@ $(document).ready(function() { content += "Conflits possibles :" content += '' } else {