leaflet-oilspill-cards.ts 43.4 KB
Newer Older
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
1 2 3 4 5 6 7 8 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
/// <reference path="def/uikit.d.ts" />
/// <reference path="def/leaflet.d.ts" />
/// <reference path="def/moment.d.ts" />
/// <reference path="def/reqwest.d.ts" />


class OilSpillCard {
    private content: any;
    public status: boolean;
    private title: HTMLDivElement;
    public badgeSpan: HTMLSpanElement;
    public titleIcon: HTMLSpanElement;

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

    public addLabelDiv(parentDiv, labelTxt, labelInfo){
        var self = this;
        var label = <HTMLLabelElement>L.DomUtil.create('label', 'uk-form-label form-label', parentDiv);
        label.textContent = labelTxt;        
        var addPositionInfo = <HTMLSpanElement>L.DomUtil.create('span', 'uk-icon-hover uk-icon-info-circle', parentDiv);
        addPositionInfo.onclick = function() {
                OilSpillCard.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')
    }


}

class OSLocation extends OilSpillCard {
    private control : any;
    public oncallback : Function;
Tomas Pettersson's avatar
Tomas Pettersson committed
83
    public nextButton : any;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
84 85 86 87 88 89 90 91 92
    public polygonButton : HTMLButtonElement;
    public pointButton : HTMLButtonElement;
    public multipointButton : HTMLButtonElement;
    public lineButton : HTMLButtonElement;
    public exitControl : L.Control;
    public obsDateInput : HTMLInputElement;    
    public obsTimeInput : HTMLInputElement; 
    public depthInput : HTMLInputElement; 
    public dateFormat : string;    
Tomas Pettersson's avatar
Tomas Pettersson committed
93 94 95 96
    public timeFormat : string;    
    public datetimeFormat : string;    
    public hasPosition : boolean;    

Tomas Pettersson's avatar
first  
Tomas Pettersson committed
97 98 99 100 101 102 103 104 105 106 107 108


    constructor(id, parentDiv, lang, langData, map) {
        var locationDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1 uk-margin-top', parentDiv);
        super(id, 'Specify time and location', parentDiv ,locationDiv);
        var self = this;
        var form = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', locationDiv);
        form.onsubmit = function(e){
            e.preventDefault();
            e.stopPropagation();
            return false;
        };
Tomas Pettersson's avatar
Tomas Pettersson committed
109
        self.datetimeFormat = 'YYYY-MM-DD HH:mm';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
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
        self.dateFormat = 'YYYY-MM-DD';
        self.timeFormat = 'HH:mm';        
        var obsdateLabelGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid', form);
        var fieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', form);
        var obsdateRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);        
        super.addLabelDiv(obsdateRowDiv, "Observation time (UTC)", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-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 = 'guideos1';
        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 depthRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);        
        super.addLabelDiv(depthRowDiv, "Outlet depth (m)", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-depth' target='_blank'>here</a>");
        var depthDiv = <HTMLDivElement>L.DomUtil.create('div', ' uk-width-1-1', depthRowDiv);
        self.depthInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-4', depthDiv);
        self.depthInput.type = 'number';
        self.depthInput.value = '0';
        self.depthInput.min = '0';

        self.depthInput.onchange = function() {
            validate();
        };

Tomas Pettersson's avatar
Tomas Pettersson committed
136
        self.hasPosition = false;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
137 138 139
        function validate() {
            var value = parseInt(self.depthInput.value);
            if (value < 0) self.depthInput.value = "0";
Tomas Pettersson's avatar
Tomas Pettersson committed
140 141 142
            var date = moment.utc(self.obsDateInput.value+' '+ self.obsTimeInput.value, self.datetimeFormat);
            if (!date.isValid()) return;
            if (!self.hasPosition) return;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
143 144 145 146 147 148
            self.status = true;
            OilSpillCard.enableNext(self.nextButton, true);
            (self.oncallback && self.oncallback());
        };

        UIkit.ready( function(){
Tomas Pettersson's avatar
Tomas Pettersson committed
149 150
            var startDatePicker = UIkit.datepicker(<any>self.obsDateInput, {  format: self.dateFormat });
            var startTimePicker = UIkit.timepicker(<any> self.obsTimeInput, { });
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
151

Tomas Pettersson's avatar
Tomas Pettersson committed
152
            self.defaults();
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
153 154 155 156 157 158
        });        
        var positionLabelGrid = <HTMLDivElement>L.DomUtil.create('div', 'uk-grid uk-margin-top', form);
        
        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/#object-fo-position' target='_blank'>here</a>");
        var positionDiv:any = <HTMLDivElement>L.DomUtil.create('div', '', form);
Tomas Pettersson's avatar
Tomas Pettersson committed
159
        positionDiv.id = 'guideos2';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        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);
        }
        self.control = new L.Control.Coordinates({
            "lang": lang,
            "langdata": langData.coordinates,
            "id": id,
			"inline" : true,
			"table" : true,
			"type" : false,
			"buttons" : false,
			"tabs" : false,
			"callback": function(latlngs, geojson) {
Tomas Pettersson's avatar
Tomas Pettersson committed
195
                self.hasPosition = false;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
196 197 198 199 200 201 202 203 204
                if (latlngs.length > 0) {
                    var toggleevt = document.createEvent("CustomEvent");
                    toggleevt.initCustomEvent('container:toggleVisibility', false, false, {
                        'show': true
                    });
                    window.dispatchEvent(toggleevt);
                    if (self.exitControl) map.removeControl(self.exitControl);
                    self.exitControl = null;
                    self.control.showTable();
Tomas Pettersson's avatar
Tomas Pettersson committed
205
                    self.hasPosition = true;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
206
                    validate();                
Tomas Pettersson's avatar
Tomas Pettersson committed
207
                } 
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
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
			}
        });
        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);
            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;
            };
            self.exitControl.addTo(map);

        };
        // 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';
