Commit de80e43a authored by Eric Seigne's avatar Eric Seigne
Browse files

creation tables ok et synchronisation offline ok

parent b34b6473
......@@ -455,6 +455,16 @@
ons.ready(function () {
document.addEventListener('deviceready', function () {
myDebug("deviceReady index.html");
let gotoLoginPage = true;
// $(document).ready(function () {
if (localGetData("email") != null) {
$("#autoLoginText").append("Compte " + localGetData("email") + " sur " + localGetData("name_server"));
$('input[name="email"]').val(localGetData("email"));
}
//On nettoie l'historique au lancement de l'appli
cleanHistorique();
......@@ -505,31 +515,25 @@
});
});
myDebug("SQL : end config ok");
if (localGetData("api_server") != null) {
gotoLoginPage = false;
//Au lancement on regarde si on a pas déjà ces infos de la dernière fois ...
// switchServer('#server', localGetData("name_server"), localGetData("api_server"));
//Et on essaye de reprendre la session !
loginWithAPIToken();
}
if (gotoLoginPage) {
// myDebug("carouselLogin 7");
carouselLogin();
}
});
myDebug("SQL : end 2 config ok");
}
let gotoLoginPage = true;
// $(document).ready(function () {
if (localGetData("email") != null) {
$("#autoLoginText").append("Compte " + localGetData("email") + " sur " + localGetData("name_server"));
$('input[name="email"]').val(localGetData("email"));
}
if (localGetData("api_server") != null) {
gotoLoginPage = false;
//Au lancement on regarde si on a pas déjà ces infos de la dernière fois ...
// switchServer('#server', localGetData("name_server"), localGetData("api_server"));
//Et on essaye de reprendre la session !
loginWithAPIToken();
}
// else {
// switchServer('#server', "CAP-REL démo", 'https://z.cap-rel.fr/ndfdemo');
// }
if (gotoLoginPage) {
// myDebug("carouselLogin 7");
carouselLogin();
}
});
});
......
......@@ -189,21 +189,20 @@ function feedToSync(formField) {
t.executeSql('SELECT * FROM ldfsToSync', [],
function (tx, rs) {
let html = "";
myDebug(" -> SQL SELECT * OK: res " + rs.rows.length);
let nbRes = rs.rows.length;
let i = 0;
let html = "<ul>";
for (i = 0; i < nbRes; i++) {
let id = rs.rows.item(i).sid;
let id = rs.rows.item(i).id;
let url = rs.rows.item(i).url;
let jsonData = rs.rows.item(i).jsonData;
let localFileName = rs.rows.item(i).localFileName;
let data = JSON.parse(jsonData);
html += "<li>" + id + ": " + data.typeFrais + " du " + data.ladate + " (" + data.label + ", " + data.ttc + " €) <ons-button modifier=\"material\" onclick=\"rSyncOne(" + id + ");\">Sync</ons-button></li>\n";
html += "<div style=\"clear:both\">" + id + ": " + data.typeFrais + " du " + data.ladate + " (" + data.label + ", " + data.ttc + " €) <br /><div style=\"float:right\"><ons-button modifier=\"material\" onclick=\"rSyncOne(" + id + ");\">Synchroniser</ons-button> <ons-button modifier=\"material\" onclick=\"rSyncDeleteConfirm(" + id + ");\">Supprimer</ons-button></div></div><hr />\n";
}
html += "</ul>";
$(formField).append(html);
},
function () {
......@@ -471,16 +470,19 @@ ons.ready(function () {
fn.back();
});
if (globalDB == null) {
myDebug("SQL : On essaye d'ouvrir la base de données ...");
globalDB = window.sqlitePlugin.openDatabase({
name: 'doliscan.db',
location: 'default',
androidDatabaseProvider: 'system'
}, function () {
myDebug("SQL : ouverture OK, les tables existent deja (page index)");
});
myDebug("SQL : end 2 config ok");
var path = window.location.pathname;
var page = path.split("/").pop();
if (page != "index.html") {
if (globalDB == null) {
myDebug("SQL : On essaye d'ouvrir la base de données ...");
globalDB = window.sqlitePlugin.openDatabase({
name: 'doliscan.db',
location: 'default',
androidDatabaseProvider: 'system'
}, function () {
myDebug("SQL : ouverture OK (ndf-head hors index.html normalement)");
});
}
}
});
});
......
......@@ -722,6 +722,20 @@ function genericCheckForm() {
}
}
//Supprime un id en attente de synchronisation
function rSyncDelete(idToDelete) {
if (globalDB != null) {
myDebug("SQL DELETE FROM ldfsToSync WHERE ID=" + idToDelete);
globalDB.executeSql('DELETE FROM ldfsToSync WHERE ID=?;', [idToDelete]);
myDebug("SQL DELETE FROM ... : ok");
gotoPage('sync.html', false);
}
else {
myDebug("ERREUR SQL DELETE impossible (rsyncdelete)");
gotoPage('sync.html', false);
}
}
//Synchronise un élément vers le serveur
function rSyncOne(idToSync) {
showWait();
......
......@@ -22,4 +22,15 @@
$(document).ready(function () {
setPageTitle("Synchronisation");
});
function rSyncDeleteConfirm(id) {
ons.notification.confirm("Voulez-vous vraiment supprimer ce document ?", {
title: "Vérification", buttonLabels: ['Non', 'Oui, supprimer'],
callback: function (index) {
if (index == 1) {
rSyncDelete(id);
}
}
});
}
</script>
Supports Markdown
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