@osimatic/helpers-js 1.1.48 → 1.1.50
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/date_time.js +2 -1
- package/form_date.js +39 -41
- package/http_client.js +2 -2
- package/package.json +1 -1
package/date_time.js
CHANGED
|
@@ -180,7 +180,8 @@ class DateTime {
|
|
|
180
180
|
|
|
181
181
|
static getFirstDayOfWeek(date) {
|
|
182
182
|
let firstDayOfWeek = new Date(date);
|
|
183
|
-
|
|
183
|
+
const day = date.getDay();
|
|
184
|
+
firstDayOfWeek.setDate(date.getDate() - day + (0 === day ? -6:1)); // First day is the day of the month - the day of the week
|
|
184
185
|
return firstDayOfWeek;
|
|
185
186
|
}
|
|
186
187
|
|
package/form_date.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// input period de type : Du <input type="date" name="start_date" /> au <input type="date" name="end_date" />
|
|
2
2
|
class InputPeriod {
|
|
3
3
|
|
|
4
|
-
static addLinks(form) {
|
|
4
|
+
static addLinks(form, timeZone="Europe/Paris") {
|
|
5
5
|
let divParent = form.find('input[type="date"][data-add_period_select_links]').parent();
|
|
6
6
|
if (divParent.hasClass('input-group')) {
|
|
7
7
|
divParent = divParent.parent();
|
|
@@ -16,109 +16,107 @@ class InputPeriod {
|
|
|
16
16
|
+'<a href="#" class="period_select_current_year">Cette année</a>'
|
|
17
17
|
+'</div>'
|
|
18
18
|
);
|
|
19
|
-
this.init(form);
|
|
19
|
+
this.init(form, timeZone);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
static init(form) {
|
|
22
|
+
static init(form, timeZone="Europe/Paris") {
|
|
23
23
|
let link;
|
|
24
24
|
//console.log(form.find('a.period_select_current_week'));
|
|
25
25
|
|
|
26
26
|
if ((link = form.find('a.period_select_today')).length) {
|
|
27
|
-
link.click(function() { InputPeriod.selectToday($(this)); return false; });
|
|
27
|
+
link.click(function() { InputPeriod.selectToday($(this), timeZone); return false; });
|
|
28
28
|
}
|
|
29
29
|
if ((link = form.find('a.period_select_yesterday')).length) {
|
|
30
|
-
link.click(function() { InputPeriod.selectPreviousDay($(this), 1); return false; });
|
|
30
|
+
link.click(function() { InputPeriod.selectPreviousDay($(this), 1, timeZone); return false; });
|
|
31
31
|
}
|
|
32
32
|
if ((link = form.find('a.period_select_tomorrow')).length) {
|
|
33
|
-
link.click(function() { InputPeriod.selectFollowingDay($(this), 1); return false; });
|
|
33
|
+
link.click(function() { InputPeriod.selectFollowingDay($(this), 1, timeZone); return false; });
|
|
34
34
|
}
|
|
35
35
|
if ((link = form.find('a.period_select_current_week')).length) {
|
|
36
|
-
link.click(function() { InputPeriod.selectCurrentWeek($(this)); return false; });
|
|
36
|
+
link.click(function() { InputPeriod.selectCurrentWeek($(this), timeZone); return false; });
|
|
37
37
|
}
|
|
38
38
|
if ((link = form.find('a.period_select_last_week')).length) {
|
|
39
|
-
link.click(function() { InputPeriod.selectPreviousWeek($(this), 1); return false; });
|
|
39
|
+
link.click(function() { InputPeriod.selectPreviousWeek($(this), 1, timeZone); return false; });
|
|
40
40
|
}
|
|
41
41
|
if ((link = form.find('a.period_select_current_month')).length) {
|
|
42
|
-
link.click(function() { InputPeriod.selectCurrentMonth($(this)); return false; });
|
|
42
|
+
link.click(function() { InputPeriod.selectCurrentMonth($(this), timeZone); return false; });
|
|
43
43
|
}
|
|
44
44
|
if ((link = form.find('a.period_select_last_month')).length) {
|
|
45
|
-
link.click(function() { InputPeriod.selectPreviousMonth($(this), 1); return false; });
|
|
45
|
+
link.click(function() { InputPeriod.selectPreviousMonth($(this), 1, timeZone); return false; });
|
|
46
46
|
}
|
|
47
47
|
if ((link = form.find('a.period_select_current_year')).length) {
|
|
48
|
-
link.click(function() { InputPeriod.selectCurrentYear($(this)); return false; });
|
|
48
|
+
link.click(function() { InputPeriod.selectCurrentYear($(this), timeZone); return false; });
|
|
49
49
|
}
|
|
50
50
|
if ((link = form.find('a.period_select_last_year')).length) {
|
|
51
|
-
link.click(function() { InputPeriod.selectCurrentYear($(this), 1); return false; });
|
|
51
|
+
link.click(function() { InputPeriod.selectCurrentYear($(this), 1, timeZone); return false; });
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
static selectToday(link) {
|
|
56
|
+
static selectToday(link, timeZone="Europe/Paris") {
|
|
57
57
|
let date = new Date();
|
|
58
|
-
this.selectPeriod(link, date, date);
|
|
58
|
+
this.selectPeriod(link, date, date, timeZone);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
static selectPreviousDay(lien, nbDays) {
|
|
62
|
-
this.selectFollowingDay(lien, -nbDays);
|
|
61
|
+
static selectPreviousDay(lien, nbDays, timeZone="Europe/Paris") {
|
|
62
|
+
this.selectFollowingDay(lien, -nbDays, timeZone);
|
|
63
63
|
}
|
|
64
|
-
static selectFollowingDay(lien, nbDays) {
|
|
64
|
+
static selectFollowingDay(lien, nbDays, timeZone="Europe/Paris") {
|
|
65
65
|
let date = new Date();
|
|
66
66
|
date.setDate(date.getDate() + nbDays);
|
|
67
|
-
this.selectPeriod(lien, date, date);
|
|
67
|
+
this.selectPeriod(lien, date, date, timeZone);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
static selectCurrentWeek(lien) {
|
|
70
|
+
static selectCurrentWeek(lien, timeZone="Europe/Paris") {
|
|
71
71
|
let date = new Date();
|
|
72
72
|
this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
|
|
73
73
|
}
|
|
74
|
-
static selectPreviousWeek(lien, nbWeeks) {
|
|
75
|
-
this.selectFollowingWeek(lien, -nbWeeks);
|
|
74
|
+
static selectPreviousWeek(lien, nbWeeks, timeZone="Europe/Paris") {
|
|
75
|
+
this.selectFollowingWeek(lien, -nbWeeks, timeZone);
|
|
76
76
|
}
|
|
77
|
-
static selectFollowingWeek(lien, nbWeeks) {
|
|
77
|
+
static selectFollowingWeek(lien, nbWeeks, timeZone="Europe/Paris") {
|
|
78
78
|
let date = new Date();
|
|
79
79
|
date.setDate(date.getDate() + (7*nbWeeks));
|
|
80
|
-
this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
|
|
80
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date), timeZone);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
static selectCurrentMonth(lien) {
|
|
83
|
+
static selectCurrentMonth(lien, timeZone="Europe/Paris") {
|
|
84
84
|
let date = new Date();
|
|
85
|
-
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
|
|
85
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date), timeZone);
|
|
86
86
|
}
|
|
87
|
-
static selectPreviousMonth(lien, nbMonths) {
|
|
88
|
-
this.selectFollowingMonth(lien, -nbMonths);
|
|
87
|
+
static selectPreviousMonth(lien, nbMonths, timeZone="Europe/Paris") {
|
|
88
|
+
this.selectFollowingMonth(lien, -nbMonths, timeZone);
|
|
89
89
|
}
|
|
90
|
-
static selectFollowingMonth(lien, nbMonths) {
|
|
90
|
+
static selectFollowingMonth(lien, nbMonths, timeZone="Europe/Paris") {
|
|
91
91
|
let date = new Date();
|
|
92
92
|
date.setDate(1);
|
|
93
93
|
date.setMonth(date.getMonth() + nbMonths);
|
|
94
|
-
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
|
|
94
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date), timeZone);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
static selectCurrentYear(lien) {
|
|
98
|
-
this.selectFollowingYear(lien, 0);
|
|
97
|
+
static selectCurrentYear(lien, timeZone="Europe/Paris") {
|
|
98
|
+
this.selectFollowingYear(lien, 0, timeZone);
|
|
99
99
|
}
|
|
100
|
-
static selectPreviousYear(lien, nbAnneesMoins) {
|
|
101
|
-
this.selectFollowingYear(lien, -nbAnneesMoins);
|
|
100
|
+
static selectPreviousYear(lien, nbAnneesMoins, timeZone="Europe/Paris") {
|
|
101
|
+
this.selectFollowingYear(lien, -nbAnneesMoins, timeZone);
|
|
102
102
|
}
|
|
103
|
-
static selectFollowingYear(lien, nbAnneesMoins) {
|
|
103
|
+
static selectFollowingYear(lien, nbAnneesMoins, timeZone="Europe/Paris") {
|
|
104
104
|
let date = new Date();
|
|
105
105
|
date.setFullYear(date.getFullYear() + nbAnneesMoins);
|
|
106
|
-
this.selectPeriod(lien, DateTime.getFirstDayOfYear(date), DateTime.getLastDayOfYear(date));
|
|
106
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfYear(date), DateTime.getLastDayOfYear(date), timeZone);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
static selectPeriod(link, startDate, endDate) {
|
|
110
|
+
static selectPeriod(link, startDate, endDate, timeZone="Europe/Paris") {
|
|
111
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
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
|
|
113
|
+
if (inputPeriodStart.length === 0 || inputPeriodEnd.length === 0) {
|
|
114
114
|
console.log('no period input found');
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
inputPeriodStart.val(DateTime.getSqlDate(startDate));
|
|
121
|
-
inputPeriodEnd.val(DateTime.getSqlDate(endDate));
|
|
118
|
+
inputPeriodStart.val(DateTime.getDateForInputDate(startDate, timeZone));
|
|
119
|
+
inputPeriodEnd.val(DateTime.getDateForInputDate(endDate, timeZone));
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
}
|
package/http_client.js
CHANGED
|
@@ -204,7 +204,7 @@ class HTTPClient {
|
|
|
204
204
|
|
|
205
205
|
let headers = HTTPClient.getHeaders(false, additionalHeaders);
|
|
206
206
|
|
|
207
|
-
if ('PATCH' === method) {
|
|
207
|
+
if ('PATCH' === method || 'DELETE' === method) {
|
|
208
208
|
headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
209
209
|
// 30/01/2023 : ajout encodeURIComponent() sinon les valeurs contenant des "+" pose pb (signe "+" retiré)
|
|
210
210
|
body = encodeURIComponent(new URLSearchParams(HTTPClient.formatFormData(data)).toString());
|
|
@@ -292,7 +292,7 @@ class HTTPClient {
|
|
|
292
292
|
method = method.toUpperCase();
|
|
293
293
|
|
|
294
294
|
let headers = HTTPClient.getHeaders(false, additionalHeaders);
|
|
295
|
-
if ('PATCH' === method) {
|
|
295
|
+
if ('PATCH' === method || 'DELETE' === method) {
|
|
296
296
|
headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
|
297
297
|
body = encodeURIComponent(new URLSearchParams(HTTPClient.formatFormData(data)).toString());
|
|
298
298
|
}
|