nitweb/angular: add linearization to model
[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 Model.loadEntity($routeParams.id,
32 function(data) {
33 $scope.mentity = data;
34 }, function(err) {
35 $scope.error = err;
36 });
37 }])
38
39 .directive('entityLink', function() {
40 return {
41 restrict: 'E',
42 scope: {
43 mentity: '='
44 },
45 templateUrl: '/directives/entity/link.html'
46 };
47 })
48
49 .directive('entityDoc', function() {
50 return {
51 restrict: 'E',
52 scope: {
53 mentity: '='
54 },
55 templateUrl: '/directives/entity/doc.html'
56 };
57 })
58
59 .directive('entitySignature', function() {
60 return {
61 restrict: 'E',
62 scope: {
63 mentity: '='
64 },
65 templateUrl: '/directives/entity/signature.html'
66 };
67 })
68
69 .directive('entityTag', function() {
70 return {
71 restrict: 'E',
72 scope: {
73 mentity: '='
74 },
75 replace: true,
76 templateUrl: '/directives/entity/tag.html'
77 };
78 })
79
80 .directive('entityLocation', function() {
81 return {
82 restrict: 'E',
83 scope: {
84 mentity: '='
85 },
86 templateUrl: '/directives/entity/location.html'
87 };
88 })
89
90 .directive('entityCard', function() {
91 return {
92 restrict: 'E',
93 scope: {
94 mentity: '='
95 },
96 replace: true,
97 templateUrl: '/directives/entity/card.html'
98 };
99 })
100
101 .directive('entityList', function() {
102 return {
103 restrict: 'E',
104 scope: {
105 listEntities: '=',
106 listId: '@',
107 listTitle: '@',
108 listObjectFilter: '=',
109 },
110 templateUrl: '/directives/entity/list.html',
111 link: function ($scope, element, attrs) {
112 $scope.showFilters = false;
113 if(!$scope.listObjectFilter) {
114 $scope.listObjectFilter = {};
115 }
116 if(!$scope.visibilityFilter) {
117 $scope.visibilityFilter = {
118 public: true,
119 protected: true,
120 private: false
121 };
122 }
123 $scope.toggleFilters = function() {
124 $scope.showFilters = !$scope.showFilters;
125 };
126 }
127 };
128 })
129 })();