cards.ts 28.3 KB
Newer Older
Tomas Pettersson's avatar
Tomas Pettersson committed
1
2
3
4
5
6
/// <reference path="../def/stwkit.d.ts" />
/// <reference path="../def/uikit.d.ts" />
/// <reference path="../def/leaflet.d.ts" />
/// <reference path="../def/leaflet-forcing-boundary.d.ts" />
/// <reference path="../def/moment.d.ts" />

Tomas Pettersson's avatar
Tomas Pettersson committed
7
8
module STWkit {
    class AccordionCard  {
Tomas Pettersson's avatar
Tomas Pettersson committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    private content: any;
    public status: boolean;
    public title: HTMLDivElement;
    public badgeSpan: HTMLSpanElement;
    public titleIcon: HTMLSpanElement;
    private changeListeners: Array<Object>;
    public disabled: boolean;

    constructor(id, label, parent, content) {
        this.status = false;
        var container = <HTMLDivElement>STWkit.DomUtil.create('div', 'accordion-card', parent);
        this.title = <HTMLDivElement>STWkit.DomUtil.create('h5', 'uk-accordion-title uk-width-1-1 chevron-title', container);
        this.title.id = id;
        this.badgeSpan = <HTMLSpanElement>STWkit.DomUtil.create('span', 'uk-badge', this.title);
        var titleSpan = <HTMLSpanElement>STWkit.DomUtil.create('span', 'title', this.title);
        titleSpan.textContent = '  ' + label;
        this.titleIcon = <HTMLSpanElement>STWkit.DomUtil.create('span', 'uk-icon-chevron-down chevron-icon', this.title);
        var accContent = <HTMLDivElement>STWkit.DomUtil.create('div', 'uk-accordion-content uk-padding-remove', container);
        accContent.appendChild(content);
        this.content = content;
        this.hide();
        this.changeListeners = [];
    }

    public addChangeFnListener(listener) {
        this.changeListeners.push(listener);
    }

    public fireChangeFn(changeCard) {
        for (var i = 0; i < this.changeListeners.length; i++) {
            var listener: any = this.changeListeners[i];
            listener.changeFn(changeCard);
        }
    }

    public addLabelDiv(parentDiv, labelTxt, labelInfo) {
        var self = this;
        var label = <HTMLLabelElement>STWkit.DomUtil.create('label', 'uk-form-label form-label', parentDiv);
        label.textContent = labelTxt;
        var addPositionInfo = <HTMLSpanElement>STWkit.DomUtil.create('span', 'uk-icon-hover uk-icon-info-circle', parentDiv);
        addPositionInfo.onclick = function () {
            AccordionCard.infoMsg(labelTxt, labelInfo);
        };
    };

    static infoMsg(title: string, msg: string) {
        return UIkit.notify("<span class='uk-icon-small uk-icon-info-circle'></span> <b>" + title + "</b><p>" + msg, { status: 'info', timeout: 10000 });
    }
    static warningMsg(title: string, msg: string) {
        return UIkit.notify("<span class='uk-icon-small uk-icon-info-circle'></span> <b>" + title + "</b><p>" + msg, { status: 'warning', timeout: 10000 });
    }

    static enableNext(button: HTMLButtonElement, enable) {
        var isEnabled = button.classList.contains('next-enabled');
        if (enable && !isEnabled) {
            button.classList.add('next-enabled');
        }
        if (!enable && isEnabled) {
            button.classList.remove('next-enabled');
        }
    }

    static isEnabled(button: HTMLButtonElement) {
        return button.classList.contains('next-enabled');
    }

    public clear() {
        this.status = false;
    }

    public hide() {
        this.title.style.display = 'none';
        this.content.style.display = 'none';
    }
    public show() {
        this.title.style.display = 'block';
        this.content.style.display = 'block';
    }

