1 define([], function () {
3 angular.module('app.yangui').controller('ListCtrl', ListCtrl);
5 ListCtrl.$inject = ['$scope', 'ListFilteringService', 'NodeWrapperService'];
7 // todo: comment the whole controller
8 function ListCtrl($scope, ListFilteringService, NodeWrapperService) {
10 $scope.actElement = null;
11 $scope.augModalView = false;
12 $scope.currentDisplayIndex = 1;
13 $scope.displayOffsets = [-1, 0, 1];
14 $scope.filterListHover = 0;
15 $scope.showListFilter = false;
16 $scope.showModal = false;
18 $scope.activeFilter = activeFilter;
19 $scope.addListElem = addListElem;
20 $scope.applyFilter = applyFilter;
21 $scope.clearFilterData = clearFilterData;
22 $scope.createNewFilter = createNewFilter;
23 $scope.existsActiveFilter = existsActiveFilter;
24 $scope.getFilterData = getFilterData;
25 $scope.getListName = getListName;
26 $scope.removeListElem = removeListElem;
27 $scope.shiftDisplayNext = shiftDisplayNext;
28 $scope.shiftDisplayPrev = shiftDisplayPrev;
29 $scope.showListFilterWin = showListFilterWin;
30 $scope.showModalWin = showModalWin;
31 $scope.showNextButton = showNextButton;
32 $scope.showPrevButton = showPrevButton;
33 $scope.switchFilter = switchFilter;
34 $scope.toggleExpanded = toggleExpanded;
35 $scope.toggleExpandedAugModal = toggleExpandedAugModal;
37 $scope.$on('EV_REFRESH_LIST_INDEX', refreshListIndex);
39 $scope.$on('EV_DISABLE_ADDING_LIST_ELEMENT', function() {
44 * Disable adding more then one element
46 $scope.init = function() {
47 $scope.disableAddingListElement = $scope.checkAddingListElement($scope.node);
49 if($scope.disableAddingListElement) {
54 function toggleExpandedAugModal(){
55 $scope.augModalView = !$scope.augModalView;
58 function refreshListIndex() {
59 $scope.currentDisplayIndex = 1;
62 function addListElem() {
63 $scope.showListFilter = false;
64 $scope.showModal = false;
65 ListFilteringService.removeEmptyFilters($scope.node);
66 $scope.node.addListElem();
69 function removeListElem(elemIndex, fromFilter) {
70 $scope.node.removeListElem(elemIndex, fromFilter);
72 $scope.currentDisplayIndex = Math.max(
73 Math.min($scope.currentDisplayIndex, $scope.node.listData.length - 2), 1
77 function toggleExpanded() {
78 $scope.node.expanded = !$scope.node.expanded;
81 function shiftDisplayNext(typeListData) {
82 $scope.currentDisplayIndex = Math.min($scope.currentDisplayIndex + 3, $scope.node[typeListData].length - 2);
85 function shiftDisplayPrev() {
86 $scope.currentDisplayIndex = Math.max($scope.currentDisplayIndex - 3, 1);
89 function showPrevButton() {
90 return $scope.currentDisplayIndex > 1;
93 function showNextButton(typeListData) {
94 return $scope.node[typeListData] &&
95 // node is selected after view is loaded
96 $scope.currentDisplayIndex < $scope.node[typeListData].length - 2;
99 function showModalWin() {
100 $scope.showModal = !$scope.showModal;
101 if ($scope.showListFilter){
102 $scope.showListFilter = !$scope.showListFilter;
106 function showListFilterWin() {
107 $scope.showListFilter = !$scope.showListFilter;
108 if ($scope.showModal){
109 $scope.showModal = !$scope.showModal;
111 ListFilteringService.showListFilterWin($scope.filterRootNode, $scope.node);
114 function getFilterData() {
115 ListFilteringService.getFilterData($scope.node);
118 function switchFilter(showedFilter) {
119 ListFilteringService.switchFilter($scope.node, showedFilter);
122 function createNewFilter() {
123 ListFilteringService.createNewFilter($scope.node);
126 function existsActiveFilter() {
127 return $scope.node.filters.some(function(filter) {
128 return filter.active == 1;
132 function applyFilter() {
133 ListFilteringService.applyFilter($scope.node);
134 $scope.showListFilter = !$scope.showListFilter;
135 $scope.currentDisplayIndex = 1;
136 if ($scope.node.filteredListData.length){
137 $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity($scope.node.filteredListData, $scope.node.refKey);
138 $scope.setStatusMessage('success', 'YANGUI_FILTER_MATCH_SUCCESS', e.message);
141 $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity(
142 $scope.node.listData,
146 if($scope.existsActiveFilter()) {
147 $scope.setStatusMessage('danger', 'YANGUI_FILTER_MATCH_ERROR', e.message);
152 function clearFilterData(changeAct, filterForClear, removeFilters) {
153 ListFilteringService.clearFilterData($scope.node, changeAct, filterForClear, removeFilters);
155 $scope.showListFilter = !$scope.showListFilter;
157 $scope.node.doubleKeyIndexes = NodeWrapperService.checkKeyDuplicity(
158 $scope.node.listData,
163 function activeFilter(filter) {
164 if (filter.active === 1) {
172 function getListName(offset, config) {
173 var createdListItemName = $scope.node.createListName($scope.currentDisplayIndex + offset);
175 if ( createdListItemName.length > 33 ) {
177 name: createdListItemName.substring(0, 30) + '...',
178 tooltip: createdListItemName,
183 createdListItemName || '[' + ($scope.currentDisplayIndex + offset) + ']' :