@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.
@@ -0,0 +1,295 @@
1
+ // /!\
2
+ // /!\ Jérôme : à mon avis celui-ci n'est pas à jour et il ne faut plus l'utiliser (provient du projet mytime/admin_osi/audioconf.),
3
+ // /!\ ou alors il faut le retirer des helpers et créer une classe spécifique dans chaque projet (si comportements différents)
4
+ // /!\
5
+
6
+
7
+
8
+ // google.load("visualization", "1", {packages:["corechart"]});
9
+ google.charts.load('current', {'packages':['bar','line','corechart']});
10
+ // google.charts.load('current', {packages:['corechart']});
11
+
12
+ google.charts.setOnLoadCallback(drawAllCharts);
13
+
14
+ function drawAllCharts() {
15
+ if (typeof(listCharts) != 'undefined' && listCharts.length > 0) {
16
+ loadListCharts(listCharts);
17
+ }
18
+ }
19
+
20
+ function loadListCharts(listCharts) {
21
+ $.each(listCharts, function(idx, chartData) {
22
+ // console.log('drawChart'+chartData.id);
23
+ drawChart(chartData.type_graph, chartData.id, chartData.title, chartData.libelle_abs, chartData.tab_data_abs, chartData.liste_libelle_ord, chartData.liste_tab_data_ord, chartData.list_color, chartData.format_ord, chartData.height, chartData.width);
24
+
25
+ /*
26
+ if (typeof(initWidth) == 'undefined' || initWidth) {
27
+ var width = 0;
28
+ $.each(listGraphStats, function(idx, tabGraph) {
29
+ if ($('#'+tabGraph.id).length) {
30
+ if ($('#'+tabGraph.id).width() > 0) {
31
+ width = $('#'+tabGraph.id).width();
32
+ }
33
+ }
34
+ });
35
+ }
36
+
37
+ $.each(listGraphStats, function(idx, tabGraph) {
38
+ drawChart(tabGraph.type_graph, tabGraph.id, tabGraph.title, tabGraph.libelle_abs, tabGraph.tab_data_abs, tabGraph.liste_libelle_ord, tabGraph.liste_tab_data_ord, tabGraph.list_color, tabGraph.format_ord, tabGraph.height, width);
39
+ });
40
+ */
41
+ });
42
+ }
43
+
44
+ function drawChart(typeGraph, idDiv, titre, libelleAbs, tabDataAbsParam, listeLibelleOrd, listeTabDataOrd, tabColor, formatData, height, width) {
45
+ if ($('#'+idDiv).length == 0) {
46
+ return;
47
+ }
48
+
49
+ var afficherLibelleOrd = false;
50
+
51
+ isStacked = false;
52
+ if (typeGraph == 'stacked_bar_chart') {
53
+ typeGraph = 'bar_chart';
54
+ isStacked = true;
55
+ }
56
+ if (typeGraph == 'stacked_column_chart') {
57
+ typeGraph = 'column_chart';
58
+ isStacked = true;
59
+ }
60
+ if (typeGraph == 'stacked_combo_chart') {
61
+ typeGraph = 'combo_chart';
62
+ isStacked = true;
63
+ }
64
+
65
+ isDualChart = false;
66
+ if (typeGraph == 'dual_column_chart') {
67
+ typeGraph = 'column_chart';
68
+ isDualChart = true;
69
+ }
70
+ if (typeGraph == 'dual_bar_chart') {
71
+ typeGraph = 'bar_chart';
72
+ isDualChart = true;
73
+ }
74
+
75
+ // Déclaration du tableau de données
76
+ var data = new google.visualization.DataTable();
77
+ data.addColumn('string', libelleAbs);
78
+ $.each(listeLibelleOrd, function(idx, libelleOrd) {
79
+ data.addColumn('number', libelleOrd);
80
+ });
81
+
82
+ // Remplissage des données
83
+ var nbCells = 0;
84
+ var numRow = 0;
85
+ $.each(tabDataAbsParam, function(idx, dataAbs) {
86
+ // dataOrd = tabDataOrd[idx];
87
+ // data.addRow([dataAbs, dataOrd]);
88
+ data.addRows(1);
89
+
90
+ data.setCell(numRow, 0, dataAbs);
91
+
92
+ var numCell = 1;
93
+ $.each(listeTabDataOrd, function(idx2, tabDataOrd) {
94
+ data.setCell(numRow, numCell, tabDataOrd[idx]);
95
+ numCell++;
96
+ });
97
+
98
+ nbCells = numCell;
99
+ numRow++;
100
+ });
101
+ nbCells -= 2;
102
+
103
+ // console.log(data);
104
+ // console.log('drawGraph : '+idDiv+' ; type : '+typeGraph);
105
+
106
+ // Options générales
107
+ var options = {
108
+ colors: tabColor,
109
+ fontName: 'Trebuchet MS',
110
+ fontSize: 12,
111
+ hAxis: {maxAlternation: 1},
112
+ vAxis: {minValue: 0, textPosition: 'out'},
113
+ //gridlines: {color: '#333', count: 1}
114
+ };
115
+
116
+ if (formatData != null) {
117
+ options.vAxis.format = formatData;
118
+ }
119
+
120
+ // Options sur le titre du graphique
121
+ options.title = titre;
122
+ if (typeGraph == 'pie_chart') {
123
+ // options.titlePosition = 'none';
124
+ }
125
+ else {
126
+ options.titlePosition = 'none';
127
+ }
128
+
129
+ // Options sur la taille du graphique
130
+ if (typeGraph == 'bar_chart') {
131
+ options.chartArea = {left:120, top:30};
132
+ options.chartArea.height = (height-60);
133
+ options.chartArea.width = "85%";
134
+ }
135
+ else {
136
+ options.chartArea = {left:"auto", top:"auto"};
137
+ if (height != null) {
138
+ options.chartArea.height = height+"%";
139
+ }
140
+ else {
141
+ options.chartArea.height = "80%";
142
+ }
143
+ options.chartArea.width = "85%";
144
+ }
145
+ // options.chartArea = {};
146
+ // options.chartArea.height = "100%";
147
+ // options.chartArea.width = "100%";
148
+
149
+ options.width = width;
150
+
151
+ // Options sur la légende
152
+ options.legend = {};
153
+ if (typeGraph == 'pie_chart') {
154
+ options.legend.position = 'right';
155
+ }
156
+ else {
157
+ options.legend.position = 'top';
158
+ }
159
+
160
+ // Options sur l'affichage des labels en absisse / ordonnée
161
+ if (typeGraph == 'bar_chart') {
162
+ // options.hAxis.title = libelleOrd;
163
+ options.vAxis.title = libelleAbs;
164
+ }
165
+ else {
166
+ options.hAxis.title = libelleAbs;
167
+ // options.vAxis.title = libelleOrd;
168
+ }
169
+
170
+ // Options sur les graphiques "dual bar chart / dual column chart"
171
+ if (isDualChart) {
172
+ options.series = {};
173
+ options.axes = {};
174
+ if (typeGraph == 'column_chart') {
175
+ options.axes.y = {};
176
+ options.vAxes = {};
177
+ }
178
+ else {
179
+ options.axes.x = {};
180
+ options.hAxes = {};
181
+ }
182
+ $.each(listeLibelleOrd, function(idx, libelleOrd) {
183
+ // console.log(idx);
184
+ if (idx <= 1) {
185
+ // key = 'series_'+idx;
186
+ key = idx;
187
+ // options.series[idx] = {axis: key, targetAxisIndex: key};
188
+ options.series[idx] = {axis: key, targetAxisIndex: idx};
189
+ if (typeGraph == 'column_chart') {
190
+ options.axes.y[key] = {label: libelleOrd};
191
+ if (idx == 1) {
192
+ options.axes.y[key].side = 'right';
193
+ }
194
+ if (formatData != null) {
195
+ options.vAxes[key] = {format: formatData};
196
+ }
197
+ }
198
+ else {
199
+ options.axes.x[key] = {label: libelleOrd};
200
+ if (idx == 1) {
201
+ options.axes.x[key].side = 'top';
202
+ }
203
+ if (formatData != null) {
204
+ options.hAxes[key] = {format: formatData};
205
+ }
206
+ }
207
+ }
208
+ });
209
+ // console.log(options.series);
210
+ // console.log(options.vAxes);
211
+ }
212
+
213
+ // Options sur les graphiques "combo chart"
214
+ if (typeGraph == 'combo_chart') {
215
+ options.seriesType = "bars";
216
+ options.series = {};
217
+ options.series[nbCells] = {type: "line"};
218
+ }
219
+
220
+ // Options sur le style des lignes pour les "line chart"
221
+ if (typeGraph == 'line_chart') {
222
+ options.series = [{lineWidth: 3}, {lineWidth: 1.5}];
223
+ options.curveType = 'function';
224
+ }
225
+
226
+ // Options sur le style pour les "pie chart"
227
+ if (typeGraph == 'pie_chart') {
228
+ options.is3D = false;
229
+ options.pieResidueSliceLabel = 'Autre';
230
+ }
231
+
232
+ if (typeGraph == 'bar_chart') {
233
+ options.bars = 'horizontal';
234
+ }
235
+
236
+ if (isStacked) {
237
+ options.isStacked = true;
238
+ }
239
+
240
+ // console.log(options);
241
+
242
+ // Création du graphique
243
+ var errorChart = false;
244
+ if (typeGraph == 'column_chart') {
245
+ // var chart = new google.visualization.ColumnChart(document.getElementById(idDiv));
246
+ var chart = new google.charts.Bar(document.getElementById(idDiv));
247
+ }
248
+ else if (typeGraph == 'bar_chart') {
249
+ // var chart = new google.visualization.BarChart(document.getElementById(idDiv));
250
+ var chart = new google.charts.Bar(document.getElementById(idDiv));
251
+ }
252
+ else if (typeGraph == 'line_chart') {
253
+ // var chart = new google.visualization.LineChart(document.getElementById(idDiv));
254
+ var chart = new google.charts.Line(document.getElementById(idDiv));
255
+ }
256
+ else if (typeGraph == 'combo_chart') {
257
+ var chart = new google.visualization.ComboChart(document.getElementById(idDiv));
258
+ }
259
+ else if (typeGraph == 'pie_chart') {
260
+ var chart = new google.visualization.PieChart(document.getElementById(idDiv));
261
+ }
262
+ else {
263
+ errorChart = true;
264
+ }
265
+
266
+ $('#'+idDiv).removeClass('ajaxLoader');
267
+ $('#'+idDiv).removeClass('graphique_load');
268
+
269
+ if (errorChart) {
270
+ console.log('erreur graphique');
271
+ $('#'+idDiv).addClass('graphique_error');
272
+ document.getElementById(idDiv).innerHTML = 'Une erreur s\'est produite lors du chargement du graphique.';
273
+ }
274
+ else {
275
+ $('#'+idDiv).addClass('graphique');
276
+ document.getElementById(idDiv).innerHTML = '';
277
+
278
+ // $('#'+idDiv).
279
+ // document.getElementById(idDiv).style.display = 'block';
280
+ var hasClassActive = $('#'+idDiv).hasClass('active');
281
+ if (!hasClassActive) {
282
+ $('#'+idDiv).addClass('active');
283
+ }
284
+ google.visualization.events.addListener(chart, 'ready', function () {
285
+ // document.getElementById(idDiv).style.display = 'none';
286
+ // $('#'+idDiv).hide();
287
+ if (!hasClassActive) {
288
+ $('#'+idDiv).removeClass('active');
289
+ }
290
+ });
291
+ // console.log($("ul li.ui-state-active").index()
292
+
293
+ chart.draw(data, options);
294
+ }
295
+ }
package/google_maps.js ADDED
@@ -0,0 +1,169 @@
1
+
2
+ class GoogleMap {
3
+ constructor(mapId) {
4
+ this.markers = [];
5
+ this.locations = [];
6
+ this.mapId = mapId;
7
+
8
+ if (!$('#'+mapId).length) {
9
+ return;
10
+ }
11
+
12
+ var mapOptions = {
13
+ // center: { lat: 46.52863469527167, lng: 2.43896484375},
14
+ // zoom: 6,
15
+ maxZoom: 18
16
+ };
17
+ this.map = new google.maps.Map(document.getElementById(mapId), mapOptions);
18
+ this.centerOnFrance();
19
+ }
20
+
21
+ static getUrl(latitude, longitude) {
22
+ return 'http://maps.google.com/?q='+latitude+','+longitude+'';
23
+ }
24
+
25
+ static getUrlFromCoordinates(locationCoordinates) {
26
+ locationCoordinates = locationCoordinates.split(',');
27
+ return this.getUrl(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
28
+ }
29
+
30
+ deleteMarkers() {
31
+ this.locations = [];
32
+
33
+ for (var i = 0; i < this.markers.length; i++ ) {
34
+ this.markers[i].setMap(null);
35
+ }
36
+ this.markers.length = 0;
37
+ this.markers = [];
38
+
39
+ // this.map.clearOverlays();
40
+ }
41
+
42
+ addMarkers(listLocation, icon) {
43
+ console.log(listLocation);
44
+ if (listLocation.length == 0) {
45
+ return;
46
+ }
47
+
48
+ for(var i= 0; i < listLocation.length; i++) {
49
+ this.addMarker(listLocation[i], icon);
50
+ }
51
+ }
52
+
53
+ addMarker(coordinates, icon, infoWindowContent, markerOnClickCallback) {
54
+ var displayInfoWindow = (typeof infoWindowContent != 'undefined' && infoWindowContent != null);
55
+
56
+ var locationCoordinates = coordinates.split(',');
57
+ var latitude = parseFloat(locationCoordinates[0]);
58
+ var longitude = parseFloat(locationCoordinates[1]);
59
+ // var locationCoordinatesString = .toFixed(8)+','+parseFloat(locationCoordinates[1]).toFixed(8);
60
+
61
+ // var myLatLng = new google.maps.LatLng(location.latitude, location.longitude);
62
+ // console.log(coordinates[0], coordinates[1]);
63
+ var myLatLng = new google.maps.LatLng(latitude, longitude);
64
+
65
+ // console.log(location[2]);
66
+ var marker = new google.maps.Marker({
67
+ position: myLatLng,
68
+ map: this.map,
69
+ title: displayInfoWindow?infoWindowContent.title:'Marker',
70
+ icon: icon
71
+ });
72
+
73
+ this.markers.push(marker);
74
+ this.locations.push(coordinates);
75
+
76
+ if (displayInfoWindow) {
77
+ var infowindow = new google.maps.InfoWindow({
78
+ content: infoWindowContent.content
79
+ });
80
+ marker.addListener('click', function() {
81
+ infowindow.open(this.map, marker);
82
+ if (typeof markerOnClickCallback == 'function') {
83
+ markerOnClickCallback();
84
+ }
85
+ });
86
+ }
87
+
88
+ return myLatLng;
89
+ }
90
+
91
+ centerOnFrance() {
92
+ this.map.setCenter({ lat: 46.52863469527167, lng: 2.43896484375});
93
+ this.map.setZoom(6);
94
+ // center: { lat: 46.52863469527167, lng: 2.43896484375},
95
+ // zoom: 6,
96
+ }
97
+
98
+ centerOnMarkers() {
99
+ if (this.locations.length == 0) {
100
+ if (this.map != null) {
101
+ this.centerOnFrance();
102
+ }
103
+ return;
104
+ }
105
+
106
+ var latlngbounds = new google.maps.LatLngBounds();
107
+ for (var i= 0; i < this.locations.length; i++) {
108
+ var locationCoordinates = this.locations[i].split(',');
109
+ latlngbounds.extend(new google.maps.LatLng(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1])));
110
+ }
111
+ this.map.setCenter(latlngbounds.getCenter());
112
+ this.map.fitBounds(latlngbounds);
113
+ }
114
+
115
+ connectMarkers() {
116
+ var prevLocation = null;
117
+ var listLineCoordinates = [];
118
+ for (var i= 0; i < this.locations.length; i++) {
119
+ var locationCoordinates = this.locations[i].split(',');
120
+ var myLatLng = new google.maps.LatLng(parseFloat(locationCoordinates[0]), parseFloat(locationCoordinates[1]));
121
+ if (prevLocation != null) {
122
+ listLineCoordinates.push([prevLocation, myLatLng]);
123
+ }
124
+ prevLocation = myLatLng;
125
+ }
126
+
127
+ for (var i= 0; i < listLineCoordinates.length; i++) {
128
+ var flightPlanCoordinates = [
129
+ listLineCoordinates[i][0],
130
+ listLineCoordinates[i][1],
131
+ ];
132
+ var flightPath = new google.maps.Polyline({
133
+ path: flightPlanCoordinates,
134
+ geodesic: true,
135
+ strokeColor: '#FF0000',
136
+ strokeOpacity: 1.0,
137
+ strokeWeight: 2
138
+ });
139
+ flightPath.setMap(this.map);
140
+ }
141
+ }
142
+ }
143
+
144
+ exports.GoogleMap = GoogleMap;
145
+
146
+ //deprecated
147
+ /*
148
+ google.maps.Map.prototype.markers = new Array();
149
+
150
+ google.maps.Map.prototype.getMarkers = function() {
151
+ return this.markers
152
+ };
153
+
154
+ google.maps.Map.prototype.clearMarkers = function() {
155
+ for(var i=0; i<this.markers.length; i++){
156
+ this.markers[i].setMap(null);
157
+ }
158
+ this.markers = new Array();
159
+ };
160
+
161
+ google.maps.Marker.prototype._setMap = google.maps.Marker.prototype.setMap;
162
+
163
+ google.maps.Marker.prototype.setMap = function(map) {
164
+ if (map) {
165
+ map.markers[map.markers.length] = this;
166
+ }
167
+ this._setMap(map);
168
+ }
169
+ */
@@ -0,0 +1,15 @@
1
+
2
+ var grecaptchaWidgets = [];
3
+
4
+ function grecaptchaOnload () {
5
+ if (typeof grecaptcha == 'undefined') {
6
+ console.log('var grecaptcha undefined');
7
+ return;
8
+ }
9
+ document.querySelectorAll('.grecaptcha').forEach(element => {
10
+ grecaptchaWidgets[element.id] = grecaptcha.render(element.id, googleReCaptchaDatas);
11
+ });
12
+ //$('.grecaptcha').each(function(idx, el) {
13
+ // grecaptchaWidgets[$(el).attr('id')] = grecaptcha.render($(el).attr('id'), googleReCaptchaDatas);
14
+ //});
15
+ }