From 3b793dc7268b2e104e60bece36735acd65fc1776 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 28 Mar 2017 23:47:41 -0300 Subject: [PATCH 01/17] Add first improvements for inventory --- kfet/forms.py | 9 +- kfet/templates/kfet/inventory_create.html | 107 +++++++++++++++------- kfet/views.py | 3 +- 3 files changed, 86 insertions(+), 33 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index 2b59e1b3..72a18ab6 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -457,7 +457,13 @@ class InventoryArticleForm(forms.Form): queryset = Article.objects.all(), widget = forms.HiddenInput(), ) - stock_new = forms.IntegerField(required = False) + stock_new = forms.IntegerField( + required=False, + widget=forms.NumberInput( + attrs={'class': 'form-control', + 'readonly': '',} + ) + ) def __init__(self, *args, **kwargs): super(InventoryArticleForm, self).__init__(*args, **kwargs) @@ -466,6 +472,7 @@ class InventoryArticleForm(forms.Form): self.stock_old = kwargs['initial']['stock_old'] self.category = kwargs['initial']['category'] self.category_name = kwargs['initial']['category__name'] + self.box_capacity = kwargs['initial']['box_capacity'] # ----- # Order forms diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index d4f53c3c..7c970c12 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -6,38 +6,83 @@ {% block content %} {% include 'kfet/base_messages.html' %} - -
- - - - - - - - - - {% for form in formset %} - {% ifchanged form.category %} +
+
+ +
ArticleThéo.Réel
+ - + + + + + + + - {% endifchanged %} - - {{ form.article }} - - - - - {% endfor %} - -
{{ form.category_name }}ArticleQuantité par caisseStock ThéoriqueCaisses en réserveCaisses en arrièreVracStock total
{{ form.name }}{{ form.stock_old }}{{ form.stock_new }}
- {% if not perms.kfet.add_inventory %} - - {% endif %} - {% csrf_token %} - {{ formset.management_form }} - -
+ + + {% for form in formset %} + {% ifchanged form.category %} + + {{ form.category_name }} + + + {% endifchanged %} + + {{ form.article }} + {{ form.name }} + {{ form.box_capacity }} + {{ form.stock_old }} + +
+
+ +
+ + +
+
+ + +
+
+ + +
+
{{ form.stock_new }}
+ + + {% endfor %} + {{ formset.management_form }} + {% if not perms.kfet.add_inventory %} + + + {% else %} + + {% endif %} + {% csrf_token %} + + + + + + + + {% endblock %} diff --git a/kfet/views.py b/kfet/views.py index b6a3338a..69df6c3f 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1658,7 +1658,8 @@ def inventory_create(request): 'stock_old': article.stock, 'name' : article.name, 'category' : article.category_id, - 'category__name': article.category.name + 'category__name': article.category.name, + 'box_capacity': article.box_capacity or 0, }) cls_formset = formset_factory( From e6a1d16860a808f778f98d7f74d11a122886d695 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 29 Mar 2017 00:58:47 -0300 Subject: [PATCH 02/17] Websocket to manage possible kpsul conflicts --- kfet/static/kfet/css/index.css | 6 ++ kfet/templates/kfet/inventory_create.html | 74 ++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/kfet/static/kfet/css/index.css b/kfet/static/kfet/css/index.css index 563d3839..fa404b5f 100644 --- a/kfet/static/kfet/css/index.css +++ b/kfet/static/kfet/css/index.css @@ -549,3 +549,9 @@ thead .tooltip { .help-block { padding-top: 15px; } + +/* Inventaires */ + +.inventory_modified { + background:rgba(236,100,0,0.15); +} diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 7c970c12..2882d5ad 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -1,4 +1,10 @@ {% extends 'kfet/base.html' %} +{% load staticfiles %} + +{% block extra_head %} + + +{% endblock %} {% block title %}Nouvel inventaire{% endblock %} {% block content-header-title %}Nouvel inventaire{% endblock %} @@ -8,7 +14,7 @@ {% include 'kfet/base_messages.html' %}
-
+ @@ -71,6 +77,11 @@ From eb7d436b90f85e97079ef9203799a2c591bce8db Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 29 Mar 2017 20:43:48 -0300 Subject: [PATCH 03/17] Add "count finished" checkbox --- kfet/static/kfet/css/jconfirm-kfet.css | 1 + kfet/templates/kfet/inventory_create.html | 111 +++++++++++++--------- 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/kfet/static/kfet/css/jconfirm-kfet.css b/kfet/static/kfet/css/jconfirm-kfet.css index 0bd53ab7..1aee70f1 100644 --- a/kfet/static/kfet/css/jconfirm-kfet.css +++ b/kfet/static/kfet/css/jconfirm-kfet.css @@ -28,6 +28,7 @@ .jconfirm .jconfirm-box .content { border-bottom:1px solid #ddd; + padding:5px 10px; } .jconfirm .jconfirm-box input { diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 2882d5ad..7c611eb6 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -25,6 +25,7 @@ + @@ -32,40 +33,41 @@ {% ifchanged form.category %} - + {% endifchanged %} {{ form.article }} - - - - + + + - - - + {% endfor %} {{ formset.management_form }} {% if not perms.kfet.add_inventory %} - + {% else %} - + {% endif %} {% csrf_token %} @@ -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,50 +121,53 @@ $(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 += '
    '; - for (let article of conflicts) { - content += '
  • '+article+'
  • '; + for (let id of conflicts) { + var name = $('input[value="'+id+'"]').siblings('.name').text(); + content += '
  • '+name+'
  • '; } content += '
' - return $.confirm({ - title: "Confirmer l'inventaire", - content: content, - backgroundDismiss: true, - animation: 'top', - closeAnimation: 'bottom', - keyboardEnabled: true, - confirm: function() { - $('#inventoryform').submit(); - }, - onOpen: function() { - var that = this; - this.$content.find('input').on('keydown', function(e) { - if (e.keyCode == 13) - that.$confirmButton.click(); - }); - }, - }); } else { - $('#inventoryform').submit(); + // 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, + animation: 'top', + closeAnimation: 'bottom', + keyboardEnabled: true, + confirm: function() { + $('#inventoryform').submit(); + }, + onOpen: function() { + var that = this; + this.$content.find('input').on('keydown', function(e) { + if (e.keyCode == 13) + that.$confirmButton.click(); + }); + }, + }); + }); From 31888e33ce54d9962dc2eb40d2366ec758283138 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 30 Mar 2017 13:30:55 -0300 Subject: [PATCH 04/17] simpler jquery selection --- kfet/templates/kfet/inventory_create.html | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 7c611eb6..80f9d4c0 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -39,27 +39,27 @@ {{ form.article }} - - + + - + {% endfor %} {{ formset.management_form }} @@ -88,10 +88,14 @@ $(document).ready(function() { $('input[type="number"]').on('input', function() { var $line = $(this).closest('tr'); 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); + 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(); + if (box_cellar || box_bar || misc) + $line.find('.stock_new input').val( + box_capacity*((+box_cellar) +(+box_bar))+(+misc)); + else + $line.find('.stock_new input').val(''); }); /* @@ -107,6 +111,7 @@ $(document).ready(function() { } }); + /** * Websocket */ From 998838ca3ee6e7125c7f9a652110df8b24a13403 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 30 Mar 2017 13:31:16 -0300 Subject: [PATCH 05/17] 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 @@ @@ -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 += '
    '; for (let id of conflicts) { - var name = $('input[value="'+id+'"]').siblings('.name').text(); - content += '
  • '+name+'
  • '; + var $line = $('input[value="'+id+'"]').closest('tr'); + var name = $line.find('.name').text(); + var stock_diff = $line.find('.stock_diff').text(); + content += '
  • '+name+' ('+stock_diff+')
  • '; } content += '
' } else { From 0c212383917d983cdd53f5a98e45475a9082ecce Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 30 Mar 2017 18:39:13 -0300 Subject: [PATCH 06/17] Change misc field when updating --- kfet/templates/kfet/inventory_create.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index e88612c7..1273d869 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -111,6 +111,12 @@ $(document).ready(function() { var stock_diff = +$line.find('.stock_diff').text(); $line.find('.current_stock').text(old_stock + stock_diff); $line.find('.stock_diff').text(''); + + if ($line.find('.stock_new input').val()) { + var old_misc = +$line.find('.misc input').val(); + $line.find('.misc input').val(old_misc + stock_diff) + .trigger('input'); + } var id = $line.find('input[type="hidden"]').val(); conflicts = conflicts.filter(item => item != id); From e54324e9f1a31ce5a9cf22dbb2219f5889fc7332 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 09:50:37 -0300 Subject: [PATCH 07/17] Use col-offset --- kfet/templates/kfet/inventory_create.html | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 1273d869..17ab9dfc 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -48,16 +48,13 @@ From 50cb6e51a14be4ceb5315150091011c98ea0f2ed Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 10:06:02 -0300 Subject: [PATCH 08/17] Use Set() natively --- kfet/templates/kfet/inventory_create.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 17ab9dfc..4fccc2be 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -134,7 +134,7 @@ $(document).ready(function() { * Websocket */ - var conflicts = []; + var conflicts = new Set(); var websocket_msg_default = {'articles':[]} var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; @@ -146,7 +146,7 @@ $(document).ready(function() { for (let article of data['articles']) { var $line = $('input[value="'+article.id+'"]').parent(); if ($line.find('.finished input').is(":checked")) { - conflicts.push(article.id); + conflicts.add(article.id); //Display warning $line.addClass('inventory_modified'); @@ -166,9 +166,8 @@ $(document).ready(function() { $('input[type="submit"]').on("click", function(e) { console.log(e.keyCode); e.preventDefault(); - conflicts = [...new Set(conflicts)]; //remove duplicates - if (conflicts.length) { + if (conflicts.size) { content = ''; content += "Conflits possibles :" content += '
    '; From 6ac1241bd38573305acb4dc2bafd14f21c5d5393 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 10:07:42 -0300 Subject: [PATCH 09/17] Listen to submit instead --- kfet/templates/kfet/inventory_create.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 4fccc2be..44780dff 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -163,8 +163,7 @@ $(document).ready(function() { } } - $('input[type="submit"]').on("click", function(e) { - console.log(e.keyCode); + $('#inventoryform').on("submit", function(e) { e.preventDefault(); if (conflicts.size) { From 530aafad19c2a92ef6c6820f9794bf21741243f3 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 11:07:37 -0300 Subject: [PATCH 10/17] Use widget_tweaks --- kfet/forms.py | 8 +------- kfet/templates/kfet/inventory_create.html | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index 72a18ab6..cee75ab2 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -457,13 +457,7 @@ class InventoryArticleForm(forms.Form): queryset = Article.objects.all(), widget = forms.HiddenInput(), ) - stock_new = forms.IntegerField( - required=False, - widget=forms.NumberInput( - attrs={'class': 'form-control', - 'readonly': '',} - ) - ) + stock_new = forms.IntegerField(required=False) def __init__(self, *args, **kwargs): super(InventoryArticleForm, self).__init__(*args, **kwargs) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 44780dff..b8a1ac08 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -1,5 +1,6 @@ {% extends 'kfet/base.html' %} {% load staticfiles %} +{% load widget_tweaks %} {% block extra_head %} @@ -54,7 +55,7 @@
From 063446efb542ca914e72987c80c2229f029466a1 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 1 Apr 2017 00:32:09 -0300 Subject: [PATCH 11/17] Use columns for authentication and submit --- kfet/static/kfet/css/index.css | 4 ++++ kfet/templates/kfet/inventory_create.html | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kfet/static/kfet/css/index.css b/kfet/static/kfet/css/index.css index 643cd52f..5a82b5cf 100644 --- a/kfet/static/kfet/css/index.css +++ b/kfet/static/kfet/css/index.css @@ -32,6 +32,7 @@ textarea { .table { margin-bottom:0; + border-bottom:1px solid #ddd; } .table { @@ -230,6 +231,9 @@ textarea { height:28px; margin:3px 0px; } + .content-center .auth-form { + margin:15px; +} /* * Pages formulaires seuls diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index b8a1ac08..3ae3337e 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -61,17 +61,17 @@ {% endfor %} - {{ formset.management_form }} - {% if not perms.kfet.add_inventory %} - - - {% else %} - - {% endif %} - {% csrf_token %} -
Caisses en arrière Vrac Stock totalCompte terminé
{{ form.category_name }}
{{ form.name }}{{ form.box_capacity }}{{ form.stock_old }} + {{ form.name }}{{ form.box_capacity }}{{ form.stock_old }}
+
+
+
{{ form.stock_new }}
{{ form.name }}{{ form.box_capacity }}{{ form.stock_old }}{{ form.box_capacity }}{{ form.stock_old }}
- +
-
+
-
+
{{ form.stock_new }}
{{ form.stock_new }}
+
-
-
+
-
-
+
-
-
{{ form.stock_new }}
+
{{ form.stock_new }}
-
{{ form.stock_new }}
+
{{ form.stock_new | attr:"readonly"| add_class:"form-control" }}
+ {{ formset.management_form }} + {% if not perms.kfet.add_inventory %} +
+ {% include "kfet/form_authentication_snippet.html" %} +
+ {% endif %} + + {% csrf_token %} +
From 8da832c1f7704b5bc0b935eaea2ddc3dcf023e39 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 1 Apr 2017 00:36:39 -0300 Subject: [PATCH 12/17] Use nice authentication in orders too --- kfet/templates/kfet/order_create.html | 10 ++++++---- kfet/templates/kfet/order_to_inventory.html | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/kfet/templates/kfet/order_create.html b/kfet/templates/kfet/order_create.html index cbd84ba8..b419621b 100644 --- a/kfet/templates/kfet/order_create.html +++ b/kfet/templates/kfet/order_create.html @@ -65,11 +65,13 @@ {% endfor %} - {% if not perms.kfet.add_order %} - - {% endif %} {{ formset.management_form }} - + {% if not perms.kfet.add_inventory %} +
+ {% include "kfet/form_authentication_snippet.html" %} +
+ {% endif %} + diff --git a/kfet/templates/kfet/order_to_inventory.html b/kfet/templates/kfet/order_to_inventory.html index ab107065..ae7bc8af 100644 --- a/kfet/templates/kfet/order_to_inventory.html +++ b/kfet/templates/kfet/order_to_inventory.html @@ -41,11 +41,13 @@ {% endfor %} - {% if not perms.kfet.order_to_inventory %} - - {% endif %} {{ formset.management_form }} - + {% if not perms.kfet.add_inventory %} +
+ {% include "kfet/form_authentication_snippet.html" %} +
+ {% endif %} + From e20ab2f352557c6ae33acd620e8b8f1e41fc3f3d Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sat, 1 Apr 2017 09:18:40 -0300 Subject: [PATCH 13/17] Use set delete() --- kfet/templates/kfet/inventory_create.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 3ae3337e..293bcd6b 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -117,7 +117,7 @@ $(document).ready(function() { } var id = $line.find('input[type="hidden"]').val(); - conflicts = conflicts.filter(item => item != id); + conflicts = conflicts.delete(id); } $('.finished input').change(function() { From b113a57b741bf05aa59ee554a73b1ce40f9aba45 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Apr 2017 11:20:56 -0300 Subject: [PATCH 14/17] Fix update function --- kfet/templates/kfet/inventory_create.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 293bcd6b..29bf2d3e 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -110,14 +110,14 @@ $(document).ready(function() { $line.find('.current_stock').text(old_stock + stock_diff); $line.find('.stock_diff').text(''); - if ($line.find('.stock_new input').val()) { + if ($line.find('.stock_new input').val() && stock_diff) { var old_misc = +$line.find('.misc input').val(); $line.find('.misc input').val(old_misc + stock_diff) .trigger('input'); } var id = $line.find('input[type="hidden"]').val(); - conflicts = conflicts.delete(id); + conflicts.delete(parseInt(id)); } $('.finished input').change(function() { From 40da3bc2995c2df5c464c21dccb2fe74e6be3180 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Apr 2017 11:21:05 -0300 Subject: [PATCH 15/17] Listen on input --- kfet/templates/kfet/inventory_create.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 29bf2d3e..61792c6d 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -164,7 +164,7 @@ $(document).ready(function() { } } - $('#inventoryform').on("submit", function(e) { + $('input[type="submit"]').on("click", function(e) { e.preventDefault(); if (conflicts.size) { From 32474a6865d233df90be46f19cd783446c37f3b4 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Apr 2017 16:03:22 -0300 Subject: [PATCH 16/17] Don't update input when unchecking --- kfet/templates/kfet/inventory_create.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 61792c6d..1098f1f8 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -101,7 +101,7 @@ $(document).ready(function() { * Remove warning and update stock */ - function update_stock($line) { + function update_stock($line, update_count) { $line.removeClass('inventory_modified'); $line.find('.inventory_update').hide(); @@ -110,7 +110,7 @@ $(document).ready(function() { $line.find('.current_stock').text(old_stock + stock_diff); $line.find('.stock_diff').text(''); - if ($line.find('.stock_new input').val() && stock_diff) { + if ($line.find('.stock_new input').val() && update_count) { var old_misc = +$line.find('.misc input').val(); $line.find('.misc input').val(old_misc + stock_diff) .trigger('input'); @@ -122,12 +122,12 @@ $(document).ready(function() { $('.finished input').change(function() { var $line = $(this).closest('tr'); - update_stock($line); + update_stock($line, false); }); $('.inventory_update button').click(function() { var $line = $(this).closest('tr'); - update_stock($line); + update_stock($line, true); }); From 51acb4e00aae09ed8e7ab7536c92c65ef380e3a9 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Apr 2017 16:05:18 -0300 Subject: [PATCH 17/17] Use new WS class --- kfet/templates/kfet/inventory_create.html | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kfet/templates/kfet/inventory_create.html b/kfet/templates/kfet/inventory_create.html index 1098f1f8..d8109f8e 100644 --- a/kfet/templates/kfet/inventory_create.html +++ b/kfet/templates/kfet/inventory_create.html @@ -80,6 +80,8 @@ $(document).ready(function() { 'use strict'; + var conflicts = new Set(); + /** * Autofill new stock from other inputs */ @@ -135,15 +137,7 @@ $(document).ready(function() { * Websocket */ - var conflicts = new Set(); - var websocket_msg_default = {'articles':[]} - - var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; - var location_host = window.location.host; - var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; - var socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); - socket.onmessage = function(e) { - var data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); + OperationWebSocket.add_handler(function(data) { for (let article of data['articles']) { var $line = $('input[value="'+article.id+'"]').parent(); if ($line.find('.finished input').is(":checked")) { @@ -162,7 +156,7 @@ $(document).ready(function() { $line.find('.current_stock').text(article.stock); } } - } + }); $('input[type="submit"]').on("click", function(e) { e.preventDefault();