blob: 78a3a610333f2ecd522e287b87c73e8f201cc5e8 [file] [log] [blame]
Matteo Scandolobf14f882016-06-02 10:01:34 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 'use strict';
19
20 angular.module('cordUser', [])
21 .controller('CordUserCtrl', function ($log, $scope, $resource, $timeout, $filter, $cookies, SubscriberUsers, cordConfig, SubscriberUsersUrlFilterLevel) {
22
23 $scope.page.curr = 'user';
24 $scope.isFamily = false;
25 $scope.newLevels = {};
26 $scope.showCheck = false;
27 $scope.ratingsShown = false;
28
29 SubscriberUsers.query({subscriberId: $cookies.get('subscriberId')}).$promise
30 .then(function(res){
31 $scope.isFamily = cordConfig.bundles[cordConfig.activeBundle].id === 'family';
32 // if bundle is family search for url_filter level
33 if ($scope.isFamily) {
34 angular.forEach(cordConfig.bundles[cordConfig.activeBundle].functions, function(fn){
35 if(fn.id === 'video'){
36 console.log(fn);
37 $scope.levels = fn.params.levels;
38 }
39 });
40 }
41 $scope.users = res;
42 })
43 .catch(function () {
44 $log.error('Problem with resource', SubscriberUsers);
45 });
46
47 $scope.updateLevel = function(user){
48 // TODO save this data and show a confirmation to the user
49 // NOTE subscriberId should be retrieved by login
50 SubscriberUsersUrlFilterLevel.updateUrlFilterLevel(1, user.id, user.level)
51 .then(function(){
52 user.updated = true;
53 })
54 .catch(function(e){
55 throw new Error(e);
56 });
57 };
58
59 $scope.showRatings = function () {
60 $scope.ratingsShown = !$scope.ratingsShown;
61 };
62
63 $log.debug('Cord User Ctrl has been created.');
64 })
65 .directive('userUpdatedTick', function($timeout){
66 return {
67 restric: 'E',
68 scope: {
69 user: '='
70 },
71 template: '<span class="icon-saved animate" ng-show="saved"></span>',
72 link: function(scope, elem){
73 scope.saved = false;
74 scope.$watch('user.updated', function(val){
75 if(val){
76 scope.saved = true;
77 $timeout(function(){
78 scope.saved = false;
79 }, 3000);
80 }
81 });
82 }
83 }
84 });
85}());