Index: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js
===================================================================
--- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js	(revision 13768)
+++ branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js	(revision 13775)
@@ -11,4 +11,5 @@
                var y = date.getFullYear();
                var hubber = $.connection.calendarHub;
+
                vm.alertMessage = "No alerts";
                vm.currentcal = [];
@@ -43,5 +44,4 @@
                        var arrdown = [];
                        var str = "";
-                       var col = "";
                        for (var i = 0; i < json.length; i++) {
                            if (json[i].DowntimeType === 0) {
@@ -60,4 +60,12 @@
                                allDay: json[i].AllDayEvent,
                                color: col,
+                               rec: {
+                                   recurrence: json[i].Recurring,
+                                   recid: json[i].RecurringId,
+                                   days: [false, false, false, false, false, false, false],
+                                   start: new Date(json[i].StartDate),
+                                   end: new Date(json[i].EndDate)
+
+                               },
                                changed: false
                            });
@@ -67,4 +75,5 @@
 
                        $scope.currentcal = $scope.treeview.currentNode.calendar;
+                       $("#resourcecalendar").fullCalendar('refresh');
                        $scope.$apply();
                    }
@@ -145,9 +154,16 @@
                            var t = arr[i].allDay.toString();
                            toadd.push([
-                               arr[i].title,
-                               "" + Date.parse(arr[i].start),
-                               "" + Date.parse(arr[i].end),
-                               t,
-                               node.Id
+                               arr[i].title,//status
+                               "" + Date.parse(arr[i].start),//start
+                               "" + Date.parse(arr[i].end),//end
+                               t,// allday
+                               node.Id, //resource id
+                               arr[i].rec.recurrence.toString(),//true on recur
+                               arr[i].rec.recid,//recur id
+                               "" + Date.parse(arr[i].rec.start),
+                               "" + Date.parse(arr[i].rec.end),
+                               arr[i].rec.days.join(",")
+                               
+
                            ]);
                        }
@@ -155,13 +171,19 @@
                            var t = arr[i].allDay.toString();
                            toupd.push([
-                               arr[i].id,
-                               arr[i].title,
-                               "" + Date.parse(arr[i].start),
-                               "" + Date.parse(arr[i].end),
-                               t
+                               arr[i].id,//id to update
+                               arr[i].title,//status
+                               "" + Date.parse(arr[i].start),//start
+                               "" + Date.parse(arr[i].end),//end
+                               t,//allday
+                               arr[i].rec.recurrence.toString(),//true on recur
+                               arr[i].rec.recid,//recur id
+                               "" + Date.parse(arr[i].rec.start),
+                               "" + Date.parse(arr[i].rec.end),
+                               arr[i].rec.days.join(",")
+                               
                            ]);
                        }
                    }
-                   vm.sendtoserv = [toadd, toupd, todel];
+                   vm.sendtoserv = [todel, toadd, toupd];
                    hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last);
                }
@@ -190,6 +212,6 @@
                        }
                    });
-                   
-                   
+
+
                }
                function createSaveRequests(node) {
@@ -201,5 +223,5 @@
                }
                $scope.clearCurrentCalendar = function () {
-                   
+
                    $scope.selectedEventId = -1;
                    $scope.treeview.currentNode.calendar = null;
@@ -253,6 +275,6 @@
                        if (node[i].end < Date.now()) {
                            if (node[i].id != '00000000-0000-0000-0000-000000000000')
-                            vm.treeview.currentNode.todelete.push(node[i].id);
-                           $scope.setChanged();
+                               vm.treeview.currentNode.todelete.push(node[i].id);
+                           $scope.setChanged(vm.selectedEventId);
                            node.splice(i, 1);
                        }
@@ -268,12 +290,12 @@
 
 
-               $scope.setChanged = function () {
-                   if (vm.selectedEventId != -1) {
-                       if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].title === "Unavailable")
-                           vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#0099cc';
+               $scope.setChanged = function (id) {
+                   if (id != -1) {
+                       if (vm.treeview.currentNode.calendar.down[0][id].title === "Unavailable")
+                           vm.treeview.currentNode.calendar.down[0][id].color = '#0099cc';
                        else
-                           vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].color = '#ff5500';
-
-                       vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].changed = true;
+                           vm.treeview.currentNode.calendar.down[0][id].color = '#ff5500';
+
+                       vm.treeview.currentNode.calendar.down[0][id].changed = true;
                    }
                    vm.treeview.currentNode.changes = true;
@@ -289,5 +311,4 @@
                    var end = new Date(dat);
                    end.setHours(dat.getHours() + 2);
-                   console.log(end);
                    vm.treeview.currentNode.calendar.down[0].push({
                        id: '00000000-0000-0000-0000-000000000000',
@@ -296,8 +317,16 @@
                        end: end,
                        allDay: date._ambigTime,
+                       rec: {
+                           recurrence: false,
+                           recid: '0',
+                           days: [false, false, false, false, false, false, false],
+                           start: dat,
+                           end: end
+
+                       },
                        _id: (newid)
                    });
                    vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;
-                   vm.setChanged();
+                   vm.setChanged(vm.selectedEventId);
                    //  $("#resourcecalendar").fullCalendar('refetchEvents');
 
