Rev 3631 | Rev 3971 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
function WidgetPhotoContact () {}WidgetPhotoContact.prototype = new WidgetPhotoCommun();WidgetPhotoContact.prototype.initTpl = function() {$( '#form-contact' ).validate({rules: {fc_sujet : 'required',fc_message : 'required',fc_utilisateur_courriel : {required : true,email : true}}});};WidgetPhotoContact.prototype.initEvts = function() {const lthis = this;$( '#form-contact' ).on( 'submit', function( event ) {event.preventDefault();lthis.envoyerCourriel();});this.initEvtsRetourPopupPhoto();};WidgetPhotoContact.prototype.initEvtsRetourPopupPhoto = function() {const lthis = this;$( '#fc_annuler.popup_url' ).on( 'click', function( event ) {event.preventDefault();lthis.retourPopupPhoto();});$( '#fc_annuler.popup_url' ).on( 'keydown', function( event ) {var isEnter = false;event = event || window.event;// event.keyCode déprécié, on tente d'abord event.keyif ( 'key' in event) {isEnter = ( event.key === 'Enter' );} else {isEnter = ( event.keyCode === 13 );}if ( isEnter ) {lthis.retourPopupPhoto();}});$( 'body' ).on( 'keyup', function( event ) {if( $( '#fenetre-modal' ).hasClass( 'show' ) ) {var isEscape = false;event = event || window.event;// event.keyCode déprécié, on tente d'abord event.keyif ( 'key' in event) {isEscape = ( event.key === 'Escape' || event.key === 'Esc' );} else {isEscape = ( event.keyCode === 27 );}if ( isEscape ) {lthis.retourPopupPhoto();}}});};WidgetPhotoContact.prototype.envoyerCourriel = function() {const lthis = this;var donnees = [];if ( $( '#form-contact' ).valid() ) {var destinataireId = $( '#fc_destinataire_id' ).val(),typeEnvoi = $( '#fc_type_envoi' ).val(),// l'envoi aux non inscrits passe par le service intermédiaire du cel// qui va récupérer le courriel associé à l'image indiquéeurlMessage = 'http://api.tela-botanica.org/service:cel:celMessage/image/' + destinataireId,erreurMsg = '';$.each( $( '#form-contact' ).serializeArray(), function ( index, champ ) {var cle = champ.name;cle = cle.replace( /^fc_/, '' );if ( cle === 'sujet' ) {champ.value += ' - Carnet en ligne - Tela Botanica';}if ( cle === 'message' ) {champ.value +="\n--\n" +"Ce message vous est envoyé par l'intermédiaire du widget photo " +"du Carnet en Ligne du réseau Tela Botanica.\n" +"http://www.tela-botanica.org/widget:cel:photo";}donnees[index] = {'name' : cle,'value': champ.value};});$.ajax({type : "POST",cache : false,url : urlMessage,data : donnees,beforeSend : function() {$( '.msg' ).remove();},success : function( data ) {$( '#fc-zone-dialogue' ).append( '<pre class="msg info">' + data.message + '</pre>' );},error : function( jqXHR, textStatus, errorThrown ) {erreurMsg += "Erreur Ajax :\ntype : " + textStatus + ' ' + errorThrown + "\n";reponse = jQuery.parseJSON( jqXHR.responseText );if ( lthis.valOk( reponse ) ) {$.each( reponse, function ( cle, valeur ) {erreurMsg += valeur + "\n";});}},complete : function( jqXHR, textStatus ) {var debugMsg = '';if ( lthis.valOk( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) ) ) {debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( "X-DebugJrest-Data" ) );if ( lthis.valOk( debugInfos ) ) {$.each( debugInfos, function ( cle, valeur ) {debugMsg += valeur + "\n";});}}if ( lthis.valOk( erreurMsg ) ) {$( '#fc-zone-dialogue' ).append('<p class="msg">' +'Une erreur est survenue lors de la transmission de votre message.<br>' +'Vous pouvez signaler le disfonctionnement à '+'<a '+'href="mailto:cel-remarques@tela-botanica.org?'+'subject=Disfonctionnement du widget carto'+"&body=" + erreurMsg + "\nDébogage :\n" + debugMsg+'"' +'>'+'cel-remarques@tela-botanica.org'+'</a>'+'.'+'</p>');}}});}return false;};WidgetPhotoContact.prototype.retourPopupPhoto = function() {const lthis = this;var popup_url = $( '#fc_annuler.popup_url' ).data( 'popup_url' );if ( lthis.valOk( popup_url ) ) {lthis.chargerContenuModale( popup_url );}};