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 @@
Caisses en arrière |
Vrac |
Stock total |
+ Compte terminé |
@@ -32,40 +33,41 @@
{% ifchanged form.category %}
{{ form.category_name }} |
- |
+ |
{% endifchanged %}
{{ form.article }}
- {{ form.name }} |
- {{ form.box_capacity }} |
- {{ form.stock_old }} |
-
+ | {{ 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 %}
@@ -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();
+ });
+ },
+ });
+
});