[Time Controller] Keep inputs in sync

Keep inputs in sync with displayed data in time controller,
without overwriting user-entered text. nasa/openmctweb#181
This commit is contained in:
Victor Woeltjen 2015-10-21 15:22:00 -07:00
parent f88e8ebb51
commit 06bcd28558

View File

@ -101,6 +101,25 @@ define(
return { start: bounds.start, end: bounds.end }; return { start: bounds.start, end: bounds.end };
} }
function updateBoundsTextForProperty(ngModel, property) {
try {
if (!$scope.boundsModel[property] ||
parseTimestamp($scope.boundsModel[property]) !==
ngModel.outer[property]) {
$scope.boundsModel[property] =
formatTimestamp(ngModel.outer[property]);
}
} catch (e) {
// User-entered text is invalid, so leave it be
// until they fix it.
}
}
function updateBoundsText(ngModel) {
updateBoundsTextForProperty(ngModel, 'start');
updateBoundsTextForProperty(ngModel, 'end');
}
function updateViewFromModel(ngModel) { function updateViewFromModel(ngModel) {
var t = now(); var t = now();
@ -109,8 +128,7 @@ define(
ngModel.inner = ngModel.inner || copyBounds(ngModel.outer); ngModel.inner = ngModel.inner || copyBounds(ngModel.outer);
// First, dates for the date pickers for outer bounds // First, dates for the date pickers for outer bounds
$scope.boundsModel.start = formatTimestamp(ngModel.outer.start); updateBoundsText(ngModel);
$scope.boundsModel.end = formatTimestamp(ngModel.outer.end);
// Then various updates for the inner span // Then various updates for the inner span
updateViewForInnerSpanFromModel(ngModel); updateViewForInnerSpanFromModel(ngModel);
@ -201,6 +219,7 @@ define(
); );
updateViewForInnerSpanFromModel(ngModel); updateViewForInnerSpanFromModel(ngModel);
updateTicks();
} }
function updateOuterEnd(t) { function updateOuterEnd(t) {
@ -221,11 +240,13 @@ define(
); );
updateViewForInnerSpanFromModel(ngModel); updateViewForInnerSpanFromModel(ngModel);
updateTicks();
} }
function updateStartFromText(value) { function updateStartFromText(value) {
try { try {
updateOuterStart(parseTimestamp(value)); updateOuterStart(parseTimestamp(value));
updateBoundsTextForProperty($scope.ngModel, 'end');
} catch (e) { } catch (e) {
return; return;
} }
@ -234,11 +255,22 @@ define(
function updateEndFromText(value) { function updateEndFromText(value) {
try { try {
updateOuterEnd(parseTimestamp(value)); updateOuterEnd(parseTimestamp(value));
updateBoundsTextForProperty($scope.ngModel, 'start');
} catch (e) { } catch (e) {
return; return;
} }
} }
function updateStartFromPicker(value) {
updateOuterStart(value);
updateBoundsText($scope.ngModel);
}
function updateEndFromPicker(value) {
updateOuterEnd(value);
updateBoundsText($scope.ngModel);
}
$scope.startLeftDrag = startLeftDrag; $scope.startLeftDrag = startLeftDrag;
$scope.startRightDrag = startRightDrag; $scope.startRightDrag = startRightDrag;
$scope.startMiddleDrag = startMiddleDrag; $scope.startMiddleDrag = startMiddleDrag;
@ -255,8 +287,8 @@ define(
$scope.$watchCollection("ngModel", updateViewFromModel); $scope.$watchCollection("ngModel", updateViewFromModel);
$scope.$watch("spanWidth", updateSpanWidth); $scope.$watch("spanWidth", updateSpanWidth);
$scope.$watch("ngModel.outer.start", updateOuterStart); $scope.$watch("ngModel.outer.start", updateStartFromPicker);
$scope.$watch("ngModel.outer.end", updateOuterEnd); $scope.$watch("ngModel.outer.end", updateEndFromPicker);
$scope.$watch("boundsModel.start", updateStartFromText); $scope.$watch("boundsModel.start", updateStartFromText);
$scope.$watch("boundsModel.end", updateEndFromText); $scope.$watch("boundsModel.end", updateEndFromText);
} }