Yangman - refactor yang-form-menu directive
[dlux.git] / modules / yangman-resources / src / main / resources / yangman / directives / yang-form-menu.directive.js
1 define(['angular'], function (angular) {
2     'use strict';
3
4     angular.module('app.yangman').directive('yangFormMenu', menuDirective);
5
6     menuDirective.$inject = [];
7
8     function menuDirective() {
9         return {
10             restrict: 'E',
11             templateUrl: 'src/app/yangman/views/directives/yang-form-menu.tpl.html',
12             scope: {
13                 node: '=',
14                 augmentations: '=',
15                 allowItems: '=',
16                 isActionMenu: '&',
17                 addListItemFunc: '&',
18                 addListItem: '=',
19                 yangForm: '=',
20                 yangList: '=',
21             },
22             controller: function ($scope) {
23                 var lastSection = null;
24
25                 $scope.infoBox = false;
26                 $scope.infoBoxSection = '';
27                 $scope.selectedListItem = 0;
28
29                 // methods
30                 $scope.switchSection = switchSection;
31                 $scope.hideInfoBox = hideInfoBox;
32
33                 /**
34                  * Switcher for info box section
35                  * @param section
36                  */
37                 function switchSection(section){
38                     if ( $scope.infoBox ) {
39                         if ( section === lastSection ) {
40                             $scope.infoBox = false;
41                         } else {
42                             $scope.infoBoxSection = section;
43                         }
44                     } else {
45                         $scope.infoBox = true;
46                         $scope.infoBoxSection = section;
47                     }
48                     lastSection = section;
49                 }
50
51                 /**
52                  * Hide menu info box
53                  */
54                 function hideInfoBox(){
55                     $scope.infoBox = false;
56                 }
57             },
58             link: function (scope, element, attrs) {
59                 scope.isActive = false;
60
61                 // methods
62                 scope.closeMenu = closeMenu;
63                 scope.openMenu = openMenu;
64
65                 /**
66                  * Close Yang menu
67                  */
68                 function closeMenu(){
69                     scope.isActive = false;
70                 }
71
72                 /**
73                  * Open Yang menu
74                  */
75                 function openMenu(){
76                     scope.isActive = true;
77                 }
78
79             },
80         };
81     }
82 });