Yangman - improvements - more info belove
[dlux.git] / modules / yangman-resources / src / main / resources / yangman / directives / ym-info-box.directive.js
1 define(['angular'], function (angular) {
2     'use strict';
3
4     angular.module('app.yangman').directive('ymInfoBox', infoBoxDirective);
5
6     infoBoxDirective.$inject = [];
7
8     function infoBoxDirective() {
9         return {
10             restrict: 'A',
11             templateUrl: 'src/app/yangman/views/directives/ym-info-box.tpl.html',
12             transclude: true,
13             scope: {
14                 node: '=',
15             },
16             link: function (scope, element) {
17                 element.addClass('info-box-container');
18             },
19             controller: function ($scope) {
20                 var description = $scope.node.getChildren('description', null, null, 'label')[0];
21
22                 $scope.description = description ? description : '';
23                 $scope.infoBox = false;
24
25                 // methods
26                 $scope.dividerCheck = dividerCheck;
27                 $scope.executeInfoBox = executeInfoBox;
28                 $scope.showBoxCheck = showBoxCheck;
29
30                 /**
31                  * Set info box value - true, false
32                  * @param value
33                  */
34                 function executeInfoBox(value){
35                     $scope.infoBox = value;
36                 }
37
38                 /**
39                  * Check if box info could be shown
40                  * @returns {boolean|*}
41                  */
42                 function showBoxCheck(){
43                     return $scope.infoBox && ($scope.description.length || $scope.node.augmentationId);
44                 }
45
46                 /**
47                  * Check for showing divider between different shown info
48                  * @param key
49                  * @returns {*}
50                  */
51                 function dividerCheck(key){
52                     return key ? $scope.description.length || $scope.node.augmentationId : $scope.description.length;
53                 }
54             },
55         };
56     }
57 });