/trunk/widget/modules/saisie/squelettes/js/Utils.js |
---|
387,6 → 387,24 |
}); |
}; |
export const tryParseJson = str => { |
if ( 'string' !== typeof str ){ |
return false; |
} |
try{ |
const json = JSON.parse( str ); |
if ( !!json && 'object' === typeof json ) { |
return json; |
} else { |
return false; |
} |
} |
catch ( e ){ |
return false; |
} |
}; |
/** |
* Permet à la fois de vérifier qu'une valeur ou objet existe et n'est pas vide |
* et de comparer à une autre valeur : |
/trunk/widget/modules/saisie/squelettes/js/WidgetSaisie.js |
---|
1,5 → 1,5 |
import {WidgetsSaisiesCommun,utils} from './WidgetsSaisiesCommun.js'; |
import {valOk} from './Utils.js'; |
import {valOk,tryParseJson} from './Utils.js'; |
/** |
* Constructeur WidgetSaisie par défaut |
358,14 → 358,42 |
} |
}; |
WidgetSaisie.prototype.validateGeometry = function( geometry ) { |
const isLineString = !!geometry && 'LineString' === geometry.type, |
validateTypeOfCoordinates = coordinates => isLineString ? Array.isArray( coordinates ) : ['number','string'].includes( typeof coordinates ); |
if ( !valOk( geometry.coordinates ) ) { |
return false; |
} |
let isValid = true; |
$.each(geometry.coordinates, (i, coordinates) => { |
if ( !validateTypeOfCoordinates( coordinates ) ) { |
isValid = false; |
} |
}); |
const isValidLength = isLineString ? ( geometry.coordinates.length >= 2 ) : ( geometry.coordinates.length === 2 ); |
return isValid && isValidLength; |
} |
// Géolocalisation *************************************************************/ |
/** |
* Fonction handler de l'évenement location du module tb-geoloc |
*/ |
WidgetSaisie.prototype.locationHandler = function( location ) { |
const locDatas = location.originalEvent.detail; |
const locDatas = location.originalEvent.detail, |
$geolocControlGroup = $( '#geoloc' ).closest( '.control-group' ); |
if ( valOk( locDatas ) ) { |
if ( !valOk( locDatas ) ) { |
console.warn( 'Error location' ); |
} else { |
if ( !this.validateGeometry( locDatas.geometry ) ) { |
$geolocControlGroup.addClass( 'error' ); |
$( '#geometry' ).val( '' ); |
} else { |
console.log( locDatas ); |
const geometry = JSON.stringify( locDatas.geometry ), |
404,13 → 432,11 |
$( '#pays' ).val( pays ); |
$( '#station' ).val( rue ); |
$( '#latitude, #longitude' ).valid(); |
if ( valOk( $( '#latitude' ).val() ) && valOk( $( '#longitude' ).val() ) ) { |
$( '#geoloc' ).closest( '.control-group' ).removeClass( 'error' ); |
} else { |
$( '#geoloc' ).closest( '.control-group' ).addClass( 'error' ); |
$geolocControlGroup.toggleClass( |
'error', |
!valOk( $( '#latitude' ).val() ) || !valOk( $( '#longitude' ).val() ) |
); |
} |
} else { |
console.warn( 'Error location' ); |
} |
} |
619,18 → 645,16 |
WidgetSaisie.prototype.validerCertitudeTaxonImage = function( hasTaxon = false, hasImages = false ) { |
const isCertain = 'certain' === $( '#certitude' ).val(); |
let isvalide = true ; |
let isvalid = true ; |
if ( this.photoObligatoire || !isCertain ) { |
isvalide = this.validerImageRequise( hasImages ); |
isvalid = this.validerImageRequise( hasImages ); |
} |
if ( isCertain ) { |
isvalide &= this.validerTaxonRequis( hasTaxon ); |
isvalid &= this.validerTaxonRequis( hasTaxon ); |
} |
return isvalide; |
return isvalid; |
}; |
WidgetSaisie.prototype.validerTaxonRequis = function( hasTaxon = false ) { |
700,7 → 724,8 |
WidgetSaisie.prototype.validerForm = function() { |
const observateur = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() && $( '#courriel_confirmation' ).valid() ), |
obs = $( '#form-observation' ).valid(), |
geoloc = ( valOk( $( '#latitude' ).val() ) && valOk( $( '#longitude' ).val() ) ) , |
parsedGeometry = tryParseJson( $( '#geometry' ).val() ), |
geoloc = this.validateGeometry( parsedGeometry ) && ( valOk( $( '#latitude' ).val() ) && valOk( $( '#longitude' ).val() ) ) , |
// validation et panneau taxon/images |
certitudeTaxonImage = this.validerCertitudeTaxonImage( |
valOk( $( '#taxon' ).val() ), |
/trunk/widget/modules/saisie/squelettes/saisie.tpl.html |
---|
233,6 → 233,11 |
</div> |
</div> |
</div> |
<?php if( $widget['type_localisation'] === 'rue' ) : ?> |
<div class="aide-txt"> |
<p><?php echo $observation['info-saisie-ligne']; ?></p> |
</div> |
<?php endif; ?> |
<div id="map-container"> |
<div |
612,18 → 617,19 |
<div class="select-wrapper add-field-select <?php echo $help; ?>"> |
<select id="<?php echo $champ['key']; ?>" class="<?php echo $champ['key'] . ' ' . $champ['element']; ?> form-control has-tooltip custom-select mb-2"<?php echo $required; ?> data-label="<?php echo $champ['name']; ?>" data-name="<?php echo $champ['key']; ?>" <?php echo $description; ?>> |
<?php foreach ( $champ['fieldValues']['listValue'] as $list_value_array ) : ?> |
<?php foreach ( $champ['fieldValues']['listValue'] as $index => $list_value_array ) : ?> |
<?php |
$selected = ''; |
if ( '#' === substr( $list_value_array[0], -1 ) ) : |
$selected = ' selected="selected"'; |
$is_default = '#' === substr( $list_value_array[0], -1 ); |
$is_placeholder = null === $list_value_array[0]; |
$selected = $is_default || $is_placeholder ? ' selected="selected"' : ''; |
if ( $is_default ) : |
$list_value_array[0] = substr( $list_value_array[0], 0, -1 ); |
endif; |
?> |
<?php if( 'other' !== $list_value_array ) : ?> |
<option value="<?php echo $list_value_array[0]; ?>"<?php echo $selected; ?> data-name="<?php echo $champ['key']; ?>"> |
<option value="<?php echo $list_value_array[0]; ?>"<?php echo $selected; ?><?php echo $is_placeholder ? ' hidden': ''; ?> data-name="<?php echo $champ['key']; ?>"> |
<?php echo ( '' !== $list_value_array[1] ) ? ucfirst($list_value_array[1]) : ucfirst($list_value_array[0]); ?> |
</option> |
<?php else : ?> |
/trunk/widget/modules/saisie/squelettes/i18n/fr.ini |
---|
55,7 → 55,7 |
geolocalisation = "Geolocalisation" |
geoloc-title = "Renseignez la localisation de votre observation" |
alertgk-title = "Information : mauvaise géolocalisation" |
alertgk = "Certaines informations de géolocalisation n'ont pas été transmises." |
alertgk = "Certaines informations de géolocalisation n'ont pas été transmises ou sont invalides." |
milieu = "Milieu" |
milieu-title = "Type d’habitat, par exemple issu des codes Corine ou Catminat" |
liste-milieu-title = "Choisir un type d'habitat" |
/trunk/widget/modules/saisie/i18n/fr.ini |
---|
54,9 → 54,10 |
titre = "Observation" |
geolocalisation = "Geolocalisation" |
info-saisie-rue = "Renseigner votre nom de rue complet suivi du nom de votre ville" |
info-saisie-ligne = "Pour être valide votre ligne doit comporter au moins deux points." |
geoloc-title = "Renseignez la localisation de votre observation" |
alertgk-title = "Information : mauvaise géolocalisation" |
alertgk = "Certaines informations de géolocalisation n'ont pas été transmises." |
alertgk = "Certaines informations de géolocalisation n'ont pas été transmises ou sont invalides." |
milieu = "Milieu" |
milieu-title = "Type d’habitat, par exemple issu des codes Corine ou Catminat" |
liste-milieu-title = "Choisir un type d'habitat" |