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

version 1.6.9

parent 601a8502
# 1.6.9
- corrige un bug d'accès en écriture en // à IndexedDB sur certains smartphone
# 1.6.8
- corrige un bug d'accès en écriture en // à IndexedDB sur certains smartphone
......
<?xml version='1.0' encoding='utf-8'?>
<widget id="fr.caprel.doliscan" version="1.6.8" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="fr.caprel.doliscan" version="1.6.9" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>doliscan</name>
<description>DoliSCAN is a tiny app for french people looking for a free and self hosting "notes de frais/expenses report" solution.</description>
<author email="eric.seigne@cap-rel.fr" href="https://cap-rel.fr">Eric Seigne</author>
......@@ -146,5 +146,5 @@
</feature>
</platform>
<plugin name="cordova-plugin-calendar" />
<preference name="OverrideUserAgent" value="Mozilla/5.0 OpenNDF/1.6.8 Android" />
<preference name="OverrideUserAgent" value="Mozilla/5.0 OpenNDF/1.6.9 Android" />
</widget>
......@@ -74,12 +74,14 @@
}
if (globalMyNavigator !== undefined) {
$('#loadingStep').text('Etape 9a');
myDebug(" Etape 9a");
myDebug(" realLoginOrMenu resetToPage login.html");
// myDebug(" realLoginOrMenu globalMyNavigator stack : " + JSON.stringify(globalMyNavigator.pages));
globalMyNavigator.resetToPage('login.html', { data: { title: 'avenir', name: "login.html" } });
}
else {
myDebug(" realLoginOrMenu pas de navigator :-(");
myDebug(" Etape 9b");
$('#loadingStep').text('Etape 9b');
}
}
......@@ -122,6 +124,7 @@
globalMyNavigator = document.getElementById('myNavigator');
myDebug(' lancement, globalMyNavigator apres = ' + globalMyNavigator);
myDebug(" Etape 1");
$('#loadingStep').text('Etape 1');
// -----------------------------
// gestion du splitter ...
......@@ -148,6 +151,7 @@
let onsRightMenu = document.getElementById('rightmenu');
if (onsRightMenu != undefined)
onsRightMenu.close();
myDebug(" Etape 2");
$('#loadingStep').text('Etape 2');
// var modal = document.querySelector('ons-modal');
......@@ -183,128 +187,114 @@
//On nettoie l'historique au lancement de l'appli
cleanHistorique();
if (globalIndexedDB == null && databaseEngine == 'IndexedDB') {
$('#loadingStep').text('Etape 3a');
// myDebug("SQL : On essaye d'ouvrir la base de données ...");
var openRequest = window.indexedDB.open(databaseName, databaseVersion);
openRequest.onerror = function (event) {
myDebug(" global db openRequest.onerror " + event.error);
myDebug(openRequest.errorCode);
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
globalIndexedDB = openRequest.result;
myDebug(" global db type IndexedDB open ok");
$('#loadingStep').text('Etape 4a');
var transaction = globalIndexedDB.transaction(['config'], "readwrite");
transaction.oncomplete = function (event) {
$('#loadingStep').text('Etape 4e');
myDebug("global db transaction.oncomplete ok");
}
transaction.onerror = function (event) {
$('#loadingStep').text('Etape 4f');
myDebug("global db transaction.onerror : " + event.error);
if (!('indexedDB' in window)) {
myDebug('This browser doesn\'t support IndexedDB');
}
else {
if (globalIndexedDB == null && databaseEngine == 'IndexedDB') {
myDebug(" Etape 3a");
$('#loadingStep').text('Etape 3a');
myDebug("SQL : On essaye d'ouvrir la base de données ..." + databaseName + " version " + databaseVersion);
var openRequest = window.indexedDB.open(databaseName, databaseVersion);
openRequest.onerror = function (event) {
myDebug(" global db openRequest.onerror " + event.error);
myDebug(openRequest.errorCode);
};
var objectStore = transaction.objectStore('config');
objectStore.openCursor().onsuccess = function (event) {
$('#loadingStep').text('Etape 5a');
var cursor = event.target.result;
if (cursor) {
$('#loadingStep').text('Etape 6a');
// myDebug("Lecture IndexedDB " + cursor.key + " is " + cursor.value.data);
let k = cursor.key;
let v = cursor.value.data;
//Mise a jour uniquement si non vide
if (v !== null && v != "") {
localStorage.setItem(k, v);
myDebug(' select localStorage ' + k + ' -> ' + v);
openRequest.onupgradeneeded = function (event) {
myDebug(" Etape 4b");
$('#loadingStep').text('Etape 4b');
myDebug(" global db upgrade or create");
// This is either a newly created database, or a new version number
// has been submitted to the open() call.
var globalIndexedDB = event.target.result;
globalIndexedDB.onerror = function () {
myDebug(globalIndexedDB.errorCode);
};
myDebug("contenu : " + JSON.stringify(globalIndexedDB.objectStoreNames));
if (!globalIndexedDB.objectStoreNames.contains('ldfsToSync')) {
var storeLDF = globalIndexedDB.createObjectStore('ldfsToSync', { autoIncrement: true });
storeLDF.createIndex('url', 'url', { unique: false });
storeLDF.createIndex('localFileName', 'localFileName', { unique: false });
storeLDF.createIndex('ladate', 'ladate', { unique: false });
myDebug("SQL : index on ldfsToSync ok");
storeLDF.transaction.oncomplete = function (event) {
};
}
if (!globalIndexedDB.objectStoreNames.contains('doliscanconfig')) {
var storeConfig = globalIndexedDB.createObjectStore('doliscanconfig', { keyPath: 'key' });
// storeConfig.createIndex('value', 'value', { unique: false });
myDebug("SQL : create config ok");
storeConfig.transaction.oncomplete = function (event) {
myDebug(" Etape 5a");
$('#loadingStep').text('Etape 5ab');
switchLoginOrMenu();
}
myDebug(" Etape 5b");
$('#loadingStep').text('Etape 5b');
};
}
openRequest.onsuccess = function (event) {
myDebug(" global db type IndexedDB open ok");
// Database is open and initialized - we're good to proceed.
globalIndexedDB = event.target.result;
myDebug(" global db type IndexedDB open ok");
myDebug(" Etape 4a");
$('#loadingStep').text('Etape 4a');
var trans = globalIndexedDB.transaction(['doliscanconfig'], "readwrite");
var objStore = trans.objectStore('doliscanconfig');
var objectCursor = objStore.openCursor();
$('#loadingStep').text('Etape 4a2');
myDebug(" Etape 4a2");
objectCursor.onsuccess = function (event) {
myDebug(" Etape 5a");
$('#loadingStep').text('Etape 5a');
var cursor = event.target.result;
if (cursor) {
myDebug(" Etape 6a");
$('#loadingStep').text('Etape 6a');
// myDebug("Lecture IndexedDB " + cursor.key + " is " + cursor.value.data);
let k = cursor.key;
let v = cursor.value.data;
//Mise a jour uniquement si non vide
if (v !== null && v != "") {
localStorage.setItem(k, v);
myDebug(' select localStorage ' + k + ' -> ' + v);
}
else {
myDebug(' select localStorage ' + k + ' -> null on ne fait donc pas le localStorage :-)');
}
// myDebug("IndexedDB : read OK");
myDebug(" Etape 7a");
$('#loadingStep').text('Etape 7a');
cursor.continue();
}
else {
myDebug(' select localStorage ' + k + ' -> null on ne fait donc pas le localStorage :-)');
myDebug(" Etape 6b");
$('#loadingStep').text('Etape 6b');
myDebug("No more entries!");
switchLoginOrMenu();
}
cursor.continue();
// myDebug("IndexedDB : read OK");
$('#loadingStep').text('Etape 7a');
}
else {
$('#loadingStep').text('Etape 6b');
myDebug("No more entries!");
};
objectCursor.onerror = function (event) {
myDebug(" IndexedDB Error " + error.message);
myDebug(" Etape 7b");
$('#loadingStep').text('Etape 7b');
switchLoginOrMenu();
}
};
objectStore.openCursor().onerror = function (event) {
myDebug(" IndexedDB Error " + error.message);
$('#loadingStep').text('Etape 7b');
switchLoginOrMenu();
}
};
openRequest.onupgradeneeded = function (event) {
$('#loadingStep').text('Etape 4b');
myDebug(" global db upgrade or create");
// This is either a newly created database, or a new version number
// has been submitted to the open() call.
var db = event.target.result;
db.onerror = function () {
myDebug(db.errorCode);
};
// Create an object store and indexes. A key is a data value used to organize
// and retrieve values in the object store. The keyPath option identifies where
// the key is stored. If a key path is specified, the store can only contain
// JavaScript objects, and each object stored must have a property with the
// same name as the key path (unless the autoIncrement option is true).
var storeLDF = db.createObjectStore('ldfsToSync', { autoIncrement: true });
// Define the indexes we want to use. Objects we add to the store don't need
// to contain these properties, but they will only appear in the specified
// index of they do.
//
// syntax: store.createIndex(indexName, keyPath[, parameters]);
//
// All these values could have duplicates, so set unique to false
storeLDF.createIndex('url', 'url', { unique: false });
//On a des frais sans photos -> donc pas unique
storeLDF.createIndex('localFileName', 'localFileName', { unique: false });
storeLDF.createIndex('ladate', 'ladate', { unique: false });
myDebug("SQL : index on ldfsToSync ok");
// Once the store is created, populate it
storeLDF.transaction.oncomplete = function (event) {
// The transaction method takes an array of the names of object stores
// and indexes that will be in the scope of the transaction (or a single
// string to access a single object store). The transaction will be
// read-only unless the optional 'readwrite' parameter is specified.
// It returns a transaction object, which provides an objectStore method
// to access one of the object stores that are in the scope of this
//transaction.
//TODO ?
// var customerStore = db.transaction('customers', 'readwrite').objectStore('customers');
// customers.forEach(function (customer) {
// customerStore.add(customer);
// });
};
var storeConfig = db.createObjectStore('config', { keyPath: 'key' });
// storeConfig.createIndex('value', 'value', { unique: false });
myDebug("SQL : create config ok");
storeConfig.transaction.oncomplete = function (event) {
$('#loadingStep').text('Etape 5a');
switchLoginOrMenu();
}
$('#loadingStep').text('Etape 5b');
};
}
else {
$('#loadingStep').text('Etape 3b ** ');
switchLoginOrMenu();
}
else {
myDebug(" Etape 3b **");
$('#loadingStep').text('Etape 3b ** ');
switchLoginOrMenu();
}
}
// myDebug("index.html : " + localGetData("official_app_message"));
});
......
......@@ -2,7 +2,7 @@
* (c) Éric Seigne <eric.seigne@cap-rel.fr> - 2019-2020 - GNU AGPLv3
* full source code in src/ subfolder, this file is minifyed
*/
var globalDevMode=false;var globalMyCamera;var globalpictureSource;var globaldestinationType;var globalNetworkResponse=Date.now();var globalCurrentPage="";var globalCurrentTitle="";var globalTenMinuts=60*10*1000;var globalCompatibleWithAPIVersion=4;var globalDoliScanDomain="";var globalLastInsertId="";var globalSyncInProgress=false;var globalPictureFileName="";var globalAppVersion="1.6.8";var dataLDF="";var dataIK="";var globalMyNavigator=undefined;var globalResumable=undefined;var globalProgressBar=undefined;var globalTypeFrais="";var globalVehiculeEd=undefined;var globalSrvKeys=['email','api_token','firstname','name','adresse','cp','ville','pays','send_copy_to','compta_email','compta_ik','compta_peage','compta_hotel','compta_train','compta_carburant','compta_taxi','compta_restauration','compta_divers','compta_compteperso','compta_tvadeductible','official_app_version','official_app_message','mode_simple'];function errorHandlerCustomFile(title,message){myDebug('errorHandlerCustomFile : '+title+' -- message follow:');myDebug(message);}
var globalDevMode=false;var globalMyCamera;var globalpictureSource;var globaldestinationType;var globalNetworkResponse=Date.now();var globalCurrentPage="";var globalCurrentTitle="";var globalTenMinuts=60*10*1000;var globalCompatibleWithAPIVersion=4;var globalDoliScanDomain="";var globalLastInsertId="";var globalSyncInProgress=false;var globalPictureFileName="";var globalAppVersion="1.6.9";var dataLDF="";var dataIK="";var globalMyNavigator=undefined;var globalResumable=undefined;var globalProgressBar=undefined;var globalTypeFrais="";var globalVehiculeEd=undefined;var globalSrvKeys=['email','api_token','firstname','name','adresse','cp','ville','pays','send_copy_to','compta_email','compta_ik','compta_peage','compta_hotel','compta_train','compta_carburant','compta_taxi','compta_restauration','compta_divers','compta_compteperso','compta_tvadeductible','official_app_version','official_app_message','mode_simple'];function errorHandlerCustomFile(title,message){myDebug('errorHandlerCustomFile : '+title+' -- message follow:');myDebug(message);}
function loadCustomCSS(){if((typeof cordova=='undefined')||(cordova===null)||(cordova=="")){return;}
if((typeof cordova.file=='undefined')||(cordova.file===null)||(cordova.file=="")){return;}
if((typeof cordova.file.cacheDirectory=='undefined')||(cordova.file.cacheDirectory===null)||(cordova.file.cacheDirectory=="")){return;}
......@@ -19,7 +19,7 @@ if((typeof cordova.file=='undefined')||(cordova.file===null)||(cordova.file=="")
if((typeof cordova.file.cacheDirectory=='undefined')||(cordova.file.cacheDirectory===null)||(cordova.file.cacheDirectory=="")){return;}
let logoFileName=cordova.file.cacheDirectory+'custom.png';window.resolveLocalFileSystemURL(logoFileName,function(fileEntry){fileEntry.file(function(file){var reader=new FileReader();var fileSize=file.size;reader.onloadend=function(){var blob=new Blob([new Uint8Array(this.result)],{type:"image/png"});$("#homeLogo").attr("src",window.URL.createObjectURL(blob));};reader.readAsArrayBuffer(file);},errorHandlerCustomFile.bind(null,logoFileName));},errorHandlerCustomFile.bind(null,logoFileName));}
function removeCustomFiles(){deleteFile(cordova.file.cacheDirectory,'custom.png');deleteFile(cordova.file.cacheDirectory,'custom.css');localStoreData("customAbout","");}
var globalDB=null;var databaseEngine='IndexedDB';var databaseName='doliscanDB';var databaseVersion=6;var globalIndexedDB=null;function readFromFile(fileName,formdata,subject){var pathToFile=cordova.file.documentsDirectory+fileName;window.resolveLocalFileSystemURL(fileName,function(fileEntry){fileEntry.file(function(file){var reader=new FileReader();var fileSize=file.size;reader.onloadend=function(e){var fileContent=new Uint8Array(reader.result);formdata.append("afile",fileContent);formdata.append("afilesize",fileSize);var today=new Date();var destFilename=today.getFullYear().toString()+('0'+(today.getMonth()+1)).slice(-2)+('0'+today.getDate()).slice(-2)+"_"
var globalDB=null;var databaseEngine='IndexedDB';var databaseName='doliscanDB';var databaseVersion=8;var globalIndexedDB=null;function readFromFile(fileName,formdata,subject){var pathToFile=cordova.file.documentsDirectory+fileName;window.resolveLocalFileSystemURL(fileName,function(fileEntry){fileEntry.file(function(file){var reader=new FileReader();var fileSize=file.size;reader.onloadend=function(e){var fileContent=new Uint8Array(reader.result);formdata.append("afile",fileContent);formdata.append("afilesize",fileSize);var today=new Date();var destFilename=today.getFullYear().toString()+('0'+(today.getMonth()+1)).slice(-2)+('0'+today.getDate()).slice(-2)+"_"
+today.getHours().toString()+today.getMinutes().toString()+"-"+subject+"-"+basename(fileName);var newFileUri=cordova.file.documentsDirectory;moveFile(fileName,destFilename);endSendForm(formdata,destFilename);};reader.readAsArrayBuffer(file);},errorHandler.bind(null,fileName));},errorHandler.bind(null,fileName));}
function searchVille(leform,ville,slug){myDebug("searchVille : "+ville);let objForm=document.getElementById(leform);let d=$('#'+ville).val();let a="";showWait();$.ajaxSetup({timeout:5000,});result=undefined;if(ajaxDistance)
ajaxDistance.abort();var ajaxDistance=$.ajax({type:"GET",timeout:5000,url:"https://geo.doliscan.fr/api/geo/"+fixedEncodeURIComponent(d)+"/"+fixedEncodeURIComponent(a),beforeSend:function(xhr){xhr.setRequestHeader('Authorization','Bearer '+localGetData("api_token"));},xhrFields:{withCredentials:true},success:function(result){myDebug('searchVille ajax ok1 ::: '+JSON.stringify(result));myDebug(result);if(result!=undefined){hideWait();if(result.departsNb==0){ons.notification.alert("Saisie manuelle nécessaire, cette ville n'est pas connue de nos serveurs",{title:"Erreur #1"});}
......@@ -220,7 +220,7 @@ let onsRightMenu=document.getElementById('rightmenu');if(onsRightMenu!=undefined
onsRightMenu.close();requestKeepAlive();return true;}
function cleanHistorique(){myDebug('call cleanHistorique');listeContent=new Array('');localStoreData("history",JSON.stringify(listeContent));}
function closeSession(){localStoreData("api_token",null);localStoreData("name_server",null);askQuitOrGoto("login.html");}
ons.ready(function(){ons.enableDeviceBackButtonHandler();ons.setDefaultDeviceBackButtonListener(function(event){fn.back();});var path=window.location.pathname;var page=path.split("/").pop();if(page!="index.html"){if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){var openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug("global db type IndexedDB open err (ndf-head)"+openRequest.errorCode);};openRequest.onsuccess=function(event){globalIndexedDB=openRequest.result;myDebug("global db type IndexedDB open ok (ndf-head)");}}}});document.addEventListener("deviceready",NDFonDeviceReady,false);function NDFonDeviceReady(){myDebug("NDFonDeviceReady de ndf.js");if(navigator.camera!==undefined){globalMyCamera=navigator.camera;globalPictureSource=navigator.camera.PictureSourceType;globalDestinationType=navigator.camera.DestinationType;globalMyCamera.cleanup();}
ons.ready(function(){ons.enableDeviceBackButtonHandler();ons.setDefaultDeviceBackButtonListener(function(event){fn.back();});var path=window.location.pathname;var page=path.split("/").pop();});document.addEventListener("deviceready",NDFonDeviceReady,false);function NDFonDeviceReady(){myDebug("NDFonDeviceReady de ndf.js");if(navigator.camera!==undefined){globalMyCamera=navigator.camera;globalPictureSource=navigator.camera.PictureSourceType;globalDestinationType=navigator.camera.DestinationType;globalMyCamera.cleanup();}
else{myDebug("Erreur: camera introuvable !");}
myDebug("NDFonDeviceReady de ndf.js : camera ready");}
function onPhotoDataSuccess(imageData){myDebug("onPhotoDataSuccess :"+imageURI);var smallImage=document.getElementById('smallImage');smallImage.style.display='block';smallImage.src="data:image/jpeg;base64,"+imageData;var photoFacturette=document.getElementById('photoFacturette');photoFacturette.value="2";}
......@@ -356,23 +356,23 @@ function deleteFile(dirName,fileName){window.resolveLocalFileSystemURL(dirName,f
function addLocalStorageEntry(liste,entry){if((typeof liste!='undefined')&&(liste!==null)&&(liste!="")){if((typeof entry!='undefined')&&(entry!==null)&&(entry!="")){let listeContent=JSON.parse(localGetData(liste));if(Array.isArray(listeContent)){listeContent.push(entry);listeContent=myUniqueSort(listeContent);}
else{listeContent=new Array(entry);}
localStoreData(liste,JSON.stringify(listeContent));}}}
function localStoreData(lakey,lavalue){localStorage.setItem(lakey,lavalue);if(lakey=="vehicules"||lakey=="vehiculesPro"){let ladate=new Date();let lastUpdate=ladate.toISOString();localStorage.setItem("vehiculesLastUpdate",lastUpdate);}
function localStoreData(lakey,lavalue){myDebug('localStoreData : '+lakey+' et '+lavalue);localStorage.setItem(lakey,lavalue);if(lakey=="vehicules"||lakey=="vehiculesPro"){let ladate=new Date();let lastUpdate=ladate.toISOString();localStorage.setItem("vehiculesLastUpdate",lastUpdate);}
if(lakey=='history'){return;}
if(databaseEngine!='IndexedDB'){return;}
if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){let openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug(openRequest.errorCode);myDebug("global db type IndexedDB re-open error");};openRequest.onsuccess=function(event){globalIndexedDB=openRequest.result;myDebug("global db type IndexedDB re-open ok");localStoreDataNext(lakey,lavalue);};}
if(globalIndexedDB==null){myDebug(' localStoreData : bdd non connectée, return');return;}
else{localStoreDataNext(lakey,lavalue);}}
function localStoreDataNext(lakey,lavalue){if(globalIndexedDB!==null&&databaseEngine=='IndexedDB'){myDebug(" localStoreData put data asked for "+lakey+":"+lavalue);if((typeof lavalue!='undefined')&&(lavalue!==null)&&(lavalue!="")){myDebug(" localStoreData on a une valeur non nulle a stocker : "+lavalue);}
function localStoreDataNext(lakey,lavalue){myDebug(' localStoreDataNext : '+lakey+' et '+lavalue);if(globalIndexedDB!==null&&databaseEngine=='IndexedDB'){myDebug(" localStoreData put data asked for "+lakey+":"+lavalue);if((typeof lavalue!='undefined')&&(lavalue!==null)&&(lavalue!="")){myDebug(" localStoreData on a une valeur non nulle a stocker : "+lavalue);}
else{myDebug(" localStoreData on a une valeur vide ou nulle a stocker");lavalue="none";}
let transaction=globalIndexedDB.transaction(['config'],"readwrite").objectStore("config").put({key:lakey,data:lavalue});}
let transaction=globalIndexedDB.transaction(['doliscanconfig'],"readwrite").objectStore('doliscanconfig').put({key:lakey,data:lavalue});}
else{myDebug(" ERR: Accès à globalIndexedDB impossible (1) pour stocker "+lakey+" val "+lavalue+" *** ");}}
function localGetData(key){if((typeof localStorage.getItem(key)!='undefined')&&(localStorage.getItem(key)!==null)&&(localStorage.getItem(key)!=null)&&(localStorage.getItem(key)!='null')&&(localStorage.getItem(key)!="")&&(localStorage.getItem(key)!=undefined)&&(localStorage.getItem(key)!='undefined')){let v=localStorage.getItem(key);myDebug('localGetData : '+key+' -> '+v);if(v=="none"){v="";}
return v;}
myDebug("localGetData: on retourne null pour "+key)
return null;}
function localStoreLDFtoSync(urlIN,jsonDataIN,localFileNameIN){return new Promise((resolve,reject)=>{myDebug("localStoreLDFtoSync :"+urlIN+" "+jsonDataIN+" "+localFileNameIN);let d=new Date();let ladateIN=d.toISOString();let lavalue={url:urlIN,jsonData:jsonDataIN,localFileName:localFileNameIN,ladate:ladateIN};let id=-1;if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){myDebug(" localStoreLDFtoSync On essaye de ré-ouvrir la base de données ...");let openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug(openRequest.errorCode);myDebug(" localStoreLDFtoSync db type IndexedDB re-open error");};openRequest.onsuccess=function(event){globalIndexedDB=openRequest.result;myDebug(" localStoreLDFtoSync db type IndexedDB re-open ok");};}
function localStoreLDFtoSync(urlIN,jsonDataIN,localFileNameIN){return new Promise((resolve,reject)=>{myDebug("localStoreLDFtoSync :"+urlIN+" "+jsonDataIN+" "+localFileNameIN);let d=new Date();let ladateIN=d.toISOString();let lavalue={url:urlIN,jsonData:jsonDataIN,localFileName:localFileNameIN,ladate:ladateIN};let id=-1;if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){myDebug(" localStoreLDFtoSync On essaye de ré-ouvrir la base de données ...");let openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug(openRequest.errorCode);myDebug(" localStoreLDFtoSync db type IndexedDB re-open error");};openRequest.onsuccess=function(event){globalIndexedDB=event.target.result;myDebug(" localStoreLDFtoSync db type IndexedDB re-open ok");};}
if(globalIndexedDB!==null&&databaseEngine=='IndexedDB'){myDebug(" localStoreLDFtoSync db type IndexedDB put data asked pour "+JSON.stringify(lavalue));let transaction=globalIndexedDB.transaction(["ldfsToSync"],"readwrite");let objectStore=transaction.objectStore("ldfsToSync");let request=objectStore.put(lavalue);request.onsuccess=function(event){myDebug(" localStoreLDFtoSync put ok, id = "+event.target.result+" pour "+urlIN);id=event.target.result;globalLastInsertId=id;myDebug(" localStoreLDFtoSync globalLastInsertId = "+globalLastInsertId);resolve(id);};request.onerror=function(event){myDebug(" localStoreLDFtoSync put err pour "+urlIN);reject(null);};}
else{myDebug(" localStoreLDFtoSync ERR: Accès à globalIndexedDB (2) impossible pour stocker "+urlIN);reject(null);}});}
function localDeleteLDFtoSync(idIN){myDebug("localDeleteLDFtoSync :"+idIN);if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){myDebug("globalIndexedDB : On essaye d'ouvrir la base de données ...");let openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug(openRequest.errorCode);myDebug(" localDeleteLDFtoSync db type IndexedDB re-open error");};openRequest.onsuccess=function(event){globalIndexedDB=openRequest.result;myDebug(" localDeleteLDFtoSync db type IndexedDB re-open ok");};}
function localDeleteLDFtoSync(idIN){myDebug("localDeleteLDFtoSync :"+idIN);if(globalIndexedDB==null&&databaseEngine=='IndexedDB'){myDebug("globalIndexedDB : On essaye d'ouvrir la base de données ...");let openRequest=window.indexedDB.open(databaseName,databaseVersion);openRequest.onerror=function(event){myDebug(openRequest.errorCode);myDebug(" localDeleteLDFtoSync db type IndexedDB re-open error");};openRequest.onsuccess=function(event){globalIndexedDB=event.target.result;myDebug(" localDeleteLDFtoSync db type IndexedDB re-open ok");};}
if(globalIndexedDB!==null&&databaseEngine=='IndexedDB'){myDebug(" localDeleteLDFtoSync db type IndexedDB put data asked ...");let transaction=globalIndexedDB.transaction(["ldfsToSync"],"readwrite");let objectStore=transaction.objectStore("ldfsToSync");let request=objectStore.delete(idIN);request.onsuccess=function(event){myDebug(" localDeleteLDFtoSync delete ok");};request.onerror=function(event){myDebug(" localDeleteLDFtoSync put err pour "+urlIN);};}
else{myDebug(" localDeleteLDFtoSync ERR: Accès à globalIndexedDB impossible (3) pour stocker "+urlIN);}}
function localUpdateLDFfileName(idIN,newFileName){if(idIN>0){if(globalIndexedDB!==null&&databaseEngine=='IndexedDB'){myDebug("localUpdateLDFfileName id="+idIN);let objectStore=globalIndexedDB.transaction("ldfsToSync").objectStore("ldfsToSync","readwrite");objectStore.get(idIN).onsuccess=function(event){myDebug(" localUpdateLDFfileName get ok "+JSON.stringify(event.target.result));let v=event.target.result;if(v!==null&&v!=""){v.localFileName=newFileName;v.notified="yes";let vUpdate=objectStore.put(v);myDebug(" localUpdateLDFfileName originated this request is "+vUpdate.transaction);vUpdate.onsuccess=()=>{myDebug(" localUpdateLDFfileName rename filename ok");};vUpdate.onerror=()=>{myDebug(" localUpdateLDFfileName rename filename error");};}}
......
......@@ -17,7 +17,7 @@ var globalSyncInProgress = false; // Pour savoir si on est en phase de syn
var globalPictureFileName = ""; // Le nom du fichier sans résolution (depuis ios wkbidule app:// ... on garde dans cette variable le path basique pour resumable & sync)
// **********************************************************************
//Ne pas toucher, mis à jour automatiquement à partir du config.xml
var globalAppVersion = "1.6.8"; // mis à jour automatiquement à partir du fichier config.xml lors du build android
var globalAppVersion = "1.6.9"; // mis à jour automatiquement à partir du fichier config.xml lors du build android
// **********************************************************************
var dataLDF = "";
var dataIK = "";
......
......@@ -5,6 +5,6 @@
var globalDB = null; // Le connecteur vers la base de données SQLite
var databaseEngine = 'IndexedDB';
var databaseName = 'doliscanDB';
var databaseVersion = 6;
var databaseVersion = 8;
var globalIndexedDB = null; // Le connecteur vers la base de données IndexedDB
......@@ -13,17 +13,17 @@ ons.ready(function () {
var path = window.location.pathname;
var page = path.split("/").pop();
if (page != "index.html") {
if (globalIndexedDB == null && databaseEngine == 'IndexedDB') {
var openRequest = window.indexedDB.open(databaseName, databaseVersion);
openRequest.onerror = function (event) {
myDebug("global db type IndexedDB open err (ndf-head)" + openRequest.errorCode);
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
globalIndexedDB = openRequest.result;
myDebug("global db type IndexedDB open ok (ndf-head)");
}
}
}
// if (page != "index.html") {
// if (globalIndexedDB == null && databaseEngine == 'IndexedDB') {
// var openRequest = window.indexedDB.open(databaseName, databaseVersion);
// openRequest.onerror = function (event) {
// myDebug("global db type IndexedDB open err (ndf-head)" + openRequest.errorCode);
// };
// openRequest.onsuccess = function (event) {
// // Database is open and initialized - we're good to proceed.
// globalIndexedDB = openRequest.result;
// myDebug("global db type IndexedDB open ok (ndf-head)");
// }
// }
// }
});
......@@ -38,6 +38,7 @@ function addLocalStorageEntry(liste, entry) {
* @return {[type]} [return description]
*/
function localStoreData(lakey, lavalue) {
myDebug('localStoreData : ' + lakey + ' et ' + lavalue);
localStorage.setItem(lakey, lavalue);
//Si c'est un véhicule on garde la date de dernière mise à jour locale pour
......@@ -58,20 +59,23 @@ function localStoreData(lakey, lavalue) {
if (databaseEngine != 'IndexedDB') {
return;
}
if (globalIndexedDB == null && databaseEngine == 'IndexedDB') {
// myDebug("SQL : On essaye d'ouvrir la base de données ...");
// if (databaseEngine == 'IndexedDB') {
let openRequest = window.indexedDB.open(databaseName, databaseVersion);
openRequest.onerror = function (event) {
myDebug(openRequest.errorCode);
myDebug("global db type IndexedDB re-open error");
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
globalIndexedDB = openRequest.result;
myDebug("global db type IndexedDB re-open ok");
localStoreDataNext(lakey, lavalue);
};
if (globalIndexedDB == null) {
myDebug(' localStoreData : bdd non connectée, return');
//On est dans les appels avant que la connexion bdd ne soit active
return;
// // myDebug("SQL : On essaye d'ouvrir la base de données ...");
// // if (databaseEngine == 'IndexedDB') {
// let openRequest = window.indexedDB.open(databaseName, databaseVersion);
// openRequest.onerror = function (event) {
// myDebug(openRequest.errorCode);
// myDebug("global db type IndexedDB re-open error");
// };
// openRequest.onsuccess = function (event) {
// // Database is open and initialized - we're good to proceed.
// globalIndexedDB = openRequest.result;
// myDebug("global db type IndexedDB re-open ok");
// localStoreDataNext(lakey, lavalue);
// };
}
else {
localStoreDataNext(lakey, lavalue);
......@@ -79,6 +83,7 @@ function localStoreData(lakey, lavalue) {
}
function localStoreDataNext(lakey, lavalue) {
myDebug(' localStoreDataNext : ' + lakey + ' et ' + lavalue);
if (globalIndexedDB !== null && databaseEngine == 'IndexedDB') {
// if (databaseEngine == 'IndexedDB') {
myDebug(" localStoreData put data asked for " + lakey + ":" + lavalue);
......@@ -92,12 +97,12 @@ function localStoreDataNext(lakey, lavalue) {
}
//Tout sur une ligne pour eviter le pb des transactions qui se chevauchent...
let transaction = globalIndexedDB.transaction(['config'], "readwrite").objectStore("config").put({ key: lakey, data: lavalue });
let transaction = globalIndexedDB.transaction(['doliscanconfig'], "readwrite").objectStore('doliscanconfig').put({ key: lakey, data: lavalue });
// transaction.oncomplete = function (event) {
// myDebug(" localStoreData global db transaction.oncomplete ok ( " + lakey + ":" + lavalue + ")");
// let objectStore = transaction.objectStore('config');
// let objectStore = transaction.objectStore('doliscanconfig');
// objectStore.oncomplete = function (event) {
// let request = objectStore.put({ key: lakey, data: lavalue });
......@@ -174,7 +179,7 @@ function localStoreLDFtoSync(urlIN, jsonDataIN, localFileNameIN) {
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
globalIndexedDB = openRequest.result;
globalIndexedDB = event.target.result;
myDebug(" localStoreLDFtoSync db type IndexedDB re-open ok");
};
}
......@@ -220,7 +225,7 @@ function localDeleteLDFtoSync(idIN) {
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
globalIndexedDB = openRequest.result;
globalIndexedDB = event.target.result;
myDebug(" localDeleteLDFtoSync db type IndexedDB re-open ok");
};
}
......
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