Tomas Pettersson's avatar
Tomas Pettersson committed
263
        self.nextButton.id = 'guideos3';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
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

        self.nextButton.guideFn = function(){
            self.nextButton.click();
        }

        OilSpillCard.enableNext(self.nextButton, false);
        
        self.nextButton.onclick = function() {
            if (!OilSpillCard.isEnabled(self.nextButton)) {
                OilSpillCard.warningMsg('Mandatory fields missing',
                'Specify a location by <b>manually entering</b> position or <b>draw</b> on the map.');
                return;
            }

            (self.oncallback && self.oncallback(true));
        };
    }

    public defaults() {
        var self = this;
        self.control.setType("point");
        var initDate = moment.utc();
        self.obsDateInput.value = initDate.format(self.dateFormat);
        self.obsTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
        self.depthInput.value = '0';

    }

    public populateCard(geojson) {
        var self = this;
        self.control.addGeoJSON(geojson);
        var type = geojson.features[0].geometry.type.toLowerCase();
        switch (type) {
            case "point":
                self.pointButton.click();
                break;
            case "multipoint":
                self.multipointButton.click();
                break;
            case "linestring":
                self.lineButton.click();
                break;
            case "polygon":
                self.polygonButton.click();
                break;
            default:
                break;
        }
    }

    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]);
Tomas Pettersson's avatar
Tomas Pettersson committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
        } 

        var observation = {
            "id": null,
            "provider": "USER",
            "providerDataRef": null,
            "providerImgRef": null,
            "providerType": null,
            "type": "MANUAL",
            "date": 1495538160000
        };
        geojson.features[0].properties["simulation"] = {};
        geojson.features[0].properties["simulation"]["depth"] = self.depthInput.value;
        geojson.features[0].properties["observation"] = {};
        geojson.features[0].properties["observation"].push(observation);
      
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
336 337 338 339 340 341 342 343
    }

    public clear() {
        var self = this;
        super.clear();
        var initDate = moment.utc();
        self.obsDateInput.value = initDate.format(self.dateFormat);
        self.obsTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
Tomas Pettersson's avatar
Tomas Pettersson committed
344
        self.depthInput.value = '0';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
345 346 347 348 349 350 351 352 353 354 355
        self.control.clear();
        self.control.hideTable();
        if (self.nextButton) OilSpillCard.enableNext(self.nextButton, false);
        (self.oncallback && self.oncallback());
    }


}

class OSPeriod extends OilSpillCard {
    public oncallback : Function;
Tomas Pettersson's avatar
Tomas Pettersson committed
356
    public nextButton : any;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    public forward : any;
    public from : any;
    public to : any;
    public durationHours : HTMLInputElement;    
    public startDateInput : HTMLInputElement;    
    public startTimeInput : HTMLInputElement;    
    public datetimeFormat : string;    
    public dateFormat : string;    
    public timeFormat : string;    
    public minDate : any;    
    public maxDate : any;    
    public slider : any;    

