Add "count finished" checkbox

This commit is contained in:
Ludovic Stephan 2017-03-29 20:43:48 -03:00
parent e6a1d16860
commit eb7d436b90
2 changed files with 65 additions and 47 deletions

View file

@ -28,6 +28,7 @@
.jconfirm .jconfirm-box .content {
border-bottom:1px solid #ddd;
padding:5px 10px;
}
.jconfirm .jconfirm-box input {

View file

@ -25,6 +25,7 @@
<td>Caisses en arrière</td>
<td>Vrac</td>
<td>Stock total</td>
<td>Compte terminé</td>
</tr>
</thead>
<tbody>
@ -32,40 +33,41 @@
{% ifchanged form.category %}
<tr class='section'>
<td>{{ form.category_name }}</td>
<td colspan="6"></td>
<td colspan="7"></td>
</tr>
{% endifchanged %}
<tr>
{{ form.article }}
<td>{{ form.name }}</td>
<td id='id_{{form.prefix}}-box_capacity'>{{ form.box_capacity }}</td>
<td>{{ form.stock_old }}</td>
<td>
<td class='name'>{{ form.name }}</td>
<td class='box_capacity' id='id_{{form.prefix}}-box_capacity'>{{ form.box_capacity }}</td>
<td class='stock_old'>{{ form.stock_old }}</td>
<td class='box_cellar'>
<div class='col-md-2'></div>
<div class='col-md-8'>
<input type='number' prefix='{{form.prefix}}' class='form-control' id='id_{{form.prefix}}-box_cellar' step='1'>
</div>
</td>
<td>
<td class='box_bar'>
<div class='col-md-2'></div>
<div class='col-md-8'><input type='number' prefix='{{form.prefix}}' class='form-control' id='id_{{form.prefix}}-box_bar' step='1'></div>
</td>
<td>
<td class='misc'>
<div class='col-md-2'></div>
<div class='col-md-8'><input type='number' prefix='{{form.prefix}}' class='form-control' id='id_{{form.prefix}}-misc' step='1'></div>
</td>
<td>
<td class='stock_new'>
<div class='col-md-2'></div>
<div class='col-md-8'>{{ form.stock_new }}</div>
</td>
<td class='finished'><input type='checkbox' prefix='{{form.prefix}}' class='form_control' id='id_{{form.prefix}}-finished'></td>
</tr>
{% endfor %}
{{ formset.management_form }}
{% if not perms.kfet.add_inventory %}
<td colspan='3'><label for='pwd'>Mot de passe :&nbsp;</label><input type="password" name="KFETPASSWORD"></td>
<td colspan='4'><input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block"></td>
<td colspan='5'><input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block"></td>
{% else %}
<td colspan='7'><input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block"></td>
<td colspan='8'><input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block"></td>
{% endif %}
{% csrf_token %}
</form>
@ -84,20 +86,32 @@ $(document).ready(function() {
*/
$('input[type="number"]').on('input', function() {
var prefix = $(this).attr('prefix');
var $line = $(this).closest('tr');
var box_capacity = +$line.find('#id_'+prefix+'-box_capacity').text();
var box_cellar = +$line.find('#id_'+prefix+'-box_cellar').val();
var box_bar = +$line.find('#id_'+prefix+'-box_bar').val();
var misc = +$line.find('#id_'+prefix+'-misc').val();
$line.find('#id_'+prefix+'-stock_new').val(box_capacity*(box_cellar +box_bar)+misc);
var box_capacity = +$line.find('.box_capacity').text();
var box_cellar = +$line.find('.box_cellar input').val();
var box_bar = +$line.find('.box_bar input').val();
var misc = +$line.find('.misc input').val();
$line.find('.stock_new input').val(box_capacity*(box_cellar +box_bar)+misc);
});
/*
* Remove warning if .finished is unchecked
*/
$('.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);
}
});
/**
* Websocket
*/
var modified = [];
var conflicts = [];
var websocket_msg_default = {'articles':[]}
var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws';
@ -107,30 +121,35 @@ $(document).ready(function() {
socket.onmessage = function(e) {
var data = $.extend({}, websocket_msg_default, JSON.parse(e.data));
for (let article of data['articles']) {
modified.push(article.id);
$('input[value="'+article.id+'"]').parent().addClass('inventory_modified');
var $line = $('input[value="'+article.id+'"]').parent();
if ($line.find('.finished input').prop("checked")) {
conflicts.push(article.id);
$line.addClass('inventory_modified');
}
}
}
$('input[type="submit"]').on("click", function(e) {
console.log(e.keyCode);
e.preventDefault();
var conflicts = [];
for (let id of modified) {
var $input = $('input[value="'+id+'"]');
if ($input.siblings(":last").find('input').val() !== "") {
conflicts.push($input.next().text());
}
}
conflicts = [...new Set(conflicts)]; //remove duplicates
if (conflicts.length) {
content = '';
content += "Conflits possibles :"
content += '<ul>';
for (let article of conflicts) {
content += '<li>'+article+'</li>';
for (let id of conflicts) {
var name = $('input[value="'+id+'"]').siblings('.name').text();
content += '<li>'+name+'</li>';
}
content += '</ul>'
return $.confirm({
} else {
// Prevent erroneous enter key confirmations
// Kinda complicated to filter if click or enter key...
content="Voulez-vous confirmer l'inventaire ?";
}
$.confirm({
title: "Confirmer l'inventaire",
content: content,
backgroundDismiss: true,
@ -148,9 +167,7 @@ $(document).ready(function() {
});
},
});
} else {
$('#inventoryform').submit();
}
});