3208 |
idir |
1 |
"use strict";
|
|
|
2 |
|
|
|
3 |
/*************************************
|
|
|
4 |
* Fonctions de Style et Affichage *
|
|
|
5 |
* des éléments "spéciaux" *
|
|
|
6 |
*************************************/
|
|
|
7 |
|
3239 |
idir |
8 |
// Volet de profil/déconnexion
|
|
|
9 |
function connexionDprodownMenu() {
|
|
|
10 |
$( '#utilisateur-connecte .volet-toggle, #profil-utilisateur a, #deconnexion a' ).click( function( event ) {
|
|
|
11 |
event.preventDefault();
|
|
|
12 |
$( '#utilisateur-connecte .volet-menu' ).toggleClass( 'hidden' );
|
|
|
13 |
});
|
|
|
14 |
}
|
|
|
15 |
|
3208 |
idir |
16 |
// Logique d'affichage pour le input type=file
|
3217 |
idir |
17 |
function inputFile() {
|
3208 |
idir |
18 |
// Initialisation des variables
|
|
|
19 |
var $fileInput = $( '.input-file' ),
|
|
|
20 |
$button = $( '.label-file' );
|
|
|
21 |
// Action lorsque la "barre d'espace" ou "Entrée" est pressée
|
|
|
22 |
$( '.label-file' ).keydown( function( event ) {
|
|
|
23 |
if ( event.keyCode == 13 || event.keyCode == 32 ) {
|
|
|
24 |
$( '#' + $( this ).attr( 'for' ) + '.input-file' ).click();
|
|
|
25 |
}
|
|
|
26 |
});
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
// Style et affichage des list-checkboxes
|
|
|
30 |
function inputListCheckbox() {
|
|
|
31 |
// On écoute le click sur une list-checkbox ('.selectBox')
|
|
|
32 |
// à tout moment de son insertion dans le dom
|
|
|
33 |
// _ S'assurer de bien viser la bonne list-checkbox
|
|
|
34 |
// _ Au click sur un autre champ remballer la list-checkbox
|
|
|
35 |
$( document ).click( function( event ) {
|
|
|
36 |
var target = event.target;
|
|
|
37 |
|
|
|
38 |
if ( !$( target ).is( '.overSelect' ) && 0 === $( target ).closest( '.checkboxes' ).length ) {
|
|
|
39 |
$( '.checkboxes' ).each( function () {
|
|
|
40 |
$( this ).addClass( 'hidden' );
|
|
|
41 |
});
|
|
|
42 |
$( '.selectBox select.focus' ).each( function() {
|
|
|
43 |
$( this ).removeClass( 'focus' );
|
|
|
44 |
});
|
|
|
45 |
}
|
|
|
46 |
});
|
|
|
47 |
|
|
|
48 |
$( '#zone-appli' ).on( 'click' , '.selectBox' , function() {
|
3240 |
idir |
49 |
// afficher/cacher le volet des checkboxes et focus
|
3208 |
idir |
50 |
$( this ).next().toggleClass( 'hidden' );
|
|
|
51 |
$( this ).find( 'select' ).toggleClass( 'focus' );
|
|
|
52 |
|
3240 |
idir |
53 |
// Cacher le volet des autres checkboxes et retirer leur focus
|
|
|
54 |
var $checkboxes = $( this ).next(),
|
|
|
55 |
count = $( '.checkboxes' ).length;
|
|
|
56 |
for ( var i = 0; i < count; i++ ) {
|
|
|
57 |
if ( $( '.checkboxes' )[i] !== $checkboxes[0] && !$checkboxes.hasClass( 'hidden' ) ) {
|
|
|
58 |
var $otherListCheckboxes = $( '.checkboxes' )[i];
|
|
|
59 |
if ( !$otherListCheckboxes.classList.contains( 'hidden' ) ) {
|
|
|
60 |
$otherListCheckboxes.classList.add( 'hidden' );
|
|
|
61 |
}
|
|
|
62 |
if( $otherListCheckboxes.previousElementSibling.firstElementChild.classList.contains( 'focus' ) ) {
|
|
|
63 |
$otherListCheckboxes.previousElementSibling.firstElementChild.classList.remove( 'focus' );
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
3208 |
idir |
68 |
});
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// Style et affichage des input type="range"
|
|
|
72 |
function inputRangeDisplayNumber() {
|
3239 |
idir |
73 |
$( 'input[type="range"]' ).each( function() {
|
|
|
74 |
|
|
|
75 |
$( this ).siblings( '.range-live-value' ).text( $( this ).val() );
|
3208 |
idir |
76 |
});
|
3239 |
idir |
77 |
$( '#zone-supp' ).on( 'input' , 'input[type="range"]' , function () {
|
|
|
78 |
$( this ).siblings( '.range-live-value' ).text( $( this ).val() );
|
3208 |
idir |
79 |
});
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// Activation/Desactivation et contenu de la modale Bootstrap
|
|
|
83 |
// https://getbootstrap.com/docs/3.3/javascript/#modals
|
3239 |
idir |
84 |
function newFieldsHelpModal() {
|
3217 |
idir |
85 |
$( '#zone-appli' ).on( 'click' , '.help-button' , function ( event ) {
|
|
|
86 |
var thisFieldKey = $( this ).data( 'key' ),
|
|
|
87 |
fileMimeType = $( this ).data( 'mime-type' );
|
|
|
88 |
|
3208 |
idir |
89 |
// Titre
|
3217 |
idir |
90 |
$( '#help-modal-label' ).text( 'Aide pour : ' + $( this ).data( 'name' ) );
|
|
|
91 |
|
|
|
92 |
if( fileMimeType.match( 'image' ) ) {
|
3239 |
idir |
93 |
var extention = fileMimeType.replace( /(?:imag)?e\/?/g , '' );
|
|
|
94 |
// var extention = 'jpg';
|
|
|
95 |
$( '#print_content' ).append( '<img src="' + CHEMIN_FICHIERS + thisFieldKey + '.' + extention + '" style="max-width:100%" alt="' + thisFieldKey + '" />' );
|
3208 |
idir |
96 |
}
|
3217 |
idir |
97 |
|
3208 |
idir |
98 |
// Sortie avec la touche escape
|
|
|
99 |
$( '#help-modal' ).modal( { keyboard : true } );
|
|
|
100 |
// Affichage
|
3217 |
idir |
101 |
$( '#help-modal' ).modal({ show: true });
|
3208 |
idir |
102 |
// Remplacer l'autofocus qui ne fonctionne plus en HTML5
|
|
|
103 |
// Message dans la doc de bootstrap :
|
|
|
104 |
// Due to how HTML5 defines its semantics,
|
|
|
105 |
// the autofocus HTML attribute has no effect in Bootstrap modals.
|
|
|
106 |
// To achieve the same effect, use some custom JavaScript
|
|
|
107 |
$( '#help-modal' ).on( 'shown.bs.modal' , function () {
|
|
|
108 |
$( '#myInput' ).trigger( 'focus' );
|
|
|
109 |
})
|
|
|
110 |
// Réinitialisation
|
|
|
111 |
$( '#help-modal' ).on( 'hidden.bs.modal' , function () {
|
|
|
112 |
$( '#help-modal-label' ).text();
|
|
|
113 |
$( '#print_content' ).empty();
|
|
|
114 |
})
|
|
|
115 |
});
|
|
|
116 |
}
|
|
|
117 |
|
3239 |
idir |
118 |
// Activation/Desactivation et contenu de la modale Bootstrap
|
|
|
119 |
// https://getbootstrap.com/docs/3.3/javascript/#modals
|
|
|
120 |
function projetHelpModale() {
|
|
|
121 |
$( '#info-button' ).click( function ( event ) {
|
|
|
122 |
var fileMimeType = $( this ).data( 'mime-info' );
|
|
|
123 |
|
|
|
124 |
// Titre
|
|
|
125 |
$( '#help-modal-label' ).text( 'Aide du projet : ' + $( '#titre-projet' ).text() );
|
|
|
126 |
|
|
|
127 |
if( fileMimeType.match( 'image' ) ) {
|
|
|
128 |
|
|
|
129 |
var extention = fileMimeType.replace( /(?:imag)?e\/?/g , '' );
|
|
|
130 |
|
|
|
131 |
$( '#print_content' ).append( '<img src="' + CHEMIN_FICHIERS + 'info.' + extention + '" style="max-width:100%" alt="info projet" />' );
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
// Sortie avec la touche escape
|
|
|
135 |
$( '#help-modal' ).modal( { keyboard : true } );
|
|
|
136 |
// Affichage
|
|
|
137 |
$( '#help-modal' ).modal({ show: true });
|
|
|
138 |
// Remplacer l'autofocus qui ne fonctionne plus en HTML5
|
|
|
139 |
// Message dans la doc de bootstrap :
|
|
|
140 |
// Due to how HTML5 defines its semantics,
|
|
|
141 |
// the autofocus HTML attribute has no effect in Bootstrap modals.
|
|
|
142 |
// To achieve the same effect, use some custom JavaScript
|
|
|
143 |
$( '#help-modal' ).on( 'shown.bs.modal' , function () {
|
|
|
144 |
$( '#myInput' ).trigger( 'focus' );
|
|
|
145 |
})
|
|
|
146 |
// Réinitialisation
|
|
|
147 |
$( '#help-modal' ).on( 'hidden.bs.modal' , function () {
|
|
|
148 |
$( '#help-modal-label' ).text();
|
|
|
149 |
$( '#print_content' ).empty();
|
|
|
150 |
});
|
|
|
151 |
|
|
|
152 |
});
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
|
3208 |
idir |
156 |
// Faire apparaitre un champ text "Autre"
|
|
|
157 |
function onOtherOption() {
|
|
|
158 |
|
|
|
159 |
const PREFIX = 'collect-other-';
|
|
|
160 |
|
|
|
161 |
// Ajouter un champ texte pour "Autre"
|
|
|
162 |
function optionAdd( otherId, $target, element ) {
|
|
|
163 |
$target.after(
|
|
|
164 |
'<label for="' + otherId + '" class="' + otherId + '">Autre option :</label>' +
|
|
|
165 |
'<input type="text" id="' + otherId + '" name="' + otherId + '" class="collect-other" data-element="' + element + '">'
|
|
|
166 |
);
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
// Supprimer un champ texte pour "Autre"
|
|
|
170 |
function optionRemove( otherId, $this ) {
|
|
|
171 |
$( '.' + otherId + ', #' + otherId ).remove();
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
$( '#form-supp .other' ).each( function() {
|
|
|
175 |
if( $( this ).hasClass( 'is-select' ) ) {
|
|
|
176 |
var otherId = PREFIX + $( this ).parent( 'select' ).attr( 'name' );
|
|
|
177 |
// Insertion du champ "Autre" après les boutons
|
|
|
178 |
optionAdd( otherId, $( this ).parent( '.select' ) , 'select' );
|
|
|
179 |
} else if ( $( this ).is( ':checked' ) ) {
|
|
|
180 |
var otherId = PREFIX + $( this ).attr( 'name' ),
|
|
|
181 |
element = $( this ).attr( 'data-element' );
|
|
|
182 |
// Insertion du champ "Autre" après les boutons
|
|
|
183 |
optionAdd( otherId, $( this ).parent( 'label' ) , element );
|
|
|
184 |
}
|
|
|
185 |
});
|
|
|
186 |
|
|
|
187 |
$( '#form-supp select' ).change( function () {
|
|
|
188 |
var otherId = PREFIX + $( this ).attr( 'name' );
|
|
|
189 |
|
|
|
190 |
if( 'other' === $( this ).val() ) {
|
|
|
191 |
// Insertion du champ "Autre" après les boutons
|
|
|
192 |
optionAdd( otherId, $( this ).parent( '.select' ), 'select' );
|
|
|
193 |
} else {
|
|
|
194 |
// Suppression du champ autre
|
|
|
195 |
optionRemove( otherId, $( this ) );
|
|
|
196 |
$( this ).find( '.other' ).val( 'other' );
|
|
|
197 |
}
|
|
|
198 |
});
|
|
|
199 |
|
|
|
200 |
$( '#form-supp input[type=radio]' ).change( function () {
|
|
|
201 |
var otherId = PREFIX + $( this ).attr( 'name' );
|
|
|
202 |
|
|
|
203 |
if( 'other' === $( this ).val() ) {
|
|
|
204 |
// Insertion du champ "Autre" après les boutons
|
|
|
205 |
optionAdd( otherId, $( this ).parent( 'label' ), 'radio' );
|
|
|
206 |
} else {
|
|
|
207 |
// Suppression du champ autre
|
|
|
208 |
optionRemove( otherId, $( this ) );
|
|
|
209 |
$( this ).closest( 'div.control-group.radio' ).find( '.other' ).val( 'other' );
|
|
|
210 |
}
|
|
|
211 |
});
|
|
|
212 |
|
|
|
213 |
$( '#form-supp .list-checkbox .other, #form-supp .checkbox .other' ).click( function () {
|
|
|
214 |
var otherId = PREFIX + $( this ).attr( 'name' ),
|
|
|
215 |
element = $( this ).attr( 'data-element' );
|
|
|
216 |
// console.log(element);
|
|
|
217 |
if( $( this ).is( ':checked' ) ) {
|
|
|
218 |
// Insertion du champ "Autre" après les boutons
|
|
|
219 |
optionAdd( otherId, $( this ).parent( 'label' ), element );
|
|
|
220 |
} else {
|
|
|
221 |
// Suppression du champ autre
|
|
|
222 |
optionRemove( otherId, $( this ) );
|
|
|
223 |
$( this ).val( 'other' );
|
|
|
224 |
}
|
|
|
225 |
});
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
function collectOtherOption() {
|
|
|
229 |
$( '#form-supp' ).on( 'change', '.collect-other', function () {
|
|
|
230 |
var otherIdSuffix = $( this ).attr( 'name' ).replace( 'collect-other-', '' ),
|
|
|
231 |
element = $( this ).attr( 'data-element' );
|
|
|
232 |
if ( '' === $( this ).val() ){
|
|
|
233 |
if ( 'select' === element ) {
|
|
|
234 |
$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', false );
|
|
|
235 |
} else {
|
|
|
236 |
$( '#other-' + otherIdSuffix ).prop( 'checked', false );
|
|
|
237 |
}
|
|
|
238 |
} else {
|
|
|
239 |
if ( 'select' === element ) {
|
|
|
240 |
$( '#' + otherIdSuffix ).find( '.other' ).val( $( this ).val() );
|
|
|
241 |
$( '#' + otherIdSuffix + ' option').not( '.other' ).prop( 'selected', false );
|
|
|
242 |
$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', true );
|
|
|
243 |
} else {
|
|
|
244 |
if ( 'radio' === element ) {
|
|
|
245 |
$( 'input[name=' + otherIdSuffix + ']' ).not( '#other-' + otherIdSuffix ).prop( 'checked', false );
|
|
|
246 |
}
|
|
|
247 |
// console.log( otherIdSuffix );
|
|
|
248 |
$( '#other-' + otherIdSuffix ).val( $( this ).val() );
|
|
|
249 |
$( '#other-' + otherIdSuffix ).prop( 'checked', true );
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
}
|
|
|
253 |
});
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
/***************************
|
|
|
257 |
* Lancement des scripts *
|
|
|
258 |
***************************/
|
3239 |
idir |
259 |
const CHEMIN_FICHIERS = $( '#zone-appli' ).data('url-fichiers');
|
|
|
260 |
|
3208 |
idir |
261 |
jQuery( document ).ready( function() {
|
3240 |
idir |
262 |
$( '#form-supp' )[0].reset();
|
3239 |
idir |
263 |
|
3240 |
idir |
264 |
// console.log( $('#taxon').val() !== '' );
|
|
|
265 |
// $('#ajouter-obs').click( function() {
|
|
|
266 |
// // console.log( $('#taxon').val() !== '' );
|
|
|
267 |
// });
|
|
|
268 |
//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)$)"
|
|
|
269 |
|
3239 |
idir |
270 |
// Volet de profil/déconnexion
|
|
|
271 |
connexionDprodownMenu();
|
|
|
272 |
|
|
|
273 |
// Modale "aide" du projet
|
|
|
274 |
projetHelpModale();
|
|
|
275 |
// Affichage input file
|
3217 |
idir |
276 |
inputFile();
|
|
|
277 |
// Affichage des List-checkbox
|
3208 |
idir |
278 |
inputListCheckbox();
|
3217 |
idir |
279 |
|
3239 |
idir |
280 |
// Affichage des Range
|
|
|
281 |
inputRangeDisplayNumber()
|
3217 |
idir |
282 |
|
|
|
283 |
// Modale "aide"
|
3239 |
idir |
284 |
newFieldsHelpModal();
|
|
|
285 |
|
3217 |
idir |
286 |
// Ajout/suppression d'un champ texte "Autre"
|
3208 |
idir |
287 |
onOtherOption();
|
3239 |
idir |
288 |
// Récupérer les données entrées dans "Autre"
|
3208 |
idir |
289 |
collectOtherOption();
|
|
|
290 |
});
|