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