Commit d8da0448 authored by lucas64500's avatar lucas64500

Session conservee entre lancements de l'app + Modification d'un rucher

parent bb6c096b
......@@ -95,7 +95,7 @@
<input class="zone_texte" type="text" value="Mot de passe" id="mdp_connexion" onfocus="if(this.value=='Mot de passe'){this.value='';this.type='password'}" onblur="if(this.value==''){this.value = 'Mot de passe'; this.type='text'}"/>
<div class="bouton" id="valider_connexion" style="display:inline-block;"><span>VALIDER</span></div>
<div class="bouton" id="commencer_inscription" style="display:inline-block;"><span>S'INSCRIRE</span></div>
<div class="bouton" id="test" style="display:inline-block;"><span>TESTER</span></div>
<!-- <div class="bouton" id="test" style="display:inline-block;"><span>TESTER</span></div> -->
</form>
<div style="clear:left;"></div>
</div>
......@@ -170,7 +170,7 @@
<div class="page" id="paccueil">
<div id="menu_haut">
<img src="img/carte.png" id="btCarte" alt="Carte" />
<img src="img/historique.png" id="btHistorique" alt="Historique" />
<!-- <img src="img/historique.png" id="btHistorique" alt="Historique" /> -->
<img class="droite" id="btReglages" src="img/reglages.png" alt="Réglages" />
</div>
......@@ -308,9 +308,7 @@
<div id="bas_triangle"></div>
<div class="corps">
<div class="sous_titre">
<span class="nav_gauche"><</span>
<span class="nav_droite">></span>
<h1>Ruchers</h1>
<h1>Modifier un rucher</h1>
</div>
<div class="contenu formulaire" id="corps-params-rucher">
</div>
......
......@@ -71,27 +71,13 @@ function notif(nom,ruche,idSeuil){
});
cordova.plugins.notification.local.on("click", function (notification) {
inotif=0;
cordova.plugins.notification.local.cancelAll();
goToListHives(1);
});
}
}
/*
function notif(nom,nomRuche){
inotif++;
cordova.plugins.notification.local.schedule({
id: inotif,
badge: inotif,
title: "Alerte ("+nomRuche+")",
text: "Seuil "+nom+" dépassé",
at: new Date()
});
cordova.plugins.notification.local.on("click", function (notification) {
inotif=0;
accueil();
});
}*/
var seuils = [
/*{
......@@ -175,7 +161,7 @@ function actuNotifs(){if(!enActualisation){
for(s=0;s<seuils.length;s++) {
if(testSeuil(donneesRuches.hivegroups[r].hives[i],seuils[s],donneesRuches.hivegroups[r].hives[i].data[seuils[s].nom].v))notif(seuils[s].nom,donneesRuches.hivegroups[r].hives[i],s);
if(testSeuil(donneesRuches.hivegroups[r].hives[i],seuils[s],donneesRuches.hivegroups[r].hives[i].data[seuils[s].nom].v))notif(seuils[s].description,donneesRuches.hivegroups[r].hives[i],s);
}
enActualisation=false;
......@@ -191,9 +177,10 @@ var slider_ruchers;
var $window=[];
var tScroll=[];
function accueil(){
cordova.plugins.notification.local.cancelAll();
//Carte
_("btCarte").addEventListener(evtclick, goToMap);
_("btHistorique").addEventListener(evtclick, goToHistorique);
//_("btHistorique").addEventListener(evtclick, goToHistorique);
nbRuchers=donneesRuches.hivegroups.length;
console.log("Nb de ruchers : "+nbRuchers);
......@@ -255,6 +242,7 @@ function nouveauRucher(){
function allerAuRucher(k){
if(!transitionEnCours&&!slider_ruchers.enTransition){
$("#sous_titre_accueil").children("h1").html(donneesRuches.hivegroups[k-1].name);
$("#sous_titre_accueil").children("h1").on("click",goToHiveGroupParameters);
var change=false;
if(rucher!=k){change=true;}
if(rucher<=nbRuchers){
......@@ -267,10 +255,7 @@ function allerAuRucher(k){
idHiveGroup = k - 1;
if(change)slider_ruchers.slidePageFrom($("#rucher"+rucher),(left?"left":"right"));
if(nbRuches[rucher]==0){
//Mieux placer le bouton + quand il est tout seul sur la page
}else{
if(nbRuches[rucher]>0){
$window[rucher].scrollTop((rucheSelect2[rucher]-1)*h);
$window[rucher].scroll(function(){defiler(rucher);});
tScroll[rucher] = setInterval(function(){defiler(rucher);}, 100);
......
......@@ -58,6 +58,8 @@ function connexion(user, passwd, success, failure) {
_("ch").style.visibility="hidden";
console.log(JSON.stringify(data));
customer = data;
window.localStorage.setItem("user",user);
window.localStorage.setItem("login",passwd);
success();
},
error: function (xhr, ajaxOptions, thrownError) {
......@@ -72,16 +74,23 @@ function connexion(user, passwd, success, failure) {
}
}
var user;
var login;
/**
* get and deal with connection data
*/
function connect() {
if (!(window.localStorage.getItem("user") === null)) {
user=window.localStorage.getItem("user");
login=window.localStorage.getItem("login");
connexion(user, login, connexion_success, connexion_failure);
}
$("#test").click(tester);
$("#valider_connexion").click(function(){
if(!enCharge){
var user = encodeURIComponent($("#email_connexion").val());
user = encodeURIComponent($("#email_connexion").val());
//console.log(user);
var login = encodeURIComponent($("#mdp_connexion").val());
login = encodeURIComponent($("#mdp_connexion").val());
//console.log(login);
connexion(user, login, connexion_success, connexion_failure);
}
......@@ -134,6 +143,7 @@ function finCharge(){
}
function logout() {
window.localStorage.clear();
charge();
$.ajax({
type: 'GET',
......
......@@ -112,6 +112,8 @@ function goToAddLogger() {
},
error: function (xhr, ajaxOptions, thrownError) {
finCharge();
afficherBd("Une erreur est survenue","Fermer");
console.log(xhr.responseText);
}
});
......@@ -128,7 +130,7 @@ function deleteHive(id,action) {
withCredentials: true
},
//data: 'idclient=1&idruche=25&nomruche=NomDeMaRuche',
success: function(data) {finCharge();action();},
success: function(data) {action();},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.responseText);
......
......@@ -85,6 +85,7 @@ function addHives() {
}
function deleteHiveGroup() {
charge();
$.ajax({
type: 'DELETE',
url: url+'pshivegroup/' + donneesRuches.hivegroups[idHiveGroup].id_hive_group,
......@@ -93,10 +94,14 @@ function deleteHiveGroup() {
withCredentials: true
},
//data: 'idclient=1&idruche=25&nomruche=NomDeMaRuche',
success: function(data) {console.log(data); $("#resultat").html(JSON.stringify(data));},
success: function(data) {
finCharge();
goToListHives(1);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.responseText);
$("#result").html(xhr.responseText);
finCharge();
console.log(thrownError);
afficherBd("Une erreur est survenue","Fermer");
}
});
}
......@@ -74,7 +74,7 @@ function afficherNotes(data, indexHive){
note.data = defaultNotes[j];
}
}
if(note.date_add.indexOf("NaN")!=-1)note.date_add="Date inconnue";
notes.push(note);
};
for(var i in customNotesSetByUser) {
......@@ -85,7 +85,7 @@ function afficherNotes(data, indexHive){
note.data = customNotesCreatedByUser[j];
}
}
if(note.date_add.indexOf("NaN")!=-1)note.date_add="Date inconnue";
notes.push(note);
};
notes.sort(function(a, b) {
......
......@@ -114,11 +114,10 @@ function debut(){
function charger(){
if(pcharge<100)pcharge++;
dessinCercleFLAT(_("canvasProgressSimple"),pcharge);
if(templateCharge){//if(pcharge==100&&templateCharge){
if(pcharge==100&&templateCharge){
transition(_("pconnexion"));
clearInterval(tcharge);
//connect();
connexion("guillaume.vizier@polytechnique.edu", "labelabeille", connexion_success, connexion_failure);
connect();
}
}
......
......@@ -86,6 +86,8 @@ function goToGeneralParameters() {
//console.log('goToGeneralParameters : end');
}
/**
* display the parameters for the selected hivegroup
*/
......@@ -95,13 +97,17 @@ function goToHiveGroupParameters() {
//console.log(listHives.ruches.length);
//console.log(JSON.stringify(listHives));
//console.log(listHives.ruches[0].name);
var h = Mustache.render(template, hiveGroups[idHiveGroup]);
//console.log(h);
var h = Mustache.render(template, donneesRuches.hivegroups[idHiveGroup]);
console.log(h);
document.getElementById("corps-params-rucher").innerHTML = h;
//console.log(document.getElementById("corps-params-rucher").innerHTML);
//console.log('goToHiveGroupParameters : before transition');
transition(_("pparametres-rucher"), "slide");
//organiserRuches(listHives.ruches.length);
$("#supprimer_rucher").on("click",function(e) {
e.preventDefault();
deleteHiveGroup();
});
if(isTest) {
$("#form-params-ruchers").find(".bouton").click(function(e){$(this).off("click");
e.preventDefault();
......@@ -113,14 +119,12 @@ function goToHiveGroupParameters() {
}
else {
$("#form-params-ruchers").find(".bouton").click(function(e){
$("#form-params-ruchers").submit();
});
$("#form-params-ruchers").submit(function(e){
//console.log("début modif");
e.preventDefault();
var donnees = $(this).serialize();
var donnees = $(this).parent().serialize();
//console.log(donnees);
console.log(donneesRuches.hivegroups[idHiveGroup]);
charge();
$.ajax({
type: 'PATCH',
url: url+'pshivegroup/'+donneesRuches.hivegroups[idHiveGroup].id_hive_group,
......@@ -131,6 +135,7 @@ function goToHiveGroupParameters() {
success: function(data) {
console.log(data);
console.log(donneesRuches.hivegroups[idHiveGroup].hives[idHive]);
finCharge();
/* go back to details */
donneesRuches.hivegroups[idHiveGroup].name = $("#apibundle_pshivegroup_name").val();
donneesRuches.hivegroups[idHiveGroup].harvest = $("#apibundle_pshivegroup_harvest").val();
......@@ -138,6 +143,8 @@ function goToHiveGroupParameters() {
},
error: function (xhr, ajaxOptions, thrownError) {
//console.log(xhr.responseText);
finCharge();
afficherBd("Un erreur est survenue","Fermer");
}
});
});
......
......@@ -245,7 +245,8 @@
<!--</div>-->
<div>
<label for="apibundle_pshivegroup_name">Nom</label>
<input type="text" id="apibundle_pshivegroup_name" name="apibundle_pshivegroup[name]" maxlength="64" />
<input type="text" id="apibundle_pshivegroup_name" name="apibundle_pshivegroup[name]" value="{{name}}" maxlength="64" />
<div class="cl"></div>
</div>
<!--<div>
<label for="apibundle_pshivegroup_note">Note</label>
......@@ -253,14 +254,18 @@
</div>-->
<div>
<label for="apibundle_pshivegroup_harvest" class="required">Récolte</label>
<input type="number" id="apibundle_pshivegroup_harvest" name="apibundle_pshivegroup[harvest]" required="required" />
<input type="number" id="apibundle_pshivegroup_harvest" name="apibundle_pshivegroup[harvest]" value="{{harvest}}" required="required" />
<div class="cl"></div>
</div>
<!--<div>
<label for="apibundle_pshivegroup_notes">Notes</label>
<textarea id="apibundle_pshivegroup_notes" name="apibundle_pshivegroup[notes]" maxlength="65535"></textarea>
</div>-->
</div>
<input class="bouton" type="submit" value="ENVOYER">
<div class="bouton"><span>VALIDER</span></div>
<br />
<div id="supprimer_rucher" class="bouton2" style="text-align:center;clear:none;" >Supprimer ce rucher</div>
</form>
</script>
<script type="text/html" id="tpl-params-ruche">
......
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