Commit e6c44c7a by Damien Moulard Committed by Alexis Aoun

fix pouchdb actions continuity

parent 9f638578
...@@ -178,7 +178,7 @@ function compute_products_coverage_qties() { ...@@ -178,7 +178,7 @@ function compute_products_coverage_qties() {
* Update order products data in case they have changed. * Update order products data in case they have changed.
*/ */
function check_products_data() { function check_products_data() {
return new Promise((resolve, reject) => { return new Promise((resolve) => {
const suppliers_id = selected_suppliers.map(s => s.id); const suppliers_id = selected_suppliers.map(s => s.id);
if (suppliers_id.length > 0) { if (suppliers_id.length > 0) {
...@@ -701,14 +701,20 @@ function update_cdb_order() { ...@@ -701,14 +701,20 @@ function update_cdb_order() {
fingerprint: fingerprint fingerprint: fingerprint
}; };
return new Promise((resolve) => {
dbc.put(order_doc, function callback(err, result) { dbc.put(order_doc, function callback(err, result) {
if (!err && result !== undefined) { if (!err && result !== undefined) {
order_doc._rev = result.rev; order_doc._rev = result.rev;
resolve();
} else { } else {
alert("Erreur lors de la sauvegarde de la commande... Si l'erreur persiste contactez un administrateur svp."); alert("Erreur lors de la sauvegarde de la commande... Si l'erreur persiste contactez un administrateur svp.");
console.log(err); console.log(err);
resolve();
} }
}); });
});
} }
/** /**
...@@ -814,10 +820,10 @@ function create_orders() { ...@@ -814,10 +820,10 @@ function create_orders() {
// Clear data // Clear data
order_doc._deleted = true; order_doc._deleted = true;
update_cdb_order(); update_cdb_order().then(() => {
reset_data();
update_order_selection_screen(); update_order_selection_screen();
})
reset_data();
switch_screen('orders_created'); switch_screen('orders_created');
closeModal(); closeModal();
}, },
...@@ -1457,7 +1463,6 @@ function update_order_selection_screen() { ...@@ -1457,7 +1463,6 @@ function update_order_selection_screen() {
} else { } else {
for (let row of result.rows) { for (let row of result.rows) {
let template = $("#templates #order_pill_template"); let template = $("#templates #order_pill_template");
template.find(".pill_order_name").text(row.id); template.find(".pill_order_name").text(row.id);
existing_orders_container.append(template.html()); existing_orders_container.append(template.html());
...@@ -1517,13 +1522,10 @@ function switch_screen(direction = 'main_screen', from = 'main_screen') { ...@@ -1517,13 +1522,10 @@ function switch_screen(direction = 'main_screen', from = 'main_screen') {
} }
$(document).ready(function() { /**
fingerprint = new Fingerprint({canvas: true}).get(); * Init the PouchDB local database & sync
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } }); */
function init_pouchdb_sync() {
openModal();
// Init CouchDB
dbc = new PouchDB(couchdb_dbname); dbc = new PouchDB(couchdb_dbname);
sync = PouchDB.sync(couchdb_dbname, couchdb_server, { sync = PouchDB.sync(couchdb_dbname, couchdb_server, {
live: true, live: true,
...@@ -1543,13 +1545,12 @@ $(document).ready(function() { ...@@ -1543,13 +1545,12 @@ $(document).ready(function() {
className: "error" className: "error"
} }
); );
update_order_selection_screen();
back(); back();
break; break;
} else if (doc._deleted === true) {
update_order_selection_screen();
} }
} }
update_order_selection_screen();
} }
}).on('error', function (err) { }).on('error', function (err) {
if (err.status === 409) { if (err.status === 409) {
...@@ -1559,6 +1560,16 @@ $(document).ready(function() { ...@@ -1559,6 +1560,16 @@ $(document).ready(function() {
console.log('erreur sync'); console.log('erreur sync');
console.log(err); console.log(err);
}); });
}
$(document).ready(function() {
fingerprint = new Fingerprint({canvas: true}).get();
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
openModal();
init_pouchdb_sync();
// Main screen // Main screen
$("#coverage_form").on("submit", function(e) { $("#coverage_form").on("submit", function(e) {
......
...@@ -206,7 +206,6 @@ ...@@ -206,7 +206,6 @@
<div id="modal_create_order"> <div id="modal_create_order">
<h3>Dernière étape...</h3> <h3>Dernière étape...</h3>
<br/> <br/>
<p> <p>
Vous vous apprêtez à générer les commandes à partir des données rentrées dans le tableau. Vous vous apprêtez à générer les commandes à partir des données rentrées dans le tableau.
</p> </p>
......
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