[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.
This commit is contained in:
Victor Woeltjen 2014-12-30 11:37:24 -08:00
parent becc858349
commit 3251be2d1c
3 changed files with 46 additions and 3 deletions

View File

@ -55,6 +55,11 @@
"key": "BottomBarController",
"implementation": "BottomBarController.js",
"depends": [ "indicators[]" ]
},
{
"key": "GetterSetterController",
"implementation": "GetterSetterController.js",
"depends": [ "$scope" ]
}
],
"directives": [

View File

@ -1,5 +1,13 @@
<!-- look at action-button for example -->
<span class="t-filter l-filter">
<input type="search" class="t-filter-input" ng-model="filter" placeholder="Filter..."/>
<a class="ui-symbol t-a-clear s-a-clear" ng-click="filter = null">x</a>
<span class="t-filter l-filter"
ng-controller="GetterSetterController">
<input type="search"
class="t-filter-input"
ng-model="getterSetter.value"
placeholder="Filter..."/>
<a class="ui-symbol t-a-clear s-a-clear"
ng-show="getterSetter.value !== ''"
ng-click="getterSetter.value = ''">
x
</a>
</span>

View File

@ -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;
}
);