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

customization + message

parent 60980cd6
......@@ -15,7 +15,7 @@
<div id="container">
<ons-row>
<ons-col>
<h2>À propos de Open Notes de Frais (DoliSCAN)</h2>
<h2>À propos de DoliSCAN</h2>
&nbsp;
</ons-col>
</ons-row>
......@@ -29,6 +29,7 @@
<ons-row>
<ons-col>
<hr />
<p>Pour plus de détails, consultez le site internet <a href="https://doliscan.fr">https://doliscan.fr</a></p>
<p>CAP-REL/DoliSCAN<br />https://cap-rel.fr<br />https://doliscan.fr</p>
</ons-col>
......
......@@ -29,6 +29,7 @@
</ons-col>
</ons-row>
<input type="hidden" name="uuid" id="uuid" value="">
<input type="hidden" name="vehiculeid" id="vehiculeid" value="">
<input type="hidden" name="proouperso" id="proouperso" value="">
<input type="hidden" name="energievalue" id="energievalue" value="">
......@@ -132,6 +133,7 @@
let vT = vehicules[i]['type'];
let vKM = vehicules[i]['kmbefore'];
let vIMMAT = vehicules[i]['immat'];
let vUUID = vehicules[i]['uuid'];
$('#nom').val(vA);
$('#vehiculeid').val(globalVehiculeEd.id);
......@@ -143,6 +145,7 @@
$('#kmbefore').val(vKM);
$('#immat').val(vIMMAT);
$('#uuid').val(vUUID);
}
});
......@@ -159,8 +162,9 @@
let type = document.getElementById('typevalue').value;
let kmbefore = document.getElementById('kmbefore').value;
let immat = document.getElementById('immat').value;
let uuid = document.getElementById('uuid').value;
updateVehicule(proouperso, id, nom, energie, puissance, type, kmbefore, immat).then(
updateVehicule(proouperso, id, nom, energie, puissance, type, kmbefore, immat, uuid).then(
ons.notification.alert("Véhicule mis à jour.", { title: "Information" }).then(
function () { closePage(true); }
)
......
......@@ -25,6 +25,13 @@
</ons-col>
</ons-row>
<ons-row>
<ons-col>
<h4>Dev</h4>
<ons-button modifier="material large" onclick="syncVehiculesWithServer();">SyncServer</ons-button>
</ons-col>
</ons-row>
<!-- <ons-row>
<ons-col>
<h4>Saisie automatique des villes</h4>
......
......@@ -76,35 +76,7 @@ function downloadCustomCSS() {
hideWait();
// myDebug('downloadCustomCSS : done');
let blob = new Blob([data], { type: "text/css" });
let cssFileName = '/custom.css';
// myDebug(blob.size);
// myDebug(data);
// cordova.file.etc is where you will save the file. In this case, inside the app folder, in the main storage in Android
window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function (directoryEntry) {
// myDebug('downloadCustomCSS Write to ' + cordova.file.cacheDirectory);
// the 'temp.pdf' is the name you want for your file.
directoryEntry.getFile(cssFileName, { create: true }, function (fileEntry) {
// myDebug('downloadCustomCSS Write to ' + cssFileName);
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
// great success!
// myDebug('downloadCustomCSS Write of file completed.');
// myDebug(fileEntry.fullPath);
// myDebug(fileEntry);
loadCustomCSS();
};
fileWriter.onerror = function (e) {
// Meh - fail
// myDebug('Write failed');
};
fileWriter.write(data);
});
});
});
saveCSSFile(data);
},
error: function (result) {
hideWait();
......@@ -116,6 +88,40 @@ function downloadCustomCSS() {
}
function saveCSSFile(css) {
let cssFileName = '/custom.css';
// myDebug(blob.size);
// myDebug(data);
// cordova.file.etc is where you will save the file. In this case, inside the app folder, in the main storage in Android
window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function (directoryEntry) {
myDebug('saveCSSFile Write to ' + cordova.file.cacheDirectory);
// the 'temp.pdf' is the name you want for your file.
directoryEntry.getFile(cssFileName, { create: true }, function (fileEntry) {
// myDebug('downloadCustomCSS Write to ' + cssFileName);
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
// great success!
myDebug('saveCSSFile Write of file completed.');
// myDebug(fileEntry.fullPath);
// myDebug(fileEntry);
loadCustomCSS();
};
fileWriter.onerror = function (e) {
// Meh - fail
// myDebug('Write failed');
};
fileWriter.write(css);
});
});
});
}
function downloadCustomLogo() {
$.ajaxSetup({
timeout: 10000,
......@@ -147,35 +153,7 @@ function downloadCustomLogo() {
hideWait();
// myDebug('downloadCustomLogo : done');
let blob = new Blob([data], { type: "image/png" });
let logoFileName = '/custom.png';
// myDebug(blob.size);
// myDebug(data);
// cordova.file.etc is where you will save the file. In this case, inside the app folder, in the main storage in Android
window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function (directoryEntry) {
// myDebug('downloadCustomLogo Write to ' + cordova.file.cacheDirectory);
// the 'temp.pdf' is the name you want for your file.
directoryEntry.getFile(logoFileName, { create: true }, function (fileEntry) {
// myDebug('downloadCustomLogo Write to ' + logoFileName);
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
// great success!
// myDebug('downloadCustomLogo Write of file completed.');
// myDebug(fileEntry.fullPath);
// myDebug(fileEntry);
loadCustomLOGO();
};
fileWriter.onerror = function (e) {
// Meh - fail
// myDebug('Write failed');
};
fileWriter.write(data);
});
});
});
saveLogoFile(data, false);
},
error: function (result) {
hideWait();
......@@ -185,6 +163,44 @@ function downloadCustomLogo() {
});
}
function saveLogoFile(data, isBase64 = false) {
myDebug("saveLogoFile");
let logoFileName = '/custom.png';
// myDebug(blob.size);
// myDebug(data);
// cordova.file.etc is where you will save the file. In this case, inside the app folder, in the main storage in Android
window.resolveLocalFileSystemURL(cordova.file.cacheDirectory, function (directoryEntry) {
myDebug(' saveLogoFile Write to ' + cordova.file.cacheDirectory);
// the 'temp.pdf' is the name you want for your file.
directoryEntry.getFile(logoFileName, { create: true }, function (fileEntry) {
myDebug(' saveLogoFile Write to ' + logoFileName);
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function (e) {
// great success!
myDebug(' saveLogoFile Write of file completed.');
// myDebug(fileEntry.fullPath);
// myDebug(fileEntry);
loadCustomLOGO();
};
fileWriter.onerror = function (e) {
// Meh - fail
myDebug(' saveLogoFile Write failed');
};
if (isBase64) {
fileWriter.write(window.atob(data));
}
else {
fileWriter.write(data);
}
});
});
});
}
/**
* Chargement du logo personnalisé
......
......@@ -27,7 +27,8 @@ function feedVehicules(storageKey) {
let vT = vehicules[i]['type'];
let vKM = vehicules[i]['kmbefore'];
let vIMMAT = vehicules[i]['immat'];
let option = vA + ";" + vE + ";" + vP + ";" + vT + ";" + vKM + ";" + vIMMAT;
let vUUID = vehicules[i]['uuid'];
let option = vA + ";" + vE + ";" + vP + ";" + vT + ";" + vKM + ";" + vIMMAT + ";" + vUUID;
if (vA !== null) {
// html += ("<option value=\"" + option + "\">" + vA + "</option>");
......@@ -180,32 +181,11 @@ function feedToSync(formField) {
//Ajout du message custom envoyé par le serveur sur la boite à propos
function feedAproposCustom() {
let htmlInfos = "";
myDebug("feedAproposCustom");
$("#feedAproposCustom").empty();
myDebug("feedAproposCustom empty ok -> feed with html now");
let aproposFileName = cordova.file.cacheDirectory + 'apropos.html';
// myDebug("loadCustomCSS : " + cssFileName);
window.resolveLocalFileSystemURL(aproposFileName, function (fileEntry) {
// myDebug("loadCustomCSS (2): " + JSON.stringify(fileEntry));
fileEntry.file(function (file) {
var reader = new FileReader();
var fileSize = file.size;
// myDebug("loadCustomCSS (3) Size = " + file.size);
reader.onloadend = function (e) {
var fileContent = reader.result;
// myDebug("loadCustomCSS : append to header " + fileContent);
$("#feedAproposCustom").append(fileContent);
};
reader.readAsText(file);
}, errorHandlerCustomFile.bind(null, "Error on FileEntry " + cssFileName));
}, errorHandlerCustomFile.bind(null, "Error on resolveLocalFileSystemURL " + cssFileName));
$("#feedAproposCustom").append(localGetData('customAbout'));
return;
}
......
......@@ -73,14 +73,45 @@ function updateLocalUserFromServer(result, callback) {
if (v.is_perso)
storageKey = "vehicules";
addVehicule(storageKey, v.name, v.energy, v.power, v.type, v.kmbefore, v.number);
// let vehiculeNew = { "nom": v.name, "energie": v.energy, "puissance": v.power, "type": v.type, "kmbefore": v.kmbefore, "immat": v.number };
addVehicule(storageKey, v.name, v.energy, v.power, v.type, v.kmbefore, v.number, v.uuid);
// myDebug(" valeur non nulle on stocke le vehicule : " + JSON.stringify(vehiculeNew));
});
// localStoreData(key, result.vehicules[key]);
ret = true;
}
//Le message custom
if ((typeof result.customMessage != 'undefined') && (result.customMessage !== null) && (result.customMessage != "")) {
myDebug(" on a peut-être du customMessage ...");
// eviter d'afficher le message à chaque lancement ... avoir un numéro ou un truc pour dire "j'ai déjà lu merci"
if (result.customMessage.original != "") {
ons.notification.alert(result.customMessage.original, { title: "Information" });
}
ret = true;
}
//La boite a propos
if ((typeof result.customAbout != 'undefined') && (result.customAbout !== null) && (result.customAbout != "")) {
myDebug(" on a peut-être du customAbout ...");
localStoreData("customAbout", result.customAbout.original);
ret = true;
}
//La feuille de style
if ((typeof result.customCSS != 'undefined') && (result.customCSS !== null) && (result.customCSS != "")) {
myDebug(" on a peut-être du css ...");
saveCSSFile(result.customCSS.original);
ret = true;
}
//Le logo
if ((typeof result.customLogo != 'undefined') && (result.customLogo !== null) && (result.customLogo != "")) {
myDebug(" on a peut-être du css ...");
saveLogoFile(result.customLogo.original, true);
ret = true;
}
myDebug("=== updateLocalUserFromServer appel de callback " + callback + " pour " + ret);
callback(ret);
}
......
......@@ -16,10 +16,10 @@ function rmVehicule(storageKey, id) {
}
//Ajoute un véhicule perso -> maximum 3 véhicules dans cette v1 !-)
function addVehicule(storageKey, nom, energie, puissance, type, kmbefore, immat) {
function addVehicule(storageKey, nom, energie, puissance, type, kmbefore, immat, uuid) {
return new Promise((resolve, reject) => {
//On cherche une place de libre (max 4 on a dit)
let vehiculeNew = { "nom": nom, "energie": energie, "puissance": puissance, "type": type, "kmbefore": kmbefore, "immat": immat };
let vehiculeNew = { "nom": nom, "energie": energie, "puissance": puissance, "type": type, "kmbefore": kmbefore, "immat": immat, "uuid": uuid };
let vehicules = JSON.parse(localGetData(storageKey));
if (vehicules === null) {
vehicules = [];
......@@ -49,10 +49,11 @@ function edVehicule(storageKey, id) {
//Ajoute un véhicule perso -> maximum 3 véhicules dans cette v1 !-)
function updateVehicule(storageKey, id, nom, energie, puissance, type, kmbefore, immat) {
function updateVehicule(storageKey, id, nom, energie, puissance, type, kmbefore, immat, uuid) {
myDebug("updateVehicule avec uuid = " + uuid);
return new Promise((resolve, reject) => {
//On cherche une place de libre (max 4 on a dit)
let vehiculeNew = { "nom": nom, "energie": energie, "puissance": puissance, "type": type, "kmbefore": kmbefore, "immat": immat };
let vehiculeNew = { "nom": nom, "energie": energie, "puissance": puissance, "type": type, "kmbefore": kmbefore, "immat": immat, "uuid": uuid };
let vehicules = JSON.parse(localGetData(storageKey));
//On ecrase avec les nouvelles données
......@@ -81,3 +82,46 @@ function switchType(id, nom) {
$('#type').append('Type: <b>' + nom + "</b>");
document.querySelector('#type-list').hideExpansion();
}
function syncVehiculesWithServer() {
myDebug('syncVehiculesWithServer : start');
$.ajaxSetup({
timeout: 10000,
headers: {
'X-CSRF-TOKEN': localGetData("api_token")
}
});
if (ajaxSyncVehicules)
ajaxSyncVehicules.abort();
var ajaxSyncVehicules = $.ajax({
type: "POST",
timeout: 5000,
url: localGetData("api_server") + "/api/Vehicule",
data: {
email: localGetData("email"),
vehicules: localGetData("vehicules"),
vehiculesPro: localGetData("vehiculesPro"),
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + localGetData("api_token"));
},
xhrFields: {
withCredentials: true
},
success: function (result) {
globalNetworkResponse = Date.now();
// myDebug('updateServerUserFromLocal : succès ...' + JSON.stringify(result));
hideWait();
updateLocalUserFromServer(result, updateLocalUserFromServerSuccessMessage);
myDebug(' syncVehiculesWithServer : done');
},
error: function (result) {
hideWait();
myDebug(' syncVehiculesWithServer : error');
}
});
}
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