@@ -317,5 +346,5 @@
                $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) {
                    vm.selectedEventId = checkId(event._id);
-                   vm.setChanged();
+                   vm.setChanged(vm.selectedEventId);
                    if (event.end == null) {
                        event.end = moment(event.start).add(2, 'hours');
@@ -336,5 +365,5 @@
                $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) {
                    vm.selectedEventId = checkId(event._id);
-                   vm.setChanged();
+                   vm.setChanged(vm.selectedEventId);
                    vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start);
                    vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end);
@@ -344,5 +373,5 @@
                $scope.remove = function (index) {
                    vm.selectedEventId = -1;
-                   vm.setChanged();
+                   vm.setChanged(vm.selectedEventId);
                    if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") {
                        vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id);
@@ -352,4 +381,114 @@
 
                };
+
+               $scope.checkDateStartEnd = function () {
+                   if ($scope.currentcal.down[0][vm.selectedEventId].rec.start > $scope.currentcal.down[0][vm.selectedEventId].rec.end ||
+                       $scope.currentcal.down[0][vm.selectedEventId].rec.end === undefined) {
+                       
+                       $scope.currentcal.down[0][vm.selectedEventId].rec.end = new Date($scope.currentcal.down[0][vm.selectedEventId].rec.start);
+                       
+                   }
+                   if ($scope.currentcal.down[0][vm.selectedEventId].rec.start < Date.now())
+                       $scope.currentcal.down[0][vm.selectedEventId].rec.start = new Date();
+                  }
+               //pushes all changes to other recurs
+               $scope.pushRecurChanges = function (recid) {
+                   ngDialog.openConfirm({
+                       template:
+                        '<p>This will change all existing recurrences and create new recurrences where needed. Are you sure?</p>' +
+                        '<div>' +
+                          '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
+                          '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
+                        '</button></div>',
+                       plain: true
+                   }).then(function (success) {
+                       var arr = vm.treeview.currentNode.calendar.down[0];
+                       var ob = $.extend(true, {}, arr[vm.selectedEventId]);
+                       for (var i = 0; i < arr.length;) {
+                           if (arr[i].rec.recid === recid) {
+                               if (new Date(arr[i].start) < new Date(ob.rec.start) ||
+                                        new Date(arr[i].end) > new Date(ob.rec.end) ||
+                                        !ob.rec.days[new Date(arr[i].start).getDay()]) {
+                                   vm.remove(i);
+                                   vm.selectedEventId = -1;
+
+                               }
+                               else {
+                                   
+                                   arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes());
+                                   arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes());
+                                   arr[i].title = ob.title;
+                                   arr[i].rec = ob.rec;
+                                   arr[i].allDay = ob.allDay;
+                                   vm.setChanged(i);
+                                   i++;
+                               }
+                           }
+                           else
+                               i++;
+                       }
+                       var start = new Date(ob.rec.start);
+                       start.setHours(2, 0, 0, 0);
+                       var end = new Date(ob.rec.end);
+                       end = new Date(end.setHours(24, 0, 0, 0) + 1000 * 3600 * 2);
+
+                       loop1:
+                           for (var d = (start.getTime()) ; d < (end.getTime()) ;) {
+                               var tog = ob.rec.days[new Date(d).getDay()];
+                               if (tog) {
+                                   loop2:
+                                       for (var i = 0; i < arr.length; i++) {
+                                           
+                                           if (arr[i].rec.recid === recid) {
+                                               var dend = (d+1000 * 3600 * 24);
+                                               if (arr[i].start.getTime() >= d &&
+                                                   arr[i].end.getTime() <= dend) {
+                                                   d += (1000 * 3600 * 24);
+                                                   continue loop1;
+                                               }
+                                           }
+                                       }
+ 
+                                   var ts = new Date(d);
+                                   ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes());
+                                   var te = new Date(d);
+                                   te.setHours(new Date(ob.end).getHours(), new Date(ob.end).getMinutes());
+                                   arr.push({
+                                       id: '00000000-0000-0000-0000-000000000000',
+                                       title: ob.title,
+                                       start: ts,
+                                       end: te,
+                                       allDay: ob.allDay,
+                                       rec: ob.rec
+                                   });
+                                   vm.setChanged(arr.length - 1);
+
+                               }
+                               
+                               d += (1000 * 3600 * 24);// 1 day
+                              
+                           }
+                   });
+               }
+               $scope.deleteAllRecurrences = function (recid) {
+                   ngDialog.openConfirm({
+                       template:
+                        '<p>This will delete every found recurrence. Are you sure?</p>' +
+                        '<div>' +
+                          '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
+                          '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
+                        '</button></div>',
+                       plain: true
+                   }).then(function (success) {
+                       var arr = vm.treeview.currentNode.calendar.down[0];
+                       for (var i = 0; i < arr.length;) {
+                           if (arr[i].rec.recid === recid)
+                               vm.remove(i);
+                           else
+                               i++;
+                       }
+                   });
+               }
+
                /* Render Tooltip */
                $scope.eventRender = function (event, element, view) {
@@ -383,23 +522,6 @@
                    }
                };
-               $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) {
-                   console.log($(".changed").length);
-                   if ($(".changed").length != 0) {
-                       ngDialog.openConfirm({
-                           template:
-                            '<p>You have unsaved changes. Are you sure you want to leave this page? All changes will be lost. </p>' +
-                            '<div>' +
-                            '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
-                            '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
-                            '</button></div>',
-                           plain: true
-                       }).then(function (success) {
-                           $rootScope.allowNavigation();
-                       });
-                   }
-                   
-                   event.preventDefault(); // This prevents the navigation from happening
-               }
-    );
+
+
 
            });
