Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 532 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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