Yang UI, Yang Utils - split services into separate files
[dlux.git] / modules / yangui-resources / src / main / resources / yangui / controllers / api / list.controller.js
1 define([], function() {
2     angular.module('app.yangui').controller('listCtrl', function ($scope, ListFilteringService, NodeWrapperService) {
3         $scope.actElement = null;
4         $scope.showModal = false;
5         $scope.showListFilter = false;
6         $scope.filterListHover = 0;
7         $scope.currentDisplayIndex = 1;
8         $scope.displayOffsets = [-1, 0, 1];
9         $scope.augModalView = false;
10
11         $scope.toggleExpandedAugModal = function(){
12             $scope.augModalView = !$scope.augModalView;
13         };
14
15         $scope.$on('EV_REFRESH_LIST_INDEX', function(event) {
16             $scope.currentDisplayIndex = 1;
17         });
18
19         $scope.addListElem = function() {
20             $scope.showListFilter = false;
21             $scope.showModal = false;
22             ListFilteringService.removeEmptyFilters($scope.node);
23             $scope.node.addListElem();
24         };
25
26         $scope.removeListElem = function(elemIndex,fromFilter) {
27             $scope.node.removeListElem(elemIndex,fromFilter);
28             $scope.preview();
29             $scope.currentDisplayIndex = Math.max(Math.min($scope.currentDisplayIndex, $scope.node.listData.length - 2), 1);
30         };
31
32         $scope.toggleExpanded = function() {
33             $scope.node.expanded = !$scope.node.expanded;
34         };
35
36         $scope.shiftDisplayNext = function(typeListData) {
37             $scope.currentDisplayIndex = Math.min($scope.currentDisplayIndex + 3, $scope.node[typeListData].length - 2);
38         };
39
40         $scope.shiftDisplayPrev = function() {
41             $scope.currentDisplayIndex = Math.max($scope.currentDisplayIndex - 3, 1);
42         };
43
44         $scope.showPrevButton = function() {
45             return $scope.currentDisplayIndex > 1;
46         };
47
48         $scope.showNextButton = function(typeListData) {
49             return $scope.node[typeListData] && $scope.currentDisplayIndex < $scope.node[typeListData].length - 2; //node is selected after view is loaded
50         };
51
52         $scope.showModalWin = function() {
53             $scope.showModal = !$scope.showModal;
54             if($scope.showListFilter){
55                 $scope.showListFilter = !$scope.showListFilter;
56             }
57         };
58
59         $scope.showListFilterWin = function() {
60             $scope.showListFilter = !$scope.showListFilter;
61             if($scope.showModal){
62                 $scope.showModal = !$scope.showModal;
63             }
64             ListFilteringService.showListFilterWin($scope.filterRootNode,$scope.node);
65         };
66
67         $scope.getFilterData = function() {
68             ListFilteringService.getFilterData($scope.node);
69         };
70
71         $scope.switchFilter = function(showedFilter) {
72             ListFilteringService.switchFilter($scope.node,showedFilter);
73         };
74
75         $scope.createNewFilter = function() {
76             ListFilteringService.createNewFilter($scope.node);
77         };
78
79         $scope.applyFilter = function() {
80             ListFilteringService.applyFilter($scope.node);
81             $scope.showListFilter = !$scope.showListFilter;
82             $scope.currentDisplayIndex = 1;
83             if($scope.node.filteredListData.length){
84                 $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity($scope.node.filteredListData,$scope.node.refKey);
85             }else{
86                 $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity($scope.node.listData,$scope.node.refKey);
87             }
88         };
89
90         $scope.clearFilterData = function(changeAct, filterForClear, removeFilters) {
91             ListFilteringService.clearFilterData($scope.node,changeAct,filterForClear,removeFilters);
92             if(changeAct){
93                 $scope.showListFilter = !$scope.showListFilter;
94             }
95             $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity($scope.node.listData,$scope.node.refKey);
96         };
97
98         $scope.activeFilter = function(filter) {
99             if(filter.active == 1){
100                 filter.active = 2;
101             }else{
102                 filter.active = 1;
103             }
104         };
105
106         $scope.getListName = function(offset, config) {
107             var createdListItemName = $scope.node.createListName($scope.currentDisplayIndex + offset);
108
109             if ( createdListItemName.length > 33 ) {
110                 return {
111                     name: createdListItemName.substring(0,30) + '...',
112                     tooltip: createdListItemName
113                 };
114             } else {
115                 return {
116                     name: config ? createdListItemName || '[' + ($scope.currentDisplayIndex + offset) + ']' : createdListItemName,
117                     tooltip: ''
118                 };
119             }
120         };
121
122     });
123
124 });