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

period fixes

parent 216ab7b8
......@@ -488,25 +488,12 @@ var STWkit;
self.backwardButton.textContent = 'Backward';
self.forwardButton.onclick = function () {
self.forward = true;
var initDate = self.getInitDate();
self.from = initDate;
initDate.add(parseInt(self.durationHours.value), 'hours');
self.to = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.updateFromStartDate();
self.fireChangeFn(self);
};
self.backwardButton.onclick = function () {
self.forward = false;
var initDate = moment.utc();
var initDate = self.getInitDate();
self.to = initDate;
initDate.subtract(parseInt(self.durationHours.value), 'hours');
self.from = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.updateFromStartDate();
self.fireChangeFn(self);
};
var clearDiv = L.DomUtil.create('div', 'uk-clearfix', periodDiv);
......@@ -599,15 +586,6 @@ var STWkit;
});
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) {
var self = this;
if ((typeof changeCard.obsDateInput !== 'undefined') && (typeof changeCard.obsTimeInput !== 'undefined')) {
......@@ -668,8 +646,10 @@ var STWkit;
var sliderOpt = {};
sliderOpt['from'] = self.from.format("X");
sliderOpt['to'] = self.to.format("X");
self.slider.update(sliderOpt);
self.validate();
if (self.slider) {
self.slider.update(sliderOpt);
self.validate();
}
};
PeriodCard.prototype.adjustDateToRange = function () {
var self = this;
......@@ -725,22 +705,39 @@ var STWkit;
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 () {
var self = this;
_super.prototype.clear.call(this);
self.forward = true;
var initDate = self.getInitDate();
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);
}
self.updateFromStartDate();
if (document.body.contains(self.forwardButton))
self.forwardButton.click();
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 {
self.forwardButton.onclick = function () {
self.forward = true;
var initDate = self.getInitDate();
self.from = initDate;
initDate.add(parseInt(self.durationHours.value), 'hours');
self.to = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.updateFromStartDate();
self.fireChangeFn(self);
};
self.backwardButton.onclick = function () {
self.forward = false;
var initDate = moment.utc();
var initDate = self.getInitDate();
self.to = initDate;
initDate.subtract(parseInt(self.durationHours.value), 'hours');
self.from = initDate;
self.adjustDateToRange();
self.updateSlider();
self.validate();
self.updateFromStartDate();
self.fireChangeFn(self);
};
......@@ -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) {
var self = this;
......@@ -731,8 +709,10 @@ module STWkit {
var sliderOpt = {};
sliderOpt['from'] = self.from.format("X");
sliderOpt['to'] = self.to.format("X");
self.slider.update(sliderOpt);
self.validate();
if (self.slider) {
self.slider.update(sliderOpt);
self.validate();
}
}
......@@ -787,23 +767,42 @@ module STWkit {
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() {
var self = this;
super.clear();
self.forward = true;
var initDate = self.getInitDate();
self.startDateInput.value = initDate.format(self.dateFormat);
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.forward = true;
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
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);
}
self.updateFromStartDate();
if (document.body.contains(self.forwardButton)) self.forwardButton.click();
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