Commit 4ba200a5 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

period initial date fixes

parent 5ca02579
...@@ -552,15 +552,13 @@ var STWkit; ...@@ -552,15 +552,13 @@ var STWkit;
self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours() + ''; self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours() + '';
} }
} }
self.updateSlider(); self.updateFromStartDate();
}; };
self.startDateInput.onchange = function (evt) { self.startDateInput.onchange = function (evt) {
self.adjustDateToRange(); self.updateFromStartDate();
self.updateSlider();
}; };
self.startTimeInput.onchange = function (evt) { self.startTimeInput.onchange = function (evt) {
self.adjustDateToRange(); self.updateFromStartDate();
self.updateSlider();
}; };
UIkit.ready(function () { UIkit.ready(function () {
if (!self.ready) { if (!self.ready) {
...@@ -575,10 +573,13 @@ var STWkit; ...@@ -575,10 +573,13 @@ var STWkit;
sliderOpt['min'] = self.minDate.format("X"); sliderOpt['min'] = self.minDate.format("X");
sliderOpt['max'] = self.maxDate.format("X"); sliderOpt['max'] = self.maxDate.format("X");
self.slider.update(sliderOpt); self.slider.update(sliderOpt);
var initDate = self.getInitDate();
self.startDateInput.value = initDate.format(self.dateFormat);
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.durationHours.value = '0';
var startDatePicker = UIkit.datepicker(self.startDateInput, { minDate: self.minDate.format(self.dateFormat), maxDate: self.maxDate.format(self.dateFormat), format: self.dateFormat }); var startDatePicker = UIkit.datepicker(self.startDateInput, { minDate: self.minDate.format(self.dateFormat), maxDate: self.maxDate.format(self.dateFormat), format: self.dateFormat });
var startTimePicker = UIkit.timepicker(self.startTimeInput, {}); var startTimePicker = UIkit.timepicker(self.startTimeInput, {});
self.ready = true; self.ready = true;
self.clear();
self.defaults(); self.defaults();
} }
}); });
...@@ -652,7 +653,6 @@ var STWkit; ...@@ -652,7 +653,6 @@ var STWkit;
sliderOpt['to'] = self.to.format("X"); sliderOpt['to'] = self.to.format("X");
if (self.slider) { if (self.slider) {
self.slider.update(sliderOpt); self.slider.update(sliderOpt);
self.validate();
} }
}; };
PeriodCard.prototype.adjustDateToRange = function () { PeriodCard.prototype.adjustDateToRange = function () {
...@@ -674,9 +674,12 @@ var STWkit; ...@@ -674,9 +674,12 @@ var STWkit;
PeriodCard.prototype.defaults = function () { PeriodCard.prototype.defaults = function () {
var self = this; var self = this;
self.durationHours.value = '48'; self.durationHours.value = '48';
self.forward = true; if (document.body.contains(self.forwardButton))
self.adjustDateToRange(); self.forwardButton.click();
self.updateSlider(); else {
self.forward = true;
self.updateFromStartDate();
}
}; };
PeriodCard.prototype.populateCard = function (geojson) { PeriodCard.prototype.populateCard = function (geojson) {
var self = this; var self = this;
...@@ -722,7 +725,8 @@ var STWkit; ...@@ -722,7 +725,8 @@ var STWkit;
} }
self.adjustDateToRange(); self.adjustDateToRange();
self.updateSlider(); self.updateSlider();
self.validate(); if (self.ready)
self.validate();
}; };
PeriodCard.prototype.getInitDate = function () { PeriodCard.prototype.getInitDate = function () {
var self = this; var self = this;
...@@ -742,10 +746,6 @@ var STWkit; ...@@ -742,10 +746,6 @@ var STWkit;
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat); self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.durationHours.value = '0'; self.durationHours.value = '0';
self.updateFromStartDate(); self.updateFromStartDate();
if (document.body.contains(self.forwardButton))
self.forwardButton.click();
AccordionCard.enableNext(self.nextButton, false);
(self.oncallback && self.oncallback());
}; };
return PeriodCard; return PeriodCard;
}(AccordionCard)); }(AccordionCard));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -540,12 +540,12 @@ module STWkit { ...@@ -540,12 +540,12 @@ module STWkit {
self.backwardButton.textContent = 'Backward'; self.backwardButton.textContent = 'Backward';
self.forwardButton.onclick = function () { self.forwardButton.onclick = function () {
self.forward = true; self.forward = true;
self.updateFromStartDate(); self.updateFromStartDate();
}; };
self.backwardButton.onclick = function () { self.backwardButton.onclick = function () {
self.forward = false; self.forward = false;
self.updateFromStartDate(); self.updateFromStartDate();
}; };
var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', periodDiv); var clearDiv = <HTMLDivElement>L.DomUtil.create('div', 'uk-clearfix', periodDiv);
...@@ -606,17 +606,15 @@ module STWkit { ...@@ -606,17 +606,15 @@ module STWkit {
self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours() + ''; self.durationHours.value = moment.duration(self.to.diff(self.from)).asHours() + '';
} }
} }
self.updateSlider(); self.updateFromStartDate();
}; };
self.startDateInput.onchange = function (evt) { self.startDateInput.onchange = function (evt) {
self.adjustDateToRange(); self.updateFromStartDate();
self.updateSlider();
}; };
self.startTimeInput.onchange = function (evt) { self.startTimeInput.onchange = function (evt) {
self.adjustDateToRange(); self.updateFromStartDate();
self.updateSlider();
}; };
...@@ -635,10 +633,14 @@ module STWkit { ...@@ -635,10 +633,14 @@ module STWkit {
sliderOpt['min'] = self.minDate.format("X"); sliderOpt['min'] = self.minDate.format("X");
sliderOpt['max'] = self.maxDate.format("X"); sliderOpt['max'] = self.maxDate.format("X");
self.slider.update(sliderOpt); self.slider.update(sliderOpt);
var initDate = self.getInitDate();
self.startDateInput.value = initDate.format(self.dateFormat);
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.durationHours.value = '0';
var startDatePicker = UIkit.datepicker(<any>self.startDateInput, { minDate: self.minDate.format(self.dateFormat), maxDate: self.maxDate.format(self.dateFormat), format: self.dateFormat }); 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, {}); var startTimePicker = UIkit.timepicker(<any>self.startTimeInput, {});
self.ready = true; self.ready = true;
self.clear();
self.defaults(); self.defaults();
} }
}); });
...@@ -714,7 +716,6 @@ module STWkit { ...@@ -714,7 +716,6 @@ module STWkit {
sliderOpt['to'] = self.to.format("X"); sliderOpt['to'] = self.to.format("X");
if (self.slider) { if (self.slider) {
self.slider.update(sliderOpt); self.slider.update(sliderOpt);
self.validate();
} }
} }
...@@ -736,9 +737,14 @@ module STWkit { ...@@ -736,9 +737,14 @@ module STWkit {
public defaults() { public defaults() {
var self = this; var self = this;
self.durationHours.value = '48'; self.durationHours.value = '48';
self.forward = true;
self.adjustDateToRange(); if (document.body.contains(self.forwardButton))
self.updateSlider(); self.forwardButton.click();
else {
self.forward = true;
self.updateFromStartDate();
}
} }
public populateCard(geojson) { public populateCard(geojson) {
...@@ -784,7 +790,7 @@ module STWkit { ...@@ -784,7 +790,7 @@ module STWkit {
self.adjustDateToRange(); self.adjustDateToRange();
self.updateSlider(); self.updateSlider();
self.validate(); if (self.ready) self.validate();
} }
private getInitDate() { private getInitDate() {
...@@ -806,10 +812,6 @@ module STWkit { ...@@ -806,10 +812,6 @@ module STWkit {
self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat); self.startTimeInput.value = initDate.startOf('hour').format(self.timeFormat);
self.durationHours.value = '0'; self.durationHours.value = '0';
self.updateFromStartDate(); self.updateFromStartDate();
if (document.body.contains(self.forwardButton)) self.forwardButton.click();
AccordionCard.enableNext(self.nextButton, false);
(self.oncallback && self.oncallback());
} }
} }
......
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