Rev 3239 | Blame | Last modification | View Log | RSS feed
"use strict";/************************************** Fonctions de Style et Affichage ** des éléments "spéciaux" **************************************/// Volet de profil/déconnexionfunction connexionDprodownMenu() {$( '#utilisateur-connecte .volet-toggle, #profil-utilisateur a, #deconnexion a' ).click( function( event ) {event.preventDefault();$( '#utilisateur-connecte .volet-menu' ).toggleClass( 'hidden' );});}// Logique d'affichage pour le input type=filefunction inputFile() {// Initialisation des variablesvar $fileInput = $( '.input-file' ),$button = $( '.label-file' );// Action lorsque la "barre d'espace" ou "Entrée" est pressée$( '.label-file' ).keydown( function( event ) {if ( event.keyCode == 13 || event.keyCode == 32 ) {$( '#' + $( this ).attr( 'for' ) + '.input-file' ).click();}});}// Style et affichage des list-checkboxesfunction inputListCheckbox() {// On écoute le click sur une list-checkbox ('.selectBox')// à tout moment de son insertion dans le dom// _ S'assurer de bien viser la bonne list-checkbox// _ Au click sur un autre champ remballer la list-checkbox$( document ).click( function( event ) {var target = event.target;if ( !$( target ).is( '.overSelect' ) && 0 === $( target ).closest( '.checkboxes' ).length ) {$( '.checkboxes' ).each( function () {$( this ).addClass( 'hidden' );});$( '.selectBox select.focus' ).each( function() {$( this ).removeClass( 'focus' );});}});$( '#zone-appli' ).on( 'click' , '.selectBox' , function() {// afficher/cacher le volet des checkboxes et focus$( this ).next().toggleClass( 'hidden' );$( this ).find( 'select' ).toggleClass( 'focus' );// Cacher le volet des autres checkboxes et retirer leur focusvar $checkboxes = $( this ).next(),count = $( '.checkboxes' ).length;for ( var i = 0; i < count; i++ ) {if ( $( '.checkboxes' )[i] !== $checkboxes[0] && !$checkboxes.hasClass( 'hidden' ) ) {var $otherListCheckboxes = $( '.checkboxes' )[i];if ( !$otherListCheckboxes.classList.contains( 'hidden' ) ) {$otherListCheckboxes.classList.add( 'hidden' );}if( $otherListCheckboxes.previousElementSibling.firstElementChild.classList.contains( 'focus' ) ) {$otherListCheckboxes.previousElementSibling.firstElementChild.classList.remove( 'focus' );}}}});}// Style et affichage des input type="range"function inputRangeDisplayNumber() {$( 'input[type="range"]' ).each( function() {$( this ).siblings( '.range-live-value' ).text( $( this ).val() );});$( '#zone-supp' ).on( 'input' , 'input[type="range"]' , function () {$( this ).siblings( '.range-live-value' ).text( $( this ).val() );});}// Activation/Desactivation et contenu de la modale Bootstrap// https://getbootstrap.com/docs/3.3/javascript/#modalsfunction newFieldsHelpModal() {$( '#zone-appli' ).on( 'click' , '.help-button' , function ( event ) {var thisFieldKey = $( this ).data( 'key' ),fileMimeType = $( this ).data( 'mime-type' );// Titre$( '#help-modal-label' ).text( 'Aide pour : ' + $( this ).data( 'name' ) );if( fileMimeType.match( 'image' ) ) {var extention = fileMimeType.replace( /(?:imag)?e\/?/g , '' );// var extention = 'jpg';$( '#print_content' ).append( '<img src="' + CHEMIN_FICHIERS + thisFieldKey + '.' + extention + '" style="max-width:100%" alt="' + thisFieldKey + '" />' );}// Sortie avec la touche escape$( '#help-modal' ).modal( { keyboard : true } );// Affichage$( '#help-modal' ).modal({ show: true });// Remplacer l'autofocus qui ne fonctionne plus en HTML5// Message dans la doc de bootstrap :// Due to how HTML5 defines its semantics,// the autofocus HTML attribute has no effect in Bootstrap modals.// To achieve the same effect, use some custom JavaScript$( '#help-modal' ).on( 'shown.bs.modal' , function () {$( '#myInput' ).trigger( 'focus' );})// Réinitialisation$( '#help-modal' ).on( 'hidden.bs.modal' , function () {$( '#help-modal-label' ).text();$( '#print_content' ).empty();})});}// Activation/Desactivation et contenu de la modale Bootstrap// https://getbootstrap.com/docs/3.3/javascript/#modalsfunction projetHelpModale() {$( '#info-button' ).click( function ( event ) {var fileMimeType = $( this ).data( 'mime-info' );// Titre$( '#help-modal-label' ).text( 'Aide du projet : ' + $( '#titre-projet' ).text() );if( fileMimeType.match( 'image' ) ) {var extention = fileMimeType.replace( /(?:imag)?e\/?/g , '' );$( '#print_content' ).append( '<img src="' + CHEMIN_FICHIERS + 'info.' + extention + '" style="max-width:100%" alt="info projet" />' );}// Sortie avec la touche escape$( '#help-modal' ).modal( { keyboard : true } );// Affichage$( '#help-modal' ).modal({ show: true });// Remplacer l'autofocus qui ne fonctionne plus en HTML5// Message dans la doc de bootstrap :// Due to how HTML5 defines its semantics,// the autofocus HTML attribute has no effect in Bootstrap modals.// To achieve the same effect, use some custom JavaScript$( '#help-modal' ).on( 'shown.bs.modal' , function () {$( '#myInput' ).trigger( 'focus' );})// Réinitialisation$( '#help-modal' ).on( 'hidden.bs.modal' , function () {$( '#help-modal-label' ).text();$( '#print_content' ).empty();});});}// Faire apparaitre un champ text "Autre"function onOtherOption() {const PREFIX = 'collect-other-';// Ajouter un champ texte pour "Autre"function optionAdd( otherId, $target, element ) {$target.after('<label for="' + otherId + '" class="' + otherId + '">Autre option :</label>' +'<input type="text" id="' + otherId + '" name="' + otherId + '" class="collect-other" data-element="' + element + '">');}// Supprimer un champ texte pour "Autre"function optionRemove( otherId, $this ) {$( '.' + otherId + ', #' + otherId ).remove();}$( '#form-supp .other' ).each( function() {if( $( this ).hasClass( 'is-select' ) ) {var otherId = PREFIX + $( this ).parent( 'select' ).attr( 'name' );// Insertion du champ "Autre" après les boutonsoptionAdd( otherId, $( this ).parent( '.select' ) , 'select' );} else if ( $( this ).is( ':checked' ) ) {var otherId = PREFIX + $( this ).attr( 'name' ),element = $( this ).attr( 'data-element' );// Insertion du champ "Autre" après les boutonsoptionAdd( otherId, $( this ).parent( 'label' ) , element );}});$( '#form-supp select' ).change( function () {var otherId = PREFIX + $( this ).attr( 'name' );if( 'other' === $( this ).val() ) {// Insertion du champ "Autre" après les boutonsoptionAdd( otherId, $( this ).parent( '.select' ), 'select' );} else {// Suppression du champ autreoptionRemove( otherId, $( this ) );$( this ).find( '.other' ).val( 'other' );}});$( '#form-supp input[type=radio]' ).change( function () {var otherId = PREFIX + $( this ).attr( 'name' );if( 'other' === $( this ).val() ) {// Insertion du champ "Autre" après les boutonsoptionAdd( otherId, $( this ).parent( 'label' ), 'radio' );} else {// Suppression du champ autreoptionRemove( otherId, $( this ) );$( this ).closest( 'div.control-group.radio' ).find( '.other' ).val( 'other' );}});$( '#form-supp .list-checkbox .other, #form-supp .checkbox .other' ).click( function () {var otherId = PREFIX + $( this ).attr( 'name' ),element = $( this ).attr( 'data-element' );// console.log(element);if( $( this ).is( ':checked' ) ) {// Insertion du champ "Autre" après les boutonsoptionAdd( otherId, $( this ).parent( 'label' ), element );} else {// Suppression du champ autreoptionRemove( otherId, $( this ) );$( this ).val( 'other' );}});}function collectOtherOption() {$( '#form-supp' ).on( 'change', '.collect-other', function () {var otherIdSuffix = $( this ).attr( 'name' ).replace( 'collect-other-', '' ),element = $( this ).attr( 'data-element' );if ( '' === $( this ).val() ){if ( 'select' === element ) {$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', false );} else {$( '#other-' + otherIdSuffix ).prop( 'checked', false );}} else {if ( 'select' === element ) {$( '#' + otherIdSuffix ).find( '.other' ).val( $( this ).val() );$( '#' + otherIdSuffix + ' option').not( '.other' ).prop( 'selected', false );$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', true );} else {if ( 'radio' === element ) {$( 'input[name=' + otherIdSuffix + ']' ).not( '#other-' + otherIdSuffix ).prop( 'checked', false );}// console.log( otherIdSuffix );$( '#other-' + otherIdSuffix ).val( $( this ).val() );$( '#other-' + otherIdSuffix ).prop( 'checked', true );}}});}/**************************** Lancement des scripts ****************************/const CHEMIN_FICHIERS = $( '#zone-appli' ).data('url-fichiers');jQuery( document ).ready( function() {$( '#form-supp' )[0].reset();// console.log( $('#taxon').val() !== '' );// $('#ajouter-obs').click( function() {// // console.log( $('#taxon').val() !== '' );// });//pattern="(^(((0[1-9]|1[0-9]|2[0-8])[\/](0[1-9]|1[012]))|((29|30|31)[\/](0[13578]|1[02]))|((29|30)[\/](0[4,6,9]|11)))[\/](19|[2-9][0-9])\d\d$)|(^29[\/]02[\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)"// Volet de profil/déconnexionconnexionDprodownMenu();// Modale "aide" du projetprojetHelpModale();// Affichage input fileinputFile();// Affichage des List-checkboxinputListCheckbox();// Affichage des RangeinputRangeDisplayNumber()// Modale "aide"newFieldsHelpModal();// Ajout/suppression d'un champ texte "Autre"onOtherOption();// Récupérer les données entrées dans "Autre"collectOtherOption();});