aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/general/common.general.directives.js
blob: 78429dc1ca16a81f1ecdffd458ea8c7e96b8486a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
define(['common/general/common.general.module'], function(general) {

  general.directive('stateIcon', function() {
      return {
          restrict: 'E',
          replace: true,
          scope: {
              stateValue: '@value'
          },
          template: '<span class="glyphicon glyphicon-{{stateIcon}}-sign"></span>',
          controller: ['$scope', function ($scope) {
              var value = $scope.stateValue;

              var icons = {1: 'ok', 0: 'exclamation'};
              var textStates = {'true': 1, 'false': 0};

              if (_.isString(value) && !value.match('^[0-9]$')) {
                  value = textStates[value];
              }
              $scope.stateIcon = icons[value];
          }]

      };
  });

  general.directive('portState', function() {
      return {
          restrict: 'E',
          replace: true,
          scope: {
              stateValue: '@value'
          },
          template: '<span ng-style="{color: stateColor}">{{stateString}}</span>',
          controller: ['$scope', function ($scope) {
              var states = {0: 'DOWN', 1: 'UP'};
              var colors = {0: 'red', 1: 'green'};

              $scope.stateString = states[$scope.stateValue];
              $scope.stateColor = colors[$scope.stateValue];
          }]
      };
  });
});