    constructor(id, parentDiv, lang, map) {
        var periodDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1 uk-margin-top', parentDiv);
        super(id, 'Simulation period', parentDiv ,periodDiv);
        var self = this;
        var form = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', periodDiv);
        form.onsubmit = function(e){
            e.preventDefault();
            e.stopPropagation();
            return false;
        };
        self.datetimeFormat = 'YYYY-MM-DD HH:mm';
        self.dateFormat = 'YYYY-MM-DD';
        self.timeFormat = 'HH:mm';
        self.minDate = moment.utc().startOf('hour').subtract(72,'hours');
        self.maxDate = moment.utc().startOf('hour').add(240,'hours');
        var fieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', form);
        var availableRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        super.addLabelDiv(availableRowDiv, "Selected period (UTC)", "See more information <a style='color:#faa732;' href='help/classic/#object-fo-period' target='_blank'>here</a>");
        var availableDiv = <HTMLDivElement>L.DomUtil.create('div', '', availableRowDiv);
        var startRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        super.addLabelDiv(startRowDiv, "Start date (UTC)", "See more information <a style='color:#faa732;' href='help/classic/#object-fo-start' target='_blank'>here</a>");
        var startDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-controls uk-form-icon uk-width-1-1', startRowDiv);
        var startIcon = <HTMLSpanElement>L.DomUtil.create('span', 'uk-icon-calendar', startDiv);
        self.startDateInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-2', startDiv);
        self.startDateInput.type = 'text';
        self.startDateInput.placeholder = self.dateFormat;
        self.startTimeInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-2', startDiv);
         self.startTimeInput.type = 'text';
        var durationRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        super.addLabelDiv(durationRowDiv, "Duration", "See more information <a style='color:#faa732;' href='help/classic/#object-fo-duration' target='_blank'>here</a>");
        var durationDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-controls uk-form-icon uk-width-1-1', durationRowDiv);
Tomas Pettersson's avatar
Tomas Pettersson committed
401
        durationDiv.id = 'guideos4';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
        var durationIcon = <HTMLSpanElement>L.DomUtil.create('span', 'uk-icon-clock-o', durationDiv);
        self.durationHours = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-2-6', durationDiv);
        self.durationHours.type = 'number';
        self.durationHours.value = '48';
        self.durationHours.min = '0';
        self.durationHours.step = '12';
        var hoursSpan = <HTMLInputElement>L.DomUtil.create('span', 'uk-width-1-6', durationDiv);
        hoursSpan.textContent = " hours";  
        var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', periodDiv);
        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';
Tomas Pettersson's avatar
Tomas Pettersson committed
418
        self.nextButton.id = 'guideos6';   
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
419 420 421 422 423 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 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
        self.nextButton.guideFn = function(){
            self.nextButton.click();
        }             
        OilSpillCard.enableNext(self.nextButton, false);
        self.nextButton.onclick = function() {
            if (!OilSpillCard.isEnabled(self.nextButton)) {
                OilSpillCard.warningMsg('Mandatory fields missing',
                'Specify a valid <b>start date</b> and <b>duration</b> period.');
                return;
            }

            (self.oncallback && self.oncallback(true));
        };

        self.clear();

        $(availableDiv).ionRangeSlider({
            min: +self.minDate.utc().format("X"),
            max: +self.maxDate.utc().format("X"),
            from: +self.from.utc().format("X"),
            to: +self.to.utc().format("X"),
            disable: true,
            step: 1800,            
            grid: false,
            type: "double",
            force_edges: true,              
            prettify: function (num) {
                return moment(num, "X").utc().format(self.datetimeFormat);
            }                      
        });

        self.slider = $(availableDiv).data("ionRangeSlider");
        self.durationHours.onchange = function() {
            var date = moment.utc(self.startDateInput.value+' '+ self.startTimeInput.value, self.datetimeFormat);
            if (self.forward) {
                date.add(parseInt(self.durationHours.value),'hours');
                if (self.isDateValid(date)) {
                    self.to = date;
                } else {
                    self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours()+'';
                }
            } else {
                date.subtract(parseInt(self.durationHours.value),'hours');
                if (self.isDateValid(date)) {
                    self.from = date;
                } else {
                    self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours()+'';
                }
            }
            self.updateSlider();
        };

        self.startDateInput.onchange = function(evt) {
            self.adjustDateToRange();
            self.updateSlider();
        };

        self.startTimeInput.onchange = function(evt) {
            self.adjustDateToRange();
            self.updateSlider();
        };
        UIkit.ready(function() {
            reqwest({
                url: "availableTimes/ms/HELCOM_NEMO",
                method: 'get',
                type: 'json',
                success: function (data) {
                    self.minDate = moment.utc(data.availableTime.start);
                    self.maxDate = moment.utc(data.availableTime.stop);
                    var sliderOpt = {};
                    sliderOpt['min'] = self.minDate.format("X");
                    sliderOpt['max'] = self.maxDate.format("X");
                    self.slider.update(sliderOpt);    
                }
            }); 

            var startDatePicker = UIkit.datepicker(<any>self.startDateInput, { minDate: self.minDate.format(self.dateFormat), maxDate: self.maxDate.format(self.dateFormat), format: self.dateFormat });
            var startTimePicker = UIkit.timepicker(<any> self.startTimeInput, { });
            self.defaults()
        });
    }

