Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 534 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 534 Rev 535
1
$(document).ready(function() {
1
$(document).ready(function() {
2
	$("#connexion").on('click', connecter);
2
	$("#connexion").on('click', connecter);
3
});
3
});
4
 
4
 
5
function connecter() {
5
function connecter() {
6
	var erreurMsg = "";
6
	var erreurMsg = "";
7
	var urlWs = URL_WS_UTILISATEUR;
7
	var urlWs = URL_WS_UTILISATEUR;
8
	var courriel = $("#courriel").val();
8
	var courriel = $("#courriel").val();
9
	var mdp = $("#mdp").val();
9
	var mdp = $("#mdp").val();
10
	var persistance = $('#persistance').attr('checked');
10
	var persistance = $('#persistance').is(':checked');
11
	var donnees = {'methode':'connexion','courriel':courriel,'mdp':mdp, 'persistance':persistance};
11
	var donnees = {'methode':'connexion', 'courriel':courriel, 'mdp':mdp, 'persistance':persistance};
12
	
12
	
13
	$.ajax({
13
	$.ajax({
14
		type : "PUT",
14
		type : "PUT",
15
		cache : false,
15
		cache : false,
16
		url : urlWs,
16
		url : urlWs,
17
		data : donnees,
17
		data : donnees,
18
		beforeSend : nettoyerMsg,
18
		beforeSend : nettoyerMsg,
19
		success : function(data) {
19
		success : function(data) {
20
			if (data.identifie) {
20
			if (data.identifie) {
21
				rechargerPage();
21
				rechargerPage();
22
			} else {
22
			} else {
23
				afficherErreur(data.message);
23
				afficherErreur(data.message);
24
			}
24
			}
25
		},
25
		},
26
		error : function(jqXHR, textStatus, errorThrown) {
26
		error : function(jqXHR, textStatus, errorThrown) {
27
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
27
			erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
28
			erreurMsg += extraireInfosReponse(jqXHR);
28
			erreurMsg += extraireInfosReponse(jqXHR);
29
			afficherErreur('Une erreur est survenue lors de la connexion.');
29
			afficherErreur('Une erreur est survenue lors de la connexion.');
30
			if (DEBUG) {
30
			if (DEBUG) {
31
				console.log('Erreur : '+erreurMsg);
31
				console.log('Erreur : '+erreurMsg);
32
			}
32
			}
33
		},
33
		},
34
		complete : function(jqXHR, textStatus) {
34
		complete : function(jqXHR, textStatus) {
35
			var debugMsg = extraireEnteteDebug(jqXHR);
35
			var debugMsg = extraireEnteteDebug(jqXHR);
36
			if (DEBUG) {
36
			if (DEBUG) {
37
				console.log('Débogage : '+debugMsg);
37
				console.log('Débogage : '+debugMsg);
38
			}
38
			}
39
		}
39
		}
40
	});
40
	});
41
	return false;
41
	return false;
42
}
42
}
43
 
43
 
44
function nettoyerMsg() {
44
function nettoyerMsg() {
45
	$(".msg").remove();
45
	$(".msg").remove();
46
}
46
}
47
 
47
 
48
function rechargerPage() {
48
function rechargerPage() {
49
	window.location.reload();
49
	window.location.reload();
50
}
50
}
51
 
51
 
52
function extraireInfosReponse(jqXHR) {
52
function extraireInfosReponse(jqXHR) {
53
	var erreurMsg = '';
53
	var erreurMsg = '';
54
	try {
54
	try {
55
		reponse = jQuery.parseJSON(jqXHR.responseText);
55
		reponse = jQuery.parseJSON(jqXHR.responseText);
56
		if (reponse != null) {
56
		if (reponse != null) {
57
			$.each(reponse, function (cle, valeur) {
57
			$.each(reponse, function (cle, valeur) {
58
				erreurMsg += valeur + "\n";
58
				erreurMsg += valeur + "\n";
59
			});
59
			});
60
		}
60
		}
61
	} catch(e) {
61
	} catch(e) {
62
		erreurMsg += "L'erreur n'était pas en JSON.";
62
		erreurMsg += "L'erreur n'était pas en JSON.";
63
	}
63
	}
64
	return erreurMsg;
64
	return erreurMsg;
65
}
65
}
66
 
66
 
67
function extraireEnteteDebug(jqXHR) {
67
function extraireEnteteDebug(jqXHR) {
68
	var debugMsg = '';
68
	var debugMsg = '';
69
	if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
69
	if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
70
		debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
70
		debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
71
		if (debugInfos != null) {
71
		if (debugInfos != null) {
72
			$.each(debugInfos, function (cle, valeur) {
72
			$.each(debugInfos, function (cle, valeur) {
73
				debugMsg += valeur + "\n";
73
				debugMsg += valeur + "\n";
74
			});
74
			});
75
		}
75
		}
76
	}
76
	}
77
	return debugMsg;
77
	return debugMsg;
78
}
78
}
79
 
79
 
80
function afficherErreur(msg) {
80
function afficherErreur(msg) {
81
	afficherTxt(msg, 'attention');
81
	afficherTxt(msg, 'attention');
82
}
82
}
83
 
83
 
84
function afficherInfo(msg) {
84
function afficherInfo(msg) {
85
	afficherTxt(msg, 'information');
85
	afficherTxt(msg, 'information');
86
}
86
}
87
 
87
 
88
function afficherMsg(msg) {
88
function afficherMsg(msg) {
89
	afficherTxt(msg);
89
	afficherTxt(msg);
90
}
90
}
91
 
91
 
92
function afficherTxt(msg, type) {
92
function afficherTxt(msg, type) {
93
	type = type ? ' '+type : '';
93
	type = type ? ' '+type : '';
94
	nettoyerMsg();
94
	nettoyerMsg();
95
	$("#zone-dialogue").append('<pre class="msg'+type+'">'+msg+'</pre>');
95
	$("#zone-dialogue").append('<pre class="msg'+type+'">'+msg+'</pre>');
96
}
96
}