@osimatic/helpers-js 1.0.2
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/array.js +84 -0
- package/bank.js +7 -0
- package/button_loader.js +50 -0
- package/contact_details.js +172 -0
- package/count_down.js +103 -0
- package/data_table.js +419 -0
- package/date_time.js +551 -0
- package/details_sub_array.js +126 -0
- package/duration.js +177 -0
- package/file.js +128 -0
- package/flash_message.js +38 -0
- package/form_date.js +262 -0
- package/form_helper.js +237 -0
- package/google_charts.js +344 -0
- package/google_charts_mytime.js +295 -0
- package/google_maps.js +169 -0
- package/google_recaptcha.js +15 -0
- package/graphiques.js +281 -0
- package/import_from_csv.js +274 -0
- package/index.js +69 -0
- package/jquery.js +5 -0
- package/jwt.js +97 -0
- package/list_box.js +113 -0
- package/location.js +391 -0
- package/media.js +82 -0
- package/multiple_action_in_table.js +229 -0
- package/network.js +554 -0
- package/number.js +90 -0
- package/package.json +12 -0
- package/paging.js +237 -0
- package/php.min.js +4 -0
- package/select_all.js +132 -0
- package/social_network.js +110 -0
- package/string.js +118 -0
- package/tree.js +71 -0
- package/util.js +23 -0
package/date_time.js
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
|
|
2
|
+
class DateTime {
|
|
3
|
+
|
|
4
|
+
static getSqlDate(jsDate, timeZone="Europe/Paris") {
|
|
5
|
+
let pad = function(num) { return ('00'+num).slice(-2) };
|
|
6
|
+
// return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
|
|
7
|
+
//return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
|
|
8
|
+
return jsDate.toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {month: '2-digit', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {day: '2-digit', timeZone: timeZone});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static getSqlTime(jsDate, timeZone="Europe/Paris") {
|
|
12
|
+
let pad = function(num) { return ('00'+num).slice(-2) };
|
|
13
|
+
// return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
|
|
14
|
+
//return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
|
|
15
|
+
return pad(jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone}));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getSqlDateTime(jsDate) {
|
|
19
|
+
return this.getSqlDate(jsDate)+' '+this.getSqlTime(jsDate);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getTimestamp(jsDate) {
|
|
23
|
+
return jsDate.getTime();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
27
|
+
return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone});
|
|
28
|
+
}
|
|
29
|
+
static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
30
|
+
return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
34
|
+
return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
35
|
+
}
|
|
36
|
+
static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
37
|
+
return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone});
|
|
38
|
+
}
|
|
39
|
+
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
40
|
+
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
41
|
+
if (jsPreviousDate != 0 && jsPreviousDate != null) {
|
|
42
|
+
let nbDaysDiff = this.getNbDayBetweenTwo(jsPreviousDate, jsDate, false);
|
|
43
|
+
if (nbDaysDiff > 0) {
|
|
44
|
+
str += ' (J+'+nbDaysDiff+')';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return str;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
51
|
+
return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static getYear(jsDate) {
|
|
55
|
+
return jsDate.getUTCFullYear();
|
|
56
|
+
}
|
|
57
|
+
static getMonth(jsDate) {
|
|
58
|
+
return jsDate.getUTCMonth()+1;
|
|
59
|
+
}
|
|
60
|
+
static getMonthName(jsDate, locale="fr-FR", isShort=false) {
|
|
61
|
+
return jsDate.toLocaleDateString(locale, {month: (isShort?'short':'long')});
|
|
62
|
+
}
|
|
63
|
+
static getDay(jsDate) {
|
|
64
|
+
return jsDate.getUTCDate();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static getDayOfMonth(jsDate) {
|
|
68
|
+
return jsDate.getUTCDate();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static getDayOfWeek(jsDate) {
|
|
72
|
+
return jsDate.getUTCDay();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static getDayName(jsDate, locale="fr-FR", isShort=false) {
|
|
76
|
+
return jsDate.toLocaleDateString(locale, {weekday: (isShort?'short':'long')});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static getNbDaysInMonth(year, month) {
|
|
80
|
+
return new Date(year, month, 0).getDate();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static getMonthNameByMonth(month, locale="fr-FR", isShort=false) {
|
|
84
|
+
let d = new Date();
|
|
85
|
+
d.setDate(1);
|
|
86
|
+
d.setMonth(month-1);
|
|
87
|
+
return this.getMonthName(d, locale, isShort);
|
|
88
|
+
}
|
|
89
|
+
static getDayNameByDayOfWeek(dayOfWeek, locale="fr-FR", isShort=false) {
|
|
90
|
+
let d = new Date();
|
|
91
|
+
// d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
|
|
92
|
+
d.setDate(d.getDate() + (dayOfWeek - d.getDay()) % 7);
|
|
93
|
+
return this.getDayName(d, locale, isShort);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
static getFirstDayOfWeek(date) {
|
|
98
|
+
let firstDayOfWeek = new Date(date);
|
|
99
|
+
firstDayOfWeek.setDate(date.getDate() - date.getDay() + 1); // First day is the day of the month - the day of the week
|
|
100
|
+
return firstDayOfWeek;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static getLastDayOfWeek(date) {
|
|
104
|
+
let lastDayOfWeek = this.getFirstDayOfWeek(date);
|
|
105
|
+
lastDayOfWeek.setDate(lastDayOfWeek.getDate() + 6); // last day is the first day + 6
|
|
106
|
+
return lastDayOfWeek;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static getFirstDayOfMonth(date) {
|
|
110
|
+
return this.getFirstDayOfMonthAndYear(date.getFullYear(), date.getMonth()+1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static getLastDayOfMonth(date) {
|
|
114
|
+
return this.getLastDayOfMonthAndYear(date.getFullYear(), date.getMonth()+1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static getFirstDayOfYear(date) {
|
|
118
|
+
date.setDate(1);
|
|
119
|
+
date.setMonth(0);
|
|
120
|
+
return new Date(date);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static getLastDayOfYear(date) {
|
|
124
|
+
date.setDate(31);
|
|
125
|
+
date.setMonth(11);
|
|
126
|
+
return new Date(date);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static getFirstDayOfWeekAndYear(year, week) {
|
|
130
|
+
let simple = new Date(year, 0, 1 + (week - 1) * 7);
|
|
131
|
+
let dow = simple.getDay();
|
|
132
|
+
let ISOweekStart = simple;
|
|
133
|
+
if (dow <= 4) {
|
|
134
|
+
ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
|
138
|
+
}
|
|
139
|
+
return ISOweekStart;
|
|
140
|
+
}
|
|
141
|
+
static getLastDayOfWeekAndYear(year, week) {
|
|
142
|
+
let firstDayOfWeek = this.getFirstDayOfWeekAndYear(year, week);
|
|
143
|
+
firstDayOfWeek.setDate(firstDayOfWeek.getDate()+6);
|
|
144
|
+
return firstDayOfWeek;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static getFirstDayOfMonthAndYear(year, month) {
|
|
148
|
+
return new Date(year, month-1, 1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static getLastDayOfMonthAndYear(year, month) {
|
|
152
|
+
return new Date(year, month, 0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static isDateEqual(jsDate1, jsDate2) {
|
|
156
|
+
return (jsDate1.getFullYear() == jsDate2.getFullYear() && jsDate1.getMonth() == jsDate2.getMonth() && jsDate1.getDate() == jsDate2.getDate());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static isDateInTheFuture(jsDate) {
|
|
160
|
+
jsDate.setHours(0);
|
|
161
|
+
jsDate.setMinutes(0);
|
|
162
|
+
jsDate.setSeconds(0);
|
|
163
|
+
let today = new Date();
|
|
164
|
+
today.setHours(0);
|
|
165
|
+
today.setMinutes(0);
|
|
166
|
+
today.setSeconds(0);
|
|
167
|
+
return jsDate.getTime() > today.getTime();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static isDateTimeInTheFuture(jsDateTime) {
|
|
171
|
+
let today = new Date();
|
|
172
|
+
return jsDateTime > today;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod, timeZone="Europe/Paris") {
|
|
176
|
+
//jsDate1.set
|
|
177
|
+
if (jsDate1 == null || jsDate2 == null) {
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let timestamp1 = jsDate1.getTime() / 1000;
|
|
182
|
+
let timestamp2 = jsDate2.getTime() / 1000;
|
|
183
|
+
|
|
184
|
+
if (!asPeriod) {
|
|
185
|
+
let jsMidnightDate1 = new Date(jsDate1.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
186
|
+
let jsMidnightDate2 = new Date(jsDate2.toLocaleDateString('en-US', {timeZone: timeZone})+' 00:00:00');
|
|
187
|
+
timestamp1 = jsMidnightDate1.getTime() / 1000;
|
|
188
|
+
timestamp2 = jsMidnightDate2.getTime() / 1000;
|
|
189
|
+
//jsDate1.setHours(0, 0, 0);
|
|
190
|
+
//jsDate2.setHours(0, 0, 0);
|
|
191
|
+
//jsDate1.setUTCHours(0, 0, 0);
|
|
192
|
+
//jsDate2.setUTCHours(0, 0, 0);
|
|
193
|
+
}
|
|
194
|
+
return parseInt(Math.round((timestamp2-timestamp1)/86400));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
class TimestampUnix {
|
|
199
|
+
static parse(timestamp) {
|
|
200
|
+
if (timestamp == null) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return new Date(parseInt(timestamp+'000'));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static getCurrent() {
|
|
207
|
+
let today = new Date();
|
|
208
|
+
return parseInt(today.getTime() / 1000);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static getDateDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
212
|
+
return DateTime.getDateDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
213
|
+
}
|
|
214
|
+
static getDateTextDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
215
|
+
return DateTime.getDateTextDisplay(this.parse(timestamp), locale, timeZone);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static getTimeDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
219
|
+
return DateTime.getTimeDisplay(this.parse(timestamp), locale, timeZone);
|
|
220
|
+
}
|
|
221
|
+
static getTimeDisplayWithNbDays(timestamp, previousTimestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
222
|
+
return DateTime.getTimeDisplayWithNbDays(this.parse(timestamp), this.parse(previousTimestamp), locale, timeZone);
|
|
223
|
+
}
|
|
224
|
+
static getTimeDigitalDisplay(timestamp, locale="fr-FR", timeZone="Europe/Paris") {
|
|
225
|
+
return DateTime.getTimeDigitalDisplay(this.parse(timestamp), locale, timeZone);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static getYear(timestamp, timeZone="Europe/Paris") {
|
|
229
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone});
|
|
230
|
+
}
|
|
231
|
+
static getMonth(timestamp, timeZone="Europe/Paris") {
|
|
232
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {month: 'numeric', timeZone: timeZone});
|
|
233
|
+
}
|
|
234
|
+
static getDayOfMonth(timestamp, timeZone="Europe/Paris") {
|
|
235
|
+
return this.parse(timestamp).toLocaleDateString('fr-FR', {day: 'numeric', timeZone: timeZone});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static getHour(timestamp, timeZone="Europe/Paris") {
|
|
239
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone});
|
|
240
|
+
}
|
|
241
|
+
static getMinute(timestamp, timeZone="Europe/Paris") {
|
|
242
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone});
|
|
243
|
+
}
|
|
244
|
+
static getSecond(timestamp, timeZone="Europe/Paris") {
|
|
245
|
+
return this.parse(timestamp).toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static getSqlDateTime(timestamp, timeZone="Europe/Paris") {
|
|
249
|
+
return this.getSqlDate(timestamp, timeZone)+' '+this.getSqlTime(timestamp, timeZone);
|
|
250
|
+
}
|
|
251
|
+
static getSqlDate(timestamp, timeZone="Europe/Paris") {
|
|
252
|
+
return DateTime.getSqlDate(this.parse(timestamp), timeZone);
|
|
253
|
+
}
|
|
254
|
+
static getSqlTime(timestamp, timeZone="Europe/Paris") {
|
|
255
|
+
return DateTime.getSqlTime(this.parse(timestamp), timeZone);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static isDateEqual(timestamp1, timestamp2) {
|
|
259
|
+
return DateTime.isDateEqual(this.parse(timestamp1), this.parse(timestamp2));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static getNbDayBetweenTwo(timestamp1, timestamp2, asPeriod, timeZone="Europe/Paris") {
|
|
263
|
+
return DateTime.getNbDayBetweenTwo(this.parse(timestamp1), this.parse(timestamp2), asPeriod, timeZone);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
static isDateInTheFuture(timestamp) {
|
|
267
|
+
return DateTime.isDateInTheFuture(this.parse(timestamp));
|
|
268
|
+
}
|
|
269
|
+
static isDateTimeInTheFuture(timestamp) {
|
|
270
|
+
return DateTime.isDateTimeInTheFuture(this.parse(timestamp));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
class SqlDate {
|
|
276
|
+
static parse(sqlDate) {
|
|
277
|
+
if (sqlDate == null) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return new Date(sqlDate.substring(0, 4), sqlDate.substring(5, 7)-1, sqlDate.substring(8, 10), 0, 0, 0);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static getCurrentSqlDate() {
|
|
284
|
+
return DateTime.getSqlDate(new Date());
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
static getDateDigitalDisplay(sqlDate, locale="fr-FR") {
|
|
288
|
+
return SqlDateTime.getDateDigitalDisplay(sqlDate+" 00:00:00", locale);
|
|
289
|
+
}
|
|
290
|
+
static getDateTextDisplay(sqlDate, locale="fr-FR") {
|
|
291
|
+
return SqlDateTime.getDateTextDisplay(sqlDate+" 00:00:00", locale);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
static getYear(sqlDate) {
|
|
295
|
+
return SqlDateTime.getYear(sqlDate+" 00:00:00");
|
|
296
|
+
}
|
|
297
|
+
static getMonth(sqlDate) {
|
|
298
|
+
return SqlDateTime.getMonth(sqlDate+" 00:00:00");
|
|
299
|
+
}
|
|
300
|
+
static getMonthName(sqlDate, locale="fr-FR", isShort=false) {
|
|
301
|
+
return SqlDateTime.getMonthName(sqlDate+" 00:00:00", locale, isShort);
|
|
302
|
+
}
|
|
303
|
+
static getDay(sqlDate) {
|
|
304
|
+
return SqlDateTime.getDay(sqlDate+" 00:00:00");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
static isDateInTheFuture(sqlDate) {
|
|
308
|
+
return DateTime.isDateInTheFuture(SqlDateTime.parse(sqlDate + " 00:00:00"));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
class SqlTime {
|
|
314
|
+
static parse(sqlTime) {
|
|
315
|
+
if (sqlTime == null) {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if ((sqlTime.match(/\:/g) || []).length == 1) {
|
|
320
|
+
sqlTime += ':00';
|
|
321
|
+
}
|
|
322
|
+
let jsDate = new Date();
|
|
323
|
+
let arrayTime = sqlTime.split(':');
|
|
324
|
+
jsDate.setHours(arrayTime[0], arrayTime[1], arrayTime[2], 0);
|
|
325
|
+
return jsDate;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static getCurrentSqlTime() {
|
|
329
|
+
return DateTime.getSqlTime(new Date());
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
static getTimeDisplay(sqlTime, locale="fr-FR") {
|
|
333
|
+
return SqlDateTime.getTimeDisplay('1970-01-01 '+sqlTime, locale);
|
|
334
|
+
}
|
|
335
|
+
static getTimeDigitalDisplay(sqlTime, locale="fr-FR") {
|
|
336
|
+
return SqlDateTime.getTimeDigitalDisplay('1970-01-01 '+sqlTime, locale);
|
|
337
|
+
}
|
|
338
|
+
static getTimeDisplayWithNbDays(sqlTime, previousSqlTime) {
|
|
339
|
+
return SqlDateTime.getTimeDisplayWithNbDays('1970-01-01 '+sqlTime, '1970-01-01 '+previousSqlTime, locale);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
class SqlDateTime {
|
|
344
|
+
static getCurrentSqlDateTime() {
|
|
345
|
+
return DateTime.getSqlDateTime(new Date());
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
static getSqlDate(sqlDateTime) {
|
|
349
|
+
if (sqlDateTime == null) {
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
return DateTime.getSqlDate(this.parse(sqlDateTime));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
static getSqlTime(sqlDateTime) {
|
|
356
|
+
if (sqlDateTime == null) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
return DateTime.getSqlTime(this.parse(sqlDateTime));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
static parse(sqlDateTime) {
|
|
363
|
+
if (sqlDateTime == null) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
return new Date(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
static getDateDigitalDisplay(sqlDateTime, locale="fr-FR") {
|
|
370
|
+
return DateTime.getDateDigitalDisplay(this.parse(sqlDateTime), locale);
|
|
371
|
+
}
|
|
372
|
+
static getDateTextDisplay(sqlDateTime, locale="fr-FR") {
|
|
373
|
+
return DateTime.getDateTextDisplay(this.parse(sqlDateTime), locale);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
static getTimeDisplay(sqlDateTime, locale="fr-FR") {
|
|
377
|
+
return DateTime.getTimeDisplay(this.parse(sqlDateTime), locale);
|
|
378
|
+
}
|
|
379
|
+
static getTimeDisplayWithNbDays(sqlDateTime, previousSqlDateTime) {
|
|
380
|
+
return DateTime.getTimeDisplayWithNbDays(this.parse(sqlDateTime), this.parse(previousSqlDateTime), locale);
|
|
381
|
+
}
|
|
382
|
+
static getTimeDigitalDisplay(sqlDateTime, locale="fr-FR") {
|
|
383
|
+
return DateTime.getTimeDigitalDisplay(this.parse(sqlDateTime), locale);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
static getDateTimeDigitalDisplay(sqlDateTime, locale="fr-FR") {
|
|
387
|
+
return DateTime.getDateTimeDigitalDisplay(this.parse(sqlDateTime), locale);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
static getYear(sqlDateTime) {
|
|
391
|
+
return DateTime.getYear(this.parse(sqlDateTime));
|
|
392
|
+
}
|
|
393
|
+
static getMonth(sqlDateTime) {
|
|
394
|
+
return DateTime.getMonth(this.parse(sqlDateTime));
|
|
395
|
+
}
|
|
396
|
+
static getMonthName(sqlDateTime, locale="fr-FR", isShort=false) {
|
|
397
|
+
return DateTime.getMonthName(this.parse(sqlDateTime), locale);
|
|
398
|
+
}
|
|
399
|
+
static getDay(sqlDateTime) {
|
|
400
|
+
return DateTime.getDay(this.parse(sqlDateTime));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
static getTimestamp(sqlDateTime) {
|
|
404
|
+
return DateTime.getTimestamp(this.parse(sqlDateTime));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
static isDateInTheFuture(sqlDateTime) {
|
|
408
|
+
return DateTime.isDateInTheFuture(this.parse(sqlDateTime));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
static isDateTimeInTheFuture(sqlDateTime) {
|
|
412
|
+
return DateTime.isDateTimeInTheFuture(this.parse(sqlDateTime));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
static getNbDayBetweenTwo(sqlDateTime1, sqlDateTime2, asPeriod) {
|
|
416
|
+
return DateTime.getNbDayBetweenTwo(this.parse(sqlDateTime1), this.parse(sqlDateTime2), asPeriod);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
class InputPeriod {
|
|
423
|
+
|
|
424
|
+
static addLinks(form) {
|
|
425
|
+
let divParent = form.find('input[type="date"][data-add_period_select_links]').parent();
|
|
426
|
+
if (divParent.hasClass('input-group')) {
|
|
427
|
+
divParent = divParent.parent();
|
|
428
|
+
}
|
|
429
|
+
divParent.append(''
|
|
430
|
+
+'<div class="select_period_links">'
|
|
431
|
+
+'<a href="#" class="period_select_yesterday">Hier</a> - '
|
|
432
|
+
+'<a href="#" class="period_select_current_week">Cette semaine</a> - '
|
|
433
|
+
+'<a href="#" class="period_select_last_week">La semaine dernière</a> - '
|
|
434
|
+
+'<a href="#" class="period_select_current_month">Ce mois-ci</a> - '
|
|
435
|
+
+'<a href="#" class="period_select_last_month">Le mois dernier</a> - '
|
|
436
|
+
+'<a href="#" class="period_select_current_year">Cette année</a>'
|
|
437
|
+
+'</div>'
|
|
438
|
+
);
|
|
439
|
+
this.init(form);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
static init(form) {
|
|
443
|
+
let link;
|
|
444
|
+
//console.log(form.find('a.period_select_current_week'));
|
|
445
|
+
|
|
446
|
+
if ((link = form.find('a.period_select_today')).length) {
|
|
447
|
+
link.click(function() { InputPeriod.selectToday($(this)); return false; });
|
|
448
|
+
}
|
|
449
|
+
if ((link = form.find('a.period_select_yesterday')).length) {
|
|
450
|
+
link.click(function() { InputPeriod.selectPreviousDay($(this), 1); return false; });
|
|
451
|
+
}
|
|
452
|
+
if ((link = form.find('a.period_select_tomorrow')).length) {
|
|
453
|
+
link.click(function() { InputPeriod.selectFollowingDay($(this), 1); return false; });
|
|
454
|
+
}
|
|
455
|
+
if ((link = form.find('a.period_select_current_week')).length) {
|
|
456
|
+
link.click(function() { InputPeriod.selectCurrentWeek($(this)); return false; });
|
|
457
|
+
}
|
|
458
|
+
if ((link = form.find('a.period_select_last_week')).length) {
|
|
459
|
+
link.click(function() { InputPeriod.selectPreviousWeek($(this), 1); return false; });
|
|
460
|
+
}
|
|
461
|
+
if ((link = form.find('a.period_select_current_month')).length) {
|
|
462
|
+
link.click(function() { InputPeriod.selectCurrentMonth($(this)); return false; });
|
|
463
|
+
}
|
|
464
|
+
if ((link = form.find('a.period_select_last_month')).length) {
|
|
465
|
+
link.click(function() { InputPeriod.selectPreviousMonth($(this), 1); return false; });
|
|
466
|
+
}
|
|
467
|
+
if ((link = form.find('a.period_select_current_year')).length) {
|
|
468
|
+
link.click(function() { InputPeriod.selectCurrentYear($(this)); return false; });
|
|
469
|
+
}
|
|
470
|
+
if ((link = form.find('a.period_select_last_year')).length) {
|
|
471
|
+
link.click(function() { InputPeriod.selectCurrentYear($(this), 1); return false; });
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
static selectToday(link) {
|
|
477
|
+
let date = new Date();
|
|
478
|
+
this.selectPeriod(link, date, date);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static selectPreviousDay(lien, nbDays) {
|
|
482
|
+
this.selectFollowingDay(lien, -nbDays);
|
|
483
|
+
}
|
|
484
|
+
static selectFollowingDay(lien, nbDays) {
|
|
485
|
+
let date = new Date();
|
|
486
|
+
date.setDate(date.getDate() + nbDays);
|
|
487
|
+
this.selectPeriod(lien, date, date);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
static selectCurrentWeek(lien) {
|
|
491
|
+
let date = new Date();
|
|
492
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
|
|
493
|
+
}
|
|
494
|
+
static selectPreviousWeek(lien, nbWeeks) {
|
|
495
|
+
this.selectFollowingWeek(lien, -nbWeeks);
|
|
496
|
+
}
|
|
497
|
+
static selectFollowingWeek(lien, nbWeeks) {
|
|
498
|
+
let date = new Date();
|
|
499
|
+
date.setDate(date.getDate() + (7*nbWeeks));
|
|
500
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfWeek(date), DateTime.getLastDayOfWeek(date));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
static selectCurrentMonth(lien) {
|
|
504
|
+
let date = new Date();
|
|
505
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
|
|
506
|
+
}
|
|
507
|
+
static selectPreviousMonth(lien, nbMonths) {
|
|
508
|
+
this.selectFollowingMonth(lien, -nbMonths);
|
|
509
|
+
}
|
|
510
|
+
static selectFollowingMonth(lien, nbMonths) {
|
|
511
|
+
let date = new Date();
|
|
512
|
+
date.setDate(1);
|
|
513
|
+
date.setMonth(date.getMonth() + nbMonths);
|
|
514
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfMonth(date), DateTime.getLastDayOfMonth(date));
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
static selectCurrentYear(lien) {
|
|
518
|
+
this.selectFollowingYear(lien, 0);
|
|
519
|
+
}
|
|
520
|
+
static selectPreviousYear(lien, nbAnneesMoins) {
|
|
521
|
+
this.selectFollowingYear(lien, -nbAnneesMoins);
|
|
522
|
+
}
|
|
523
|
+
static selectFollowingYear(lien, nbAnneesMoins) {
|
|
524
|
+
let date = new Date();
|
|
525
|
+
date.setFullYear(date.getFullYear() + nbAnneesMoins);
|
|
526
|
+
this.selectPeriod(lien, DateTime.getFirstDayOfYear(date), DateTime.getLastDayOfYear(date));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
static selectPeriod(link, startDate, endDate) {
|
|
531
|
+
let inputPeriodStart = link.parent().parent().find('input[type="date"]').filter('[name="date_start"], [name="start_date"], [name="start_period"], [name="period_start_date"]');
|
|
532
|
+
let inputPeriodEnd = link.parent().parent().find('input[type="date"]').filter('[name="date_end"], [name="end_date"], [name="end_period"], [name="period_end_date"]');
|
|
533
|
+
if (inputPeriodStart.length == 0 || inputPeriodEnd.length == 0) {
|
|
534
|
+
console.log('no period input found');
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
//console.log(startDate);
|
|
539
|
+
//console.log(endDate);
|
|
540
|
+
inputPeriodStart.val(DateTime.getSqlDate(startDate));
|
|
541
|
+
inputPeriodEnd.val(DateTime.getSqlDate(endDate));
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
exports.DateTime = DateTime;
|
|
547
|
+
exports.TimestampUnix = TimestampUnix;
|
|
548
|
+
exports.SqlDate = SqlDate;
|
|
549
|
+
exports.SqlTime = SqlTime;
|
|
550
|
+
exports.SqlDateTime = SqlDateTime;
|
|
551
|
+
exports.InputPeriod = InputPeriod;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
class DetailsSubArray {
|
|
2
|
+
|
|
3
|
+
static initDetailsLink(table, callbackOnDetailsActionRequestSuccess, callbackOnDetailsActionRequestError, callbackOnDetailsActionRequestBeforeSend) {
|
|
4
|
+
function getNbColumns(tr) {
|
|
5
|
+
return tr.closest('table').find('thead tr').children().length;
|
|
6
|
+
}
|
|
7
|
+
function displayErrorRow(tr) {
|
|
8
|
+
tr.after($('<tr class="text-error"><td colspan="'+getNbColumns(tr)+'">'+labelErrorOccured+'</td></tr>'));
|
|
9
|
+
}
|
|
10
|
+
function displayDetailsRow(tr, content) {
|
|
11
|
+
var trContent = $(''
|
|
12
|
+
+ '<tr class="participants">'
|
|
13
|
+
+ '<td colspan="'+getNbColumns(tr)+'">'
|
|
14
|
+
+ '</td>'
|
|
15
|
+
+ '</tr>'
|
|
16
|
+
);
|
|
17
|
+
trContent.find('td').append(content);
|
|
18
|
+
tr.after(trContent);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hideDetailsRow(link) {
|
|
22
|
+
var tr = link.closest('tr').addClass('folded');
|
|
23
|
+
if (tr.next().hasClass('participants') ) {
|
|
24
|
+
tr.next().remove();
|
|
25
|
+
}
|
|
26
|
+
showPlusButton(link);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function showPlusButton(link) {
|
|
30
|
+
link.prop('title', showDetailsLabel).attr('disabled', false).html($('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>'));
|
|
31
|
+
}
|
|
32
|
+
function showMinusButton(link) {
|
|
33
|
+
link.prop('title', hideDetailsLabel).attr('disabled', false).html($('<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function displayLoading(link) {
|
|
37
|
+
link.attr('disabled', true).html($('<i class="fa fa-circle-notch fa-spin"></i>'));
|
|
38
|
+
var tr = link.closest('tr');
|
|
39
|
+
tr.after($('<tr class="waiting_icon"><td colspan="'+getNbColumns(tr)+'" class="center"><i class="fa fa-circle-notch fa-spin"></i></td></tr>'));
|
|
40
|
+
}
|
|
41
|
+
function hideLoading(link) {
|
|
42
|
+
// todo : cacher que le loader du lien au lieu de tous les loaders (cas ou l'user clique sur tous les boutons rapidement)
|
|
43
|
+
if ($('tr.waiting_icon').length > 0) {
|
|
44
|
+
$(('tr.waiting_icon')).remove();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setHideDetailsLink(link) {
|
|
49
|
+
showMinusButton(link);
|
|
50
|
+
link.click(function() {
|
|
51
|
+
$(this).stop();
|
|
52
|
+
hideDetailsRow(link);
|
|
53
|
+
setDisplayDetailsLink(link);
|
|
54
|
+
return false;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function setDisplayDetailsLink(link) {
|
|
59
|
+
link.click(function() {
|
|
60
|
+
$(this).stop().off('click');
|
|
61
|
+
hideDetailsRow(link);
|
|
62
|
+
doDetailsActionRequest(link);
|
|
63
|
+
return false;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function doDetailsActionRequest(link) {
|
|
68
|
+
displayLoading(link);
|
|
69
|
+
|
|
70
|
+
if (typeof callbackOnDetailsActionRequestBeforeSend != 'undefined' && callbackOnDetailsActionRequestBeforeSend != null) {
|
|
71
|
+
displayDetailsRow(link.closest('tr'), callbackOnDetailsActionRequestBeforeSend(link));
|
|
72
|
+
hideLoading(link);
|
|
73
|
+
setHideDetailsLink(link);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//link.attr('disabled', true).button('loading');
|
|
78
|
+
$.ajax({
|
|
79
|
+
url: link.data("url_details"),
|
|
80
|
+
method: 'GET',
|
|
81
|
+
headers: httpHeaders,
|
|
82
|
+
cache: false,
|
|
83
|
+
dataType: 'json',
|
|
84
|
+
success: function (jsonObj) {
|
|
85
|
+
if (jsonObj == null) {
|
|
86
|
+
if (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
|
|
87
|
+
callbackOnDetailsActionRequestError(link);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
displayErrorRow(link.closest('tr'));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (typeof callbackOnDetailsActionRequestSuccess != 'undefined' && callbackOnDetailsActionRequestSuccess != null) {
|
|
95
|
+
displayDetailsRow(link.closest('tr'), callbackOnDetailsActionRequestSuccess(jsonObj, link));
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
error: function (jqxhr, status, exception) {
|
|
99
|
+
console.log('Detail request failure. Status: '+status+' ; Exception: '+exception);
|
|
100
|
+
|
|
101
|
+
if (typeof callbackOnDetailsActionRequestError != 'undefined' && callbackOnDetailsActionRequestError != null) {
|
|
102
|
+
callbackOnDetailsActionRequestError(link);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
link.closest('tr').after($('<tr class="error"><td colspan="6" class="center">'+labelErrorOccured+'</td></tr>'));
|
|
107
|
+
//window.location.replace(decodeURIComponent(urlRetour));
|
|
108
|
+
},
|
|
109
|
+
complete: function() {
|
|
110
|
+
hideLoading(link);
|
|
111
|
+
setHideDetailsLink(link);
|
|
112
|
+
//link.attr('disabled', false).button('reset');
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
table.find('a.details_link').each(function(idx, link) {
|
|
118
|
+
$(link).removeClass('hide');
|
|
119
|
+
setDisplayDetailsLink($(link));
|
|
120
|
+
showPlusButton($(link));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
exports.DetailsSubArray = DetailsSubArray;
|