New file |
0,0 → 1,836 |
//+----------------------------------------------------------------------------------------------------------+ |
// Initialisation de Jquery mobile |
$(document).on('mobileinit', function() { |
$.mobile.defaultPageTransition = 'fade'; |
}); |
$(document).on('online', function(event) { |
console.log('online'); |
miseAJourObs(); |
}); |
|
function changerPage(id, event) { |
$.mobile.changePage(id); |
event.stopPropagation(); |
event.preventDefault(); |
} |
//+----------------------------------------------------------------------------------------------------------+ |
// Gestion des paramètres URL |
var modal_recherche = false; |
$.urlParam = function(name){ |
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); |
return decodeURIComponent(results[1]) || 0; |
} |
function recupererParametresUrl() { |
$('#referentiel').val($.urlParam('ref')); |
$('#nom').html($.urlParam('nom_sci')); |
$('#nom-sci-select').val($.urlParam('nom_sci')); |
$('#num-nom-select').val($.urlParam('num_nom')); |
} |
$(document).ready(function() { |
$('#geolocaliser').on('vclick', obtenirPosition); |
|
$('body').on('pagebeforeshow', '#infos', obtenirDate); |
$('body').on('pageshow', '#saisie', function(event) { |
if (!modal_recherche) { |
obtenirPosition(event); |
recupererParametresUrl(); |
} else { |
modal_recherche = false; |
} |
}); |
$('body').on('pagehide', '#saisie-popup', function() { |
modal_recherche = true; |
}); |
}); |
|
//+----------------------------------------------------------------------------------------------------------+ |
// Géolocalisation et date du jour |
var gps = navigator.geolocation; |
|
function obtenirPosition(event) { |
event.stopImmediatePropagation(); |
event.stopPropagation(); |
event.preventDefault(); |
|
obtenirDate(); |
geolocaliser(); |
} |
function geolocaliser() { |
if (gps) { |
navigator.geolocation.getCurrentPosition(surSuccesGeoloc, surErreurGeoloc); |
} else { |
var erreur = {code:'0', message: 'Géolocalisation non supportée par le navigateur'}; |
surErreurGeoloc(erreur); |
} |
} |
function surSuccesGeoloc(position){ |
if (position) { |
var lat = position.coords.latitude; |
var lng = position.coords.longitude; |
$('#lat').html(lat); |
$('#lng').html(lng); |
|
console.log('Geolocation SUCCESS'); |
var url_service = SERVICE_NOM_COMMUNE_URL; |
var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng); |
$.ajax({ |
url : urlNomCommuneFormatee, |
type : 'GET', |
dataType : 'jsonp', |
success : function(data) { |
console.log('NOM_COMMUNE found.'); |
$('#location').html(data['nom']); |
$('#code-insee').val(data['codeINSEE']); |
}, |
complete : function() { |
var texte = ($('#location').html() == '') ? TEXTE_HORS_LIGNE : $('#location').html(); |
$('#location').html(texte); |
} |
}); |
} |
} |
function surErreurGeoloc(error){ |
alert('Echec de la géolocalisation, code: ' + error.code + ' message: '+ error.message); |
} |
|
function obtenirDate() { |
var d = new Date(); |
var jour = d.getDate(); |
var mois = d.getMonth()+1; |
var annee = d.getFullYear(); |
var aujourdhui = |
( (''+jour).length < 2 ? '0' : '') + jour + '/' + |
( (''+mois).length < 2 ? '0' : '') + mois + '/' + |
annee; |
$('#date').html(aujourdhui); |
$('#annee').html(annee); |
} |
//+----------------------------------------------------------------------------------------------------------+ |
// Local Storage |
$(document).ready(function() { |
$('#sauver-obs').on('click', ajouterObs); |
$('#valider-photos').on('click', ajoutPhoto); |
$('body').on('pageshow', '#liste', chargerListeObs); |
$('body').on('pageshow', '#transmission', miseAJourObs); |
}); |
|
var bdd = window.localStorage, |
index_obs = (bdd.getItem('index_obs') == null) ? 1 : bdd.getItem('index_obs'), |
index_photos = (bdd.getItem('index_photos') == null) ? 1 : bdd.getItem('index_photos'); |
//bdd.clear(); |
|
console.log(bdd); |
function ajouterObs(event) { |
if ($('#nom').html() != '') { |
var obs = { |
num:TEXTE_OBS, |
maj:0, |
date:'', |
referentiel:'', |
lat:'', lng:'', |
commune:'', code_insee: 0, |
nom:'', |
nom_sci_select:'', |
nn_select:'', |
nom_sci_retenu:'', |
nn_retenu:'', |
num_taxon:'', |
famille:'' |
}; |
|
obs.num += index_obs++; |
obs.date = $('#date').html(); |
obs.referentiel = $('#referentiel').val(); |
obs.lat = $('#lat').html(); |
obs.lng = $('#lng').html(); |
obs.commune = $('#location').html(); |
obs.code_insee = $('#code-insee').val(); |
obs.nom = $('#nom').html(); |
obs.referentiel = $('#referentiel').val(); |
obs.nom_sci_select = $('#nom-sci-select').val(); |
obs.nn_select = $('#num-nom-select').val(); |
|
var cle = obs.num; |
sauvegarderObs(cle, obs); |
bdd.setItem('index_obs', index_obs); |
effacerFormulaire(); |
changerPage('#liste', event); |
} else { |
changerPage('#saisie', event); |
} |
} |
|
function sauvegarderObs(cle, obs) { |
var val = JSON.stringify(obs), |
poids = JSON.stringify(bdd).length + val.length; |
if (poids > 2621940) { |
$('#cache-plein').popup('open'); |
} |
bdd.setItem(cle, val); |
} |
|
function effacerFormulaire() { |
$('#lat').html(''); |
$('#lng').html(''); |
$('#location').html(''); |
} |
|
function chargerListeObs() { |
console.log('space used: '+JSON.stringify(bdd).length); |
$('#liste-obs').empty(); |
|
var nbre = bdd.length; |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_OBS) !== -1) { |
var obs = JSON.parse(bdd.getItem(cle)); |
console.log(obs); |
$('#liste-obs').prepend( |
'<li>'+ |
'<a href="#" onclick="detailsObs(this);" data-split-icon="next" data-split-theme="a" title="Voir la fiche" data-obs-num="' + obs.num + '">' + |
'<strong>' + obs.nom + '</strong> <br />' + obs.date + |
((obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') ? '' : (' à ' + obs.commune)) + |
'<br />(Nbre photos : ' + compterPhotos(obs.num) + ')<br />' + |
'</a>'+ |
'<a href="#" onclick="supprimerObs(this);" title="Supprimer l\'observation" ' + |
'data-obs-num="' + obs.num + '">' + |
'Supprimer'+ |
'</a>'+ |
'</li>' |
); |
} |
$('#liste-obs').listview('refresh'); |
} |
} |
|
function compterPhotos(num_obs) { |
var compteur = 0; |
if (num_obs != '') { |
var nbre = bdd.length; |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_PHOTO) !== -1) { |
var photo = JSON.parse(bdd.getItem(cle)); |
if (photo.parent == num_obs) { |
compteur++; |
} |
} |
} |
} |
return compteur; |
} |
|
function supprimerObs(data) { |
var cle_obs = data.getAttribute('data-obs-num'), |
obs = JSON.parse(bdd.getItem(cle_obs)), |
nbre = bdd.length, |
a_supprimer = new Array(); |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_PHOTO) !== -1) { |
var photo = JSON.parse(bdd.getItem(cle)); |
if (photo.parent == obs.num) { |
a_supprimer.push(photo.num); |
} |
} |
} |
for (var c = 0; c < a_supprimer.length; c++) { |
bdd.removeItem(a_supprimer[c]); |
} |
bdd.removeItem(cle_obs); |
|
var txt = obs.num + ' supprimée.'; |
$('#obs-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">'+txt+'</p>') |
.fadeIn(0) |
.delay(1600) |
.fadeOut('slow'); |
|
chargerListeObs(); |
} |
|
function detailsObs(data) { |
var num_obs = data.getAttribute('data-obs-num'); |
var obs = JSON.parse(bdd.getItem(num_obs)); |
$('#id-obs').html(obs.num); |
|
var texte = '<strong>' + obs.nom + '</strong> vue le ' + obs.date; |
texte += (obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') ? '' : ' à ' + obs.commune; |
$('#details-obs').html(texte); |
$.mobile.changePage('#observation'); |
afficherPhotos(obs.num); |
} |
|
function ajoutPhoto() { |
var id_obs = $('#id-obs').html(); |
if (id_obs != '') { |
$.each($('#pic').get(0).files, function(index, valeur) { |
var reader = new FileReader(); |
reader.addEventListener('loadend', function () { |
var photo_nom = valeur.name, |
arr_nom = photo_nom.split("."), |
dernier = arr_nom.length - 1; |
if (arr_nom[dernier].toUpperCase() != "JPG" && arr_nom[dernier].toUpperCase() != "JPEG") { |
$('#pic').val(''); |
var txt = 'Seuls les fichiers .JPG ou .JPEG sont acceptés.'; |
$('#photo-suppression-infos').html('<p class="reponse ui-btn-inner ui-btn-corner-all">' + txt + '</p>') |
.fadeIn(0) |
.delay(1600) |
.fadeOut('slow'); |
} else { |
var photo = { |
num: TEXTE_PHOTO, |
nom: '', |
parent: '', |
base64: 0 |
}; |
photo.num += index_photos++; |
photo.nom = photo_nom; |
photo.parent = id_obs; |
photo.base64 = reader.result; |
|
var cle = photo.num; |
sauvegarderObs(cle, photo); |
bdd.setItem('index_photos', index_photos); |
afficherPhotos(id_obs); |
} |
}, false); |
reader.readAsDataURL(valeur); |
}); |
} |
} |
|
function afficherPhotos(num_obs) { |
$('#pic').val(''); |
$('#photos-obs').empty(); |
if (num_obs != '') { |
var nbre = bdd.length; |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_PHOTO) !== -1) { |
var photo = JSON.parse(bdd.getItem(cle)); |
if (photo.parent == num_obs) { |
$('#photos-obs').prepend( |
'<li>'+ |
'<a href="#" onclick="afficherVue(this);" data-ajax="false" data-role="button" data-inline="true" data-photo-num="' + photo.num + '">' + |
'<img src="' + photo.base64 + '" />' + |
photo.nom + |
'</a>' + |
'<a href="#" onclick="supprimerPhoto(this);" title="Supprimer la photo" ' + |
'data-icon="delete" data-photo-num="' + photo.num + '" data-photo-parent="' + num_obs + '"' + |
'data-theme="c">' + |
'Supprimer cette photo' + |
'</a>' + |
'</li>' |
); |
} |
} |
$('#photos-obs').listview('refresh'); |
} |
} |
} |
|
function afficherVue(data) { |
var cle_photo = data.getAttribute('data-photo-num'), |
photo = JSON.parse(bdd.getItem(cle_photo)); |
$('#photo-zoom-infos').html('<img class="photo-popup" width="80%" src="' + photo.base64 + '" />'); |
$('#photo-zoom') |
.popup('open') |
.on('popupafterclose', function(event) { |
event.stopImmediatePropagation(); |
event.stopPropagation(); |
event.preventDefault(); |
}); |
} |
|
function supprimerPhoto(data) { |
var cle_photo = data.getAttribute('data-photo-num'), |
parent = data.getAttribute('data-photo-parent'), |
photo = JSON.parse(bdd.getItem(cle_photo)); |
bdd.removeItem(cle_photo); |
|
afficherPhotos(parent); |
} |
|
function miseAJourObs() { |
console.log('majObs'); |
var nbre = bdd.length; |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_OBS) !== -1) { |
var obs = JSON.parse(bdd.getItem(cle)); |
|
if (obs.maj == 0) { |
var maj = 1; |
|
if (obs.commune == TEXTE_HORS_LIGNE || obs.commune == '') { |
var url_service = SERVICE_NOM_COMMUNE_URL; |
var urlNomCommuneFormatee = url_service.replace('{lat}', lat).replace('{lon}', lng); |
jQuery.ajax({ |
url: urlNomCommuneFormatee, |
type : 'GET', |
dataType : 'jsonp', |
success: function(data) { |
obs.commune = data['nom']; |
obs.code_insee = data['codeINSEE']; |
}, |
error: function() { |
maj = 0; |
}, |
async: false |
}); |
} |
|
if (obs.nom_sci_retenu == '') { |
jQuery.ajax({ |
url: '/service:eflore:0.1/' + obs.referentiel + '/noms?' |
+ 'masque.nn=' + obs.nn_select |
+ '&retour.champs=num_taxonomique', |
success: function(data) { |
var cle = '', |
compteur = 0; |
for (name in data['resultat']) { |
if (compteur == 0) { |
cle = name; |
} |
compteur++; |
} |
obs.num_taxon = data['resultat'][cle]['num_taxonomique']; |
jQuery.ajax({ |
url: '/service:eflore:0.1/' + obs.referentiel + '/noms?' |
+ 'masque.nt=' + obs.num_taxon |
+ '&retour.champs=famille' |
+ '&retour.tri=retenu', |
type : 'GET', |
dataType : 'jsonp', |
success: function(data) { |
var cle = ''; |
for (name in data['resultat']) { |
if (data['resultat'][name]['retenu'] == 'true') { |
cle = name; |
break; |
} |
} |
obs.famille = data['resultat'][cle]['famille']; |
obs.nom_sci_retenu = data['resultat'][cle]['nom_sci']; |
obs.nn_retenu = cle; |
}, |
error: function() { |
maj = 0; |
}, |
async: false |
}); |
}, |
async: false |
}); |
} |
|
obs.maj = maj; |
} |
|
sauvegarderObs(obs.num, obs); |
} |
} |
} |
|
//+----------------------------------------------------------------------------------------------------------+ |
// Autocomplétion des noms latins |
var recherche = ''; |
$(document).on('pageinit', '#saisie', function() { |
$('#liste-noms-latins').on('listviewbeforefilter', function(e, data) { |
var $input = $(data.input); |
recherche = $input.val(); |
|
$input.keyup(function() { |
clearTimeout($.data(this, 'timer')); |
var wait = setTimeout(lancerRecherche, DELAI_RECHERCHE); |
$(this).data('timer', wait); |
}); |
}); |
}); |
|
function lancerRecherche() { |
var $ul = $('#liste-noms-latins'), |
html = ''; |
$ul.html(''); |
|
if (recherche && recherche.length > 2) { |
afficherChargement(); |
$ul.html('<li><div class="ui-loader"><span class="ui-icon ui-icon-loading"></span></div></li>'); |
$ul.listview('refresh'); |
$.ajax({ }) |
.then(function() { |
for (index in BDTFX) { |
var espece = BDTFX[index], |
nom_sci = espece['nom_sci'], |
num_nom = espece['num_nom'], |
auteur = espece['auteur'], |
annee = espece['annee'], |
nom_sci_complet = nom_sci + ((auteur == '' || auteur == null) ? '' : (' ' + auteur)) + ((annee == '' || annee == null) ? '' : (' (' + annee + ')')); |
|
if (nom_sci !== '') { |
var arr_nom_sci = nom_sci.split(' '), |
arr_recherche = recherche.split(' '); |
|
if (arr_nom_sci[1] !== undefined) { |
nom_sci_recherche = arr_nom_sci[1]; |
|
if (arr_nom_sci[1].toLowerCase() == 'x') { |
nom_sci_recherche = arr_nom_sci[2]; |
} |
} else { |
nom_sci_recherche = arr_nom_sci[0]; |
} |
|
if ((arr_nom_sci[0].toLowerCase().substring(0, arr_recherche[0].length)) == arr_recherche[0].toLowerCase()) { |
var flag = true; |
if (arr_recherche[1] !== undefined) { |
flag = ( (nom_sci_recherche.toLowerCase().substring(0, arr_recherche[1].length)) == arr_recherche[1].toLowerCase() ); |
} |
|
if (flag) { |
html += '<li>' |
+ '<a href="#" data-nom-sci="' + nom_sci + '" data-num-nom="' + num_nom + '" ' |
+ ' data-auteur="' + auteur + '" data-nom-sci-complet="' + nom_sci_complet |
+ '" class="noms-latins" >' |
+ nom_sci_complet |
+ '</a>' |
+ '</li>'; |
} |
} |
} |
} |
$.mobile.loading('hide'); |
$ul.html(html); |
$ul.listview('refresh'); |
$ul.trigger('updatelayout'); |
$('.noms-latins').on('click', choisirEspece); |
}); |
} |
} |
|
function afficherChargement() { |
var $this = $('#recherche-chargement'), |
theme = $this.jqmData("theme") || $.mobile.loader.prototype.options.theme, |
msgText = $this.jqmData("msgtext") || $.mobile.loader.prototype.options.text, |
textVisible = $this.jqmData("textvisible") || $.mobile.loader.prototype.options.textVisible, |
textonly = !!$this.jqmData("textonly"); |
html = $this.jqmData("html") || ""; |
$.mobile.loading( 'show', { |
text: msgText, |
textVisible: textVisible, |
theme: theme, |
textonly: textonly, |
html: html |
}); |
} |
|
function choisirEspece(event) { |
var espece = event.currentTarget, |
auteur = espece.getAttribute('data-auteur'), |
nom_sci = espece.getAttribute('data-nom-sci'), |
nom_sci_complet = espece.getAttribute('data-nom-sci-complet') |
num_nom = espece.getAttribute('data-num-nom'); |
|
$('#nom').html(nom_sci_complet); |
$('#nom-sci-select').val(nom_sci); |
$('#num-nom-select').val(num_nom); |
$('#liste-noms-latins').html(''); |
$('#saisie-popup').dialog('close'); |
} |
|
//+----------------------------------------------------------------------------------------------------------+ |
// Manifest Cache |
var appCache = window.applicationCache; |
console.log(appCache); |
appCache.addEventListener('updateready', function() { |
if (appCache.status === appCache.UPDATEREADY) { |
surMiseAJourCache(); |
} |
}); |
|
function surMiseAJourCache() { |
appCache.swapCache(); |
if (confirm('Une nouvelle version de ce site est disponible. Mettre à jour ?')) { |
window.location.reload(); |
} |
} |
|
//+----------------------------------------------------------------------------------------------------------+ |
//Transmission données |
$(document).ready(function() { |
$('#transmettre-obs').on('click', transmettreObs); |
}); |
|
function transmettreObs() { |
var msg = '', |
courriel = ($('#courriel').val() == '') ? bdd.getItem('utilisateur.courriel') : $('#courriel').val(); |
if (recupererStatutIdentite() == 'true' && validerCourriel(courriel)) { |
if (verifierConnexion()) { |
var nbre = bdd.length; |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf('obs') !== -1) { |
var obs = JSON.parse(bdd.getItem(cle)); |
stockerObsData(obs); |
} |
} |
|
var observations = $('#details-obs').data(); |
if (observations == undefined || jQuery.isEmptyObject(observations)) { |
msg = 'Aucune observation à transmettre.'; |
} else { |
msg = 'Transmission en cours...'; |
observations['projet'] = TAG_PROJET; |
observations['tag-obs'] = ''; |
observations['tag-img'] = ''; |
|
var utilisateur = new Object(); |
utilisateur.id_utilisateur = ($('#id-utilisateur').val() == '') ? bdd.getItem('utilisateur.id') : $('#id-utilisateur').val(); |
utilisateur.prenom = ($('#prenom-utilisateur').val() == '') ? bdd.getItem('utilisateur.prenom') : $('#prenom-utilisateur').val(); |
utilisateur.nom = ($('#nom-utilisateur').val() == '') ? bdd.getItem('utilisateur.nom') : $('#nom-utilisateur').val(); |
utilisateur.courriel = courriel; |
observations['utilisateur'] = utilisateur; |
envoyerObsAuCel(observations); |
} |
} else { |
msg = 'Aucune connexion disponible. Merci de réessayer ultérieurement.'; |
} |
} else { |
msg = 'Merci de vérifier et de confirmer votre adresse e-mail avant de transmettre vos observations.'; |
} |
|
if (msg != '') { |
$('#identification-infos').html('<p class="reponse">' + msg + '</p>') |
.fadeIn(0) |
.delay(2000) |
.fadeOut('slow'); |
} |
} |
|
function verifierConnexion() { |
return ( ('onLine' in navigator) && (navigator.onLine)); |
} |
|
function stockerObsData(obs) { |
var nbre = bdd.length, |
img_noms = new Array(), |
img_codes = new Array(); |
for (var i = 0; i < nbre; i++) { |
var cle = bdd.key(i); |
if (cle.indexOf(TEXTE_PHOTO) !== -1) { |
var photo = JSON.parse(bdd.getItem(cle)); |
if (photo.parent == obs.num) { |
img_noms.push(photo.nom); |
img_codes.push(photo.base64); |
} |
} |
} |
|
$('#details-obs').data(obs.num, { |
'date' : obs.date, |
'notes' : '', |
|
'nom_sel' : obs.nom, |
'num_nom_sel' : obs.nn_select, |
'nom_ret' : obs.nom_sci_retenu, |
'num_nom_ret' : obs.nn_retenu, |
'num_taxon' : obs.num_taxon, |
'famille' : obs.famille, |
'referentiel' : obs.referentiel, |
|
'latitude' : obs.lat, |
'longitude' : obs.lng, |
'commune_nom' : obs.commune, |
'commune_code_insee' : obs.code_insee, |
'lieudit' : '', |
'station' : '', |
'milieu' : '', |
|
//Ajout des champs images |
'image_nom' : img_noms, |
'image_b64' : img_codes |
}); |
} |
|
|
function envoyerObsAuCel(observations) { |
console.log(observations); |
var msg = ''; |
var erreurMsg = ''; |
$.ajax({ |
url : SERVICE_SAISIE_URL, |
type : 'POST', |
data : observations, |
dataType : 'json', |
success : function(data, textStatus, jqXHR) { |
console.log('Transmission SUCCESS.'); |
msg = 'Transmission réussie ! Vos observations sont désormais disponibles sur votre carnet en ligne et ont été supprimées sur cette application.'; |
$('#identification-infos').html('<p class="reponse">' + msg + '</p>') |
.fadeIn(0) |
.delay(2000) |
.fadeOut('slow'); |
}, |
statusCode : { |
500 : function(jqXHR, textStatus, errorThrown) { |
erreurMsg += 'Erreur 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n'; |
msg = 'Erreur 500. Merci de contacter le responsable.'; |
} |
}, |
error : function(jqXHR, textStatus, errorThrown) { |
erreurMsg += 'Erreur Ajax :\ntype : ' + textStatus + ' ' + errorThrown + '\n'; |
msg = 'Erreur indéterminée. Merci de contacter le responsable.'; |
try { |
reponse = jQuery.parseJSON(jqXHR.responseText); |
if (reponse != null) { |
$.each(reponse, function (cle, valeur) { |
erreurMsg += valeur + '\n'; |
}); |
} |
} catch(e) { |
erreurMsg += 'L\'erreur n\'était pas en JSON.'; |
} |
}, |
complete : function(jqXHR, textStatus) { |
console.log('complete'); |
console.log(jqXHR); |
} |
}); |
} |
|
//+---------------------------------------------------------------------------------------------------------+ |
//IDENTITÉ |
$(document).ready(function() { |
$('#courriel').on('blur', requeterIdentite); |
$('#courriel').on('keypress', function(event) { |
if (event.which == 13) { |
requeterIdentite(); |
} |
}); |
|
$('body').on('pagebeforeshow', '#transmission', completerCompte); |
$('body').on('pagebeforeshow', '#identification-popup', testerLancementRequeteIdentite); |
|
$('#valider-courriel').on('vmousedown', requeterIdentite); |
$('#valider-identification').on('vmousedown', confirmerIdentification); |
}); |
|
function completerCompte() { |
if (bdd.getItem('utilisateur.courriel') != null) { |
var courriel = bdd.getItem('utilisateur.courriel'); |
$('#identification-texte').html(TEXTE_OUI_COMPTE); |
$('#utilisateur-compte').html(courriel); |
$('#identification-btn * .ui-btn-text').html('Modifier le compte'); |
} else { |
$('#identification-texte').html(TEXTE_NON_COMPTE); |
$('#identification-btn * .ui-btn-text').html('Ajouter un compte'); |
} |
} |
|
function testerLancementRequeteIdentite(event) { |
if (bdd.getItem('utilisateur.courriel') != null) { |
var courriel = bdd.getItem('utilisateur.courriel'); |
$('#courriel').val(courriel); |
|
if (recupererStatutIdentite() == 'true') { |
$('#courriel-confirmation').val(courriel); |
} |
} |
if (bdd.getItem('utilisateur.nom') != null) { |
$('#nom-utilisateur').val(bdd.getItem('utilisateur.nom')); |
} |
if (bdd.getItem('utilisateur.prenom') != null) { |
$('#prenom-utilisateur').val(bdd.getItem('utilisateur.prenom')); |
} |
if (bdd.getItem('utilisateur.id') != null) { |
$('#id-utilisateur').val(bdd.getItem('utilisateur.id')); |
} |
|
event.preventDefault(); |
event.stopPropagation(); |
} |
|
function recupererStatutIdentite() { |
return bdd.getItem('utilisateur.identite'); |
} |
|
function confirmerIdentification(event) { |
confirmerCourriel(); |
changerPage('#transmission', event); |
} |
|
function confirmerCourriel() { |
if (validerCourriel($('#courriel').val())) { |
if ($('#courriel').val() == $('#courriel-confirmation').val()) { |
bdd.setItem('utilisateur.identite', true); |
} else { |
bdd.setItem('utilisateur.identite', false); |
} |
} else { |
$('#identification-infos').html('<p class="reponse">Adresse e-mail invalide.</p>') |
.fadeIn(0) |
.delay(2000) |
.fadeOut('slow'); |
} |
} |
|
function requeterIdentite(event) { |
var courriel = $('#courriel').val(); |
if (validerCourriel(courriel)) { |
miseAJourCourriel(); |
var urlAnnuaire = SERVICE_ANNUAIRE + courriel; |
$.ajax({ |
url : urlAnnuaire, |
type : 'GET', |
success : function(data, textStatus, jqXHR) { |
console.log('Annuaire SUCCESS : ' + textStatus); |
if (data != undefined && data[courriel] != undefined) { |
var infos = data[courriel]; |
$('#id-utilisateur').val(infos.id); |
$('#prenom-utilisateur').val(infos.prenom); |
$('#nom-utilisateur').val(infos.nom); |
$('#courriel-confirmation').val(courriel); |
$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').attr('disabled', 'disabled'); |
|
if ($('#courriel-memoire').is(':checked')) { |
bdd.setItem('utilisateur.prenom', $("#prenom-utilisateur").val()); |
bdd.setItem('utilisateur.nom', $("#nom-utilisateur").val()); |
bdd.setItem('utilisateur.id', $("#id-utilisateur").val()); |
} |
} else { |
surErreurCompletionCourriel(); |
} |
}, |
error : function(jqXHR, textStatus, errorThrown) { |
console.log('Annuaire ERREUR : ' + textStatus); |
surErreurCompletionCourriel(); |
}, |
complete : function(jqXHR, textStatus) { |
console.log('Annuaire COMPLETE : ' + textStatus); |
$('#zone-prenom-nom').removeClass('hidden'); |
$('#zone-courriel-confirmation').removeClass('hidden'); |
} |
}); |
} |
|
event.preventDefault(); |
event.stopPropagation(); |
} |
|
function validerCourriel(email) { |
var regex = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i), |
flag = regex.test(email); |
|
console.log('Valid email ? (', email, ') : ', flag); |
return flag; |
} |
|
function miseAJourCourriel() { |
if ($('#courriel-memoire').is(':checked')) { |
bdd.setItem('utilisateur.courriel', $("#courriel").val()); |
} |
} |
|
function surErreurCompletionCourriel() { |
$('#id-utilisateur').val(''); |
$('#prenom-utilisateur, #nom-utilisateur, #courriel-confirmation').removeAttr('disabled'); |
} |