    public visible() {
        return (this.title.style.display == 'block')
    }

Tomas Pettersson's avatar
Tomas Pettersson committed
92
    }
Tomas Pettersson's avatar
Tomas Pettersson committed
93

Tomas Pettersson's avatar
Tomas Pettersson committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    export class LocationCard extends AccordionCard {
        private control: any;
        public oncallback: Function;
        public nextButton: any;
        public polygonButton: HTMLButtonElement;
        public pointButton: HTMLButtonElement;
        public lineButton: HTMLButtonElement;
        public exitControl: L.Control;
        public obsDateInput: HTMLInputElement;
        public obsTimeInput: HTMLInputElement;
        public dateFormat: string;
        public timeFormat: string;
        public datetimeFormat: string;
        public datetimeTFormat: string;
        public hasPosition: boolean;
        public geometryType: string;
        private satObs: any;
        private satDetectionContent: HTMLDivElement;
        private satDetectionChevronIcon: HTMLSpanElement;    
        private forcingBoundary: any;
    
        constructor(id, parentDiv, lang, langData, map, forcing, obs) {
            var locationDiv = <HTMLDivElement>STWkit.DomUtil.create('div', 'uk-width-1-1 uk-margin-top', parentDiv);
            super(id, 'Specify time and location', parentDiv, locationDiv);
            var self = this;
    
            if (forcing) self.forcingBoundary = new Forcing.Boundary(locationDiv, map, forcing);            
            
    
            var satCallbackFn = function(latlngs, geojsonfeature, timestamp, id){
                self.clear();
                var geojson:any = {};
                geojson["type"] = "FeatureCollection";
                geojson["features"] = [];
                geojson["features"].push(geojsonfeature);
                var observation = {
                    "id": id,
                    "provider": "EMSA",
                    "providerDataRef": null,
                    "providerImgRef": null,
                    "providerType": null,
                    "type": "SAT",
                    "date": moment.utc(timestamp).valueOf()
                };
                geojson.features[0].properties["observation"] = [];
                geojson.features[0].properties["observation"].push(observation);
                geojson.features[0].properties["simulation"] = {};            
                self.populateCard(geojson);
Tomas Pettersson's avatar
Tomas Pettersson committed
142
            };
Tomas Pettersson's avatar
Tomas Pettersson committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
            
            function legendBox(fieldset: HTMLFieldSetElement, color, text, size) {
                var rowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row uk-margin-remove', fieldset);
                var legendBox = <HTMLDivElement>L.DomUtil.create('div', 'legend-box', rowDiv);
                legendBox.style.backgroundColor = color;
                legendBox.style.width = size;
                legendBox.style.height = size;
                legendBox.title = text;
                var legendText = <HTMLDivElement>L.DomUtil.create('div', 'legend-text', rowDiv);
                legendText.textContent = text;
            }
    
    
            if (obs && obs.sat) {
                self.satObs = new Observation.Sat(map, satCallbackFn, 'observation/oo');       
                var satDetectionDiv = <HTMLDivElement>L.DomUtil.create('div', '', locationDiv);
                var satDetectionList = <HTMLDListElement>L.DomUtil.create('dl', 'uk-description-list-line', satDetectionDiv);
                var satDetectionItem = <HTMLDListElement>L.DomUtil.create('dt', '', satDetectionList);
                var satDetectionHeading = <HTMLHeadingElement>L.DomUtil.create('h5', 'uk-width-1-1 chevron-title', satDetectionItem);
                satDetectionHeading.textContent = "Satellite oil detections";
                self.satDetectionChevronIcon = <HTMLSpanElement>L.DomUtil.create('span', 'uk-icon-chevron-down chevron-icon', satDetectionHeading);
                self.satDetectionContent = <HTMLDivElement>L.DomUtil.create('div', 'uk-animation-fade', satDetectionItem);
                self.satDetectionContent.style.display = 'none';
                satDetectionHeading.onclick = function (evt) {
                    if (self.satDetectionChevronIcon.classList.contains('uk-icon-chevron-down')) {
                        self.satDetectionChevronIcon.classList.remove('uk-icon-chevron-down');
                        self.satDetectionChevronIcon.classList.add('uk-icon-chevron-up');
                        self.satDetectionContent.style.display = "";
                        self.satObs.show();     
                    } else {
                        self.satDetectionChevronIcon.classList.remove('uk-icon-chevron-up');
                        self.satDetectionChevronIcon.classList.add('uk-icon-chevron-down');
                        self.satDetectionContent.style.display = 'none';
                        self.satObs.hide();     
                    }
                };
Tomas Pettersson's avatar
Tomas Pettersson committed
179
        
Tomas Pettersson's avatar
Tomas Pettersson committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
                var satDetectionform = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', self.satDetectionContent);
                satDetectionform.onsubmit = function (e) {
                    e.preventDefault();
                    e.stopPropagation();
                    return false;
                };
                
                var satDetectionfieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', satDetectionform);
                var satDetectionRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row uk-margin-top', satDetectionfieldset);
                super.addLabelDiv(satDetectionRowDiv, "Detection frequency", "See more information <a style='color:#faa732;' href='help/classic/#oil-oo-satdetection' target='_blank'>here</a>");
                legendBox(satDetectionfieldset, 'rgb(255, 0, 0)', 'Past day', '10px');
                legendBox(satDetectionfieldset, 'rgb(255, 153, 0)', 'Past week', '10px');
                legendBox(satDetectionfieldset, 'rgb(255, 255, 0)', 'Two weeks', '10px');
                legendBox(satDetectionfieldset, 'rgb(255, 255, 204)', 'Older', '10px');
Tomas Pettersson's avatar
Tomas Pettersson committed
194
    
Tomas Pettersson's avatar
Tomas Pettersson committed
195
196
197
198
199
            }
                
    
            var obsform = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', locationDiv);
            obsform.onsubmit = function (e) {
Tomas Pettersson's avatar
Tomas Pettersson committed
200
201
202
203
                e.preventDefault();
                e.stopPropagation();
                return false;
            };
Tomas Pettersson's avatar
Tomas Pettersson committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
            self.datetimeFormat = 'YYYY-MM-DD HH:mm';
            self.datetimeTFormat = 'YYYY-MM-DDTHH:mm:ss.000';
            self.dateFormat = 'YYYY-MM-DD';
            self.timeFormat = 'HH:mm';
            var obsdateLabelGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid', obsform);
            var obsfieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', obsform);
            var obsdateRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', obsfieldset);
            super.addLabelDiv(obsdateRowDiv, "Observation time (UTC)", "See more information <a style='color:#faa732;' href='help/classic/#oil-oo-time' target='_blank'>here</a>");
            var obsdateDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-controls uk-form-icon uk-width-1-1', obsdateRowDiv);
            obsdateDiv.id = 'guideoo1';
            var obsdateIcon = <HTMLSpanElement>L.DomUtil.create('span', 'uk-icon-calendar', obsdateDiv);
            self.obsDateInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-2', obsdateDiv);
            self.obsDateInput.type = 'text';
            self.obsDateInput.placeholder = self.dateFormat;
            self.obsTimeInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-2', obsdateDiv);
            self.obsTimeInput.type = 'text';
    
            var typeLabelGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid uk-margin-top', obsform);
            var objectlabelDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2', typeLabelGrid);
            super.addLabelDiv(objectlabelDiv, "Outlet type", "See more information <a style='color:#faa732;' href='help/classic/#oil-oo-type' target='_blank'>here</a>");
            var typeDiv = <HTMLDivElement>L.DomUtil.create('div', '', obsform);
            typeDiv.id = 'guidefo1';
            typeDiv.setAttribute('data-uk-button-radio', '');
            var typeButtonGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid uk-grid-small', typeDiv);
            var objectbuttonsDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2', typeButtonGrid);
            var objectButtonGroup = <HTMLDivElement>L.DomUtil.create('div', 'uk-button-group', objectbuttonsDiv);
            self.pointButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', objectButtonGroup);
            self.pointButton.textContent = 'Single';
    
            self.lineButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', objectButtonGroup);
            self.lineButton.textContent = 'Line';
            self.lineButton.disabled = false;
    
            self.polygonButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', objectButtonGroup);
            self.polygonButton.textContent = 'Area';
    
            self.pointButton.onclick = function () { self.geometryType = "point"; self.control.setType(self.geometryType); }
            self.lineButton.onclick = function () { self.geometryType = "linestring"; self.control.setType(self.geometryType); }
            self.polygonButton.onclick = function () { self.geometryType = "polygon"; self.control.setType(self.geometryType); }
            self.polygonButton.disabled = false;
    
            self.hasPosition = false;
            function validate() {
                var date = moment.utc(self.obsDateInput.value + ' ' + self.obsTimeInput.value, self.datetimeFormat);
                if (!date.isValid()) return;
                if (!self.hasPosition) return;
                self.status = true;
                AccordionCard.enableNext(self.nextButton, true);
                (self.oncallback && self.oncallback());
            };
            var positionLabelGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid uk-margin-top', obsform);
    
            var positionlabelDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1', positionLabelGrid);
            super.addLabelDiv(positionlabelDiv, "Position", "See more information <a style='color:#faa732;' href='help/classic/#oil-oo-position' target='_blank'>here</a>");
            var positionDiv: any = <HTMLDivElement>L.DomUtil.create('div', '', obsform);
            positionDiv.id = 'guideoo2';
            var positionButtonGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid uk-grid-small', positionDiv);
            var latlonDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2', positionButtonGrid);
            var drawDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2', positionButtonGrid);
            // var importDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-3', positionButtonGrid);
            var latlngButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', latlonDiv);
            latlngButton.textContent = 'Enter manually';
            var drawButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small uk-align-right uk-margin-remove', drawDiv);
            drawButton.textContent = 'Free hand draw';
            // var importButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', importDiv);
            // importButton.textContent = 'Import';
    
            positionDiv.guideFn = function () {
                var geojson = {};
                geojson["type"] = "FeatureCollection";
                geojson["features"] = [];
                var feature = {};
                feature['type'] = "Feature";
                feature['geometry'] = {};
                feature['geometry']['type'] = "Point";
                feature['geometry']['coordinates'] = [];
                feature['geometry']['coordinates'].push(19.0);
                feature['geometry']['coordinates'].push(56.0);
                geojson["features"].push(feature);
                self.control.addGeoJSON(geojson);
            }
    
            var bbox = {};
            bbox['s'] = -90;
            bbox['n'] = 90;
            bbox['w'] = -180;
            bbox['e'] = 180;
            if (forcing) bbox = forcing.features[0].properties.bbox;
    
            self.control = new L.Control.Coordinates({
                "lang": lang,
                "langdata": langData.coordinates,
                "id": id,
                "inline": true,
                "bbox" : bbox,
                "table": true,
                "type": false,
                "buttons": false,
                "tabs": false,
                "callback": function (latlngs, geojson) {
                    self.hasPosition = false;
                    if (latlngs.length > 0) {
                        var toggleevt = document.createEvent("CustomEvent");
                        toggleevt.initCustomEvent('container:toggleVisibility', false, false, {
                            'show': true
                        });
                        window.dispatchEvent(toggleevt);
                        self.fireChangeFn(self);
                        if (self.exitControl) map.removeControl(self.exitControl);
                        self.exitControl = null;
                        var coordinates = [];
                        switch (self.geometryType) {
                            case 'point':
                                coordinates.push([latlngs[0][0].lng, latlngs[0][0].lat]);
                                break;
                            case 'multipoint':
                                coordinates = geojson.features[0].geometry.coordinates;
                                break;
                            case 'linestring':
                                var center = L.polyline(latlngs).getBounds().getCenter()
                                coordinates.push([center.lng, center.lat]);
                                break;
                            case 'polygon':
                                var center = L.polygon(latlngs).getBounds().getCenter();   
                                coordinates.push([center.lng, center.lat]);
                                break;
                        
                            default:
                                break;
                        }
                        if (self.forcingBoundary) self.forcingBoundary.validate(coordinates);
                        self.control.showTable();
                        self.hasPosition = true;
                        validate();
Tomas Pettersson's avatar
Tomas Pettersson committed
338
339
340
                    }
                }
            });
Tomas Pettersson's avatar
Tomas Pettersson committed
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
            var content = self.control.onAdd(map);
            var coordinateDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-margin-top uk-margin-bottom', locationDiv);
            coordinateDiv.appendChild(content);
            self.control.hideTable();
    
            latlngButton.onclick = function () { self.control.latlng(); };
            drawButton.onclick = function () {
                var toggleevt = document.createEvent("CustomEvent");
                toggleevt.initCustomEvent('container:toggleVisibility', false, false, {
                    'show': false
                });
                window.dispatchEvent(toggleevt);
                if (self.forcingBoundary) self.forcingBoundary.show();
                self.control.draw();
                self.exitControl = new L.Control({ position: 'bottomright' });
                self.exitControl.onAdd = function (map: L.Map) {
                    var container = L.DomUtil.create('div', 'exit-control');
                    var exitPanel = L.DomUtil.create('div', 'uk-panel uk-panel-box', container);
                    var finnishButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small uk-button-primary uk-margin-right', exitPanel);
                    finnishButton.textContent = 'Finnish';
                    finnishButton.onclick = function (e) {
                        map.fire('draw:canceled');
                    };
                    finnishButton.style.display = 'none';
                    // 3 is multipoint type in coordinates control
                    if (self.control.getType() == 3) finnishButton.style.display = '';
                    var cancelButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-button-small', exitPanel);
                    cancelButton.textContent = 'Cancel';
                    cancelButton.onclick = function (e) {
                        if (self.exitControl) map.removeControl(self.exitControl);
                        self.exitControl = null;
                        var toggleevt = document.createEvent("CustomEvent");
                        toggleevt.initCustomEvent('container:toggleVisibility', false, false, {
                            'show': true
                        });
                        window.dispatchEvent(toggleevt);
                        self.clear();
                    };
    
                    L.DomEvent.disableClickPropagation(container);
                    return container;
Tomas Pettersson's avatar
Tomas Pettersson committed
382
                };
Tomas Pettersson's avatar
Tomas Pettersson committed
383
384
                self.exitControl.addTo(map);
    
Tomas Pettersson's avatar
Tomas Pettersson committed
385
            };
Tomas Pettersson's avatar
Tomas Pettersson committed
386
387
388
389
390
391
392
393
394
395
396
397
398
            // importButton.onclick = function(){self.control.import();};
            var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', locationDiv);
            var clearButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-margin-top uk-align-left', clearDiv);
            clearButton.textContent = 'Clear';
            clearButton.onclick = function () {
                self.clear();
            };
            self.nextButton = <HTMLButtonElement>L.DomUtil.create('button', 'uk-button uk-margin-top uk-align-right', clearDiv);
            self.nextButton.textContent = 'Next';
            self.nextButton.id = 'guideoo3';
    
            self.nextButton.guideFn = function () {
                self.nextButton.click();
Tomas Pettersson's avatar
Tomas Pettersson committed
399
            }
Tomas Pettersson's avatar
Tomas Pettersson committed
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
    
            AccordionCard.enableNext(self.nextButton, false);
    
            self.nextButton.onclick = function () {
                if (!AccordionCard.isEnabled(self.nextButton)) {
                    AccordionCard.warningMsg('Mandatory fields missing',
                        'Specify a location by <b>manually entering</b> position or <b>draw</b> on the map.');
                    return;
                }
                if (self.forcingBoundary) self.forcingBoundary.hide();
                (self.oncallback && self.oncallback(true));
            };
            UIkit.ready(function () {
                var startDatePicker = UIkit.datepicker(<any>self.obsDateInput, { format: self.dateFormat });
                var startTimePicker = UIkit.timepicker(<any>self.obsTimeInput, {});
    
                self.defaults();
            });
    
Tomas Pettersson's avatar
Tomas Pettersson committed
419
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
420
421
422
    
        public show() {
            super.show();
Tomas Pettersson's avatar
Tomas Pettersson committed
423
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
    
        public hide() {
            super.hide();
        }
    
    
        public defaults() {
            var self = this;
            if (document.body.contains(self.pointButton)) self.pointButton.click();
            var initDate = moment.utc();
            self.obsDateInput.value = initDate.format(self.dateFormat);
            self.obsTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
        }
    
        public populateCard(geojson) {
            var self = this;
            var simulation = geojson.features[0].properties.simulation;
            var observation = geojson.features[0].properties.observation[0];
            var date = moment.utc(observation.date).format(self.dateFormat);
            self.obsDateInput.value = date;
            var time = moment.utc(observation.date).format(self.timeFormat);
            self.obsTimeInput.value = time;
            var type = geojson.features[0].geometry.type.toLowerCase();
            switch (type) {
                case "point":
                self.pointButton.click();
                break;
                case "linestring":
                self.lineButton.click();
                break;
                case "polygon":
                self.polygonButton.click();
                break;
                default:
                break;
            }
            self.control.setType(type);
            self.control.addGeoJSON(geojson);
Tomas Pettersson's avatar
Tomas Pettersson committed
462
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    
        public populateData(geojson) {
            var self = this;
            var json = self.control.getGeoJSON();
            for (var i = 0; i < json.features.length; i++) {
                json.features[i]["properties"] = {};
                geojson.features.push(json.features[i]);
            }
    
            var observation = {
                "id": null,
                "provider": "USER",
                "providerDataRef": null,
                "providerImgRef": null,
                "providerType": null,
                "type": "MANUAL",
                "date": moment.utc(self.obsDateInput.value + ' ' + self.obsTimeInput.value, self.datetimeFormat).valueOf()
    
            };
            geojson.features[0].properties["observation"] = [];
            geojson.features[0].properties["observation"].push(observation);
            geojson.features[0].properties["simulation"] = {};
    
Tomas Pettersson's avatar
Tomas Pettersson committed
486
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    
        public clear() {
            var self = this;
            super.clear();
            if (self.satObs) {
                if (self.satDetectionChevronIcon.classList.contains('uk-icon-chevron-up')) {
                    self.satDetectionChevronIcon.classList.remove('uk-icon-chevron-up');
                    self.satDetectionChevronIcon.classList.add('uk-icon-chevron-down');
                    self.satDetectionContent.style.display = 'none';
                    self.satObs.hide();
                }     
            }   
            if (self.forcingBoundary) self.forcingBoundary.hide();        
            var initDate = moment.utc();
            self.obsDateInput.value = initDate.format(self.dateFormat);
            self.obsTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
            self.control.clear();
            self.control.hideTable();
            if (self.nextButton) AccordionCard.enableNext(self.nextButton, false);
            (self.oncallback && self.oncallback());
        }
    
    
Tomas Pettersson's avatar
Tomas Pettersson committed
510
    }
Tomas Pettersson's avatar
Tomas Pettersson committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
    
    
   export  class CardControl extends L.Control {
    
        private lang: string;
        private langData: any;
        private domain: string;
        private cardMap: any;
        
        constructor(options) {
            super(options);
            this.domain = "HELCOM";
            if (options.domain) {
                this.domain = options.domain;
            }
            this.lang = "en";
            if (options.lang) {
                this.lang = options.lang;
Tomas Pettersson's avatar
Tomas Pettersson committed
529
            }
Tomas Pettersson's avatar
Tomas Pettersson committed
530
531
532
533
            if (options.langdata) {
                this.langData = options.langdata;
            } 
            this.cardMap = {};               
Tomas Pettersson's avatar
Tomas Pettersson committed
534
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    
        private updateBadgeStatus() {
            var self = this;
            var min = 0, count = 0;
            for (var i in self.cardMap) {
                if (self.cardMap.hasOwnProperty(i)) {
                    count++;
                    var classList = self.cardMap[i].badgeSpan.classList;
                    if (classList.contains('uk-icon-check')) classList.remove('uk-icon-check');
                    if (classList.contains('uk-icon-square-o')) classList.remove('uk-icon-square-o');
                    if (classList.contains('badge-neutral')) classList.remove('badge-neutral');
                    if (classList.contains('uk-badge-warning')) classList.remove('uk-badge-warning');
                    if (classList.contains('uk-badge-success')) classList.remove('uk-badge-success');
                    if (min == 0 && !self.cardMap[i].status) min = count;
Tomas Pettersson's avatar
Tomas Pettersson committed
549
                }
Tomas Pettersson's avatar
Tomas Pettersson committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
            }
            count = 0;
            for (var i in self.cardMap) {
                if (self.cardMap.hasOwnProperty(i)) {
                    count++;
                    var classList = self.cardMap[i].badgeSpan.classList;
                    if (count == min) {
                        classList.add('uk-icon-square-o');
                        classList.add('uk-badge-warning');
    
                    }
                    else if (self.cardMap[i].status) {
                        classList.add('uk-icon-check');
                        classList.add('uk-badge-success');
                    } else {
                        classList.add('uk-icon-square-o');
                        classList.add('badge-neutral');
                    }
Tomas Pettersson's avatar
Tomas Pettersson committed
568
569
570
                }
            }
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
571
572
573
574
575
576
577
578
579
    
        private openCard(id, open) {
            var self = this;
            for (var i in self.cardMap) {
                if (self.cardMap.hasOwnProperty(i)) {
                    if (self.cardMap[i].titleIcon.classList.contains('uk-icon-chevron-up')) {
                        self.cardMap[i].titleIcon.classList.remove('uk-icon-chevron-up');
                        self.cardMap[i].titleIcon.classList.add('uk-icon-chevron-down');
                    }
Tomas Pettersson's avatar
Tomas Pettersson committed
580
581
                }
            }
Tomas Pettersson's avatar
Tomas Pettersson committed
582
583
584
585
586
            if (open) {
                if (self.cardMap[id].titleIcon.classList.contains('uk-icon-chevron-down')) {
                    self.cardMap[id].titleIcon.classList.remove('uk-icon-chevron-down');
                    self.cardMap[id].titleIcon.classList.add('uk-icon-chevron-up');
                }
Tomas Pettersson's avatar
Tomas Pettersson committed
587
588
            }
        }
Tomas Pettersson's avatar
Tomas Pettersson committed
589
590
    
    
Tomas Pettersson's avatar
Tomas Pettersson committed
591
592
    }

Tomas Pettersson's avatar
Tomas Pettersson committed
593
}
Tomas Pettersson's avatar
Tomas Pettersson committed
594