Commit 10f5d6e7 by Damien Moulard

lint reception js

parent 5da77cc3
...@@ -50,11 +50,11 @@ function set_local_storage(order_data) { ...@@ -50,11 +50,11 @@ function set_local_storage(order_data) {
} }
/* /*
* Remove from local storage orders that have a wrong status * Remove from local storage orders that have a wrong status
* (-> order has been updated elsewhere) * (-> order has been updated elsewhere)
*/ */
function clean_local_storage() { function clean_local_storage() {
var stored_order = null var stored_order = null;
// Loop through local storage // Loop through local storage
for (key of Object.keys(localStorage)) { for (key of Object.keys(localStorage)) {
...@@ -64,19 +64,20 @@ function clean_local_storage() { ...@@ -64,19 +64,20 @@ function clean_local_storage() {
// Loop through orders in table to find match // Loop through orders in table to find match
var i = 0; var i = 0;
var found = false; var found = false;
while (i < table_orders.rows().data().length && !found) { while (i < table_orders.rows().data().length && !found) {
var uptodate_order = table_orders.rows(i).data()[0] var uptodate_order = table_orders.rows(i).data()[0];
// If status in local storage is wrong // If status in local storage is wrong
if (stored_order.id == uptodate_order.id if (stored_order.id == uptodate_order.id
&& stored_order.reception_status != uptodate_order.reception_status) { && stored_order.reception_status != uptodate_order.reception_status) {
// Remove from local storage // Remove from local storage
localStorage.removeItem("order_" + uptodate_order.id); localStorage.removeItem("order_" + uptodate_order.id);
// Evolution: warn user (order modified elsewhere, local data has been deleted) // Evolution: warn user (order modified elsewhere, local data has been deleted)
found = true; found = true;
} }
i++; i++;
} }
...@@ -111,7 +112,7 @@ function create_groups_from_server_data() { ...@@ -111,7 +112,7 @@ function create_groups_from_server_data() {
} }
// Add server groups to stored groups // Add server groups to stored groups
grouped_orders = grouped_orders.concat(server_stored_groups) grouped_orders = grouped_orders.concat(server_stored_groups);
localStorage.setItem('grouped_orders', JSON.stringify(grouped_orders)); localStorage.setItem('grouped_orders', JSON.stringify(grouped_orders));
} }
...@@ -120,7 +121,7 @@ function create_groups_from_server_data() { ...@@ -120,7 +121,7 @@ function create_groups_from_server_data() {
*/ */
function extract_grouped_orders() { function extract_grouped_orders() {
var saved_grouped_orders = JSON.parse(localStorage.getItem('grouped_orders')); var saved_grouped_orders = JSON.parse(localStorage.getItem('grouped_orders'));
var groups_to_delete = [] // indexes var groups_to_delete = []; // indexes
// if there are grouped orders // if there are grouped orders
if (saved_grouped_orders != null) { if (saved_grouped_orders != null) {
...@@ -146,7 +147,7 @@ function extract_grouped_orders() { ...@@ -146,7 +147,7 @@ function extract_grouped_orders() {
// No order found, delete group and skip the rest // No order found, delete group and skip the rest
if (g.length == 0) { if (g.length == 0) {
groups_to_delete.push(group_index) groups_to_delete.push(group_index);
continue; continue;
} }
...@@ -163,12 +164,12 @@ function extract_grouped_orders() { ...@@ -163,12 +164,12 @@ function extract_grouped_orders() {
} }
if (g[0].reception_status == 'False') { if (g[0].reception_status == 'False') {
group_row += "<button class='btn--primary' onClick='group_goto(" group_row += "<button class='btn--primary' onClick='group_goto("
+ saved_groups.length + saved_groups.length
+ ")'>Compter les produits</button>"; + ")'>Compter les produits</button>";
} else { } else {
group_row += "<button class='btn--success' onClick='group_goto(" group_row += "<button class='btn--success' onClick='group_goto("
+ saved_groups.length + saved_groups.length
+ ")'>Mettre à jour les prix</button>"; + ")'>Mettre à jour les prix</button>";
} }
...@@ -181,7 +182,7 @@ function extract_grouped_orders() { ...@@ -181,7 +182,7 @@ function extract_grouped_orders() {
if (groups_to_delete.length > 0) { if (groups_to_delete.length > 0) {
for (index of groups_to_delete) { for (index of groups_to_delete) {
saved_grouped_orders.splice(index, 1) saved_grouped_orders.splice(index, 1);
} }
localStorage.setItem('grouped_orders', JSON.stringify(saved_grouped_orders)); localStorage.setItem('grouped_orders', JSON.stringify(saved_grouped_orders));
} }
...@@ -208,7 +209,7 @@ function validatePrices() { ...@@ -208,7 +209,7 @@ function validatePrices() {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(update_data), data: JSON.stringify(update_data),
success: function(data) { success: function() {
localStorage.removeItem("order_" + order["id"]); localStorage.removeItem("order_" + order["id"]);
callback_update = true; callback_update = true;
reload(); reload();
...@@ -237,7 +238,7 @@ function validatePrices() { ...@@ -237,7 +238,7 @@ function validatePrices() {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(updates), data: JSON.stringify(updates),
success: function(data) { success: function() {
callback_report = true; callback_report = true;
reload(); reload();
}, },
...@@ -265,7 +266,7 @@ function group_action() { ...@@ -265,7 +266,7 @@ function group_action() {
for (var i = 0; i < selected_data.length; i++) { for (var i = 0; i < selected_data.length; i++) {
group_ids.push(selected_data[i].id); group_ids.push(selected_data[i].id);
} }
// Notify server that group is created // Notify server that group is created
$.ajax({ $.ajax({
type: "POST", type: "POST",
...@@ -274,7 +275,7 @@ function group_action() { ...@@ -274,7 +275,7 @@ function group_action() {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(group_ids), data: JSON.stringify(group_ids),
success: function(data) { success: function() {
var min_id = 9999999; var min_id = 9999999;
for (var i = 0; i < selected_data.length; i++) { for (var i = 0; i < selected_data.length; i++) {
...@@ -307,14 +308,14 @@ function group_action() { ...@@ -307,14 +308,14 @@ function group_action() {
error: function(data) { error: function(data) {
if (data != null && data.status == 409) { if (data != null && data.status == 409) {
alert("Un groupe a déjà été formé sur un autre poste " alert("Un groupe a déjà été formé sur un autre poste "
+ "avec au moins l'une des commandes sélectionnées. Merci de rafraichir la page.") + "avec au moins l'une des commandes sélectionnées. Merci de rafraichir la page.");
} }
} }
}); });
} else { } else {
alert("Le local storage n'est pas disponible. Merci de contacter un.e salarié.e !") alert("Le local storage n'est pas disponible. Merci de contacter un.e salarié.e !");
} }
} else if (pswd == null) { } else if (pswd == null) {
...@@ -326,15 +327,13 @@ function group_action() { ...@@ -326,15 +327,13 @@ function group_action() {
$(document).ready(function() { $(document).ready(function() {
openModal() openModal();
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } }); $.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
// Set date format for DataTable so date ordering can work // Set date format for DataTable so date ordering can work
$.fn.dataTable.moment('D/M/Y'); $.fn.dataTable.moment('D/M/Y');
var saved_grouped_orders = JSON.parse(localStorage.getItem('grouped_orders'));
table_orders = $('#orders').DataTable({ table_orders = $('#orders').DataTable({
ajax: "get_list_orders", ajax: "get_list_orders",
columns:[ columns:[
...@@ -342,7 +341,7 @@ $(document).ready(function() { ...@@ -342,7 +341,7 @@ $(document).ready(function() {
data:"id", data:"id",
title:"Sélectionner", title:"Sélectionner",
className:"dt-body-center", className:"dt-body-center",
render: function (data, type, full, meta) { render: function (data) {
return '<input type="checkbox" id="select_bc_'+data+'" value="'+data+'">'; return '<input type="checkbox" id="select_bc_'+data+'" value="'+data+'">';
}, },
width: "4%", width: "4%",
...@@ -352,7 +351,7 @@ $(document).ready(function() { ...@@ -352,7 +351,7 @@ $(document).ready(function() {
{ {
data:"partner", data:"partner",
title:"Fournisseur", title:"Fournisseur",
render: function (data, type, full, meta) { render: function (data, type, full) {
// Add tooltip with PO over partner name // Add tooltip with PO over partner name
return '<div class="tooltip">' + data + ' <span class="tooltiptext">' + full.name + '</span> </div>'; return '<div class="tooltip">' + data + ' <span class="tooltiptext">' + full.name + '</span> </div>';
} }
...@@ -360,7 +359,7 @@ $(document).ready(function() { ...@@ -360,7 +359,7 @@ $(document).ready(function() {
{ {
data:"reception_status", data:"reception_status",
className:"dt-body-center", className:"dt-body-center",
render: function (data, type, full, meta) { render: function (data) {
if (data == "qty_valid") { if (data == "qty_valid") {
return "<span class='btn--danger'>Pas de prix sur le bon de livraison</span>"; return "<span class='btn--danger'>Pas de prix sur le bon de livraison</span>";
} else { } else {
...@@ -374,7 +373,7 @@ $(document).ready(function() { ...@@ -374,7 +373,7 @@ $(document).ready(function() {
data:"reception_status", data:"reception_status",
title:"Statut", title:"Statut",
className:"dt-body-center", className:"dt-body-center",
render: function (data, type, full, meta) { render: function (data) {
switch (data) { switch (data) {
case 'qty_valid': case 'qty_valid':
return "<span class='btn--success'>Mettre à jour les prix</span>"; return "<span class='btn--success'>Mettre à jour les prix</span>";
...@@ -396,11 +395,11 @@ $(document).ready(function() { ...@@ -396,11 +395,11 @@ $(document).ready(function() {
], ],
iDisplayLength: 25, iDisplayLength: 25,
language: {url : '/static/js/datatables/french.json'}, language: {url : '/static/js/datatables/french.json'},
initComplete: function(settings, json) { // After data is loaded initComplete: function() { // After data is loaded
clean_local_storage() clean_local_storage();
create_groups_from_server_data() create_groups_from_server_data();
extract_grouped_orders() extract_grouped_orders();
closeModal() closeModal();
} }
}); });
...@@ -459,9 +458,7 @@ $(document).ready(function() { ...@@ -459,9 +458,7 @@ $(document).ready(function() {
selection_type = null; selection_type = null;
document.getElementById("group_action").hidden = true; document.getElementById("group_action").hidden = true;
} }
} } else if (this.cellIndex == 4) { // Click on last cell button -> go to products page
// Click on last cell button -> go to products page
else if (this.cellIndex == 4) {
// Extra security if order with a different status gets lost in here // Extra security if order with a different status gets lost in here
if (row_data.reception_status == "qty_valid" || row_data.reception_status == "False") { if (row_data.reception_status == "qty_valid" || row_data.reception_status == "False") {
// Use local storage to pass order data to next page // Use local storage to pass order data to next page
...@@ -469,9 +466,8 @@ $(document).ready(function() { ...@@ -469,9 +466,8 @@ $(document).ready(function() {
goto(row_data.id); goto(row_data.id);
} }
} } else if (this.cellIndex == 3 && row_data.reception_status == "qty_valid") {
// If 'update prices' step, click on before-last cell -> validate all prices // If 'update prices' step, click on before-last cell -> validate all prices
else if (this.cellIndex == 3 && row_data.reception_status == "qty_valid") {
order = row_data; order = row_data;
openModal($('#modal_no_prices').html(), validatePrices, 'Confirmer', false); openModal($('#modal_no_prices').html(), validatePrices, 'Confirmer', false);
} }
......
...@@ -18,13 +18,13 @@ var orders = {}, ...@@ -18,13 +18,13 @@ var orders = {},
is_group = false, is_group = false,
group_ids = []; group_ids = [];
var reception_status, var reception_status = null,
list_to_process = [], list_to_process = [],
list_processed = [], list_processed = [],
table_to_process, table_to_process = null,
table_processed, table_processed = null,
editing_product = null, // Store the product currently being edited editing_product = null, // Store the product currently being edited
editing_origin, // Keep track of where editing_product comes from editing_origin = null, // Keep track of where editing_product comes from
processed_row_counter = 0, // Order in which products were added in processed list processed_row_counter = 0, // Order in which products were added in processed list
user_comments = "", user_comments = "",
updatedProducts = [], // Keep record of updated products updatedProducts = [], // Keep record of updated products
...@@ -108,6 +108,8 @@ function select_product_from_bc(barcode) { ...@@ -108,6 +108,8 @@ function select_product_from_bc(barcode) {
console.error(err); console.error(err);
report_JS_error(err, 'reception'); report_JS_error(err, 'reception');
} }
return 0;
} }
/* INIT */ /* INIT */
...@@ -231,7 +233,7 @@ function initLists() { ...@@ -231,7 +233,7 @@ function initLists() {
data:"product_id.1", data:"product_id.1",
title:"Produit", title:"Produit",
width: "45%", width: "45%",
render: function (data, type, full, meta) { render: function (data, type, full) {
// Add tooltip with barcode over product name // Add tooltip with barcode over product name
let display_barcode = "Aucun"; let display_barcode = "Aucun";
...@@ -300,7 +302,7 @@ function initLists() { ...@@ -300,7 +302,7 @@ function initLists() {
data:"product_id.1", data:"product_id.1",
title:"Produit", title:"Produit",
width: "55%", width: "55%",
render: function (data, type, full, meta) { render: function (data, type, full) {
// Add tooltip with barcode over product name // Add tooltip with barcode over product name
let display_barcode = "Aucun"; let display_barcode = "Aucun";
...@@ -344,7 +346,7 @@ function initLists() { ...@@ -344,7 +346,7 @@ function initLists() {
title:"Autres", title:"Autres",
className:"dt-body-center", className:"dt-body-center",
orderable: false, orderable: false,
render: function (data, type, full, meta) { render: function (data, type, full) {
let disabled = (full.supplier_shortage) ? "disabled" : ''; let disabled = (full.supplier_shortage) ? "disabled" : '';
return "<select class='select_product_action'>" return "<select class='select_product_action'>"
...@@ -900,10 +902,12 @@ function validateEdition(form) { ...@@ -900,10 +902,12 @@ function validateEdition(form) {
// Set the quantity to 0 for all the products in to_process // Set the quantity to 0 for all the products in to_process
function setAllQties() { function setAllQties() {
// Iterate over all rows in to_process // Iterate over all rows in to_process
table_to_process.rows().every(function (rowIdx, tableLoop, rowLoop) { table_to_process.rows().every(function () {
var data = this.data(); var data = this.data();
editProductInfo(data, 0); editProductInfo(data, 0);
return true;
}); });
list_to_process = []; list_to_process = [];
table_to_process.rows().remove() table_to_process.rows().remove()
...@@ -1128,7 +1132,7 @@ function send() { ...@@ -1128,7 +1132,7 @@ function send() {
traditional: true, traditional: true,
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
data: JSON.stringify(update_data), data: JSON.stringify(update_data),
success: function(data) { success: function() {
closeModal(); closeModal();
try { try {
...@@ -1215,11 +1219,11 @@ function send() { ...@@ -1215,11 +1219,11 @@ function send() {
} }
// Go back to to_process list if modal closed // Go back to to_process list if modal closed
$('#modal_closebtn_top').on('click', function (e) { $('#modal_closebtn_top').on('click', function () {
document.location.href = "/reception"; document.location.href = "/reception";
}); });
$('#modal_closebtn_bottom').on('click', function (e) { $('#modal_closebtn_bottom').on('click', function () {
document.location.href = "/reception"; document.location.href = "/reception";
}); });
...@@ -1305,7 +1309,7 @@ function confirmPricesAllValid() { ...@@ -1305,7 +1309,7 @@ function confirmPricesAllValid() {
function confirm_all_left_is_good() { function confirm_all_left_is_good() {
// all products left are to be considered as well filled // all products left are to be considered as well filled
// Iterate over all rows in to_process // Iterate over all rows in to_process
table_to_process.rows().every(function (rowIdx, tableLoop, rowLoop) { table_to_process.rows().every(function () {
let data = this.data(); let data = this.data();
var value = null; var value = null;
...@@ -1315,6 +1319,8 @@ function confirm_all_left_is_good() { ...@@ -1315,6 +1319,8 @@ function confirm_all_left_is_good() {
value = data.price_unit; value = data.price_unit;
} }
editProductInfo(data, value); editProductInfo(data, value);
return true;
}); });
list_to_process = []; list_to_process = [];
table_to_process.rows().remove() table_to_process.rows().remove()
...@@ -1562,12 +1568,12 @@ $(document).ready(function() { ...@@ -1562,12 +1568,12 @@ $(document).ready(function() {
container_edition.addEventListener('animationend', onAnimationEnd); container_edition.addEventListener('animationend', onAnimationEnd);
container_edition.addEventListener('webkitAnimationEnd', onAnimationEnd); container_edition.addEventListener('webkitAnimationEnd', onAnimationEnd);
function onAnimationEnd(e) { function onAnimationEnd() {
container_edition.classList.remove('blink_me'); container_edition.classList.remove('blink_me');
} }
// Disable mousewheel on an input number field when in focus // Disable mousewheel on an input number field when in focus
$('#edition_input').on('focus', function (e) { $('#edition_input').on('focus', function () {
$(this).on('wheel.disableScroll', function (e) { $(this).on('wheel.disableScroll', function (e) {
e.preventDefault(); e.preventDefault();
/* /*
...@@ -1582,7 +1588,7 @@ $(document).ready(function() { ...@@ -1582,7 +1588,7 @@ $(document).ready(function() {
*/ */
}); });
}) })
.on('blur', function (e) { .on('blur', function () {
$(this).off('wheel.disableScroll'); $(this).off('wheel.disableScroll');
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment