Subversion Repositories eFlore/Applications.cel

Rev

Rev 3976 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3976 Rev 3977
1
function WidgetPhotoContact () {}
1
function WidgetPhotoContact () {}
2
 
2
 
3
WidgetPhotoContact.prototype = new WidgetPhotoCommun();
3
WidgetPhotoContact.prototype = new WidgetPhotoCommun();
4
 
4
 
5
WidgetPhotoContact.prototype.initTpl = function() {
5
WidgetPhotoContact.prototype.initTpl = function() {
6
	$( '#form-contact' ).validate({
6
	$( '#form-contact' ).validate({
7
		rules: {
7
		rules: {
8
			fc_sujet : 'required',
8
			fc_sujet : 'required',
9
			fc_message : 'required',
9
			fc_message : 'required',
10
			fc_utilisateur_courriel : {
10
			fc_utilisateur_courriel : {
11
				required : true,
11
				required : true,
12
				email : true
12
				email : true
13
			}
13
			}
14
		}
14
		}
15
	});
15
	});
16
};
16
};
17
 
17
 
18
WidgetPhotoContact.prototype.initEvts = function() {
18
WidgetPhotoContact.prototype.initEvts = function() {
19
	const lthis = this;
19
	const lthis = this;
20
 
20
 
21
	$( '#form-contact' ).on( 'submit', function( event ) {
21
	$( '#form-contact' ).on( 'submit', function( event ) {
22
		event.preventDefault();
22
		event.preventDefault();
23
		lthis.envoyerCourriel();
23
		lthis.envoyerCourriel();
24
	});
24
	});
25
	this.initEvtsRetourPopupPhoto();
25
	this.initEvtsRetourPopupPhoto();
26
};
26
};
27
 
27
 
28
WidgetPhotoContact.prototype.initEvtsRetourPopupPhoto = function() {
28
WidgetPhotoContact.prototype.initEvtsRetourPopupPhoto = function() {
29
	const lthis = this;
29
	const lthis = this;
30
 
30
 
31
	$( '#fc_annuler.popup_url' ).on( 'click', function( event ) {
31
	$( '#fc_annuler.popup_url' ).on( 'click', function( event ) {
32
		event.preventDefault();
32
		event.preventDefault();
33
		lthis.retourPopupPhoto();
33
		lthis.retourPopupPhoto();
34
	});
34
	});
35
	$( '#fc_annuler.popup_url' ).on( 'keydown', function( event ) {
35
	$( '#fc_annuler.popup_url' ).on( 'keydown', function( event ) {
36
		var isEnter = false;
36
		var isEnter = false;
37
 
37
 
38
		event = event || window.event;
38
		event = event || window.event;
39
		// event.keyCode déprécié, on tente d'abord event.key
39
		// event.keyCode déprécié, on tente d'abord event.key
40
		if ( 'key' in event) {
40
		if ( 'key' in event) {
41
			isEnter = ( event.key === 'Enter' );
41
			isEnter = ( event.key === 'Enter' );
42
		} else {
42
		} else {
43
			isEnter = ( event.keyCode === 13 );
43
			isEnter = ( event.keyCode === 13 );
44
		}
44
		}
45
		if ( isEnter ) {
45
		if ( isEnter ) {
46
			lthis.retourPopupPhoto();
46
			lthis.retourPopupPhoto();
47
		}
47
		}
48
	});
48
	});
49
	$( 'body' ).on( 'keyup', function( event ) {
49
	$( 'body' ).on( 'keyup', function( event ) {
50
		if( $( '#fenetre-modal' ).hasClass( 'show' ) ) {
50
		if( $( '#fenetre-modal' ).hasClass( 'show' ) ) {
51
			var isEscape = false;
51
			var isEscape = false;
52
 
52
 
53
			event = event || window.event;
53
			event = event || window.event;
54
			// event.keyCode déprécié, on tente d'abord event.key
54
			// event.keyCode déprécié, on tente d'abord event.key
55
			if ( 'key' in event) {
55
			if ( 'key' in event) {
56
				isEscape = ( event.key === 'Escape' || event.key === 'Esc' );
56
				isEscape = ( event.key === 'Escape' || event.key === 'Esc' );
57
			} else {
57
			} else {
58
				isEscape = ( event.keyCode === 27 );
58
				isEscape = ( event.keyCode === 27 );
59
			}
59
			}
60
			if ( isEscape ) {
60
			if ( isEscape ) {
61
				lthis.retourPopupPhoto();
61
				lthis.retourPopupPhoto();
62
			}
62
			}
63
		}
63
		}
64
	});
64
	});
65
};
65
};
66
 
66
 
