Index: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js
===================================================================
--- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js	(revision 13782)
+++ branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js	(revision 13795)
@@ -14,4 +14,5 @@
                vm.alertMessage = "No alerts";
                vm.currentcal = [];
+               $scope.permission = false;
                vm.selectedEventId = -1;
                vm.groups = [];
@@ -27,8 +28,10 @@
                        hubber.server.requestInfo();
                    });
-                   hubber.client.processData = function (data) {
+                   hubber.client.processData = function (data, users, groups) {
                        vm.data = JSON.parse(data);
+                       vm.permUsers = JSON.parse(users);
+                       vm.permGroups = JSON.parse(groups);
                        $scope.buildTree();
-
+                      
                        $scope.$apply();
                    };
@@ -48,4 +51,12 @@
                        $scope.$apply();
                    }
+                   hubber.client.processPermissions = function (id, perm) {
+                       var json = JSON.parse(perm);
+                      
+                       $scope.treeview.currentNode.permissions = json;
+                       refreshPermissions();
+                       $scope.permissionLoader = false;
+                       $scope.$apply();
+                   }
                    hubber.client.processDowntime = function (id, down) {
                        var json = JSON.parse(down);
@@ -91,13 +102,15 @@
                        $(".selected.ng-binding").addClass('loaded');
                        $scope.selectedEventId = -1;
+                       
                        if ($scope.treeview.currentNode != null && $scope.treeview.currentNode.Id != undefined) {
                            if ($scope.treeview.currentNode.calendar.length === 0) {
+                               hubber.server.requestPermissions(vm.treeview.currentNode.Id);
                                hubber.server.requestDownTime(vm.treeview.currentNode.Id);
-
+                               vm.permissionLoader = true;
                            }
                            else {
                                $timeout(function () {
+                                   refreshPermissions();
                                    $scope.currentcal = $scope.treeview.currentNode.calendar;
-
                                }, 0);
 
@@ -106,4 +119,20 @@
 
                    });
+               }
+               function refreshPermissions() {
+                   for (var i = 0; i < $scope.permUsers.length; i++){
+                       $scope.permUsers[i].state = false;
+                       for (var j = 0; j < $scope.treeview.currentNode.permissions.length; j++) {
+                           if($scope.permUsers[i].Id === $scope.treeview.currentNode.permissions[j].GrantedUserId)
+                               $scope.permUsers[i].state = true;
+                       }
+                   }
+                   for (var i = 0; i < $scope.permGroups.length; i++) {
+                       $scope.permGroups[i].state = false;
+                       for (var j = 0; j < $scope.treeview.currentNode.permissions.length; j++) {
+                           if ($scope.permGroups[i].Id === $scope.treeview.currentNode.permissions[j].GrantedUserId)
+                               $scope.permGroups[i].state = true;
+                       }
+                   }
                }
                $scope.clearTreeSelect = function () {
@@ -179,10 +208,22 @@
                    return current;
                }
-
                $scope.toggleDisposable = function () {
                    $scope.calendarDispose = true;
                    hubber.server.toggleDisposable(vm.treeview.currentNode.Id);
                }
-
+               $scope.pushPermissions = function () {
+                   var perms = [];
+                   $scope.permissionLoader = true;
+                   var node = $scope.treeview.currentNode;
+                   for (var i = 0; i < $scope.permGroups.length; i++) {
+                       if ($scope.permGroups[i].state === true)
+                           perms.push($scope.permGroups[i].Id);
+                   }
+                   for (var i = 0; i < $scope.permUsers.length; i++) {
+                       if ($scope.permUsers[i].state === true)
+                           perms.push($scope.permUsers[i].Id);
+                   }
+                   hubber.server.changePermissions(perms, node.Id);
+               }
                function collectInfoToSave(node, refresh, last) {
                    var arr = node.calendar.down[0];
@@ -273,4 +314,5 @@
                    $scope.currentcal = [];
                    hubber.server.requestDownTime(vm.treeview.currentNode.Id);
+                   $(".selected.ng-scope").removeClass('changed');
                    $(".selected.ng-binding").removeClass('changed');
 
@@ -293,5 +335,7 @@
                function clearAllCalendarsFunc() {
                    $(".ng-binding.changed").removeClass('changed');
+                   $(".ng-scope.changed").removeClass('changed');
                    $(".ng-binding.loaded").removeClass('loaded');
+                   $(".ng-scope.loaded").removeClass('loaded');
                    $scope.selectedEventId = -1;
                    $scope.treeview.currentNode.calendar = null;
@@ -301,4 +345,5 @@
                    hubber.server.requestDownTime(vm.treeview.currentNode.Id);
                    $(".selected.ng-binding").addClass('loaded');
+                   $(".selected.ng-scope").addClass('loaded');
                }
                function clearCalendarsRecurse(node) {
@@ -361,5 +406,5 @@
                    }
                    vm.treeview.currentNode.changes = true;
-                   $(".selected.ng-binding").addClass('changed');
+                   $(".selected").addClass('changed');
                }
                //*Add event by click
