Add update button

This commit is contained in:
Ludovic Stephan 2017-03-30 13:31:16 -03:00
parent 31888e33ce
commit 998838ca3e
2 changed files with 47 additions and 10 deletions

View file

@ -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;
}

View file

@ -58,6 +58,7 @@
<td class='stock_new'>
<div class='col-md-2'></div>
<div class='col-md-8'>{{ form.stock_new }}</div>
<div class='col-md-2 inventory_update'><button type='button' class='btn-sm btn-primary'>MàJ</button></div>
</td>
<td class='finished'><input type='checkbox' class='form_control'></td>
</tr>
@ -99,16 +100,30 @@ $(document).ready(function() {
});
/*
* Remove warning if .finished is unchecked
* Remove warning and update stock
*/
$('.finished input').change(function() {
if (!$(this).is(":checked")) {
var $line = $(this).closest('tr');
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();
$(this).closest('tr').removeClass('inventory_modified');
conflicts = conflicts.filter(item => item != id);
}
$('.finished input').change(function() {
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 += '<ul>';
for (let id of conflicts) {
var name = $('input[value="'+id+'"]').siblings('.name').text();
content += '<li>'+name+'</li>';
var $line = $('input[value="'+id+'"]').closest('tr');
var name = $line.find('.name').text();
var stock_diff = $line.find('.stock_diff').text();
content += '<li>'+name+' ('+stock_diff+')</li>';
}
content += '</ul>'
} else {