    private isDateValid(date) {
        var self = this;
        if (!date.isValid()) return false;
        if (date.isBefore(self.minDate) || date.isAfter(self.maxDate)) return false;
        return true;
    }        

    private getValidDateInfo() {
        var self = this;
        var result:any = {};
        result.valid = false;
        var date = moment.utc(self.startDateInput.value+' '+ self.startTimeInput.value, self.datetimeFormat);
        (self.forward)? date.add(parseInt(self.durationHours.value),'hours'):date.subtract(parseInt(self.durationHours.value),'hours');
        result.date = date;
        if (self.isDateValid(date)) {
            result.valid = true;
        }
        return result;
    }


    private validate() {
        var self = this;
        self.status = false;
        OilSpillCard.enableNext(self.nextButton, false);
        var dateinfo = self.getValidDateInfo();
        if (typeof dateinfo.valid == 'undefined') {
            (self.oncallback && self.oncallback());
            return;
        };
        if (moment.duration(self.to.diff(self.from)).asHours() == 0) {
            (self.oncallback && self.oncallback());
            return;
        };
        if (!dateinfo.valid) {
            self.from = moment.utc(self.slider.result.from*1000);
            self.to = moment.utc(self.slider.result.to*1000);
            var duration = moment.duration(self.to.diff(self.from)).asHours();
            self.durationHours.value = duration+'';
            if (duration == 0) return;
        }
        self.status = true;
        OilSpillCard.enableNext(self.nextButton, true);
        (self.oncallback && self.oncallback());
    }

    private updateSlider() {
        var self = this;
        var sliderOpt = {};
        sliderOpt['from'] = self.from.format("X");
        sliderOpt['to'] = self.to.format("X");
        self.slider.update(sliderOpt);     
        self.validate();             
    }


    private adjustDateToRange() {
        var self = this;
        var date = moment.utc(self.startDateInput.value+' '+ self.startTimeInput.value, self.datetimeFormat);
        if (date.isBefore(self.minDate))  self.startTimeInput.value = self.minDate.startOf('hour').format(self.timeFormat);
        if (date.isAfter(self.maxDate))  self.startTimeInput.value = self.maxDate.startOf('hour').format(self.timeFormat);
        if (self.forward) {
            self.from = date.clone();
            self.to = date.add(self.durationHours.value, 'hours');
        } else {
            self.to = date.clone();
            self.from = date.subtract(self.durationHours.value, 'hours');
        }
    }

    public defaults(){
        var self = this;
        self.durationHours.value = '48';
Tomas Pettersson's avatar
Tomas Pettersson committed
574
        self.forward = true;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
        self.adjustDateToRange();
        self.updateSlider();
    }

    public populateCard(geojson) {
        var self = this;
        var simulation = geojson.features[0].properties.simulation;
        var startDate = moment.utc(simulation.startDate);
        var stopDate = moment.utc(simulation.stopDate);
        var forward = simulation.forwardCalculation;
        if (forward) {
            self.from = startDate;
            self.to = stopDate;
            self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours()+'';
        } else {
            self.from = stopDate;
            self.to = startDate;
            self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours()+'';
        }
    }

    public populateData(geojson) {
        var self = this;
        geojson.features[0].properties["simulation"]["forwardCalculation"] = self.forward;
        geojson.features[0].properties["simulation"]["startDate"] = self.from.valueOf();
        geojson.features[0].properties["simulation"]["stopDate"] = self.to.valueOf();
        if (!self.forward) {
            geojson.features[0].properties["simulation"]["startDate"] = self.to.valueOf();
            geojson.features[0].properties["simulation"]["stopDate"] = self.from.valueOf();
        } 
    }

    public clear() {
        var self = this;
        super.clear();
        var initDate = moment.utc();
        if (initDate.isBefore(self.minDate) ||initDate.isAfter(self.maxDate)) initDate = self.minDate; 
        self.startDateInput.value = initDate.format(self.dateFormat);
         self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
        self.forward = true;
        self.durationHours.value = '0';
        self.from = initDate.clone(); 
        self.to = initDate.clone().add(self.durationHours.value, 'hours');    
        if (self.slider) {
            var sliderOpt = {};
            sliderOpt['from'] = self.from.format("X");
            sliderOpt['to'] = self.to.format("X");
            self.slider.update(sliderOpt);               
        }
        OilSpillCard.enableNext(self.nextButton, false);        
        (self.oncallback && self.oncallback());
    }
}

class OSType extends OilSpillCard {
    public oncallback : Function;
Tomas Pettersson's avatar
Tomas Pettersson committed
631
    public nextButton : any;
Tomas Pettersson's avatar
Tomas Pettersson committed
632 633
    public selectOilClass : HTMLSelectElement;
    public selectOilSpecific : HTMLSelectElement;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
634 635

