From 3251be2d1cb4ff36a12813d87b8c6ae5129ddff8 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 30 Dec 2014 11:37:24 -0800 Subject: [PATCH] [Autoflow] Add getter-setter controller Add a utility controller for interacting with getter-setter style ngModels (similar to ng-model-options with getterSetter: true, but support for that is not present in the current version of Angular.) Specifically, this is used to support the input filter control, which in turn is used within the autoflow tabular view. WTD-614. --- platform/commonUI/general/bundle.json | 5 ++++ .../res/templates/controls/input-filter.html | 14 +++++++-- .../general/src/GetterSetterController.js | 30 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 platform/commonUI/general/src/GetterSetterController.js diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index ca98296be4..8d0d7e39a4 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -55,6 +55,11 @@ "key": "BottomBarController", "implementation": "BottomBarController.js", "depends": [ "indicators[]" ] + }, + { + "key": "GetterSetterController", + "implementation": "GetterSetterController.js", + "depends": [ "$scope" ] } ], "directives": [ diff --git a/platform/commonUI/general/res/templates/controls/input-filter.html b/platform/commonUI/general/res/templates/controls/input-filter.html index 303a8db257..3c6be1684e 100644 --- a/platform/commonUI/general/res/templates/controls/input-filter.html +++ b/platform/commonUI/general/res/templates/controls/input-filter.html @@ -1,5 +1,13 @@ - - - x + + + + x + \ No newline at end of file diff --git a/platform/commonUI/general/src/GetterSetterController.js b/platform/commonUI/general/src/GetterSetterController.js new file mode 100644 index 0000000000..0e58220ee2 --- /dev/null +++ b/platform/commonUI/general/src/GetterSetterController.js @@ -0,0 +1,30 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + function GetterSetterController($scope) { + + function updateGetterSetter() { + if (typeof $scope.ngModel === 'function') { + $scope.getterSetter.value = $scope.ngModel(); + } + } + + function updateNgModel() { + if (typeof $scope.ngModel === 'function') { + $scope.ngModel($scope.getterSetter.value); + } + } + + $scope.$watch("ngModel()", updateGetterSetter); + $scope.$watch("getterSetter.value", updateNgModel); + $scope.getterSetter = {}; + } + + return GetterSetterController; + + } +); \ No newline at end of file