nitweb: move ui-router config to users module
[nit.git] / share / nitweb / javascripts / users.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('users', ['ngSanitize', 'model'])
20
21 .config(function($stateProvider, $locationProvider) {
22 $stateProvider
23 .state('user', {
24 url: '/user',
25 templateUrl: 'views/user.html',
26 controller: 'UserCtrl',
27 controllerAs: 'userCtrl'
28 })
29 .state('login', {
30 url: '/login',
31 controller : function(){
32 window.location.replace('/login');
33 },
34 template : "<div></div>"
35 })
36 .state('logout', {
37 controller : function(){
38 window.location.replace('/logout');
39 },
40 template : "<div></div>"
41 })
42 })
43
44 .controller('UserCtrl', ['User', '$scope', function(User, $scope) {
45 this.loadUser = function() {
46 User.loadUser(
47 function(data) {
48 $scope.user = data;
49 }, function(err) {
50 $scope.error = err;
51 });
52 };
53 this.loadGrades = function() {
54 User.loadUserStars(
55 function(data) {
56 $scope.ratings = data;
57 }, function(err) {
58 $scope.error = err;
59 });
60 };
61 this.loadUser();
62 this.loadGrades();
63 }])
64
65 .directive('userMenu', ['User', '$rootScope', function(User, $rootScope) {
66 return {
67 restrict: 'E',
68 templateUrl: '/directives/user/user-menu.html',
69 link: function ($scope, element, attrs) {
70 $scope.loadUser = function() {
71 User.loadUser(
72 function(data) {
73 $rootScope.user = data;
74 }, function(err) {
75 //$scope.error = err;
76 });
77 }
78 $scope.loadUser();
79 }
80 };
81 }])
82
83 .directive('userSidebar', ['User', '$rootScope', function(User, $rootScope) {
84 return {
85 restrict: 'E',
86 templateUrl: '/directives/user/sidebar.html',
87 };
88 }])
89 })();