    constructor(id, parentDiv, lang, map) {
Tomas Pettersson's avatar
Tomas Pettersson committed
636 637
        var oiltypeDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1 uk-margin-top', parentDiv);
        super(id, 'Type of oil', parentDiv ,oiltypeDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
638
        var self = this;
Tomas Pettersson's avatar
Tomas Pettersson committed
639
        var form = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', oiltypeDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
640 641 642 643 644 645 646
        form.onsubmit = function(e){
            e.preventDefault();
            e.stopPropagation();
            return false;
        };
        
        var fieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', form);
Tomas Pettersson's avatar
Tomas Pettersson committed
647 648 649 650
        var oiltypeRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        var switchOiltype = <HTMLUListElement>L.DomUtil.create('ul', 'uk-tab', oiltypeRowDiv);
        switchOiltype.setAttribute('data-uk-tab',"{connect:'#osoiltype-switch'}");
        var oilClass = <HTMLAnchorElement>L.DomUtil.create('a', '', L.DomUtil.create('li', '', switchOiltype));
Tomas Pettersson's avatar
Tomas Pettersson committed
651
        oilClass.id = 'osOilClassTab';
Tomas Pettersson's avatar
Tomas Pettersson committed
652 653
        oilClass.textContent = 'Oil class';
        var specificOil = <HTMLAnchorElement>L.DomUtil.create('a', '', L.DomUtil.create('li', '', switchOiltype));
Tomas Pettersson's avatar
Tomas Pettersson committed
654
        specificOil.id = 'osOilSpecificTab';
Tomas Pettersson's avatar
Tomas Pettersson committed
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
        specificOil.textContent = 'Specific oil';
        var contentOiltype = <HTMLUListElement>L.DomUtil.create('ul', 'uk-switcher', oiltypeRowDiv);
        contentOiltype.id = 'osoiltype-switch';

        function addOption(parent, value, txt ) {
            var option = <HTMLOptionElement>L.DomUtil.create('option', '', parent);
            option.value = value;
            option.textContent = txt;
        }
    
        var contentoilClass = <HTMLLIElement>L.DomUtil.create('li', 'uk-margin-top', contentOiltype);
        super.addLabelDiv(contentoilClass, "Select oil class", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-oilclass' target='_blank'>here</a>");
        var divOilClass = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-select', contentoilClass);
        divOilClass.setAttribute('data-uk-form-select','');
        var selectedOilClass = <HTMLSpanElement>L.DomUtil.create('span', '', divOilClass);
Tomas Pettersson's avatar
Tomas Pettersson committed
670 671 672 673 674 675
        self.selectOilClass = <HTMLSelectElement>L.DomUtil.create('select', '', divOilClass);
        self.selectOilClass.size = 3;
        self.selectOilClass.style.width = '240px';
        addOption(self.selectOilClass,'Light oils (0-100 cSt)', 'Light oils (0-100 cSt)');
        addOption(self.selectOilClass,'Medium oils (100-1000 cSt)', 'Medium oils (100-1000 cSt)');
        addOption(self.selectOilClass,'Heavy oils (>1000 cSt)', 'Heavy oils (>1000 cSt)');
Tomas Pettersson's avatar
Tomas Pettersson committed
676 677 678 679 680 681

        var contentspecificOil = <HTMLLIElement>L.DomUtil.create('li', 'uk-margin-top', contentOiltype);
        super.addLabelDiv(contentspecificOil, "Select specific oil", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-specificoil' target='_blank'>here</a>");
        var divOilSpecific = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-select', contentspecificOil);
        divOilSpecific.setAttribute('data-uk-form-select','');
        var selectedOilSpecific = <HTMLSpanElement>L.DomUtil.create('span', '', divOilSpecific);
Tomas Pettersson's avatar
Tomas Pettersson committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
        self.selectOilSpecific = <HTMLSelectElement>L.DomUtil.create('select', '', divOilSpecific);
        self.selectOilSpecific.size = 3;
        self.selectOilSpecific.style.width = '240px';
        addOption(self.selectOilSpecific,'GASOLINE', 'Gasoline (700.0 kg/m³)');
        addOption(self.selectOilSpecific,'JET FUEL AND KEROSINE', 'Jet Fuel and Kerosene (802.0 kg/m³)');
        addOption(self.selectOilSpecific,'LIGHT DIESEL FUEL', 'Light Diesel Fuel (852.5 kg/m³)');
        addOption(self.selectOilSpecific,'FUEL OIL NO. 2', 'Fuel Oil no. 2 (852.5 kg/m³)');
        addOption(self.selectOilSpecific,'LIGHT-MEDIUM CRUDE', 'Light-medium Crude (864.0 kg/m³)');
        addOption(self.selectOilSpecific,'LUBRICATING OIL', 'Lubricating Oil (872.0 kg/m³)');
        addOption(self.selectOilSpecific,'INTERMEDIATE OIL', 'Intermediate Oil (904.0 kg/m³)');
        addOption(self.selectOilSpecific,'BUNKER B', 'Bunker B (914.0 kg/m³)');
        addOption(self.selectOilSpecific,'BUNKER C', 'Bunker C (986.2 kg/m³)');
        addOption(self.selectOilSpecific,'HEAVY CRUDE', 'Heavy Crude (990.0 kg/m³)');
        addOption(self.selectOilSpecific,'ASPHALT', 'Asphalt (1000.0 kg/m³)');
        addOption(self.selectOilSpecific,'ORIMULSION (TEST)', 'Orimulsion (test) (1020.0 kg/m³)');
        addOption(self.selectOilSpecific,'HIGH VISCOSITY FUEL OIL (TEST)', 'High Viscosity Fuel Oil (test) (1015.0 kg/m³)');
        addOption(self.selectOilSpecific,'BALDER (IKU-96)', 'Balder (IKU-96)');
        addOption(self.selectOilSpecific,'EKOFISK BLEND 2000', 'Ekofisk Blend 2000');
        addOption(self.selectOilSpecific,'GRANE (SINTEF)', 'Grane (SINTEF)');
        addOption(self.selectOilSpecific,'GULLFAKS A-B', 'Gullfaks A-B');
        addOption(self.selectOilSpecific,'GULLFAKS SOER (IKU)', 'Gullfaks Soer (IKU)');
        addOption(self.selectOilSpecific,'KRISTIN_CORR', 'Kristin_Corr');
        addOption(self.selectOilSpecific,'NORNE (IKU)', 'Norne (IKU)');
        addOption(self.selectOilSpecific,'OSEBERG A (IKU)', 'Oseberg A');
        addOption(self.selectOilSpecific,'SLEIPNER (IKU)', 'Sleipner (IKU)');
        addOption(self.selectOilSpecific,'STATFJORD A', 'Statfjord A');
        addOption(self.selectOilSpecific,'ULA (IKU)', 'Ula (IKU)');
        addOption(self.selectOilSpecific,'VALHALL 2000', 'Valhall 2000');
        addOption(self.selectOilSpecific,'AASGARD 2002', 'Aasgard 2002');
        addOption(self.selectOilSpecific,'DUC (IKU)', 'Duc (IKU)');
        addOption(self.selectOilSpecific,'SIRI', 'Siri');
        addOption(self.selectOilSpecific,'SOUTH ARNE 5C', 'South Arne 5C');
        addOption(self.selectOilSpecific,'SOUTH ARNE 13C', 'South Arne 13C');
        addOption(self.selectOilSpecific,'FUEL OIL NO 6LS (IKU)', 'Fuel Oil No 6LS (IKU)');
        addOption(self.selectOilSpecific,'IF 180-LS ESSO (SINTEF)', 'IF 180-LS Esso (SINTEF)');
        addOption(self.selectOilSpecific,'IF 180-NS ESSO (SINTEF)', 'IF 180-NS Esso (SINTEF)');
        addOption(self.selectOilSpecific,'IF-180 SHELL', 'IF-180 Shell');
        addOption(self.selectOilSpecific,'IF-380 HEAVY FUEL OIL', 'IF-380 Heavy Fuel Oil');
        addOption(self.selectOilSpecific,'IF-30 BUNKER (IKU)', 'IF-30 Bunker (IKU)');
        addOption(self.selectOilSpecific,'MARINE DIESEL (IKU)', 'Marine diesel (IKU)');
        addOption(self.selectOilSpecific,'IFO 380 FU SHAN HAI', 'Ifo 380 Fu Shan Hai');

        // var oilstateRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        // super.addLabelDiv(oilstateRowDiv, "State of oil", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-oilstate' target='_blank'>here</a>");
        // var oilstateDiv = <HTMLDivElement>L.DomUtil.create('div', '', oilstateRowDiv);
        // oilstateDiv.id = 'guideos7'; 
Tomas Pettersson's avatar
Tomas Pettersson committed
728 729 730


        var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', oiltypeDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
731 732 733 734 735 736
        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);
Tomas Pettersson's avatar
Tomas Pettersson committed
737
        self.nextButton.id = 'guideos8'; 
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
738 739 740 741 742 743 744 745
        self.nextButton.textContent = 'Next';
        self.nextButton.guideFn = function(){
            self.nextButton.click();
        }        
        OilSpillCard.enableNext(self.nextButton, false);
        self.nextButton.onclick = function() {
            if (!OilSpillCard.isEnabled(self.nextButton)) {
                OilSpillCard.warningMsg('Mandatory fields missing',
Tomas Pettersson's avatar
Tomas Pettersson committed
746
                'Specify a valid <b>oil class</b> or <b>specific oil</b>.');
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
747 748 749 750 751 752 753
                return;
            }

            (self.oncallback && self.oncallback(true));
        };

        UIkit.ready(function() {
Tomas Pettersson's avatar
Tomas Pettersson committed
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
            self.defaults();
            $(switchOiltype).on('show.uk.switcher', function(event, area){
                self.clear();                
            });
            self.selectOilClass.onchange = function(evt){
                self.status = true;
                OilSpillCard.enableNext(self.nextButton, true);
                (self.oncallback && self.oncallback());
            };
            self.selectOilSpecific.onchange = function(evt){
                self.status = true;
                OilSpillCard.enableNext(self.nextButton, true);
                (self.oncallback && self.oncallback());
            };

Tomas Pettersson's avatar
first  
Tomas Pettersson committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782
        });

    }

    public defaults() {
        var self = this;
    }
    public populateCard(geojson) {
        var self = this;
        var simulation = geojson.features[0].properties.simulation;
    }

    public populateData(geojson) {
        var self = this;
Tomas Pettersson's avatar
Tomas Pettersson committed
783 784 785 786 787 788 789 790
        if (self.selectOilClass.selectedIndex !== -1) {
            geojson.features[0].properties["simulation"]["oilclass"] = 'Oil classes';
            geojson.features[0].properties["simulation"]["oilclass"] = self.selectOilClass.options[self.selectOilClass.selectedIndex].value;
        }
        if (self.selectOilSpecific.selectedIndex !== -1) {
            geojson.features[0].properties["simulation"]["oilclass"] = 'Oil, specific';
            geojson.features[0].properties["simulation"]["oilclass"] = self.selectOilSpecific.options[self.selectOilSpecific.selectedIndex].value;
        }
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
791 792 793 794 795 796
    }


    public clear() {
        var self = this;
        super.clear();
Tomas Pettersson's avatar
Tomas Pettersson committed
797 798
        self.selectOilClass.selectedIndex = -1;
        self.selectOilSpecific.selectedIndex = -1;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
799 800 801 802 803 804 805 806 807
        OilSpillCard.enableNext(self.nextButton, false);
        self.status = false;
        (self.oncallback && self.oncallback());
    }
}


class OSAmount extends OilSpillCard {
    public oncallback : Function;
Tomas Pettersson's avatar
Tomas Pettersson committed
808 809
    public amountInput : HTMLInputElement;
    public durationInput : HTMLInputElement;
Tomas Pettersson's avatar
Tomas Pettersson committed
810 811
    public amountSelect : HTMLSelectElement;
    public durationSelect : HTMLSelectElement;
Tomas Pettersson's avatar
Tomas Pettersson committed
812
    public nextButton : any;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
813 814

    constructor(id, parentDiv, lang, map) {
Tomas Pettersson's avatar
Tomas Pettersson committed
815 816
        var amountDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1 uk-margin-top', parentDiv);
        super(id, 'Amount', parentDiv ,amountDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
817
        var self = this;
Tomas Pettersson's avatar
Tomas Pettersson committed
818
        var form = <HTMLFormElement>L.DomUtil.create('form', 'uk-form uk-form-stacked', amountDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
819 820 821 822 823 824
        form.onsubmit = function(e){
            e.preventDefault();
            e.stopPropagation();
            return false;
        };
        
Tomas Pettersson's avatar
Tomas Pettersson committed
825 826 827 828 829
        function addOption(parent, value, txt ) {
            var option = <HTMLOptionElement>L.DomUtil.create('option', '', parent);
            option.value = value;
            option.textContent = txt;
        }
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
830 831


Tomas Pettersson's avatar
Tomas Pettersson committed
832 833 834 835 836 837 838 839 840 841 842 843
        var fieldset = <HTMLFieldSetElement>L.DomUtil.create('fieldset', '', form);
        var amountRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        super.addLabelDiv(amountRowDiv, "Total amount/rate", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-totalamount' target='_blank'>here</a>");
        var amountValueDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-1', amountRowDiv);
        amountValueDiv.id = 'guideos7'; 
        self.amountInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-4', amountValueDiv);
        self.amountInput.type = 'number';
        self.amountInput.step = '100';
        self.amountInput.min = '0';
        var amountUnitDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2 uk-form-select select', amountValueDiv);
        amountUnitDiv.setAttribute('data-uk-form-select','');
        var selectedAmountUnit = <HTMLSpanElement>L.DomUtil.create('span', '', amountUnitDiv);
Tomas Pettersson's avatar
Tomas Pettersson committed
844 845 846 847 848 849 850
        self.amountSelect = <HTMLSelectElement>L.DomUtil.create('select', '', amountUnitDiv);
        addOption(self.amountSelect, 'm3', '');
        addOption(self.amountSelect, 'tonnes', 'tonnes');
        addOption(self.amountSelect, 'm3/hour', 'm³ / hour');
        addOption(self.amountSelect, 'tonnes/hour', 'tonnes / hour');
        addOption(self.amountSelect, 'm3/day', 'm³ / day');
        addOption(self.amountSelect, 'tonnes/day', 'tonnes / day');
Tomas Pettersson's avatar
Tomas Pettersson committed
851 852 853 854 855 856 857 858 859 860 861 862
        
        var durationRowDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-form-row', fieldset);
        super.addLabelDiv(durationRowDiv, "Duration", "See more information <a style='color:#faa732;' href='help/classic/#oil-os-amount-duration' target='_blank'>here</a>");
        var durationDiv = <HTMLDivElement>L.DomUtil.create('div', '', durationRowDiv);
        durationDiv.id = 'guideos7'; 
        self.durationInput = <HTMLInputElement>L.DomUtil.create('input', 'uk-width-1-4', durationDiv);
        self.durationInput.type = 'number';
        self.durationInput.step = '1';
        self.durationInput.min = '0';
        var durationUnitDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-width-1-2 uk-form-select select', durationDiv);
        durationUnitDiv.setAttribute('data-uk-form-select','');
        var selectedDurationUnit = <HTMLSpanElement>L.DomUtil.create('span', '', durationUnitDiv);
Tomas Pettersson's avatar
Tomas Pettersson committed
863 864 865
        self.durationSelect = <HTMLSelectElement>L.DomUtil.create('select', '', durationUnitDiv);
        addOption(self.durationSelect, 'hours', 'hours');
        addOption(self.durationSelect, 'days', 'days');
Tomas Pettersson's avatar
Tomas Pettersson committed
866 867 868 869 870

        self.amountInput.onchange = function() {
            validate();
        };
        self.durationInput.onchange = function() {
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
871 872 873 874
            validate();
        };

        function validate() {
Tomas Pettersson's avatar
Tomas Pettersson committed
875 876 877 878 879 880 881 882 883 884 885 886 887
            var amountValue = parseInt(self.amountInput.value);
            var amountOk = false;
            if (amountValue < 0) self.amountInput.value = "0";
            if (amountValue > 0) amountOk = true;
            var durationValue = parseInt(self.durationInput.value);
            var durationOk = false;
            if (durationValue < 0) self.durationInput.value = "0";
            if (durationValue > 0) durationOk = true;
            if (amountOk && durationOk) {
                self.status = true;
                OilSpillCard.enableNext(self.nextButton, true);
                (self.oncallback && self.oncallback());
            }
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
888 889 890
        };


Tomas Pettersson's avatar
Tomas Pettersson committed
891
        var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', amountDiv);
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
892 893 894 895 896 897
        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);
Tomas Pettersson's avatar
Tomas Pettersson committed
898
        self.nextButton.id = 'guideos8'; 
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
899 900 901 902 903 904 905 906
        self.nextButton.textContent = 'Next';
        self.nextButton.guideFn = function(){
            self.nextButton.click();
        }        
        OilSpillCard.enableNext(self.nextButton, false);
        self.nextButton.onclick = function() {
            if (!OilSpillCard.isEnabled(self.nextButton)) {
                OilSpillCard.warningMsg('Mandatory fields missing',
Tomas Pettersson's avatar
Tomas Pettersson committed
907
                'Specify a valid <b>amount</b> and <b>duration</b>.');
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
                return;
            }

            (self.oncallback && self.oncallback(true));
        };

        UIkit.ready(function() {
           self.defaults();
        });

    }

    public defaults() {
        var self = this;
    }
    public populateCard(geojson) {
        var self = this;
        var simulation = geojson.features[0].properties.simulation;
    }

    public populateData(geojson) {
        var self = this;
Tomas Pettersson's avatar
Tomas Pettersson committed
930 931 932 933
        geojson.features[0].properties["simulation"]["amount"] = self.amountInput.value;
        geojson.features[0].properties["simulation"]["amountUnit"] = self.amountSelect.options[self.amountSelect.selectedIndex].value;
        geojson.features[0].properties["simulation"]["duration"] = self.durationInput.value;
        geojson.features[0].properties["simulation"]["durationUnit"] = self.durationSelect.options[self.durationSelect.selectedIndex].value;
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
934 935 936 937 938 939
    }


    public clear() {
        var self = this;
        super.clear();
Tomas Pettersson's avatar
Tomas Pettersson committed
940 941
        self.amountInput.value = '';
        self.durationInput.value = '';
Tomas Pettersson's avatar
first  
Tomas Pettersson committed
942 943 944 945 946
        OilSpillCard.enableNext(self.nextButton, false);
        self.status = false;
        (self.oncallback && self.oncallback());
    }
}