4428c897ef0b50d703661aa4aa174a15c135a4a7
[nit.git] / share / nitweb / javascripts / entities.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('entities', ['ui', 'model'])
20
21 .controller('EntityCtrl', ['Model', '$routeParams', '$scope', function(Model, $routeParams, $scope) {
22 this.loadEntityLinearization = function() {
23 Model.loadEntityLinearization($routeParams.id,
24 function(data) {
25 $scope.linearization = data;
26 }, function(err) {
27 $scope.error = err;
28 });
29 };
30
31 this.loadEntityCode = function() {
32 Model.loadEntityCode($routeParams.id,
33 function(data) {
34 $scope.code = data;
35 }, function(err) {
36 $scope.code = err;
37 });
38 };
39
40 Model.loadEntity($routeParams.id,
41 function(data) {
42 $scope.mentity = data;
43 }, function(err) {
44 $scope.error = err;
45 });
46 }])
47
48 .directive('entityLink', function() {
49 return {
50 restrict: 'E',
51 scope: {
52 mentity: '='
53 },
54 templateUrl: '/directives/entity/link.html'
55 };
56 })
57
58 .directive('entityDoc', function() {
59 return {
60 restrict: 'E',
61 scope: {
62 mentity: '='
63 },
64 templateUrl: '/directives/entity/doc.html'
65 };
66 })
67
68 .directive('entitySignature', function() {
69 return {
70 restrict: 'E',
71 scope: {
72 mentity: '='
73 },
74 templateUrl: '/directives/entity/signature.html'
75 };
76 })
77
78 .directive('entityTag', function() {
79 return {
80 restrict: 'E',
81 scope: {
82 mentity: '='
83 },
84 replace: true,
85 templateUrl: '/directives/entity/tag.html'
86 };
87 })
88
89 .directive('entityLocation', function() {
90 return {
91 restrict: 'E',
92 scope: {
93 mentity: '='
94 },
95 templateUrl: '/directives/entity/location.html'
96 };
97 })
98
99 .directive('entityCard', function() {
100 return {
101 restrict: 'E',
102 scope: {
103 mentity: '='
104 },
105 replace: true,
106 templateUrl: '/directives/entity/card.html'
107 };
108 })
109
110 .directive('entityList', function() {
111 return {
112 restrict: 'E',
113 scope: {
114 listEntities: '=',
115 listId: '@',
116 listTitle: '@',
117 listObjectFilter: '=',
118 },
119 templateUrl: '/directives/entity/list.html',
120 link: function ($scope, element, attrs) {
121 $scope.showFilters = false;
122 if(!$scope.listObjectFilter) {
123 $scope.listObjectFilter = {};
124 }
125 if(!$scope.visibilityFilter) {
126 $scope.visibilityFilter = {
127 public: true,
128 protected: true,
129 private: false
130 };
131 }
132 $scope.toggleFilters = function() {
133 $scope.showFilters = !$scope.showFilters;
134 };
135 }
136 };
137 })
138
139 .directive('entityLinearization', function() {
140 return {
141 restrict: 'E',
142 scope: {
143 listEntities: '=',
144 listTitle: '@',
145 listFocus: '='
146 },
147 templateUrl: '/directives/entity/linearization.html'
148 };
149 })
150
151 .directive('entityDef', ['Model', function(Model, Code) {
152 return {
153 restrict: 'E',
154 scope: {
155 definition: '=',
156 focus: '='
157 },
158 link: function ($scope, element, attrs) {
159 $scope.$watch("definition", function() {
160 /*.loadEntityDefs($scope.definition.full_name,
161 function(data) {
162 $scope.mentity = data;
163 }, function(err) {
164 $scope.error = err;
165 });
166 Model.loadEntityCode($scope.definition.full_name,
167 function(data) {
168 $scope.code = data;
169 }, function(err) {
170 $scope.error = err;
171 });*/
172 });
173 },
174 templateUrl: '/directives/entity/defcard.html'
175 };
176 }])
177 })();