67
WidgetPhotoContact.prototype.envoyerCourriel = function() {
67
WidgetPhotoContact.prototype.envoyerCourriel = function() {
68
	const lthis = this;
68
	const lthis = this;
69
	var donnees = [];
69
	var donnees = [];
70
 
70
 
71
	if ( $( '#form-contact' ).valid() ) {
71
	if ( $( '#form-contact' ).valid() ) {
72
		var destinataireId = $( '#fc_destinataire_id' ).val(),
72
		var destinataireId = $( '#fc_destinataire_id' ).val(),
73
			typeEnvoi      = $( '#fc_type_envoi' ).val(),
73
			typeEnvoi      = $( '#fc_type_envoi' ).val(),
74
		// l'envoi aux non inscrits passe par le service intermédiaire du cel
74
		// l'envoi aux non inscrits passe par le service intermédiaire du cel
75
		// qui va récupérer le courriel associé à l'image indiquée
75
		// qui va récupérer le courriel associé à l'image indiquée
76
			urlMessage     = 'https://api-test.tela-botanica.org/service:cel:celMessage/image/' + destinataireId,
76
			urlMessage     = 'https://api.tela-botanica.org/service:cel:celMessage/image/' + destinataireId,
77
			erreurMsg      = '';
77
			erreurMsg      = '';
78
 
78
 
79
		$.each( $( '#form-contact' ).serializeArray(), function ( index, champ ) {
79
		$.each( $( '#form-contact' ).serializeArray(), function ( index, champ ) {
80
			var cle = champ.name;
80
			var cle = champ.name;
81
 
81
 
82
			cle = cle.replace( /^fc_/, '' );
82
			cle = cle.replace( /^fc_/, '' );
83
			if ( cle === 'sujet' ) {
83
			if ( cle === 'sujet' ) {
84
				champ.value += ' - Carnet en ligne - Tela Botanica';
84
				champ.value += ' - Carnet en ligne - Tela Botanica';
85
			}
85
			}
86
			if ( cle === 'message' ) {
86
			if ( cle === 'message' ) {
87
				champ.value +=
87
				champ.value +=
88
					"\n--\n" +
88
					"\n--\n" +
89
					"Ce message vous est envoyé par l'intermédiaire du widget photo " +
89
					"Ce message vous est envoyé par l'intermédiaire du widget photo " +
90
					"du Carnet en Ligne du réseau Tela Botanica.\n" +
90
					"du Carnet en Ligne du réseau Tela Botanica.\n" +
91
					"http://www.tela-botanica.org/widget:cel:photo";
91
					"http://www.tela-botanica.org/widget:cel:photo";
92
			}
92
			}
93
			donnees[index] = {
93
			donnees[index] = {
94
				'name' : cle,
94
				'name' : cle,
95
				'value': champ.value
95
				'value': champ.value
96
			};
96
			};
97
		});
97
		});
98
		console.log(donnees);
-
 
99
		var xhr = new XMLHttpRequest();
-
 
100
		xhr.open("POST", urlMessage, true);
-
 
101
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-
 
102
 
-
 
103
		xhr.onreadystatechange = function () {
-
 
104
			if (xhr.readyState === 4) { // Request is complete
-
 
105
				// Remove existing messages
-
 
106
				document.querySelectorAll('.msg').forEach(function (msg) {
-
 
107
					msg.remove();
-
 
108
				});
-
 
109
 
-
 
110
				if (xhr.status >= 200 && xhr.status < 300) { // Request was successful
-
 
111
					var data = JSON.parse(xhr.responseText);
-
 
112
					document.getElementById('fc-zone-dialogue').innerHTML += '<pre class="msg info">' + data.message + '</pre>';
-
 
113
				} else { // Error during the request
-
 
114
					var erreurMsg = "Erreur Ajax :\ntype : " + xhr.statusText + ' ' + xhr.status + "\n";
-
 
115
					var reponse = JSON.parse(xhr.responseText);
-
 
116
 
-
 
117
					if (lthis.valOk(reponse)) {
-
 
118
						Object.values(reponse).forEach(function (valeur) {
-
 
119
							erreurMsg += valeur + "\n";
-
 
120
						});
-
 
121
					}
-
 
122
 
-
 
123
					var debugMsg = '';
-
 
124
					var debugInfos = JSON.parse(xhr.getResponseHeader("X-DebugJrest-Data"));
-
 
125
 
-
 
126
					if (lthis.valOk(debugInfos)) {
-
 
127
						Object.values(debugInfos).forEach(function (valeur) {
-
 
128
							debugMsg += valeur + "\n";
-
 
129
						});
-
 
130
					}
-
 
131
 
-
 
132
					document.getElementById('fc-zone-dialogue').innerHTML +=
-
 
133
						'<p class="msg">' +
-
 
134
						'Une erreur est survenue lors de la transmission de votre message.<br>' +
-
 
135
						'Vous pouvez signaler le disfonctionnement à ' +
-
 
136
						'<a ' +
-
 
137
						'href="mailto:cel-remarques@tela-botanica.org?' +
-
 
138
						'subject=Disfonctionnement du widget carto' +
-
 
139
						"&body=" + erreurMsg + "\nDébogage :\n" + debugMsg +
-
 
140
						'"' +
-
 
141
						'>' +
-
 
142
						'cel-remarques@tela-botanica.org' +
-
 
143
						'</a>' +
-
 
144
						'.' +
-
 
145
						'</p>';
-
 
146
				}
-
 
147
			}
-
 
148
		};
-
 
149
 
-
 
150
// Send the request with the donnees variable
-
 
151
		xhr.send(donnees);
-
 
152
 
-
 
153
		/*
98
 
154
		$.ajax({
99
		$.ajax({
155
			type       : "POST",
100
			type       : "POST",
156
			cache      : false,
101
			cache      : false,
157
			url        : urlMessage,
102
			url        : urlMessage,
158
			data       : donnees,
103
			data       : donnees,
159
			beforeSend : function() {
104
			beforeSend : function() {
160
				$( '.msg' ).remove();
105
				$( '.msg' ).remove();
161
			},
106
			},
162
			success    : function( data ) {
107
			success    : function( data ) {
163
				$( '#fc-zone-dialogue' ).append( '<pre class="msg info">' + data.message + '</pre>' );
108
				$( '#fc-zone-dialogue' ).append( '<pre class="msg info">' + data.message + '</pre>' );
164
			},
109
			},
165
			error      : function( jqXHR, textStatus, errorThrown ) {
110
			error      : function( jqXHR, textStatus, errorThrown ) {
166
				erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
111
				erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";
167
				reponse = jQuery.parseJSON( jqXHR.responseText );
112
				reponse = jQuery.parseJSON( jqXHR.responseText );
168
				if ( lthis.valOk( reponse ) ) {
113
				if ( lthis.valOk( reponse ) ) {
169
					$.each( reponse, function ( cle, valeur ) {
114
					$.each( reponse, function ( cle, valeur ) {
170
						erreurMsg += valeur + "\n";
115
						erreurMsg += valeur + "\n";
171
					});
116
					});
172
				}
117
				}
173
			},
118
			},
174
			complete   : function( jqXHR, textStatus ) {
119
			complete   : function( jqXHR, textStatus ) {
175
				var debugMsg = '';
120
				var debugMsg = '';
176
				if ( lthis.valOk( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) ) ) {
121
				if ( lthis.valOk( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) ) ) {
177
					debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) );
122
					debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) );
178
					if ( lthis.valOk( debugInfos ) ) {
123
					if ( lthis.valOk( debugInfos ) ) {
179
						$.each( debugInfos, function ( cle, valeur ) {
124
						$.each( debugInfos, function ( cle, valeur ) {
180
							debugMsg += valeur + "\n";
125
							debugMsg += valeur + "\n";
181
						});
126
						});
182
					}
127
					}
183
				}
128
				}
184
				if ( lthis.valOk( erreurMsg ) ) {
129
				if ( lthis.valOk( erreurMsg ) ) {
185
					$( '#fc-zone-dialogue' ).append(
130
					$( '#fc-zone-dialogue' ).append(
186
						'<p class="msg">' +
131
						'<p class="msg">' +
187
							'Une erreur est survenue lors de la transmission de votre message.<br>' +
132
							'Une erreur est survenue lors de la transmission de votre message.<br>' +
188
							'Vous pouvez signaler le disfonctionnement à '+
133
							'Vous pouvez signaler le disfonctionnement à '+
189
							'<a '+
134
							'<a '+
190
								'href="mailto:cel-remarques@tela-botanica.org?'+
135
								'href="mailto:cel-remarques@tela-botanica.org?'+
191
									'subject=Disfonctionnement du widget carto'+
136
									'subject=Disfonctionnement du widget carto'+
192
									"&body=" + erreurMsg + "\nDébogage :\n" + debugMsg+
137
									"&body=" + erreurMsg + "\nDébogage :\n" + debugMsg+
193
								'"' +
138
								'"' +
194
							'>'+
139
							'>'+
195
								'cel-remarques@tela-botanica.org'+
140
								'cel-remarques@tela-botanica.org'+
196
							'</a>'+
141
							'</a>'+
197
							'.'+
142
							'.'+
198
						'</p>'
143
						'</p>'
199
					);
144
					);
200
				}
145
				}
201
			}
146
			}
202
		});
147
		});
203
		 */
148
 
204
	}
149
	}
205
	return false;
150
	return false;
206
};
151
};
207
 
152
 
208
 
153
 
209
WidgetPhotoContact.prototype.retourPopupPhoto = function() {
154
WidgetPhotoContact.prototype.retourPopupPhoto = function() {
210
	const lthis = this;
155
	const lthis = this;
211
	var popup_url = $( '#fc_annuler.popup_url' ).data( 'popup_url' );
156
	var popup_url = $( '#fc_annuler.popup_url' ).data( 'popup_url' );
212
	if ( lthis.valOk( popup_url ) ) {
157
	if ( lthis.valOk( popup_url ) ) {
213
		lthis.chargerContenuModale( popup_url );
158
		lthis.chargerContenuModale( popup_url );
214
	}
159
	}
215
};
160
};