@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/duration.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
class Duration {
|
|
3
|
+
|
|
4
|
+
static formatNbDays(nbDays) {
|
|
5
|
+
return NumberValue.format(nbDays, 2, locale);
|
|
6
|
+
}
|
|
7
|
+
static formatNbDaysIfPositive(nbDays) {
|
|
8
|
+
return nbDays < 0 ? '-' : this.formatNbDays(nbDays);
|
|
9
|
+
}
|
|
10
|
+
static formatNbDaysWithColor(nbDays) {
|
|
11
|
+
return '<span class="text-'+(nbDays<0?'danger':'success')+'">'+this.formatNbDays(nbDays)+'</span>';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static convertToDurationAsCentieme(durationInSeconds) {
|
|
15
|
+
var hour = Math.floor(durationInSeconds / 3600);
|
|
16
|
+
var minutes = durationInSeconds % 3600;
|
|
17
|
+
minutes = Math.floor(minutes / 60);
|
|
18
|
+
// minutes = minutes - (minutes % 60);
|
|
19
|
+
var minCentieme = Math.round( (minutes / 60 ) * 100 );
|
|
20
|
+
return parseFloat(hour+'.'+minCentieme);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static convertToDurationAsInputTimeValue(durationInSeconds) {
|
|
24
|
+
return Duration.convertToDurationInHourChronoDisplay(Math.abs(durationInSeconds), 'input_time');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static convertToDurationInHourChronoDisplay(durationInSeconds, displayMode) {
|
|
28
|
+
displayMode = typeof displayMode != 'undefined' ? displayMode : 'chrono';
|
|
29
|
+
|
|
30
|
+
var durationInSecondsOriginal = durationInSeconds;
|
|
31
|
+
durationInSeconds = Math.abs(durationInSeconds);
|
|
32
|
+
var seconds = ( durationInSeconds % 60 );
|
|
33
|
+
var remander = ( durationInSeconds % 3600 ) - seconds;
|
|
34
|
+
var minutes = ( remander / 60 );
|
|
35
|
+
remander = ( durationInSeconds ) - ( durationInSeconds % 3600 );
|
|
36
|
+
var hours = ( remander / 3600 );
|
|
37
|
+
if(hours.toString().length < 2) hours = '0'+hours;
|
|
38
|
+
if(hours.toString().charAt(0) == "-") hours[0] = '0';
|
|
39
|
+
if(minutes.toString().length < 2) minutes = '0'+minutes;
|
|
40
|
+
if(minutes.toString().charAt(0) == "-") minutes[0] = '0';
|
|
41
|
+
if(seconds.toString().length < 2) seconds = '0'+seconds;
|
|
42
|
+
return (durationInSecondsOriginal < 0 ? '- ' : '')+hours+':'+minutes+(displayMode==='input_time'?':':'.')+seconds;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static convertToDurationInHourStringDisplay(durationInSeconds, withSecondes, withMinutes, withLibelleMinute, libelleEntier) {
|
|
46
|
+
if (withSecondes == null) withSecondes = true;
|
|
47
|
+
if (withMinutes == null) withMinutes = true;
|
|
48
|
+
if (withLibelleMinute == null) withLibelleMinute = true;
|
|
49
|
+
if (libelleEntier == null) libelleEntier = false;
|
|
50
|
+
|
|
51
|
+
// Heures
|
|
52
|
+
var strHeure = '';
|
|
53
|
+
var nbHeures = this.getNbHoursOfDurationInSeconds(durationInSeconds);
|
|
54
|
+
strHeure += nbHeures;
|
|
55
|
+
if (libelleEntier) {
|
|
56
|
+
strHeure += ' heure'+(nbHeures>1?'s':'');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
strHeure += 'h';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Minutes
|
|
63
|
+
var strMinute = '';
|
|
64
|
+
var nbMinutes = 0;
|
|
65
|
+
if (withMinutes) {
|
|
66
|
+
nbMinutes = this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
|
|
67
|
+
strMinute += ' ';
|
|
68
|
+
//strMinute += sprintf('%02d', nbMinutes);
|
|
69
|
+
strMinute += nbMinutes.toString().padStart(2, '0');
|
|
70
|
+
if (withLibelleMinute) {
|
|
71
|
+
if (libelleEntier) {
|
|
72
|
+
strMinute += ' minute'+(nbMinutes>1?'s':'');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
strMinute += 'min';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Secondes
|
|
81
|
+
var strSeconde = '';
|
|
82
|
+
if (withSecondes) {
|
|
83
|
+
var nbSecondes = this.getNbSecondsRemainingOfDurationInSeconds(durationInSeconds);
|
|
84
|
+
strSeconde += ' ';
|
|
85
|
+
//strSeconde += sprintf('%02d', nbSecondes);
|
|
86
|
+
strSeconde += nbSecondes.toString().padStart(2, '0');
|
|
87
|
+
if (libelleEntier) {
|
|
88
|
+
strSeconde += ' seconde'+(nbSecondes>1?'s':'');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
strSeconde += 's';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (strHeure+strMinute+strSeconde).trim();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static roundNbSeconds(durationInSeconds, roundPrecision, roundMode) {
|
|
99
|
+
var hours = Math.floor(durationInSeconds / 3600);
|
|
100
|
+
var minutes = Math.floor((durationInSeconds % 3600) / 60);
|
|
101
|
+
var seconds = durationInSeconds % 60;
|
|
102
|
+
|
|
103
|
+
var hoursRounded = hours;
|
|
104
|
+
var minutesRounded = minutes;
|
|
105
|
+
var secondsRounded = seconds;
|
|
106
|
+
|
|
107
|
+
if (roundPrecision > 0) {
|
|
108
|
+
var minutesRemaining = minutes % roundPrecision;
|
|
109
|
+
var minutesRemainingAndSecondsAsCentieme = minutesRemaining + seconds/60;
|
|
110
|
+
if (minutesRemainingAndSecondsAsCentieme == 0) {
|
|
111
|
+
// pas d'arrondissement
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
var halfRoundPrecision = roundPrecision / 2;
|
|
115
|
+
hoursRounded = hours;
|
|
116
|
+
secondsRounded = 0;
|
|
117
|
+
if (roundMode == 'up' || (roundMode == 'close' && minutesRemainingAndSecondsAsCentieme > halfRoundPrecision)) {
|
|
118
|
+
// Arrondissement au dessus
|
|
119
|
+
if (minutes > (60-roundPrecision)) {
|
|
120
|
+
minutesRounded = 0;
|
|
121
|
+
hoursRounded++;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
minutesRounded = (minutes-minutesRemaining)+roundPrecision;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// Arrondissement au dessous
|
|
129
|
+
minutesRounded = (minutes-minutesRemaining);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// console.log(element.data('duration_default'), durationInSeconds, hours, minutes, seconds, '->', secondsTotalRounded, hoursRounded, minutesRounded, secondsRounded);
|
|
134
|
+
return hoursRounded * 3600 + minutesRounded * 60 + secondsRounded;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static getNbDaysOfDurationInSeconds(durationInSeconds) {
|
|
138
|
+
return Math.floor(durationInSeconds / 86400);
|
|
139
|
+
}
|
|
140
|
+
static getNbHoursOfDurationInSeconds(durationInSeconds) {
|
|
141
|
+
return Math.floor(durationInSeconds / 3600);
|
|
142
|
+
}
|
|
143
|
+
static getNbMinutesOfDurationInSeconds(durationInSeconds) {
|
|
144
|
+
return Math.floor(durationInSeconds / 60);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
static getNbMinutesRemaining(durationInSeconds) {
|
|
149
|
+
var remander = ( durationInSeconds % 3600 ) - ( durationInSeconds % 60 );
|
|
150
|
+
return ( remander / 60 );
|
|
151
|
+
}
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/*
|
|
155
|
+
static getNbHoursOfDurationInSeconds(durationInSeconds) {
|
|
156
|
+
// return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24)+this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds);
|
|
157
|
+
return (durationInSeconds - (durationInSeconds % 3600)) / 3600;
|
|
158
|
+
}
|
|
159
|
+
static getNbMinutesOfDurationInSeconds(durationInSeconds) {
|
|
160
|
+
// return (this.getNbDaysOfDurationInSeconds(durationInSeconds)*24*60)+(this.getNbHoursRemainingOfDurationInSeconds(durationInSeconds)*60)+this.getNbMinutesRemainingOfDurationInSeconds(durationInSeconds);
|
|
161
|
+
return (durationInSeconds - (durationInSeconds % 60)) / 60;
|
|
162
|
+
}
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
static getNbHoursRemainingOfDurationInSeconds(durationInSeconds) {
|
|
166
|
+
return this.getNbHoursOfDurationInSeconds(durationInSeconds % 86400);
|
|
167
|
+
}
|
|
168
|
+
static getNbMinutesRemainingOfDurationInSeconds(durationInSeconds) {
|
|
169
|
+
return this.getNbMinutesOfDurationInSeconds(durationInSeconds % 3600);
|
|
170
|
+
}
|
|
171
|
+
static getNbSecondsRemainingOfDurationInSeconds(durationInSeconds) {
|
|
172
|
+
return durationInSeconds % 60;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
exports.Duration = Duration;
|
package/file.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
|
|
2
|
+
class File {
|
|
3
|
+
static download(data, contentType, contentDisposition) {
|
|
4
|
+
var filename = "";
|
|
5
|
+
var disposition = contentDisposition;
|
|
6
|
+
if (disposition && (disposition.indexOf('inline') !== -1 || disposition.indexOf('attachment') !== -1)) {
|
|
7
|
+
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
8
|
+
var matches = filenameRegex.exec(disposition);
|
|
9
|
+
if (matches != null && matches[1]) {
|
|
10
|
+
filename = matches[1].replace(/['"]/g, '');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
var type = contentType;
|
|
14
|
+
|
|
15
|
+
var blob = new Blob([data], {
|
|
16
|
+
type: type
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//console.log('disposition: '+disposition+' ; filename: '+filename+' ; type: '+type);
|
|
20
|
+
//console.log('blob: %o', blob);
|
|
21
|
+
|
|
22
|
+
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
23
|
+
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
|
|
24
|
+
window.navigator.msSaveBlob(blob, filename);
|
|
25
|
+
} else {
|
|
26
|
+
var URL = window.URL || window.webkitURL;
|
|
27
|
+
var downloadUrl = URL.createObjectURL(blob);
|
|
28
|
+
|
|
29
|
+
var a = document.createElement("a");
|
|
30
|
+
// safari doesn't support this yet
|
|
31
|
+
if (typeof a.download === 'undefined') {
|
|
32
|
+
window.location = downloadUrl;
|
|
33
|
+
} else {
|
|
34
|
+
a.href = downloadUrl;
|
|
35
|
+
a.download = (filename?filename:'file.pdf');
|
|
36
|
+
document.body.appendChild(a);
|
|
37
|
+
a.click();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setTimeout(function () {
|
|
41
|
+
URL.revokeObjectURL(downloadUrl);
|
|
42
|
+
}, 100); // cleanup
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static formatFileSize(fileSizeInBytes, fractionDigits, locale) {
|
|
47
|
+
fractionDigits = (typeof fractionDigits != 'undefined' ? fractionDigits : 2);
|
|
48
|
+
var i = -1;
|
|
49
|
+
var byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
50
|
+
if (fileSizeInBytes === 0) {
|
|
51
|
+
return '0 ' + byteUnits[0];
|
|
52
|
+
}
|
|
53
|
+
do {
|
|
54
|
+
fileSizeInBytes = fileSizeInBytes / 1024;
|
|
55
|
+
i++;
|
|
56
|
+
}
|
|
57
|
+
while (fileSizeInBytes > 1024);
|
|
58
|
+
//var size = Math.max(fileSizeInBytes, 0.1).toFixed(fractionDigits);
|
|
59
|
+
var size = Math.max(fileSizeInBytes, 0.1);
|
|
60
|
+
return (new Intl.NumberFormat(locale, {
|
|
61
|
+
maximumFractionDigits: fractionDigits
|
|
62
|
+
}).format(size)) + ' ' + byteUnits[i];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const CSV_FILE_EXTENSION = "csv";
|
|
67
|
+
const CSV_MIME_TYPES = [
|
|
68
|
+
'text/csv',
|
|
69
|
+
'txt/csv',
|
|
70
|
+
'application/octet-stream',
|
|
71
|
+
'application/csv-tab-delimited-table',
|
|
72
|
+
'application/vnd.ms-excel',
|
|
73
|
+
'application/vnd.ms-pki.seccat',
|
|
74
|
+
'text/plain',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
class CSV {
|
|
78
|
+
static checkFile(filename, fileType) {
|
|
79
|
+
return CSV_MIME_TYPES.indexOf(fileType) !== -1 && filename.split('.').pop().toLowerCase() === CSV_FILE_EXTENSION;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
class Img {
|
|
85
|
+
static compress(oData) {
|
|
86
|
+
var a = [];
|
|
87
|
+
var len = oData.length;
|
|
88
|
+
var p = -1;
|
|
89
|
+
for (var i=0;i<len;i+=4) {
|
|
90
|
+
if (oData[i] > 0)
|
|
91
|
+
a[++p] = String.fromCharCode(oData[i]);
|
|
92
|
+
};
|
|
93
|
+
return a.join("");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static initImg(div) {
|
|
97
|
+
div.find('.asynchronously_img').each(function(idx, img) {
|
|
98
|
+
Img.loadImgUrl($(img).data('url'), $(img));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static loadImgUrl(url, img) {
|
|
103
|
+
$.ajax({
|
|
104
|
+
type: 'GET',
|
|
105
|
+
url: url,
|
|
106
|
+
headers: httpHeaders,
|
|
107
|
+
cache: false,
|
|
108
|
+
xhrFields: {responseType: 'blob'},
|
|
109
|
+
success: (data) => {
|
|
110
|
+
// var urlCreator = window.URL || window.webkitURL;
|
|
111
|
+
// $(img).attr('src', urlCreator.createObjectURL(data));
|
|
112
|
+
Img.setBlobToImg($(img), data);
|
|
113
|
+
},
|
|
114
|
+
error: (jqxhr, status, exception) => console.log('request failure. Status: '+status+'Exception: '+exception),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static setBlobToImg(img, blob) {
|
|
119
|
+
// img.attr('src', btoa(unescape(encodeURIComponent(data))));
|
|
120
|
+
// img.attr('src', 'data:image/png;base64, '+btoa(unescape(encodeURIComponent(data))));
|
|
121
|
+
var urlCreator = window.URL || window.webkitURL;
|
|
122
|
+
img.attr('src', urlCreator.createObjectURL(blob));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
exports.File = File;
|
|
127
|
+
exports.CSV = CSV;
|
|
128
|
+
exports.Img = Img;
|
package/flash_message.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class FlashMessage {
|
|
2
|
+
|
|
3
|
+
static displayRequestFailure(status, exception, modal) {
|
|
4
|
+
console.log('request failure. Status: ', status, ' Exception: ', exception);
|
|
5
|
+
this.display('danger', "Une erreur s'est produite.", false, modal);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static displaySuccess(message, reload, modal) {
|
|
9
|
+
this.display('success', message, reload, modal);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static displayError(message, modal) {
|
|
13
|
+
this.display('danger', message, false, modal);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static display(type, message, reload, modal) {
|
|
17
|
+
if ('undefined' !== typeof modal) {
|
|
18
|
+
modal.modal('hide');
|
|
19
|
+
}
|
|
20
|
+
if ($('div.snackbar').length !== 0) {
|
|
21
|
+
$('div.snackbar').remove();
|
|
22
|
+
}
|
|
23
|
+
var snackbar = $('<div class="snackbar '+type+'"></div>');
|
|
24
|
+
$('html body').append(snackbar);
|
|
25
|
+
snackbar.html(message);
|
|
26
|
+
snackbar.addClass('show');
|
|
27
|
+
|
|
28
|
+
setTimeout(function () {
|
|
29
|
+
$('div.snackbar').remove();
|
|
30
|
+
}, 6000);
|
|
31
|
+
|
|
32
|
+
if (true === reload) {
|
|
33
|
+
document.location.reload();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.FlashMessage = FlashMessage;
|
package/form_date.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
|
|
2
|
+
$(function() {
|
|
3
|
+
// ---------- Choix période (new) ----------
|
|
4
|
+
|
|
5
|
+
// Formulaire de sélection de période
|
|
6
|
+
|
|
7
|
+
if ($('form select.periode').length > 0) {
|
|
8
|
+
$('form select.periode').change(function() {
|
|
9
|
+
majSelectPeriode($(this));
|
|
10
|
+
|
|
11
|
+
if ($(this).attr('id') == 'periode') {
|
|
12
|
+
majSelectCompare();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function majSelectPeriode(select) {
|
|
18
|
+
if (select.find(':selected').attr('value') == 'perso') {
|
|
19
|
+
select.parent().parent().next().removeClass('hide');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
select.parent().parent().next().addClass('hide');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function majSelectCompare() {
|
|
27
|
+
if ($('form select#periodeCompare').length == 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var listValues = [];
|
|
32
|
+
periodeSelected = $('form select.periode :selected').attr('value');
|
|
33
|
+
selectCompare = $('form select#periodeCompare');
|
|
34
|
+
periodeCompareSelected = selectCompare.find(':selected').attr('value');
|
|
35
|
+
|
|
36
|
+
selectCompare.find('option').removeAttr('disabled');
|
|
37
|
+
|
|
38
|
+
$.each(listePeriodeCompare, function(idx, tabListPeriode) {
|
|
39
|
+
if (idx != 0) {
|
|
40
|
+
listKeyPeriode = array_keys(tabListPeriode.list);
|
|
41
|
+
if (in_array(periodeSelected, listKeyPeriode)) {
|
|
42
|
+
listValues = listKeyPeriode;
|
|
43
|
+
valueDefault = listKeyPeriode[1];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
selectCompare.find('option[value="'+listKeyPeriode[0]+'"]').parent().children().attr('disabled', 'disabled');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (periodeSelected == 'perso') {
|
|
52
|
+
valueDefault = 'perso';
|
|
53
|
+
}
|
|
54
|
+
else if (periodeCompareSelected != 'perso' && in_array(periodeCompareSelected, listValues)) {
|
|
55
|
+
valueDefault = periodeCompareSelected;
|
|
56
|
+
}
|
|
57
|
+
selectCompare.find('option[value="'+valueDefault+'"]').attr('selected', 'selected');
|
|
58
|
+
|
|
59
|
+
majSelectPeriode(selectCompare);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
majSelectCompare();
|
|
63
|
+
// majSelectPeriode($('form select#periodeCompare'));
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// ---------- Choix période (old) ----------
|
|
67
|
+
|
|
68
|
+
if ($('form #day').length > 0 && $('form #month').length > 0 && $('form #year').length > 0) {
|
|
69
|
+
$('form #year').after(
|
|
70
|
+
'<br/>'+
|
|
71
|
+
'<p class="select_date_fastly">'+
|
|
72
|
+
' <a href="#" class="lien_form_today">Auj.</a> - '+
|
|
73
|
+
' <a href="#" class="lien_form_yesterday">Hier</a> - '+
|
|
74
|
+
' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
|
|
75
|
+
' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
|
|
76
|
+
' <a href="#" class="lien_form_current_year">Cette année</a>'+
|
|
77
|
+
' - '+
|
|
78
|
+
' <a href="#" class="lien_form_date_prev_day">Jour précédent</a>'+
|
|
79
|
+
' - '+
|
|
80
|
+
' <a href="#" class="lien_form_date_next_day">Jour suivant</a>'+
|
|
81
|
+
'</p>'+
|
|
82
|
+
''
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
else if ($('form #month').length > 0 && $('form #year').length > 0) {
|
|
86
|
+
$('form #year').after(
|
|
87
|
+
'<br/>'+
|
|
88
|
+
'<p class="select_date_fastly">'+
|
|
89
|
+
' <a href="#" class="lien_form_current_month">Ce mois-ci</a> - '+
|
|
90
|
+
' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
|
|
91
|
+
' <a href="#" class="lien_form_current_year">Cette année</a>'+
|
|
92
|
+
'</p>'+
|
|
93
|
+
''
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if ($('form #dayCompare').length > 0 && $('form #monthCompare').length > 0 && $('form #yearCompare').length > 0) {
|
|
98
|
+
$('form #yearCompare').after(
|
|
99
|
+
'<br/>'+
|
|
100
|
+
'<p class="select_date_fastly">'+
|
|
101
|
+
' <a href="#" class="lien_form_yesterday">Hier</a> - '+
|
|
102
|
+
' <a href="#" class="lien_form_day_moins_7">J-7</a> - '+
|
|
103
|
+
' <a href="#" class="lien_form_day_moins_8">J-8</a> - '+
|
|
104
|
+
' <a href="#" class="lien_form_last_month">Le mois dernier</a> - '+
|
|
105
|
+
' <a href="#" class="lien_form_month_moins_2">Mois M-2</a> - '+
|
|
106
|
+
' <a href="#" class="lien_form_last_year">L\'année dernière</a>'+
|
|
107
|
+
'</p>'+
|
|
108
|
+
''
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Lien de sélection de date
|
|
113
|
+
|
|
114
|
+
if ($('form a.lien_form_today').length > 0) {
|
|
115
|
+
$('form a.lien_form_today').click(function() {
|
|
116
|
+
selectFormDateToday($(this));
|
|
117
|
+
return false;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if ($('form a.lien_form_yesterday').length > 0) {
|
|
122
|
+
$('form a.lien_form_yesterday').click(function() {
|
|
123
|
+
selectFormDateDayMoinsNb($(this), 1);
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if ($('form a.lien_form_day_moins_7').length > 0) {
|
|
129
|
+
$('form a.lien_form_day_moins_7').click(function() {
|
|
130
|
+
selectFormDateDayMoinsNb($(this), 7);
|
|
131
|
+
return false;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if ($('form a.lien_form_day_moins_8').length > 0) {
|
|
136
|
+
$('form a.lien_form_day_moins_8').click(function() {
|
|
137
|
+
selectFormDateDayMoinsNb($(this), 8);
|
|
138
|
+
return false;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if ($('form a.lien_form_current_month').length > 0) {
|
|
143
|
+
$('form a.lien_form_current_month').click(function() {
|
|
144
|
+
selectFormDateCurrentMonth($(this));
|
|
145
|
+
return false;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if ($('form a.lien_form_last_month').length > 0) {
|
|
150
|
+
$('form a.lien_form_last_month').click(function() {
|
|
151
|
+
selectFormDateMonthMoinsNb($(this), 1);
|
|
152
|
+
return false;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if ($('form a.lien_form_month_moins_2').length > 0) {
|
|
157
|
+
$('form a.lien_form_month_moins_2').click(function() {
|
|
158
|
+
selectFormDateMonthMoinsNb($(this), 2);
|
|
159
|
+
return false;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if ($('form a.lien_form_current_year').length > 0) {
|
|
164
|
+
$('form a.lien_form_current_year').click(function() {
|
|
165
|
+
selectFormDateCurrentYear($(this));
|
|
166
|
+
return false;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if ($('form a.lien_form_last_year').length > 0) {
|
|
171
|
+
$('form a.lien_form_last_year').click(function() {
|
|
172
|
+
selectFormDateYearMoinsNb($(this), 1);
|
|
173
|
+
return false;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if ($('form a.lien_form_date_prev_day').length > 0) {
|
|
178
|
+
$('form a.lien_form_date_prev_day').click(function() {
|
|
179
|
+
selectFormDateAddDayFromSelectedDay($(this), -1);
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if ($('form a.lien_form_date_next_day').length > 0) {
|
|
184
|
+
$('form a.lien_form_date_next_day').click(function() {
|
|
185
|
+
selectFormDateAddDayFromSelectedDay($(this), 1);
|
|
186
|
+
return false;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
if ($('form select[name=select_date_fastly]').length > 0) {
|
|
192
|
+
$('form select[name=select_date_fastly]').change(function() {
|
|
193
|
+
valueOptionSelected = $('form select[name=select_date_fastly] option:selected').attr('value');
|
|
194
|
+
if (valueOptionSelected == 'today') {
|
|
195
|
+
selectFormDateToday();
|
|
196
|
+
}
|
|
197
|
+
else if (valueOptionSelected == 'current_month') {
|
|
198
|
+
selectFormDateCurrentMonth();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
function selectFormDateToday(lien) {
|
|
205
|
+
date = new Date();
|
|
206
|
+
selectFormDate(lien, date.getDate(), (date.getMonth()+1), date.getFullYear());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function selectFormDateDayMoinsNb(lien, nbJoursMoins) {
|
|
210
|
+
date = new Date();
|
|
211
|
+
date.setDate(date.getDate() - nbJoursMoins);
|
|
212
|
+
selectFormDate(lien, date.getDate(), (date.getMonth()+1), date.getFullYear());
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function selectFormDateCurrentMonth(lien) {
|
|
216
|
+
date = new Date();
|
|
217
|
+
selectFormDate(lien, -1, (date.getMonth()+1), date.getFullYear());
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function selectFormDateMonthMoinsNb(lien, nbMoisMoins) {
|
|
221
|
+
date = new Date();
|
|
222
|
+
date.setDate(1);
|
|
223
|
+
date.setMonth(date.getMonth() - nbMoisMoins);
|
|
224
|
+
selectFormDate(lien, -1, (date.getMonth()+1), date.getFullYear());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function selectFormDateCurrentYear(lien) {
|
|
228
|
+
today = new Date();
|
|
229
|
+
selectFormDate(lien, -1, -1, today.getFullYear());
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function selectFormDateYearMoinsNb(lien, nbAnneesMoins) {
|
|
233
|
+
today = new Date();
|
|
234
|
+
selectFormDate(lien, -1, -1, today.getFullYear()-nbAnneesMoins);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function selectFormDateAddDayFromSelectedDay(lien, nbDaysAdded) {
|
|
238
|
+
date = getDateObjectSelected(lien);
|
|
239
|
+
date.setDate(date.getDate() + nbDaysAdded);
|
|
240
|
+
selectFormDate(lien, date.getDate(), (date.getMonth()+1), date.getFullYear());
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function getDateObjectSelected(lien) {
|
|
244
|
+
selectorDay = '#'+(lien.parent().prev().prev().prev().prev().attr('id'))+' option:selected';
|
|
245
|
+
selectorMonth = '#'+(lien.parent().prev().prev().prev().attr('id'))+' option:selected';
|
|
246
|
+
selectorYear = '#'+(lien.parent().prev().prev().attr('id'))+' option:selected';
|
|
247
|
+
if ($(selectorDay).length > 0 && $(selectorMonth).length > 0 && $(selectorYear).length > 0) {
|
|
248
|
+
return new Date($(selectorYear).attr('value'), $(selectorMonth).attr('value')-1, $(selectorDay).attr('value'));
|
|
249
|
+
}
|
|
250
|
+
return new Date();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function selectFormDate(lien, day, month, year) {
|
|
254
|
+
selectorDay = '#'+(lien.parent().prev().prev().prev().prev().attr('id'))+' option[value='+day+']';
|
|
255
|
+
selectorMonth = '#'+(lien.parent().prev().prev().prev().attr('id'))+' option[value='+month+']';
|
|
256
|
+
selectorYear = '#'+(lien.parent().prev().prev().attr('id'))+' option[value='+year+']';
|
|
257
|
+
if ($(selectorDay).length > 0) $(selectorDay).prop('selected', 'selected');
|
|
258
|
+
if ($(selectorMonth).length > 0) $(selectorMonth).prop('selected', 'selected');
|
|
259
|
+
if ($(selectorYear).length > 0) $(selectorYear).prop('selected', 'selected');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
});
|