@osimatic/helpers-js 1.0.23 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/form_date.js CHANGED
@@ -1,28 +1,521 @@
1
- class FormDate {
1
+ // input period de type : Du <input type="date" name="start_date" /> au <input type="date" name="end_date" />
2
+ class InputPeriod {
3
+
4
+ static addLinks(form) {
5
+ let divParent = form.find('input[type="date"][data-add_period_select_links]').parent();
6
+ if (divParent.hasClass('input-group')) {
7
+ divParent = divParent.parent();
8
+ }
9
+ divParent.append(''
10
+ +'<div class="select_period_links">'
11
+ +'<a href="#" class="period_select_yesterday">Hier</a> - '
12
+ +'<a href="#" class="period_select_current_week">Cette semaine</a> - '
13
+ +'<a href="#" class="period_select_last_week">La semaine dernière</a> - '
14
+ +'<a href="#" class="period_select_current_month">Ce mois-ci</a> - '
15
+ +'<a href="#" class="period_select_last_month">Le mois dernier</a> - '
16
+ +'<a href="#" class="period_select_current_year">Cette année</a>'
17
+ +'</div>'
18
+ );
19
+ this.init(form);
20
+ }
21
+
22
+ static init(form) {
23
+ let link;
24
+ //console.log(form.find('a.period_select_current_week'));
25
+
26
+ if ((link = form.find('a.period_select_today')).length) {
27
+ link.click(function() { InputPeriod.selectToday($(this)); return false; });
28
+ }
29
+ if ((link = form.find('a.period_select_yesterday')).length) {
30
+ link.click(function() { InputPeriod.selectPreviousDay($(this), 1); return false; });
31
+ }
32
+ if ((link = form.find('a.period_select_tomorrow')).length) {
33
+ link.click(function() { InputPeriod.selectFollowingDay($(this), 1); return false; });
34
+ }
35
+ if ((link = form.find('a.period_select_current_week')).length) {
36
+ link.click(function() { InputPeriod.selectCurrentWeek($(this)); return false; });
37
+ }
38
+ if ((link = form.find('a.period_select_last_week')).length) {
39
+ link.click(function() { InputPeriod.selectPreviousWeek($(this), 1); return false; });
40
+ }
41
+ if ((link = form.find('a.period_select_current_month')).length) {
42
+ link.click(function() { InputPeriod.selectCurrentMonth($(this)); return false; });
43
+ }
44
+ if ((link = form.find('a.period_select_last_month')).length) {
45
+ link.click(function() { InputPeriod.selectPreviousMonth($(this), 1); return false; });
46
+ }
47
+ if ((link = form.find('a.period_select_current_year')).length) {
48
+ link.click(function() { InputPeriod.selectCurrentYear($(this)); return false; });
49
+ }
50
+ if ((link = form.find('a.period_select_last_year')).length) {
51
+ link.click(function() { InputPeriod.selectCurrentYear($(this), 1); return false; });
52
+ }
53
+ }
54
+
55
+
56
+ static selectToday(link) {
57
+ let date = new Date();
58
+ this.selectPeriod(link, date, date);
59
+ }
60
+
61
+ static selectPreviousDay(lien, nbDays) {
62
+ this.selectFollowingDay(lien, -nbDays);
63
+ }
64
+ static selectFollowingDay(lien, nbDays) {
65
+ let date = new Date();
66
+ date.setDate(date.getDate() + nbDays);
67
+ this.selectPeriod(lien, date, date);
68
+ }
69
+
70
+ static selectCurrentWeek(lien) {
71
+ let date = new Date();
72
+ this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
73
+ }
74
+ static selectPreviousWeek(lien, nbWeeks) {
75
+ this.selectFollowingWeek(lien, -nbWeeks);
76
+ }
77
+ static selectFollowingWeek(lien, nbWeeks) {
78
+ let date = new Date();
79
+ date.setDate(date.getDate() + (7*nbWeeks));
80
+ this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
81
+ }
82
+
83
+ static selectCurrentMonth(lien) {
84
+ let date = new Date();
85
+ this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
86
+ }
87
+ static selectPreviousMonth(lien, nbMonths) {
88
+ this.selectFollowingMonth(lien, -nbMonths);
89
+ }
90
+ static selectFollowingMonth(lien, nbMonths) {
91
+ let date = new Date();
92
+ date.setDate(1);
93
+ date.setMonth(date.getMonth() + nbMonths);
94
+ this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
95
+ }
96
+
97
+ static selectCurrentYear(lien) {
98
+ this.selectFollowingYear(lien, 0);
99
+ }
100
+ static selectPreviousYear(lien, nbAnneesMoins) {
101
+ this.selectFollowingYear(lien, -nbAnneesMoins);
102
+ }
103
+ static selectFollowingYear(lien, nbAnneesMoins) {
104
+ let date = new Date();
105
+ date.setFullYear(date.getFullYear() + nbAnneesMoins);
106
+ this.selectPeriod(lien, DateTime.getFirstDayOfYear(date), DateTime.getLastDayOfYear(date));
107
+ }
108
+
109
+
110
+ static selectPeriod(link, startDate, endDate) {
111
+ let inputPeriodStart = link.parent().parent().find('input[type="date"]').filter('[name="date_start"], [name="start_date"], [name="start_period"], [name="period_start_date"]');
112
+ let inputPeriodEnd = link.parent().parent().find('input[type="date"]').filter('[name="date_end"], [name="end_date"], [name="end_period"], [name="period_end_date"]');
113
+ if (inputPeriodStart.length == 0 || inputPeriodEnd.length == 0) {
114
+ console.log('no period input found');
115
+ return;
116
+ }
117
+
118
+ //console.log(startDate);
119
+ //console.log(endDate);
120
+ inputPeriodStart.val(DateTime.getSqlDate(startDate));
121
+ inputPeriodEnd.val(DateTime.getSqlDate(endDate));
122
+ }
123
+
124
+ }
125
+
126
+ // input period de type : <select class="period">Aujourd'hui / Ce mois-ci / etc. / Personnalisé</select>
127
+ class FormDate {
128
+ static initForm(form) {
129
+
130
+ function fillPeriodSelect(select) {
131
+ Object.entries(FormDate.getPeriodList()).forEach(([idx, tabListPeriode]) => {
132
+ let html = '<optgroup label="'+tabListPeriode['label']+'">';
133
+ Object.entries(tabListPeriode['list']).forEach(([key, label]) => {
134
+ html += '<option value="'+key+'">'+label+'</option>';
135
+ });
136
+ html += '</optgroup>';
137
+ select.append(html);
138
+ });
139
+ if (select.data('default_value')) {
140
+ select.val(select.data('default_value'));
141
+ }
142
+ }
143
+
144
+ function updatePeriodSelect(select) {
145
+ if (select.val() === 'perso') {
146
+ select.closest('.form-group').next().removeClass('hide');
147
+ }
148
+ else {
149
+ select.closest('.form-group').next().addClass('hide');
150
+ }
151
+ }
152
+
153
+ function updateForm(form) {
154
+ let periodSelect = form.find('select.periode');
155
+ if (periodSelect.length === 0) {
156
+ return;
157
+ }
158
+
159
+ updatePeriodSelect(periodSelect);
160
+
161
+ let comparedPeriodSelect = form.find('select.periodeCompare');
162
+ if (comparedPeriodSelect.length === 0) {
163
+ return;
164
+ }
165
+
166
+ let listValues = [];
167
+ let valueDefault = null;
168
+
169
+ comparedPeriodSelect.find('option').attr('disabled', false);
170
+
171
+ Object.entries(FormDate.getPeriodList()).forEach(([idx, tabListPeriode]) => {
172
+ if (idx != 0) {
173
+ let listKeyPeriode = Object.entries(tabListPeriode['list']).map(([key, value]) => key);
174
+ if (listKeyPeriode.indexOf(periodSelect.val()) !== -1) {
175
+ listValues = listKeyPeriode;
176
+ valueDefault = listKeyPeriode[1];
177
+ }
178
+ else {
179
+ comparedPeriodSelect.find('option[value="' + listKeyPeriode[0] + '"]').parent().children().attr('disabled', true);
180
+ }
181
+ }
182
+ });
183
+
184
+ if (periodSelect.val() === 'perso') {
185
+ valueDefault = 'perso';
186
+ }
187
+ else if (comparedPeriodSelect.val() !== 'perso' && listValues.indexOf(comparedPeriodSelect.val()) !== -1) {
188
+ valueDefault = comparedPeriodSelect.val();
189
+ }
190
+ comparedPeriodSelect.val(valueDefault);
191
+
192
+ updatePeriodSelect(comparedPeriodSelect);
193
+ }
194
+
195
+ // ---------- Choix période (new) ----------
196
+
197
+ if (form.find('select.periode').length > 0) {
198
+ fillPeriodSelect(form.find('select.periode'));
199
+ form.find('select.periode').change(function() {
200
+ updateForm($(this).closest('form'));
201
+ });
202
+ }
203
+
204
+ if (form.find('select.periodeCompare').length > 0) {
205
+ fillPeriodSelect(form.find('select.periodeCompare'));
206
+ form.find('select.periodeCompare').change(function() {
207
+ updateForm($(this).closest('form'));
208
+ });
209
+ }
210
+
211
+ updateForm(form);
212
+
213
+ // ---------- Choix période (old) ----------
214
+
215
+ if (form.find('select.day').length > 0 && form.find('select.month').length > 0 && form.find('select.year').length > 0) {
216
+ form.find('select.year').after(
217
+ '<br/>'+
218
+ '<p class="select_date_fastly">'+
219
+ ' <a href="#" class="lien_form_today">Auj.</a> - '+
220
+ ' <a href="#" class="lien_form_yesterday">Hier</a> - '+
221
+ ' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
222
+ ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
223
+ ' <a href="#" class="lien_form_current_year">Cette année</a>'+
224
+ ' - '+
225
+ ' <a href="#" class="lien_form_date_prev_day">Jour précédent</a>'+
226
+ ' - '+
227
+ ' <a href="#" class="lien_form_date_next_day">Jour suivant</a>'+
228
+ '</p>'
229
+ );
230
+ }
231
+ else if (form.find('select.month').length > 0 && form.find('select.year').length > 0) {
232
+ form.find('select.year').after(
233
+ '<br/>'+
234
+ '<p class="select_date_fastly">'+
235
+ ' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
236
+ ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
237
+ ' <a href="#" class="lien_form_current_year">Cette année</a>'+
238
+ '</p>'
239
+ );
240
+ }
241
+
242
+ if (form.find('select.dayCompare').length > 0 && form.find('select.monthCompare').length > 0 && form.find('select.yearCompare').length > 0) {
243
+ form.find('select.yearCompare').after(
244
+ '<br/>'+
245
+ '<p class="select_date_fastly">'+
246
+ ' <a href="#" class="lien_form_yesterday">Hier</a> - '+
247
+ ' <a href="#" class="lien_form_day_moins_7">J-7</a> - '+
248
+ ' <a href="#" class="lien_form_day_moins_8">J-8</a> - '+
249
+ ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
250
+ ' <a href="#" class="lien_form_month_moins_2">Mois M-2</a> - '+
251
+ ' <a href="#" class="lien_form_last_year">L’année dernière</a>'+
252
+ '</p>'
253
+ );
254
+ }
255
+
256
+ // Lien de sélection de date
257
+
258
+ if (form.find('a.lien_form_today').length > 0) {
259
+ form.find('a.lien_form_today').click(function() {
260
+ FormDate.setTodaySelected($(this).closest('.form-group'));
261
+ return false;
262
+ });
263
+ }
264
+ if (form.find('a.lien_form_yesterday').length > 0) {
265
+ form.find('a.lien_form_yesterday').click(function() {
266
+ FormDate.addNbDaysToToday($(this).closest('.form-group'), -1);
267
+ return false;
268
+ });
269
+ }
270
+ if (form.find('a.lien_form_day_moins_7').length > 0) {
271
+ form.find('a.lien_form_day_moins_7').click(function() {
272
+ FormDate.addNbDaysToToday($(this).closest('.form-group'), -7);
273
+ return false;
274
+ });
275
+ }
276
+ if (form.find('a.lien_form_day_moins_8').length > 0) {
277
+ form.find('a.lien_form_day_moins_8').click(function() {
278
+ FormDate.addNbDaysToToday($(this).closest('.form-group'), -8);
279
+ return false;
280
+ });
281
+ }
282
+
283
+ if (form.find('a.lien_form_current_month').length > 0) {
284
+ form.find('a.lien_form_current_month').click(function() {
285
+ FormDate.setCurrentMonthSelected($(this).closest('.form-group'));
286
+ return false;
287
+ });
288
+ }
289
+ if (form.find('a.lien_form_last_month').length > 0) {
290
+ form.find('a.lien_form_last_month').click(function() {
291
+ FormDate.addNbMonthsToToday($(this).closest('.form-group'), -1);
292
+ return false;
293
+ });
294
+ }
295
+ if (form.find('a.lien_form_month_moins_2').length > 0) {
296
+ form.find('a.lien_form_month_moins_2').click(function() {
297
+ FormDate.addNbMonthsToToday($(this).closest('.form-group'), -2);
298
+ return false;
299
+ });
300
+ }
301
+
302
+ if (form.find('a.lien_form_current_year').length > 0) {
303
+ form.find('a.lien_form_current_year').click(function() {
304
+ FormDate.setCurrentYearSelected($(this).closest('.form-group'));
305
+ return false;
306
+ });
307
+ }
308
+ if (form.find('a.lien_form_last_year').length > 0) {
309
+ form.find('a.lien_form_last_year').click(function() {
310
+ FormDate.addNbYearsToToday($(this).closest('.form-group'), -1);
311
+ return false;
312
+ });
313
+ }
314
+
315
+ if (form.find('a.lien_form_date_prev_day').length > 0) {
316
+ form.find('a.lien_form_date_prev_day').click(function() {
317
+ FormDate.addNbDaysToSelectedDate($(this).closest('.form-group'), -1);
318
+ return false;
319
+ });
320
+ }
321
+ if (form.find('a.lien_form_date_next_day').length > 0) {
322
+ form.find('a.lien_form_date_next_day').click(function() {
323
+ FormDate.addNbDaysToSelectedDate($(this).closest('.form-group'), 1);
324
+ return false;
325
+ });
326
+ }
327
+
328
+ //if ($('form select[name=select_date_fastly]').length > 0) {
329
+ // $('form select[name=select_date_fastly]').change(function() {
330
+ // valueOptionSelected = $('form select[name=select_date_fastly] option:selected').attr('value');
331
+ // if (valueOptionSelected == 'today') {
332
+ // selectFormDateToday();
333
+ // }
334
+ // else if (valueOptionSelected == 'current_month') {
335
+ // selectFormDateCurrentMonth();
336
+ // }
337
+ // });
338
+ //}
339
+ }
340
+
341
+ static getPeriodList() {
342
+ return {
343
+ other: {label: 'Autre', list: {
344
+ perso: 'Personnalisé',
345
+ }},
346
+ '1d': {label: 'Un jour', list: { // 1 jour
347
+ 'ajd': 'Aujourd’hui',
348
+ 'hier': 'Hier',
349
+ 'jourMoins2': 'Avant-hier',
350
+ 'jourMoins3': 'J-3',
351
+ 'jourMoins7': 'J-7',
352
+ 'jourMoins8': 'J-8',
353
+ 'same_day_last_year': 'Même jour l’année dernière',
354
+ 'same_day_least_2_years': 'Même jour l’année A-2',
355
+ 'same_day_as_yesterday_last_year': 'Même jour qu’hier l’année dernière',
356
+ 'same_day_as_yesterday_least_2_years': 'Même jour qu’hier l’année A-2'
357
+ }},
358
+ '1w': {label: 'Une semaine', list: { // 1 semaine
359
+ 'curr_week': 'Cette semaine',
360
+ 'last_week': 'La semaine dernière',
361
+ 'weekMoins2': 'Semaine S-2',
362
+ 'weekMoins3': 'Semaine S-3',
363
+ 'weekMoins4': 'Semaine S-4',
364
+ }},
365
+ '7d': {label: '7 jours', list: { // 7 jours
366
+ 'last_7_days': 'Les 7 derniers jours',
367
+ 'last_7_days_before': 'Les 7 jours avant',
368
+ 'last_7_days_least_1_year': 'Les mêmes 7 jours l’année dernière',
369
+ 'last_7_days_least_2_years': 'Les mêmes 7 jours l’année A-2',
370
+ }},
371
+ '14d': {label: '14 jours', list: { // 14 jours
372
+ 'last_14_days': 'Les 14 derniers jours',
373
+ 'last_14_days_before': 'Les 14 jours avant',
374
+ 'last_14_days_least_1_year': 'Les mêmes 14 jours l’année dernière',
375
+ 'last_14_days_least_2_years': 'Les mêmes 14 jours l’année A-2',
376
+ }},
377
+ // 30 jours
378
+ '30d': {label: '30 jours', list: {
379
+ 'last_30_days': 'Les 30 derniers jours',
380
+ 'last_30_days_before': 'Les 30 jours avant',
381
+ 'last_30_days_least_1_year': 'Les mêmes 30 jours l’année dernière',
382
+ 'last_30_days_least_2_years': 'Les mêmes 30 jours l’année A-2',
383
+ }},
384
+ '60d': {label: '60 jours', list: { // 60 jours
385
+ 'last_60_days': 'Les 60 derniers jours',
386
+ 'last_60_days_before': 'Les 60 jours avant',
387
+ 'last_60_days_least_1_year': 'Les mêmes 60 jours l’année dernière',
388
+ 'last_60_days_least_2_years': 'Les mêmes 60 jours l’année A-2',
389
+ }},
390
+ '1m': {label: 'Un mois', list: { // 1 mois
391
+ 'curr_month': 'Ce mois-ci',
392
+ 'last_month': 'Le mois dernier',
393
+ 'monthMoins2': 'Mois M-2',
394
+ 'monthMoins3': 'Mois M-3',
395
+ 'monthMoins4': 'Mois M-4',
396
+ 'monthMoins5': 'Mois M-5',
397
+ 'monthMoins6': 'Mois M-6',
398
+ 'same_month_last_year': 'Même mois l’année dernière',
399
+ 'same_month_least_2_years': 'Même mois l’année A-2',
400
+ }},
401
+ '3m': {label: '3 mois', list: { // 3 mois
402
+ 'last_3_month': 'Les 3 derniers mois',
403
+ 'last_3_month_before': 'Les 3 mois avant',
404
+ 'last_3_month_least_1_year': 'Les mêmes 3 mois l’année dernière',
405
+ 'last_3_month_least_2_years': 'Les mêmes 3 mois l’année A-2',
406
+ }},
407
+ '6m': {label: '6 mois', list: { // 6 mois
408
+ 'last_6_month': 'Les 6 derniers mois',
409
+ 'last_6_month_before': 'Les 6 mois avant',
410
+ 'last_6_month_least_1_year': 'Les mêmes 6 mois l’année dernière',
411
+ 'last_6_month_least_2_years': 'Les mêmes 6 mois l’année A-2',
412
+ }},
413
+ '12m': {label: '12 mois', list: { // 12 mois
414
+ 'last_12_month': 'Les 12 derniers mois',
415
+ 'last_12_month_before': 'Les 12 mois avant',
416
+ 'last_12_month_least_1_year': 'Les mêmes 12 mois l’année dernière',
417
+ 'last_12_month_least_2_years': 'Les mêmes 12 mois l’année A-2',
418
+ }},
419
+ '24m': {label: '24 mois', list: { // 24 mois
420
+ 'last_24_month': 'Les 24 derniers mois',
421
+ 'last_24_month_before': 'Les 24 mois avant',
422
+ 'last_24_month_least_1_year': 'Les mêmes 24 mois l’année dernière',
423
+ 'last_24_month_least_2_years': 'Les mêmes 24 mois l’année A-2',
424
+ }},
425
+ '1y': {label: 'Une année', list: { // 1 année
426
+ 'curr_year': 'Cette année',
427
+ 'last_year': 'L’année dernière',
428
+ 'yearMoins2': 'Année A-2',
429
+ 'yearMoins3': 'Année A-3',
430
+ 'yearMoins4': 'Année A-4',
431
+ }},
432
+ };
433
+ }
434
+ static setTodaySelected(periodFormGroup) {
435
+ let date = new Date();
436
+ FormDate.setSelectedDate(periodFormGroup, date.getDate(), (date.getMonth() + 1), date.getFullYear());
437
+ }
438
+ static setCurrentMonthSelected(periodFormGroup) {
439
+ let date = new Date();
440
+ FormDate.setSelectedDate(periodFormGroup, -1, (date.getMonth() + 1), date.getFullYear());
441
+ }
442
+ static setCurrentYearSelected(periodFormGroup) {
443
+ let today = new Date();
444
+ FormDate.setSelectedDate(periodFormGroup, -1, -1, today.getFullYear());
445
+ }
446
+
447
+ static addNbDaysToToday(periodFormGroup, nbDays) {
448
+ FormDate.addNbDaysToSelectedDate(periodFormGroup, nbDays, false);
449
+ }
450
+ static addNbMonthsToToday(periodFormGroup, nbMonths) {
451
+ FormDate.addNbMonthsToSelectedDate(periodFormGroup, nbMonths, false);
452
+ }
453
+ static addNbYearsToToday(periodFormGroup, nbYears) {
454
+ FormDate.addNbYearsToSelectedDate(periodFormGroup, nbYears, false);
455
+ }
456
+
457
+ static addNbDaysToSelectedDate(periodFormGroup, nbDays, fromSelectedDate) {
458
+ let date = typeof fromSelectedDate == 'undefined' || fromSelectedDate ? FormDate.getSelectedDate(periodFormGroup) : new Date();
459
+ date.setDate(date.getDate() + nbDays);
460
+ FormDate.setSelectedDate(periodFormGroup, date.getDate(), (date.getMonth() + 1), date.getFullYear());
461
+ }
462
+ static addNbMonthsToSelectedDate(periodFormGroup, nbMonths, fromSelectedDate) {
463
+ let date = typeof fromSelectedDate == 'undefined' || fromSelectedDate ? FormDate.getSelectedDate(periodFormGroup) : new Date();
464
+ date.setDate(1);
465
+ date.setMonth(date.getMonth() - nbMonths);
466
+ FormDate.setSelectedDate(periodFormGroup, -1, (date.getMonth() + 1), date.getFullYear());
467
+ }
468
+ static addNbYearsToSelectedDate(periodFormGroup, nbYears, fromSelectedDate) {
469
+ let date = typeof fromSelectedDate == 'undefined' || fromSelectedDate ? FormDate.getSelectedDate(periodFormGroup) : new Date();
470
+ FormDate.setSelectedDate(periodFormGroup, -1, -1, date.getFullYear() - nbYears);
471
+ }
472
+
473
+ static getSelectedDate(periodFormGroup) {
474
+ let day = periodFormGroup.find('select.day').val();
475
+ let month = periodFormGroup.find('select.month').val();
476
+ let year = periodFormGroup.find('select.year').val();
477
+ if (null != day && null != month && null != year) {
478
+ return new Date(year, month - 1, day);
479
+ }
480
+ return new Date();
481
+ }
482
+
483
+ static setSelectedDate(periodFormGroup, day, month, year) {
484
+ periodFormGroup.find('select.day').val(day);
485
+ periodFormGroup.find('select.month').val(month);
486
+ periodFormGroup.find('select.year').val(year);
487
+ }
488
+
489
+
490
+
491
+ /*
492
+ // deprecated
493
+
2
494
  static majSelectPeriode(select) {
3
- if (select.find(':selected').attr('value') == 'perso') {
495
+ if (select.find(':selected').attr('value') === 'perso') {
4
496
  select.parent().parent().next().removeClass('hide');
5
497
  }
6
498
  else {
7
499
  select.parent().parent().next().addClass('hide');
8
500
  }
9
501
  }
10
-
502
+
11
503
  static majSelectCompare() {
12
- if ($('form select#periodeCompare').length == 0) {
504
+ if ($('form select#periodeCompare').length === 0) {
13
505
  return;
14
506
  }
15
-
16
- var listValues = [];
17
- periodeSelected = $('form select.periode :selected').attr('value');
18
- selectCompare = $('form select#periodeCompare');
19
- periodeCompareSelected = selectCompare.find(':selected').attr('value');
20
-
507
+
508
+ let listValues = [];
509
+ let periodeSelected = $('form select.periode :selected').attr('value');
510
+ let selectCompare = $('form select#periodeCompare');
511
+ let periodeCompareSelected = selectCompare.find(':selected').attr('value');
512
+ let valueDefault = null;
513
+
21
514
  selectCompare.find('option').removeAttr('disabled');
22
-
515
+
23
516
  $.each(listePeriodeCompare, function (idx, tabListPeriode) {
24
517
  if (idx != 0) {
25
- listKeyPeriode = array_keys(tabListPeriode.list);
518
+ let listKeyPeriode = array_keys(tabListPeriode.list);
26
519
  if (in_array(periodeSelected, listKeyPeriode)) {
27
520
  listValues = listKeyPeriode;
28
521
  valueDefault = listKeyPeriode[1];
@@ -32,234 +525,68 @@
32
525
  }
33
526
  }
34
527
  });
35
-
36
- if (periodeSelected == 'perso') {
528
+
529
+ if (periodeSelected === 'perso') {
37
530
  valueDefault = 'perso';
38
531
  }
39
- else if (periodeCompareSelected != 'perso' && in_array(periodeCompareSelected, listValues)) {
532
+ else if (periodeCompareSelected !== 'perso' && in_array(periodeCompareSelected, listValues)) {
40
533
  valueDefault = periodeCompareSelected;
41
534
  }
42
535
  selectCompare.find('option[value="' + valueDefault + '"]').attr('selected', 'selected');
43
-
44
- majSelectPeriode(selectCompare);
536
+
537
+ FormDate.majSelectPeriode(selectCompare);
45
538
  }
46
-
539
+
47
540
  static selectFormDateToday(lien) {
48
- date = new Date();
49
- selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
541
+ let date = new Date();
542
+ FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
50
543
  }
51
-
52
544
  static selectFormDateDayMoinsNb(lien, nbJoursMoins) {
53
- date = new Date();
545
+ let date = new Date();
54
546
  date.setDate(date.getDate() - nbJoursMoins);
55
- selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
547
+ FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
56
548
  }
57
-
58
549
  static selectFormDateCurrentMonth(lien) {
59
- date = new Date();
60
- selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
550
+ let date = new Date();
551
+ FormDate.selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
61
552
  }
62
-
63
553
  static selectFormDateMonthMoinsNb(lien, nbMoisMoins) {
64
- date = new Date();
554
+ let date = new Date();
65
555
  date.setDate(1);
66
556
  date.setMonth(date.getMonth() - nbMoisMoins);
67
- selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
557
+ FormDate.selectFormDate(lien, -1, (date.getMonth() + 1), date.getFullYear());
68
558
  }
69
-
70
559
  static selectFormDateCurrentYear(lien) {
71
- today = new Date();
72
- selectFormDate(lien, -1, -1, today.getFullYear());
560
+ let today = new Date();
561
+ FormDate.selectFormDate(lien, -1, -1, today.getFullYear());
73
562
  }
74
-
75
563
  static selectFormDateYearMoinsNb(lien, nbAnneesMoins) {
76
- today = new Date();
77
- selectFormDate(lien, -1, -1, today.getFullYear() - nbAnneesMoins);
564
+ let today = new Date();
565
+ FormDate.selectFormDate(lien, -1, -1, today.getFullYear() - nbAnneesMoins);
78
566
  }
79
-
80
567
  static selectFormDateAddDayFromSelectedDay(lien, nbDaysAdded) {
81
- date = getDateObjectSelected(lien);
568
+ let date = FormDate.getDateObjectSelected(lien);
82
569
  date.setDate(date.getDate() + nbDaysAdded);
83
- selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
570
+ FormDate.selectFormDate(lien, date.getDate(), (date.getMonth() + 1), date.getFullYear());
84
571
  }
85
-
86
572
  static getDateObjectSelected(lien) {
87
- selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option:selected';
88
- selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option:selected';
89
- selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option:selected';
573
+ let selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option:selected';
574
+ let selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option:selected';
575
+ let selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option:selected';
90
576
  if ($(selectorDay).length > 0 && $(selectorMonth).length > 0 && $(selectorYear).length > 0) {
91
577
  return new Date($(selectorYear).attr('value'), $(selectorMonth).attr('value') - 1, $(selectorDay).attr('value'));
92
578
  }
93
579
  return new Date();
94
580
  }
95
-
96
581
  static selectFormDate(lien, day, month, year) {
97
- selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option[value=' + day + ']';
98
- selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option[value=' + month + ']';
99
- selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option[value=' + year + ']';
582
+ let selectorDay = '#' + (lien.parent().prev().prev().prev().prev().attr('id')) + ' option[value=' + day + ']';
583
+ let selectorMonth = '#' + (lien.parent().prev().prev().prev().attr('id')) + ' option[value=' + month + ']';
584
+ let selectorYear = '#' + (lien.parent().prev().prev().attr('id')) + ' option[value=' + year + ']';
100
585
  if ($(selectorDay).length > 0) $(selectorDay).prop('selected', 'selected');
101
586
  if ($(selectorMonth).length > 0) $(selectorMonth).prop('selected', 'selected');
102
587
  if ($(selectorYear).length > 0) $(selectorYear).prop('selected', 'selected');
103
588
  }
589
+ */
104
590
  }
105
591
 
106
- module.exports = { FormDate };
107
-
108
-
109
- //A DEPLACER DANS LE PROJET MYTIME
110
- /*$(function() {
111
- // ---------- Choix période (new) ----------
112
-
113
- // Formulaire de sélection de période
114
-
115
- if ($('form select.periode').length > 0) {
116
- $('form select.periode').change(function() {
117
- majSelectPeriode($(this));
118
-
119
- if ($(this).attr('id') == 'periode') {
120
- majSelectCompare();
121
- }
122
- });
123
- }
124
-
125
- majSelectCompare();
126
- // majSelectPeriode($('form select#periodeCompare'));
127
-
128
-
129
- // ---------- Choix période (old) ----------
130
-
131
- if ($('form #day').length > 0 && $('form #month').length > 0 && $('form #year').length > 0) {
132
- $('form #year').after(
133
- '<br/>'+
134
- '<p class="select_date_fastly">'+
135
- ' <a href="#" class="lien_form_today">Auj.</a> - '+
136
- ' <a href="#" class="lien_form_yesterday">Hier</a> - '+
137
- ' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
138
- ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
139
- ' <a href="#" class="lien_form_current_year">Cette année</a>'+
140
- ' - '+
141
- ' <a href="#" class="lien_form_date_prev_day">Jour précédent</a>'+
142
- ' - '+
143
- ' <a href="#" class="lien_form_date_next_day">Jour suivant</a>'+
144
- '</p>'+
145
- ''
146
- );
147
- }
148
- else if ($('form #month').length > 0 && $('form #year').length > 0) {
149
- $('form #year').after(
150
- '<br/>'+
151
- '<p class="select_date_fastly">'+
152
- ' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
153
- ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
154
- ' <a href="#" class="lien_form_current_year">Cette année</a>'+
155
- '</p>'+
156
- ''
157
- );
158
- }
159
-
160
- if ($('form #dayCompare').length > 0 && $('form #monthCompare').length > 0 && $('form #yearCompare').length > 0) {
161
- $('form #yearCompare').after(
162
- '<br/>'+
163
- '<p class="select_date_fastly">'+
164
- ' <a href="#" class="lien_form_yesterday">Hier</a> - '+
165
- ' <a href="#" class="lien_form_day_moins_7">J-7</a> - '+
166
- ' <a href="#" class="lien_form_day_moins_8">J-8</a> - '+
167
- ' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
168
- ' <a href="#" class="lien_form_month_moins_2">Mois M-2</a> - '+
169
- ' <a href="#" class="lien_form_last_year">L\'année dernière</a>'+
170
- '</p>'+
171
- ''
172
- );
173
- }
174
-
175
- // Lien de sélection de date
176
-
177
- if ($('form a.lien_form_today').length > 0) {
178
- $('form a.lien_form_today').click(function() {
179
- selectFormDateToday($(this));
180
- return false;
181
- });
182
- }
183
-
184
- if ($('form a.lien_form_yesterday').length > 0) {
185
- $('form a.lien_form_yesterday').click(function() {
186
- selectFormDateDayMoinsNb($(this), 1);
187
- return false;
188
- });
189
- }
190
-
191
- if ($('form a.lien_form_day_moins_7').length > 0) {
192
- $('form a.lien_form_day_moins_7').click(function() {
193
- selectFormDateDayMoinsNb($(this), 7);
194
- return false;
195
- });
196
- }
197
-
198
- if ($('form a.lien_form_day_moins_8').length > 0) {
199
- $('form a.lien_form_day_moins_8').click(function() {
200
- selectFormDateDayMoinsNb($(this), 8);
201
- return false;
202
- });
203
- }
204
-
205
- if ($('form a.lien_form_current_month').length > 0) {
206
- $('form a.lien_form_current_month').click(function() {
207
- selectFormDateCurrentMonth($(this));
208
- return false;
209
- });
210
- }
211
-
212
- if ($('form a.lien_form_last_month').length > 0) {
213
- $('form a.lien_form_last_month').click(function() {
214
- selectFormDateMonthMoinsNb($(this), 1);
215
- return false;
216
- });
217
- }
218
-
219
- if ($('form a.lien_form_month_moins_2').length > 0) {
220
- $('form a.lien_form_month_moins_2').click(function() {
221
- selectFormDateMonthMoinsNb($(this), 2);
222
- return false;
223
- });
224
- }
225
-
226
- if ($('form a.lien_form_current_year').length > 0) {
227
- $('form a.lien_form_current_year').click(function() {
228
- selectFormDateCurrentYear($(this));
229
- return false;
230
- });
231
- }
232
-
233
- if ($('form a.lien_form_last_year').length > 0) {
234
- $('form a.lien_form_last_year').click(function() {
235
- selectFormDateYearMoinsNb($(this), 1);
236
- return false;
237
- });
238
- }
239
-
240
- if ($('form a.lien_form_date_prev_day').length > 0) {
241
- $('form a.lien_form_date_prev_day').click(function() {
242
- selectFormDateAddDayFromSelectedDay($(this), -1);
243
- return false;
244
- });
245
- }
246
- if ($('form a.lien_form_date_next_day').length > 0) {
247
- $('form a.lien_form_date_next_day').click(function() {
248
- selectFormDateAddDayFromSelectedDay($(this), 1);
249
- return false;
250
- });
251
- }
252
-
253
- //if ($('form select[name=select_date_fastly]').length > 0) {
254
- // $('form select[name=select_date_fastly]').change(function() {
255
- // valueOptionSelected = $('form select[name=select_date_fastly] option:selected').attr('value');
256
- // if (valueOptionSelected == 'today') {
257
- // selectFormDateToday();
258
- // }
259
- // else if (valueOptionSelected == 'current_month') {
260
- // selectFormDateCurrentMonth();
261
- // }
262
- // });
263
- //}
264
-
265
- });*/
592
+ module.exports = { FormDate, InputPeriod };