nitweb/angular: filter entity lists
[nit.git] / share / nitweb / javascripts / ui.js
1 /*
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 (function() {
18 angular
19 .module('ui', [ 'model' ])
20
21 .directive('uiFilters', function() {
22 return {
23 restrict: 'E',
24 scope: {
25 property: '=',
26 classesOn: '=',
27 classesOff: '='
28 },
29 replace: true,
30 templateUrl: '/directives/ui-filter-button-vis.html',
31 link: function ($scope, element, attrs) {
32 $scope.toggle = function() {
33 $scope.property = !$scope.property;
34 }
35 }
36 };
37 })
38
39 .filter('visibility', function() {
40 return function(input, visibilityFilter) {
41 var res = [];
42 input.forEach(function(entry) {
43 if(visibilityFilter.public == false && entry.visibility == "public") {
44 return;
45 }
46 if(visibilityFilter.protected == false && entry.visibility == "protected") {
47 return;
48 }
49 if(visibilityFilter.private == false && entry.visibility == "private") {
50 return;
51 }
52 res.push(entry);
53 });
54 return res;
55 };
56 })
57
58 .directive('uiFilterForm', function() {
59 return {
60 restrict: 'E',
61 scope: {
62 searchFilter: '=',
63 visibilityFilter: '='
64 },
65 replace: true,
66 templateUrl: '/directives/ui-filter-form.html'
67 };
68 })
69
70 .directive('uiFilterField', function() {
71 return {
72 restrict: 'E',
73 scope: {
74 property: '='
75 },
76 replace: true,
77 templateUrl: '/directives/ui-filter-field.html'
78 };
79 })
80
81 .directive('uiFilterGroupVis', function() {
82 return {
83 restrict: 'E',
84 scope: {
85 property: '='
86 },
87 replace: true,
88 templateUrl: '/directives/ui-filter-group-vis.html'
89 };
90 })
91
92 .directive('uiFilterButtonVis', function() {
93 return {
94 restrict: 'E',
95 scope: {
96 property: '=',
97 classesOn: '=',
98 classesOff: '='
99 },
100 replace: true,
101 templateUrl: '/directives/ui-filter-button-vis.html',
102 link: function ($scope, element, attrs) {
103 $scope.toggle = function() {
104 $scope.property = !$scope.property;
105 }
106 }
107 };
108 })
109 })();