Commit ea05d579 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

period fixes

parent 216ab7b8
...@@ -488,25 +488,12 @@ var STWkit; ...@@ -488,25 +488,12 @@ var STWkit;
self.backwardButton.textContent = 'Backward'; self.backwardButton.textContent = 'Backward';
self.forwardButton.onclick = function () { self.forwardButton.onclick = function () {
self.forward = true; self.forward = true;
var initDate = self.getInitDate(); self.updateFromStartDate();
self.from = initDate;
initDate.add(parseInt(self.durationHours.value), 'hours');
self.to = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.fireChangeFn(self); self.fireChangeFn(self);
}; };
self.backwardButton.onclick = function () { self.backwardButton.onclick = function () {
self.forward = false; self.forward = false;
var initDate = moment.utc(); self.updateFromStartDate();
var initDate = self.getInitDate();
self.to = initDate;
initDate.subtract(parseInt(self.durationHours.value), 'hours');
self.from = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.fireChangeFn(self); self.fireChangeFn(self);
}; };
var clearDiv = L.DomUtil.create('div', 'uk-clearfix', periodDiv); var clearDiv = L.DomUtil.create('div', 'uk-clearfix', periodDiv);
...@@ -599,15 +586,6 @@ var STWkit; ...@@ -599,15 +586,6 @@ var STWkit;
}); });
return _this; return _this;
} }
PeriodCard.prototype.getInitDate = function () {
var self = this;
var initDate = moment.utc();
if (self.obsdate)
initDate = self.obsdate;
if (initDate.isBefore(self.minDate) || initDate.isAfter(self.maxDate))
initDate = self.minDate;
return initDate;
};
PeriodCard.prototype.changeFn = function (changeCard) { PeriodCard.prototype.changeFn = function (changeCard) {
var self = this; var self = this;
if ((typeof changeCard.obsDateInput !== 'undefined') && (typeof changeCard.obsTimeInput !== 'undefined')) { if ((typeof changeCard.obsDateInput !== 'undefined') && (typeof changeCard.obsTimeInput !== 'undefined')) {
...@@ -668,8 +646,10 @@ var STWkit; ...@@ -668,8 +646,10 @@ var STWkit;
var sliderOpt = {}; var sliderOpt = {};
sliderOpt['from'] = self.from.format("X"); sliderOpt['from'] = self.from.format("X");
sliderOpt['to'] = self.to.format("X"); sliderOpt['to'] = self.to.format("X");
self.slider.update(sliderOpt); if (self.slider) {
self.validate(); self.slider.update(sliderOpt);
self.validate();
}
}; };
PeriodCard.prototype.adjustDateToRange = function () { PeriodCard.prototype.adjustDateToRange = function () {
var self = this; var self = this;
...@@ -725,22 +705,39 @@ var STWkit; ...@@ -725,22 +705,39 @@ var STWkit;
geojson.features[0].properties["simulation"]["stopDate"] = self.from.valueOf(); geojson.features[0].properties["simulation"]["stopDate"] = self.from.valueOf();
} }
}; };
PeriodCard.prototype.updateFromStartDate = function () {
var self = this;
var date = moment.utc(self.startDateInput.value + ' ' + self.startTimeInput.value, self.datetimeFormat);
if (self.forward) {
self.from = date.clone();
self.to = date.clone().add(self.durationHours.value, 'hours');
}
else {
self.to = date.clone();
self.from = date.clone().subtract(parseInt(self.durationHours.value), 'hours');
}
self.adjustDateToRange();
self.updateSlider();
self.validate();
};
PeriodCard.prototype.getInitDate = function () {
var self = this;
var initDate = moment.utc();
if (self.obsdate)
initDate = self.obsdate;
if (initDate.isBefore(self.minDate) || initDate.isAfter(self.maxDate))
initDate = self.minDate;
return initDate;
};
PeriodCard.prototype.clear = function () { PeriodCard.prototype.clear = function () {
var self = this; var self = this;
_super.prototype.clear.call(this); _super.prototype.clear.call(this);
self.forward = true;
var initDate = self.getInitDate(); var initDate = self.getInitDate();
self.startDateInput.value = initDate.format(self.dateFormat); self.startDateInput.value = initDate.format(self.dateFormat);
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat); self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.forward = true;
self.durationHours.value = '0'; self.durationHours.value = '0';
self.from = initDate.clone(); self.updateFromStartDate();
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);
}
if (document.body.contains(self.forwardButton)) if (document.body.contains(self.forwardButton))
self.forwardButton.click(); self.forwardButton.click();
AccordionCard.enableNext(self.nextButton, false); AccordionCard.enableNext(self.nextButton, false);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -540,27 +540,12 @@ module STWkit { ...@@ -540,27 +540,12 @@ module STWkit {
self.forwardButton.onclick = function () { self.forwardButton.onclick = function () {
self.forward = true; self.forward = true;
var initDate = self.getInitDate(); self.updateFromStartDate();
self.from = initDate;
initDate.add(parseInt(self.durationHours.value), 'hours');
self.to = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.fireChangeFn(self); self.fireChangeFn(self);
}; };
self.backwardButton.onclick = function () { self.backwardButton.onclick = function () {
self.forward = false; self.forward = false;
var initDate = moment.utc(); self.updateFromStartDate();
var initDate = self.getInitDate();
self.to = initDate;
initDate.subtract(parseInt(self.durationHours.value), 'hours');
self.from = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.fireChangeFn(self); self.fireChangeFn(self);
}; };
...@@ -663,13 +648,6 @@ module STWkit { ...@@ -663,13 +648,6 @@ module STWkit {
}); });
} }
private getInitDate() {
var self = this;
var initDate = moment.utc();
if (self.obsdate) initDate = self.obsdate;
if (initDate.isBefore(self.minDate) || initDate.isAfter(self.maxDate)) initDate = self.minDate;
return initDate;
}
public changeFn(changeCard) { public changeFn(changeCard) {
var self = this; var self = this;
...@@ -731,8 +709,10 @@ module STWkit { ...@@ -731,8 +709,10 @@ module STWkit {
var sliderOpt = {}; var sliderOpt = {};
sliderOpt['from'] = self.from.format("X"); sliderOpt['from'] = self.from.format("X");
sliderOpt['to'] = self.to.format("X"); sliderOpt['to'] = self.to.format("X");
self.slider.update(sliderOpt); if (self.slider) {
self.validate(); self.slider.update(sliderOpt);
self.validate();
}
} }
...@@ -787,23 +767,42 @@ module STWkit { ...@@ -787,23 +767,42 @@ module STWkit {
geojson.features[0].properties["simulation"]["stopDate"] = self.from.valueOf(); geojson.features[0].properties["simulation"]["stopDate"] = self.from.valueOf();
} }
} }
private updateFromStartDate() {
var self = this;
var date = moment.utc(self.startDateInput.value + ' ' + self.startTimeInput.value, self.datetimeFormat)
if (self.forward) {
self.from = date.clone();
self.to = date.clone().add(self.durationHours.value, 'hours');
} else {
self.to = date.clone();
self.from = date.clone().subtract(parseInt(self.durationHours.value), 'hours');
}
self.adjustDateToRange();
self.updateSlider();
self.validate();
}
private getInitDate() {
var self = this;
var initDate = moment.utc();
if (self.obsdate) initDate = self.obsdate;
if (initDate.isBefore(self.minDate) || initDate.isAfter(self.maxDate)) initDate = self.minDate;
return initDate;
}
public clear() { public clear() {
var self = this; var self = this;
super.clear(); super.clear();
self.forward = true;
var initDate = self.getInitDate(); var initDate = self.getInitDate();
self.startDateInput.value = initDate.format(self.dateFormat); self.startDateInput.value = initDate.format(self.dateFormat);
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat); self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.forward = true;
self.durationHours.value = '0'; self.durationHours.value = '0';
self.from = initDate.clone(); self.updateFromStartDate();
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);
}
if (document.body.contains(self.forwardButton)) self.forwardButton.click(); if (document.body.contains(self.forwardButton)) self.forwardButton.click();
AccordionCard.enableNext(self.nextButton, false); AccordionCard.enableNext(self.nextButton, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment