78429dc1ca16a81f1ecdffd458ea8c7e96b8486a
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / dlux / dlux-web / src / common / general / common.general.directives.js
1 define(['common/general/common.general.module'], function(general) {
2
3   general.directive('stateIcon', function() {
4       return {
5           restrict: 'E',
6           replace: true,
7           scope: {
8               stateValue: '@value'
9           },
10           template: '<span class="glyphicon glyphicon-{{stateIcon}}-sign"></span>',
11           controller: ['$scope', function ($scope) {
12               var value = $scope.stateValue;
13
14               var icons = {1: 'ok', 0: 'exclamation'};
15               var textStates = {'true': 1, 'false': 0};
16
17               if (_.isString(value) && !value.match('^[0-9]$')) {
18                   value = textStates[value];
19               }
20               $scope.stateIcon = icons[value];
21           }]
22
23       };
24   });
25
26   general.directive('portState', function() {
27       return {
28           restrict: 'E',
29           replace: true,
30           scope: {
31               stateValue: '@value'
32           },
33           template: '<span ng-style="{color: stateColor}">{{stateString}}</span>',
34           controller: ['$scope', function ($scope) {
35               var states = {0: 'DOWN', 1: 'UP'};
36               var colors = {0: 'red', 1: 'green'};
37
38               $scope.stateString = states[$scope.stateValue];
39               $scope.stateColor = colors[$scope.stateValue];
40           }]
41       };
42   });
43 });