Commit 2352252f authored by Eric Seigne's avatar Eric Seigne
Browse files

amelioration pour la popup de mise à jour de l'appli

parent 4f1b2a1f
......@@ -39,6 +39,12 @@
<script type="text/javascript" src="js/session-timeout.js"></script>
<script type="text/javascript" src="js/resumable.js"></script>
<script type="text/javascript">
$(document).ready(function () {
if (compareVersions(localGetData("official_app_version"), globalAppVersion) > 0) {
myDebug("bingo : " + localGetData("official_app_message"));
ons.notification.alert(localGetData("official_app_message"), { title: "Nouvelle version" });
}
});
</script>
</html>
......@@ -187,15 +187,10 @@
if (typeof result !== 'undefined') {
// myDebug("loginWithAPIToken : result ok");
// myDebug(result.data);
if (typeof result.data !== 'undefined') {
if (typeof result.data !== 'undefined' && typeof result.data.api_token !== 'undefined') {
// myDebug("loginWithAPIToken : result.data ok, on compare " + globalCompatibleWithAPIVersion + " et " + result.data.api_version);
//On a la même version d'API entre client & serveur
if (result.data.api_version == globalCompatibleWithAPIVersion) {
// myDebug("API Token tout est ok on bascule sur app.html");
//Peut-être qu'il existe néanmoins une mise à jour du client ...
if (result.data.app_version != 'undefined' && compareVersions(result.data.app_version, globalAppVersion) > 0) {
ons.notification.alert(result.data.app_version_message, { title: "Nouvelle version" });
}
//Dans tous les cas on peut continuer
updateLocalUserFromServer(result, updateLocalUserFromServerSuccess);
}
......@@ -317,56 +312,36 @@
email: lemail,
password: lpassword,
},
success: function (result) {
success: function (result, textStatus, request) {
globalNetworkResponse = Date.now();
hideWait();
//alert(JSON.stringify(result));
if (typeof result !== 'undefined') {
if (typeof result.data !== 'undefined') {
if (typeof result.data.api_token !== 'undefined') {
hideWait();
if (result.data.api_version == globalCompatibleWithAPIVersion) {
if (result.data.app_version != 'undefined' && compareVersions(result.data.app_version, globalAppVersion) > 0) {
ons.notification.alert(result.data.app_version_message, { title: "Nouvelle version" });
}
updateLocalUserFromServer(result, updateLocalUserFromServerSuccess);
}
else {
// myDebug("result.data.api_token undefined : " + result);
if (typeof result.data.api_version_message !== 'undefined') {
$("#messagePopupMessage").replaceWith(result.data.api_version_message);
$("#messagePopup").show();
}
}
// myDebug("carouselLogin 2");
carouselLogin();
// setTimeout(function(){ $("#erreurLogin").hide(); }, 5000);
if (typeof result.data !== 'undefined' && typeof result.data.api_token !== 'undefined') {
if (result.data.api_version == globalCompatibleWithAPIVersion) {
updateLocalUserFromServer(result, updateLocalUserFromServerSuccess);
}
else {
hideWait();
carouselLogin();
// myDebug("result.data.api_token undefined : " + result);
if (typeof result.data.api_version_message !== 'undefined') {
$("#messagePopupMessage").replaceWith(result.data.api_version_message);
$("#messagePopup").show();
}
}
carouselLogin();
// myDebug("carouselLogin 2");
// setTimeout(function(){ $("#erreurLogin").hide(); }, 5000);
}
else {
hideWait();
// myDebug("result.data undefined : " + result);
$("#erreurLogin").show();
// myDebug("carouselLogin 3");
carouselLogin();
// setTimeout(function(){ $("#erreurLogin").hide(); }, 5000);
}
}
else {
hideWait();
// myDebug("result undefined : " + result);
$("#erreurLogin").show();
// setTimeout(function(){ $("#erreurLogin").hide(); }, 5000);
// myDebug("carouselLogin 4");
carouselLogin();
}
if (localGetData("api_server") == null) {
hideWait();
// myDebug('index.html : erreur 1 ...');
$("#erreurLogin").show();
// setTimeout(function(){ $("#erreurLogin").hide(); }, 5000);
......@@ -412,7 +387,7 @@
ons.ready(function () {
document.addEventListener('deviceready', function () {
// myDebug("deviceReady index.html");
myDebug("deviceReady index.html");
let gotoLoginPage = true;
// $(document).ready(function () {
......@@ -490,19 +465,18 @@
// myDebug("SQL : end 2 config ok");
}
});
$(".toggle-password").click(function () {
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $($(this).attr("toggle"));
if (input.attr("type") == "password") {
input.attr("type", "text");
} else {
input.attr("type", "password");
}
});
});
$(".toggle-password").click(function () {
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $($(this).attr("toggle"));
if (input.attr("type") == "password") {
input.attr("type", "text");
} else {
input.attr("type", "password");
}
});
</script>
......
......@@ -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 globalDB=null;var globalTenMinuts=60*10*1000;var globalCompatibleWithAPIVersion=4;var globalDoliScanDomain="";var globalLastInsertId="";var globalSyncInProgress=false;var globalAppVersion="1.0.15";var dataLDF="";var globalResumable;var globalProgressBar;var globalTypeFrais="";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','mode_simple'];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 globalDevMode=false;var globalMyCamera;var globalpictureSource;var globaldestinationType;var globalNetworkResponse=Date.now();var globalCurrentPage="";var globalCurrentTitle="";var globalDB=null;var globalTenMinuts=60*10*1000;var globalCompatibleWithAPIVersion=4;var globalDoliScanDomain="";var globalLastInsertId="";var globalSyncInProgress=false;var globalAppVersion="1.0.15";var dataLDF="";var globalResumable;var globalProgressBar;var globalTypeFrais="";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 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 distanceAutomatique(depart,arrivee){showWait();$.ajaxSetup({timeout:5000,});$.ajax({type:"GET",timeout:5000,url:"https://geo.doliscan.fr/api/geo/"+depart+"/"+arrivee,beforeSend:function(xhr){xhr.setRequestHeader('Authorization','Bearer '+localGetData("api_token"));},success:function(result){if(result!='undefined'){hideWait();updateDistanceFromServer(result);}
else{hideWait();ons.notification.alert("Saisie manuelle nécessaire, cette distance n'est pas connue sur nos serveurs",{title:"Erreur"});}},error:function(result){hideWait();ons.notification.alert("Saisie manuelle nécessaire, cette distance n'est pas connue sur nos serveurs",{title:"Erreur"});}});}
......@@ -71,7 +71,7 @@ listeContent.push(page);listeContent.splice(0,listeContent.length-20);}
else{listeContent=new Array(page);}
localStoreData("history",JSON.stringify(listeContent));}}
function gotoPage(destination,saveHistory=true){requestKeepAlive();var menu=document.getElementById('menu');var vA=localGetData("configMode");if(saveHistory){historique(destination);}
$('#container').load(destination,function(){globalCurrentPage=destination;if(dataLDF!=""){completePageAfterGoto(dataLDF);}});if(destination.indexOf("frais-")>=0){$('#menuHautDroite').replaceWith('<div id="menuHautDroite" class="right"><ons-toolbar-button onclick="checkForm();"><i class="fas fa-check"></i></ons-toolbar-button></div>');}
$('#container').load(destination,function(){globalCurrentPage=destination;if(dataLDF!=""&&destination!="menu.html"){completePageAfterGoto(dataLDF);}});if(destination.indexOf("frais-")>=0){$('#menuHautDroite').replaceWith('<div id="menuHautDroite" class="right"><ons-toolbar-button onclick="checkForm();"><i class="fas fa-check"></i></ons-toolbar-button></div>');}
menu.close();}
function cleanHistorique(){listeContent=new Array('');localStoreData("history",JSON.stringify(listeContent));}
function closeSession(){localStoreData('api_token','');globalDB.close(function(){},function(error){});window.location.replace('index.html');}
......@@ -103,7 +103,7 @@ return r;}
function feedObjets(objets){if((typeof objets!=='undefined')&&(objets!=null)&&(objets!="")){for(var i=0;i<objets.length&&i<15;i++){$('#listeObjets').append('<div class=\"expandable-content list-item__expandable-content\"><a href="#" onclick="selectLabel(\''+objets[i]+'\');">'+objets[i]+'</a></div>');}}}
function selectLabel(objet){if((typeof objets!=='undefined')&&(objets!=null)&&(objets!="")){$('#label').val(objet);$('#listeObjets').hide();}}
function setPageTitle(titre){globalCurrentTitle=titre;$('#titreDoliScan').replaceWith('<div id="titreDoliScan" class="left" onclick="fn.back();"><i class="zmdi chevron-circle-left"></i> '+titre+'</div>');}
function completePageAfterGoto(dataLDF){document.getElementById("updateID").value=dataLDF['sid'];document.getElementById("photoFacturette").value="UPDATE";fieldsToValidate=['nom','arrivee','depart','distance','label','ladate','ttc','typeFrais','moyenPaiement','photoFacturette','tvaVal1','tvaVal2','tvaVal3','tvaVal4'];for(let i=0;i<fieldsToValidate.length;i++){field=fieldsToValidate[i];switch(field){case 'photoFacturette':$("#smallImage").attr("src",dataLDF[field]);break;case 'moyenPaiement':break;default:if(document.getElementById(field)){document.getElementById(field).value=dataLDF[field];}}}}
function completePageAfterGoto(dataLDF){myDebug("completePageAfterGoto ...");document.getElementById("updateID").value=dataLDF['sid'];document.getElementById("photoFacturette").value="UPDATE";fieldsToValidate=['nom','arrivee','depart','distance','label','ladate','ttc','typeFrais','moyenPaiement','photoFacturette','tvaVal1','tvaVal2','tvaVal3','tvaVal4'];for(let i=0;i<fieldsToValidate.length;i++){field=fieldsToValidate[i];switch(field){case 'photoFacturette':$("#smallImage").attr("src",dataLDF[field]);break;case 'moyenPaiement':break;default:if(document.getElementById(field)){document.getElementById(field).value=dataLDF[field];}}}}
ons.ready(function(){document.addEventListener('deviceready',function(){$('#label').keyup(function(){$('#listeObjets').show();});window.fn={};window.fn.open=function(){var menu=document.getElementById('menu');menu.open();};window.fn.load=function(page){historique(page);var content=document.getElementById('content');var menu=document.getElementById('menu');content.load(page).then(menu.close.bind(menu));};window.fn.back=function(){var listeContent=JSON.parse(localGetData("history"));if(Array.isArray(listeContent)&&(listeContent.length>1)){var currentPage=listeContent.pop();var prevPage=listeContent.pop();if(prevPage==""){if(globalCurrentTitle=="DoliSCAN"){askQuitOrMenu();}
else{cleanHistorique();globalCurrentTitle="DoliSCAN";$('#container').load("menu.html");}}
else{listeContent.push(prevPage);localStoreData("history",JSON.stringify(listeContent));$('#container').load(prevPage);globalCurrentPage=prevPage;return;}}
......
......@@ -26,5 +26,5 @@ var globalTypeFrais = "";
//liste des donnees que le serveur peut eventuellement échanger avec nous (factorisation de code)
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', 'mode_simple'];
'compta_compteperso', 'compta_tvadeductible', 'official_app_version', 'official_app_message', 'mode_simple'];
......@@ -64,9 +64,9 @@ function gotoPage(destination, saveHistory = true) {
}
$('#container').load(destination, function () {
globalCurrentPage = destination;
//Si on est en mode modification de frais dataLDF n'est pas vide...
//on demande donc a completer la page automatiquement
if (dataLDF != "") {
//Si on est en mode modification de frais dataLDF n'est pas vide...
//on demande donc a completer la page automatiquement
if (dataLDF != "" && destination != "menu.html") {
completePageAfterGoto(dataLDF);
}
});
......@@ -83,17 +83,17 @@ function cleanHistorique() {
// myDebug('on vide l historique');
listeContent = new Array('');
localStoreData("history", JSON.stringify(listeContent));
}
}
//Fermeture de session
function closeSession() {
//Fermeture de session
function closeSession() {
localStoreData('api_token', '');
globalDB.close(function () {
// myDebug('database is closed ok');
// myDebug('database is closed ok');
}, function (error) {
// myDebug('ERROR closing database');
// myDebug('ERROR closing database');
});
window.location.replace('index.html');
}
}
......@@ -276,7 +276,7 @@ function setPageTitle(titre) {
//sera appellee lorsque la page sera bien chargee pour completer automatiquement le formulaire
//avec les donnees a modifier
function completePageAfterGoto(dataLDF) {
// myDebug("completePageAfterGoto ...");
myDebug("completePageAfterGoto ...");
document.getElementById("updateID").value = dataLDF['sid'];
document.getElementById("photoFacturette").value = "UPDATE";
......
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