Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs	(revision 13782)
@@ -1,3 +1,4 @@
-﻿using HeuristicLab.Clients.Access.Administration;
+﻿using HeuristicLab.Clients.Access;
+using HeuristicLab.Clients.Access.Administration;
 using HeuristicLab.Clients.Hive.WebJobManager.Services;
 using Microsoft.AspNet.Hosting;
@@ -8,4 +9,5 @@
 using System.Linq;
 using System.ServiceModel.Security;
+using System.Threading;
 using System.Threading.Tasks;
 
@@ -17,4 +19,5 @@
         private HiveServiceLocatorWeb serviceLocator;
         private AccessAdministrationClient accessClient;
+        private HiveAdminClientWeb adminClient;
         private Guid userId;
 
@@ -37,4 +40,5 @@
                 userId = Guid.Parse(u);
                 serviceLocator = weblog.getServiceLocator(userId);
+                adminClient = weblog.getAdminClient(userId);
                 accessClient = weblog.getAccessAdminClient(userId);
                 return serviceLocator.CheckLogin();
@@ -56,4 +60,96 @@
             }
         }
+        [HttpPost]
+        public IActionResult changeParent(string inpid, string inpidpar)
+        {
+            if (init())
+            {
+                var gid = Guid.Parse(inpid);
+                
+
+                adminClient.Refresh();
+                var tochange = adminClient.Resources.ToList().Find(x => x.Id == gid);
+                
+                if (inpidpar != null && inpidpar != "") {
+                    Guid tempid = Guid.Parse(inpidpar);
+                    while (tempid != null)
+                    {
+                        if (tempid != gid)
+                        {
+                            tempid = (Guid)adminClient.Resources.ToList().Find(x => x.Id == tempid).ParentResourceId;
+                        }
+                        else
+                            break;
+                    }
+                    if(tempid == null)
+                        tochange.ParentResourceId = Guid.Parse(inpidpar);
+                }
+                else
+                    tochange.ParentResourceId = null;
+                adminClient.Store(tochange, CancellationToken.None);
+
+                return RedirectToAction("Index", "Resource");
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+        [HttpPost]
+        public IActionResult deleteClientGroup(string inpid)
+        {
+            if (init())
+            {
+                var gid = Guid.Parse(inpid);
+
+                adminClient.Refresh();
+                var group = adminClient.Resources.ToList().Find(x => x.Id == gid);
+                var list = adminClient.Resources.ToList().FindAll(x => x.ParentResourceId == gid);
+                foreach(var cl in list)
+                {
+                    cl.ParentResourceId = group.ParentResourceId;
+                    adminClient.Store(cl, CancellationToken.None);
+                }
+                adminClient.Delete(group);
+
+                return RedirectToAction("Index", "Resource");
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
+
+        [HttpPost]
+        public IActionResult newClientGroup(string inpname, int inpheart, string inpparent, string[] clientstoadd)
+        {
+            if (init()) {
+                adminClient.Refresh();
+
+                SlaveGroup sg = new SlaveGroup();
+                sg.Id = Guid.Empty;
+                sg.Name = inpname;
+                sg.HbInterval = inpheart;
+                if (inpparent != "")
+                    sg.ParentResourceId = Guid.Parse(inpparent);
+                sg.OwnerUserId = serviceLocator.getHiveServiceClient().GetUserIdByUsername(serviceLocator.getHiveServiceClient().ClientCredentials.UserName.UserName);
+                adminClient.Store(sg, CancellationToken.None);
+                adminClient.Refresh();
+                var id = adminClient.Resources.ToList().Find(x => x.Name == inpname).Id;
+                foreach(var s in clientstoadd)
+                {
+                    var cid = Guid.Parse(s);
+                    var client = adminClient.Resources.ToList().Find(x => x.Id == cid);
+                    client.ParentResourceId = id;
+                    adminClient.Store(client, CancellationToken.None);
+                }
+
+                return RedirectToAction("Index", "Resource");
+            }
+            else
+            {
+                return RedirectToAction("Index", "Home");
+            }
+        }
     }
 }
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs	(revision 13782)
@@ -47,4 +47,15 @@
             var down = JsonConvert.SerializeObject(adminClient.Downtimes);
             Clients.Caller.processDowntime(id, down);
+        }
+        public void toggleDisposable(string id)
+        {
+            loader();
+            adminClient.Refresh();
+            Guid c = Guid.Parse(id);
+            var obj = adminClient.Resources.ToList().Find(x => x.Id == c);
+            ((Slave)(obj)).IsDisposable = !((Slave)(obj)).IsDisposable;
+            adminClient.Store(obj, CancellationToken.None);
+            Clients.Caller.processDispose( ((Slave)(obj)).IsDisposable);
+
         }
         public void saveCalendar(string id, string[] del, string[][] add, string[][] upd, bool fresh, bool last)
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js	(revision 13782)
@@ -15,5 +15,6 @@
                vm.currentcal = [];
                vm.selectedEventId = -1;
-
+               vm.groups = [];
+               vm.clients = [];
                vm.init = function () {
 
@@ -33,11 +34,18 @@
                    };
                    hubber.client.savingCurrentDone = function () {
+                       vm.calendarSaver = false;
                        $scope.clearCurrentCalendar();
                        $scope.$apply();
                    };
                    hubber.client.savingAllDone = function () {
+                       vm.calendarSaver = false;
                        clearAllCalendarsFunc();
                        $scope.$apply();
                    };
+                   hubber.client.processDispose = function (disp) {
+                       vm.treeview.currentNode.IsDisposable = disp;
+                       $scope.calendarDispose = false;
+                       $scope.$apply();
+                   }
                    hubber.client.processDowntime = function (id, down) {
                        var json = JSON.parse(down);
@@ -83,5 +91,5 @@
                        $(".selected.ng-binding").addClass('loaded');
                        $scope.selectedEventId = -1;
-                       if ($scope.treeview.currentNode != null) {
+                       if ($scope.treeview.currentNode != null && $scope.treeview.currentNode.Id != undefined) {
                            if ($scope.treeview.currentNode.calendar.length === 0) {
                                hubber.server.requestDownTime(vm.treeview.currentNode.Id);
@@ -98,4 +106,11 @@
 
                    });
+               }
+               $scope.clearTreeSelect = function () {
+                   if (vm.treeview.currentNode != undefined) {
+                       vm.treeview.currentNode.selected = undefined;
+                       vm.treeview.currentNode = undefined;
+                       vm.selectedEventId = -1;
+                   }
                }
                $scope.buildTree = function () {
@@ -103,15 +118,30 @@
                    vm.temptree = [];
                    vm.top = false;
+                   var ungrouped = {
+                       children: [],
+                       Name: 'Ungrouped'
+                   }
                    for (; vm.data.length > 0;) {
 
-                       if (vm.data[0].ParentResourceId == null) {
+                       if (vm.data[0].ParentResourceId == null && vm.data[0].IsDisposable !== undefined) {
                            var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           vm.clients.push(curr);
+                           ungrouped.children.push(curr);
+                       }
+                       else if (vm.data[0].ParentResourceId == null) {
+                           var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           vm.groups.push(curr);
                            vm.tree.push(curr);
                        }
                        else {
                            var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           if (curr.IsDisposable !== undefined)
+                               vm.clients.push(curr);
+                           else
+                               vm.groups.push(curr);
                            vm.temptree.push(curr);
                        }
                    }
+                   vm.tree.push(ungrouped);
 
                };
@@ -134,4 +164,8 @@
                    for (var t = 0; t < vm.data.length;) {
                        if (current.Id == vm.data[t].ParentResourceId) {
+                           if (vm.data[t].IsDisposable !== undefined)
+                               vm.clients.push(vm.data[t]);
+                           else
+                               vm.groups.push(vm.data[t]);
                            current.children.push(vm.data.splice(t, 1)[0]);
                        }
@@ -145,4 +179,10 @@
                    return current;
                }
+
+               $scope.toggleDisposable = function () {
+                   $scope.calendarDispose = true;
+                   hubber.server.toggleDisposable(vm.treeview.currentNode.Id);
+               }
+
                function collectInfoToSave(node, refresh, last) {
                    var arr = node.calendar.down[0];
@@ -164,5 +204,5 @@
                                "" + Date.parse(arr[i].rec.end),
                                arr[i].rec.days.join(",")
-                               
+
 
                            ]);
@@ -181,5 +221,5 @@
                                "" + Date.parse(arr[i].rec.end),
                                arr[i].rec.days.join(",")
-                               
+
                            ]);
                        }
@@ -189,8 +229,10 @@
                }
                $scope.saveCurrentCalendar = function () {
+                   vm.calendarSaver = true;
                    collectInfoToSave(vm.treeview.currentNode, true, false);
                    //true for refresh, false for showing it's only one calendar saved.
                }
                $scope.saveAllCalendars = function () {
+
                    $scope.allSave = [];
                    for (var i = 0; i < $scope.tree.length; i++)
@@ -205,4 +247,5 @@
                        plain: true
                    }).then(function (success) {
+                       vm.calendarSaver = true;
                        for (var i = 0; i < $scope.allSave.length; i++) {
                            if (i >= $scope.allSave.length - 1)
@@ -255,9 +298,9 @@
                    $scope.currentcal = [];
                    for (var i = 0; i < $scope.tree.length; i++)
-                       removeCalendarsRecurse($scope.tree[i]);
+                       clearCalendarsRecurse($scope.tree[i]);
                    hubber.server.requestDownTime(vm.treeview.currentNode.Id);
                    $(".selected.ng-binding").addClass('loaded');
                }
-               function removeCalendarsRecurse(node) {
+               function clearCalendarsRecurse(node) {
 
                    node.calendar = [];
@@ -265,9 +308,26 @@
                    node.changes = false;
                    for (var i = 0; i < node.children.length; i++) {
-                       removeCalendarsRecurse(node.children[i]);
-                   }
-               }
-
+                       clearCalendarsRecurse(node.children[i]);
+                   }
+               }
+               $scope.deleteAllEvents = function () {
+                   vm.calendarDeleter = true;
+                   vm.selectedEventId = -1;
+                   var node = vm.treeview.currentNode.calendar.down[0];
+                   for (var i = 0; i < node.length;) {
+                       if (node[i].id != '00000000-0000-0000-0000-000000000000')
+                           vm.treeview.currentNode.todelete.push(node[i].id);
+                       $scope.setChanged(vm.selectedEventId);
+                       node.splice(i, 1);
+                   }
+                   vm.calendarDeleter = false;
+                   ngDialog.open({
+                       template:
+                        '<p>All events have been deleted. Save the changes to confirm deletion, clearing will restore all the events from the server</p>',
+                       plain: true
+                   });
+               }
                $scope.deleteAllPreviousEvents = function () {
+                   vm.calendarDeleter = true;
                    vm.selectedEventId = -1;
                    var node = vm.treeview.currentNode.calendar.down[0];
@@ -282,4 +342,5 @@
                            i++;
                    }
+                   vm.calendarDeleter = false;
                    ngDialog.open({
                        template:
@@ -329,5 +390,7 @@
                    vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;
                    vm.setChanged(vm.selectedEventId);
-                   //  $("#resourcecalendar").fullCalendar('refetchEvents');
+                   $scope.currentcal = [];
+                   $scope.currentcal = vm.treeview.currentNode.calendar;
+
 
                }
@@ -342,4 +405,8 @@
                $scope.eventClick = function (date, jsEvent, view) {
                    vm.selectedEventId = checkId(date._id);
+               };
+               $scope.eventClickBtn = function (id) {
+                   vm.selectedEventId = checkId(id);
+                   vm.goToDate();
                };
                /* alert on Drop */
@@ -381,15 +448,26 @@
 
                };
+               $scope.removeList = function (id) {
+                   var index = checkId(id);
+                   vm.selectedEventId = -1;
+                   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);
+                   }
+                   vm.treeview.currentNode.calendar.down[0].splice(index, 1);
+
+
+               };
 
                $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) {
@@ -415,5 +493,5 @@
                                }
                                else {
-                                   
+
                                    arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes());
                                    arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes());
@@ -439,7 +517,7 @@
                                    loop2:
                                        for (var i = 0; i < arr.length; i++) {
-                                           
+
                                            if (arr[i].rec.recid === recid) {
-                                               var dend = (d+1000 * 3600 * 24);
+                                               var dend = (d + 1000 * 3600 * 24);
                                                if (arr[i].start.getTime() >= d &&
                                                    arr[i].end.getTime() <= dend) {
@@ -449,5 +527,5 @@
                                            }
                                        }
- 
+
                                    var ts = new Date(d);
                                    ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes());
@@ -465,7 +543,7 @@
 
                                }
-                               
+
                                d += (1000 * 3600 * 24);// 1 day
-                              
+
                            }
                    });
@@ -491,4 +569,7 @@
                }
 
+               $scope.goToDate = function () {
+                   $("#resourcecalendar").fullCalendar('gotoDate', vm.currentcal.down[0][vm.selectedEventId].start);
+               }
                /* Render Tooltip */
                $scope.eventRender = function (event, element, view) {
@@ -508,5 +589,5 @@
                        header: {
                            left: 'title',
-                           center: '',
+                           center: 'agendaWeek, agendaDay',
                            right: 'today prev,next'
                        },
@@ -520,9 +601,34 @@
 
 
-                   }
-               };
-
-
-
+
+                   }
+               };
+
+
+
+           }).filter('disp', function () {
+               return function (input) {
+                   return input ? 'Disposable' : 'Not disposable';
+               }
+           }).directive('animateOnChange', function ($timeout) {
+               return function (scope, element, attr) {
+                   scope.$watch(attr.animateOnChange, function (nv, ov) {
+
+                       if (nv != ov) {
+                           if (scope.currentcal.down[0][scope.selectedEventId].title === "Unavailable") {
+                               element.addClass('changed');
+                               $timeout(function () {
+                                   element.removeClass('changed');
+                               }, 250); // Could be enhanced to take duration as a parameter
+                           }
+                           else {
+                               element.addClass('changedshut');
+                               $timeout(function () {
+                                   element.removeClass('changedshut');
+                               }, 250); // Could be enhanced to take duration as a parameter
+                           }
+                       }
+                   });
+               };
            });
 
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Styling/StyleSheet.css
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Styling/StyleSheet.css	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Styling/StyleSheet.css	(revision 13782)
@@ -202,2 +202,16 @@
         font-style:oblique;
     }
+    [animate-on-change] {
+  transition: all 1s;
+  -webkit-transition: all 1s;
+}
+[animate-on-change].changed {
+  background-color: lightblue;
+  transition: none;
+  -webkit-transition: none;
+}
+[animate-on-change].changedshut {
+  background-color: lightsalmon;
+  transition: none;
+  -webkit-transition: none;
+}
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/HiveServiceLocatorWeb.cs
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/HiveServiceLocatorWeb.cs	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Services/Imports/HiveServiceLocatorWeb.cs	(revision 13782)
@@ -38,5 +38,5 @@
 
 
-        #region #unknownCalls
+
         public void CallHiveService(Action<IHiveService> call)
         {
@@ -80,5 +80,4 @@
             }
         }
-        #endregion unknown
 
         /// <summary>
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Resource/Index.cshtml
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Resource/Index.cshtml	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Resource/Index.cshtml	(revision 13782)
@@ -5,7 +5,8 @@
     @Html.Partial("Navbar", new HeuristicLab.Clients.Hive.WebJobManager.ViewModels.NavbarViewModel("Resource"))
 
-    
+
 
     <div class="col-sm-4">
+        <div class="btn btn-block btn-success" ng-click="clearTreeSelect()">Add group</div>
         <div data-angular-treeview="true"
              data-tree-id="treeview"
@@ -17,56 +18,115 @@
         </div>
     </div>
-    <div ng-if="treeview.currentNode" class="col-sm-8 panel  panel-primary" style="margin-bottom:200px">
-        <div class="row panel-heading">
-            <h3>{{treeview.currentNode.Name}} <span ng-if="treeview.currentNode.IsDisposable === undefined"> - Client group</span></h3>
-            <table class="table">
-                <tbody>
-                    <tr>
-                        <td>Heartbeat</td>
-                        <td>
-                            Every {{treeview.currentNode.HbInterval}} sec
-                            <span ng-if="treeview.currentNode.IsDisposable !== undefined">
-                                - Last beat {{treeview.currentNode.LastHeartbeat | date:'HH:mm dd/MM/yyyy' }}
-                            </span>
-                        </td>
-                    </tr>
-                    <tr>
-                        <td>Name</td>
-                        <td>{{treeview.currentNode.Name}}</td>
-                    </tr>
-                    <tr>
-                        <td>Id</td>
-                        <td>{{treeview.currentNode.Id}}</td>
-                    </tr>
-                    <tr>
-                        <td>Disposable</td>
-                        <td><input type="checkbox" ng-checked="treeview.currentNode.IsDisposable" /></td>
-                    </tr>
-                </tbody>
-                <tbody ng-if="treeview.currentNode.IsDisposable !== undefined">
-                    <tr>
-                        <td>Cores (free/total)</td>
-                        <td>{{treeview.currentNode.FreeCores}} | {{treeview.currentNode.Cores}}</td>
-
-
-                    </tr>
-                    <tr>
-                        <td>Memory (free/total)</td>
-                        <td>{{treeview.currentNode.FreeMemory}} MB | {{treeview.currentNode.Memory}} MB</td>
-                    </tr>
-
-                </tbody>
-            </table>
+    <div ng-if="treeview.currentNode && treeview.currentNode.Id !== undefined" class="col-sm-8 panel  panel-primary" style="margin-bottom:200px">
+        <div class="row panel-heading"
+             style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+            <h3>
+                {{treeview.currentNode.Name}}
+                <span ng-if="treeview.currentNode.IsDisposable === undefined"> - Client group</span>
+                <a ng-if="treeview.currentNode.IsDisposable !== undefined"
+                   class="btn pull-right"
+                   style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;font-weight:bold;margin-bottom:5px"
+                   ng-class="{ 'btn-success': treeview.currentNode.IsDisposable, 'btn-warning': !treeview.currentNode.IsDisposable }"
+                   ng-click="toggleDisposable()">
+                    <span ng-if="calendarDispose"><i class="fa fa-save fa-spin"></i> </span> {{ treeview.currentNode.IsDisposable | disp}}
+                </a>
+            </h3>
+            <form method="post"
+                  asp-action="deleteClientGroup"
+                  ng-init="checkDel = false"
+                  asp-controller="Resource"
+                  enctype="multipart/form-data"
+                  class="row panel-heading"
+                  style="padding:10px">
+                <table class="table" style="margin-bottom:0px">
+                    <tbody>
+                        <tr>
+                            <td>Heartbeat</td>
+                            <td>
+                                Every {{treeview.currentNode.HbInterval}} sec
+                                <span ng-if="treeview.currentNode.IsDisposable !== undefined">
+                                    - Last beat {{treeview.currentNode.LastHeartbeat | date:'HH:mm dd/MM/yyyy' }}
+                                </span>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>Name</td>
+                            <td>{{treeview.currentNode.Name}}</td>
+                        </tr>
+                        <tr>
+                            <td>Id</td>
+                            <td>{{treeview.currentNode.Id}}</td>
+                        </tr>
+                        <tr ng-if="treeview.currentNode.IsDisposable === undefined">
+
+                            <td>
+
+                                <input style="display:none" type="text" id="inpid" name="inpid" value="{{treeview.currentNode.Id}}" />
+                                <input type="checkbox" ng-model="checkDel" /> I want to delete this group
+                            </td>
+                            <td>
+                                <button type="submit"
+                                        id="inpsaver"
+                                        ng-disabled="!checkDel"
+                                        class="btn btn-danger">
+                                    <i class="fa fa-trash-o"></i>
+                                    Delete group (irriversible action!)
+                                </button>
+
+                            </td>
+
+                        </tr>
+                    </tbody>
+                    <tbody ng-if="treeview.currentNode.IsDisposable !== undefined">
+                        <tr>
+                            <td>Cores (free/total)</td>
+                            <td>{{treeview.currentNode.FreeCores}} / {{treeview.currentNode.Cores}} @@ {{treeview.currentNode.CpuSpeed/1000 | number:1}} GHz</td>
+
+
+                        </tr>
+                        <tr>
+                            <td>Memory (free/total)</td>
+                            <td>{{treeview.currentNode.FreeMemory/1024 | number:1}} GB / {{treeview.currentNode.Memory/1024 | number:1}} GB</td>
+                        </tr>
+
+                    </tbody>
+                </table>
+            </form>
+            <form method="post"
+                  asp-action="changeParent"
+                  asp-controller="Resource"
+                  enctype="multipart/form-data"
+                  class="row"
+                  style="padding:10px"
+                  >
+                <input style="display:none" type="text" id="inpid" name="inpid" value="{{treeview.currentNode.Id}}" />
+
+                <span style="padding:0px" class="col-sm-4">Change parent resource: </span>
+                
+                <select class="form-control col-sm-5" 
+                        style="width:200px" 
+                        id="inpidpar" 
+                        name="inpidpar" 
+                        ng-model="treeview.currentNode.ParentResourceId">
+                    <option value="">None</option>
+                    <option ng-repeat="group in groups | orderBy:'Name'" 
+                            value="{{group.Id}}"
+                            ng-if="group.Id !=treeview.currentNode.Id && group.ParentResourceId != treeview.currentNode.Id">
+                        {{group.Name}}
+                    </option>
+
+                </select>
+                <button type="submit"
+                        id="inpsaver"
+                        class="btn btn-warning col-sm-3 pull-right">
+                    <i class="fa fa-save"></i>
+                    Change parent
+                </button>
+            </form>
         </div>
         <div class="panel-body row" style="text-align:center">
-            <div class="row" style="padding-bottom:30px;">
-                <button class="btn btn-success" ng-click="saveCurrentCalendar()">Save current changes</button>
-                <button class="btn btn-success" ng-click="saveAllCalendars()">Save all changes</button>
-                <button class="btn btn-warning" ng-click="clearCurrentCalendar()">Clear current changes</button>
-                <button class="btn btn-warning" ng-click="clearAllCalendars()">Clear all changes</button>
-            </div>
-            <div class="row" style="padding-bottom:30px;">
-                <button class="btn btn-info" ng-click="deleteAllPreviousEvents()">Delete all previous events to date</button>
-            </div>
+
             <i ng-if="currentcal.length  === 0" class="fa fa-cog fa-5x fa-spin"></i>
             <div ng-if="currentcal.length != 0"
@@ -76,8 +136,18 @@
                  class="span8 calendar"
                  ng-model="currentcal.down"></div>
-            <table ng-if="selectedEventId != -1" class="table">
-                <tr>
-                    <th colspan="2"> Selected event</th>
-
+            <table ng-if="selectedEventId != -1"
+                   animate-on-change="selectedEventId"
+                   class="table">
+                <tr>
+                    <th> Selected event</th>
+                    <th>
+                        <div class="btn btn-default"
+                             ng-click="goToDate()"
+                             ng-style="{'background-color':currentcal.down[0][selectedEventId].color }"
+                             style="color:white;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;font-weight:bold;">
+                            <i class="fa fa-calendar"></i> Go to date
+                        </div>
+                    </th>
                 </tr>
                 <tr>
@@ -119,21 +189,21 @@
                     </td>
                     <td>
-                        <input type="date" 
-                               ng-model="currentcal.down[0][selectedEventId].rec.start" 
+                        <input type="date"
+                               ng-model="currentcal.down[0][selectedEventId].rec.start"
                                ng-change="checkDateStartEnd()" />
                     </td>
                 </tr>
-                <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence" >
+                <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence">
                     <td>
                         End
                     </td>
                     <td>
-                        <input type="date" 
-                               ng-model="currentcal.down[0][selectedEventId].rec.end" 
-                               ng-change="checkDateStartEnd()" 
-                               min="{{currentcal.down[0][selectedEventId].rec.start | date:'yyyy-MM-dd'}}"/>
-                    </td>
-                </tr>
-                
+                        <input type="date"
+                               ng-model="currentcal.down[0][selectedEventId].rec.end"
+                               ng-change="checkDateStartEnd()"
+                               min="{{currentcal.down[0][selectedEventId].rec.start | date:'yyyy-MM-dd'}}" />
+                    </td>
+                </tr>
+
                 <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence">
                     <td colspan="2">
@@ -146,5 +216,5 @@
                         <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[0]">Sunday</label>
                     </td>
-                    
+
                 </tr>
                 <tr>
@@ -153,5 +223,7 @@
                         <button class="btn btn-info"
                                 ng-click="pushRecurChanges(currentcal.down[0][selectedEventId].rec.recid)"
-                                ng-if="currentcal.down[0][selectedEventId].rec.recid != '0' && 
+                                style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;"
+                                ng-if="currentcal.down[0][selectedEventId].rec.recid != '0' &&
                                 currentcal.down[0][selectedEventId].rec.recid != '00000000-0000-0000-0000-000000000000' &&
                                 currentcal.down[0][selectedEventId].changed">
@@ -159,4 +231,6 @@
                         </button>
                         <button class="btn btn-danger"
+                                style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;"
                                 ng-click="remove(selectedEventId)">
                             <i class="fa fa-trash-o"></i>
@@ -164,4 +238,6 @@
                         </button>
                         <button class="btn btn-danger"
+                                style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;"
                                 ng-click="deleteAllRecurrences(currentcal.down[0][selectedEventId].rec.recid)"
                                 ng-if="currentcal.down[0][selectedEventId].rec.recid != '0'
@@ -173,18 +249,198 @@
             </table>
             <table ng-if="selectedEventId === -1" class="table">
-            <tr>
-                <th colspan="2"> Select an event to show information</th>
-
-            </tr>
-            <tr>
-                <td>Time / Select an event</td>
-                   </tr>
-            <tr>
-                <td>Status / Select an event</td>
-            </tr>
+                <tr>
+                    <th colspan="2"> Select an event to show information</th>
+
+                </tr>
+                <tr>
+                    <td>Time / Select an event</td>
+                </tr>
+                <tr>
+                    <td>Status / Select an event</td>
+                </tr>
             </table>
+            <div ng-if="calendarSaver">
+                <i class="fa fa-save fa-4x fa-spin"></i>
+            </div>
+            <div ng-if="calendarDeleter">
+                <i class="fa fa-trash-o fa-4x fa-spin"></i>
+            </div>
+            <div class="row">
+                <h3>Current calendar - actions</h3>
+                <div class="btn-group btn-group-justified"
+                     role="group"
+                     style="padding-bottom:20px;">
+
+                    <div ng-if="treeview.currentNode.changes"
+                         class="btn btn-success"
+                         ng-click="saveCurrentCalendar()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Save current changes
+                    </div>
+                    <div ng-if="treeview.currentNode.changes"
+                         class="btn btn-warning"
+                         ng-click="clearCurrentCalendar()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Clear current changes
+                    </div>
+                    <div class="btn btn-danger"
+                         ng-click="deleteAllPreviousEvents()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Delete past events
+                    </div>
+                    <div class="btn btn-danger"
+                         ng-click="deleteAllEvents()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Delete all events
+                    </div>
+                </div>
+            </div>
+            <div class="row">
+                <h3>All loaded calendars - actions</h3>
+                <div class="btn-group btn-group-justified"
+                     role="group"
+                     style="padding-bottom:20px;">
+
+                    <div class="btn btn-success"
+                         ng-click="saveAllCalendars()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Save all changes
+                    </div>
+
+                    <div class="btn btn-warning"
+                         ng-click="clearAllCalendars()"
+                         style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                        Clear all changes
+                    </div>
+                </div>
+            </div>
+
         </div>
 
         <div class="row panel-footer">
+            <h2>All events </h2><h5>(sorted by changed and start date)</h5>
+            <div class="row" ng-repeat="ev in currentcal.down[0] | orderBy:['!changed','start'] track by $index">
+                <div class="btn-group-justified btn-block">
+
+                    <div class="btn btn-default" ng-style="{'background-color': ev.color}"
+                         ng-click="eventClickBtn(ev._id)"
+                         style="width:6%;color:white;
+                            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);text-shadow:2px 2px black;">
+                        {{ev.title }}
+                        <span ng-if="!ev.allDay">
+                            from {{ev.start | date : 'HH:mm dd/MM/yy' : 'utc'}}
+                            <span ng-if="ev.end">
+                                to {{ev.end | date : 'HH:mm dd/MM/yy': 'utc'}}
+                            </span>
+                        </span>
+                        <span ng-if="ev.allDay">
+                            all day from {{ev.start | date : 'dd/MM/yy' : 'utc'}}
+                            <span ng-if="ev.end">
+                                to {{ev.end | date : 'dd/MM/yy': 'utc'}}
+                            </span>
+                        </span>
+                        <span ng-if="ev.rec.recurrence">
+                            | recurring event
+                        </span>
+                    </div>
+                    <a id="del"
+                       style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;"
+                       class='btn btn-group btn-danger'
+                       ng-click="removeList(ev._id)">
+                        <span class='glyphicon glyphicon-trash' aria-hidden='true'></span>
+                    </a>
+                </div>
+
+            </div>
+
+        </div>
+    </div>
+    <div ng-show="treeview.currentNode === undefined"
+         style="margin-bottom:200px">
+        <form method="post"
+              ng-init="newName = ''"
+              asp-action="newClientGroup"
+              asp-controller="Resource"
+              enctype="multipart/form-data"
+              class="col-sm-8 panel  panel-primary">
+            <div class="row panel-heading"
+                 style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+                <h3>
+                    Add new client group
+                </h3>
+                <table class="table">
+                    <tbody>
+                        <tr>
+                            <td>Heartbeat</td>
+                            <td>
+                                <i class="fa fa-clock-o fa-2x pull-left"></i> <input type="number" class="form-control" style="width:70px" name="inpheart" id="inpheart" value="60" placeholder="60" />
+
+
+                            </td>
+                        </tr>
+                        <tr>
+                            <td>Name</td>
+                            <td><input type="text" class="form-control" id="inpname" name="inpname" ng-model="newName" placeholder="Group name" /></td>
+                        </tr>
+                        <tr>
+                            <td>Assign parent group</td>
+                            <td>
+                                <select class="form-control" id="inpparent" name="inpparent">
+                                    <option value="">None</option>
+                                    <option ng-repeat="group in groups | orderBy:'Name'" value="{{group.Id}}">{{group.Name}}</option>
+
+                                </select>
+                            </td>
+                        </tr>
+                    </tbody>
+
+                </table>
+                <button type="submit"
+                        id="inpsaver"
+                        ng-disabled="newName === ''"
+                        class="btn btn-success">
+                    <i class="fa fa-save"></i>
+                    Add {{newName}} group
+                </button>
+            </div>
+            <div class="panel-body row">
+                <h3>Choose clients </h3>
+                <h5>(This will overwrite the group set for these clients)</h5>
+                <table>
+                    <tr ng-repeat="client in clients  | orderBy:['Name'] track by $index" class="checkbox col-md-6 col-lg-4">
+                        <td>
+                            <label>
+                                <input type="checkbox"
+                                       name="clientstoadd"
+                                       value="{{client.Id}}">
+                                <i class="fa fa-desktop" aria-hidden="true"></i> {{client.Name | limitTo : 7}} - {{client.Cores}}x {{client.CpuSpeed/1000 |  number:1}} GHz - {{client.Memory / 1024 | number:1}} GB
+                            </label>
+                        </td>
+                    </tr>
+                </table>
+            </div>
+        </form>
+    </div>
+
+    <div ng-if="treeview.currentNode !== undefined && treeview.currentNode.Id === undefined"
+         class="col-sm-8 panel  panel-primary"
+         style="margin-bottom:200px">
+        <div class="row panel-heading"
+             style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
+                            text-shadow:2px 2px black;">
+            <h2>
+                Ungrouped
+            </h2>
+            <h3>
+                All unassigned clients arrive here. Assign them to a group to remove them from this group.
+            </h3>
 
         </div>
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/css/site.min.css
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/css/site.min.css	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/css/site.min.css	(revision 13782)
@@ -1,3 +1,3 @@
-@import url(http://fonts.googleapis.com/css?family=Roboto:400);.wrapper,h4{text-align:center}.label,sub,sup{vertical-align:baseline}[role=button],div[data-tree-model] li i,div[data-tree-model] li span{cursor:pointer}.fc table,table{border-spacing:0}.btn-group>.btn-group,.btn-toolbar .btn,.btn-toolbar .btn-group,.btn-toolbar .input-group,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9,.dropdown-menu{float:left}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse,.pre-scrollable{max-height:340px}.fa,.glyphicon{-moz-osx-font-smoothing:grayscale}body{-webkit-font-smoothing:antialiased;font:400 14px Roboto,arial,sans-serif}.container{padding:25px;position:fixed}.form-login{background-color:#EDEDED;border-radius:15px;border-color:#d2d2d2;border-width:5px;box-shadow:0 1px 0 #cfcfcf;padding:10px 20px 20px;padding:10px 20px 20px}h4{border:0 solid #fff;border-bottom-width:1px;padding-bottom:10px}.panel-warning>.panel-heading{background-image:linear-gradient(to bottom,#eb9114 0,#f1b25b 100%)!important;color:#fff!important}.panel-danger>.panel-heading{background-image:linear-gradient(to bottom,#c12e2a 0,#d9534f 100%)!important;color:#fff!important}.label-as-badge{border-radius:1em}.bar-off{fill:#c2c2d6}.bar-off:hover{fill:#e0e0eb}.bar-wait{fill:#f0a742}.bar-wait:hover{fill:#f4bd71}.bar-trans{fill:#80d4ff}.bar-trans:hover{fill:#9df}.bar-calc{fill:#2f6fa6}.bar-calc:hover{fill:#3884c7}.bar-paus{fill:#47476b}.bar-paus:hover{fill:#5c5c8a}.bar-fin{fill:#5cb85c}.bar-fin:hover{fill:#71c171}.bar-abo{fill:#c2302c}.bar-abo:hover{fill:#d54944}.bar-fail{fill:#c2302c}.bar-fail:hover{fill:#d54944}rect.selection{stroke:gray;stroke-dasharray:4px;stroke-opacity:.5;fill:transparent}svg ::selection{background:0 0}svg ::-moz-selection{background:0 0}svg ::-webkit-selection{background:0 0}.btn-danger:focus,.btn-danger:hover,.btn-default:focus,.btn-default:hover,.btn-info:focus,.btn-info:hover,.btn-primary:focus,.btn-primary:hover,.btn-success:focus,.btn-success:hover,.btn-warning:focus,.btn-warning:hover{background-position:0 -15px}div[data-tree-model] li .changed{background-color:#ff0;font-weight:700;padding:1px 5px}div[data-tree-model] li .loaded{text-decoration:underline;font-style:oblique}div[data-angular-treeview]{-moz-user-select:-moz-none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;font-family:Tahoma;font-size:13px;color:#555;text-decoration:none}div[data-tree-model] ul{margin:0;padding:0;list-style:none;border:none;overflow:hidden}div[data-tree-model] li{position:relative;padding:0 0 0 20px;line-height:20px}div[data-tree-model] li .expanded{padding:1px 10px;background-image:url(../img/folder.png);background-repeat:no-repeat}div[data-tree-model] li .collapsed{padding:1px 10px;background-image:url(../img/folder-closed.png);background-repeat:no-repeat}div[data-tree-model] li .normal{padding:1px 10px;background-image:url(../img/file.png);background-repeat:no-repeat}div[data-tree-model] li .selected{background-color:#adf;font-weight:700;padding:1px 5px}/*!
+@import url(http://fonts.googleapis.com/css?family=Roboto:400);.wrapper,h4{text-align:center}.label,sub,sup{vertical-align:baseline}[role=button],div[data-tree-model] li i,div[data-tree-model] li span{cursor:pointer}.fc table,table{border-spacing:0}.btn-group>.btn-group,.btn-toolbar .btn,.btn-toolbar .btn-group,.btn-toolbar .input-group,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9,.dropdown-menu{float:left}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse,.pre-scrollable{max-height:340px}.fa,.glyphicon{-moz-osx-font-smoothing:grayscale}body{-webkit-font-smoothing:antialiased;font:400 14px Roboto,arial,sans-serif}.container{padding:25px;position:fixed}.form-login{background-color:#EDEDED;border-radius:15px;border-color:#d2d2d2;border-width:5px;box-shadow:0 1px 0 #cfcfcf;padding:10px 20px 20px;padding:10px 20px 20px}h4{border:0 solid #fff;border-bottom-width:1px;padding-bottom:10px}.panel-warning>.panel-heading{background-image:linear-gradient(to bottom,#eb9114 0,#f1b25b 100%)!important;color:#fff!important}.panel-danger>.panel-heading{background-image:linear-gradient(to bottom,#c12e2a 0,#d9534f 100%)!important;color:#fff!important}.label-as-badge{border-radius:1em}.bar-off{fill:#c2c2d6}.bar-off:hover{fill:#e0e0eb}.bar-wait{fill:#f0a742}.bar-wait:hover{fill:#f4bd71}.bar-trans{fill:#80d4ff}.bar-trans:hover{fill:#9df}.bar-calc{fill:#2f6fa6}.bar-calc:hover{fill:#3884c7}.bar-paus{fill:#47476b}.bar-paus:hover{fill:#5c5c8a}.bar-fin{fill:#5cb85c}.bar-fin:hover{fill:#71c171}.bar-abo{fill:#c2302c}.bar-abo:hover{fill:#d54944}.bar-fail{fill:#c2302c}.bar-fail:hover{fill:#d54944}rect.selection{stroke:gray;stroke-dasharray:4px;stroke-opacity:.5;fill:transparent}svg ::selection{background:0 0}svg ::-moz-selection{background:0 0}svg ::-webkit-selection{background:0 0}.btn-danger:focus,.btn-danger:hover,.btn-default:focus,.btn-default:hover,.btn-info:focus,.btn-info:hover,.btn-primary:focus,.btn-primary:hover,.btn-success:focus,.btn-success:hover,.btn-warning:focus,.btn-warning:hover{background-position:0 -15px}div[data-tree-model] li .changed{background-color:#ff0;font-weight:700;padding:1px 5px}div[data-tree-model] li .loaded{text-decoration:underline;font-style:oblique}[animate-on-change]{transition:all 1s;-webkit-transition:all 1s}[animate-on-change].changed{background-color:#add8e6;transition:none;-webkit-transition:none}[animate-on-change].changedshut{background-color:#ffa07a;transition:none;-webkit-transition:none}div[data-angular-treeview]{-moz-user-select:-moz-none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;font-family:Tahoma;font-size:13px;color:#555;text-decoration:none}div[data-tree-model] ul{margin:0;padding:0;list-style:none;border:none;overflow:hidden}div[data-tree-model] li{position:relative;padding:0 0 0 20px;line-height:20px}div[data-tree-model] li .expanded{padding:1px 10px;background-image:url(../img/folder.png);background-repeat:no-repeat}div[data-tree-model] li .collapsed{padding:1px 10px;background-image:url(../img/folder-closed.png);background-repeat:no-repeat}div[data-tree-model] li .normal{padding:1px 10px;background-image:url(../img/file.png);background-repeat:no-repeat}div[data-tree-model] li .selected{background-color:#adf;font-weight:700;padding:1px 5px}/*!
  * Bootstrap v3.3.6 (http://getbootstrap.com)
  * Copyright 2011-2015 Twitter, Inc.
Index: /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js
===================================================================
--- /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js	(revision 13781)
+++ /branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js	(revision 13782)
@@ -15,5 +15,6 @@
                vm.currentcal = [];
                vm.selectedEventId = -1;
-
+               vm.groups = [];
+               vm.clients = [];
                vm.init = function () {
 
@@ -33,11 +34,18 @@
                    };
                    hubber.client.savingCurrentDone = function () {
+                       vm.calendarSaver = false;
                        $scope.clearCurrentCalendar();
                        $scope.$apply();
                    };
                    hubber.client.savingAllDone = function () {
+                       vm.calendarSaver = false;
                        clearAllCalendarsFunc();
                        $scope.$apply();
                    };
+                   hubber.client.processDispose = function (disp) {
+                       vm.treeview.currentNode.IsDisposable = disp;
+                       $scope.calendarDispose = false;
+                       $scope.$apply();
+                   }
                    hubber.client.processDowntime = function (id, down) {
                        var json = JSON.parse(down);
@@ -83,5 +91,5 @@
                        $(".selected.ng-binding").addClass('loaded');
                        $scope.selectedEventId = -1;
-                       if ($scope.treeview.currentNode != null) {
+                       if ($scope.treeview.currentNode != null && $scope.treeview.currentNode.Id != undefined) {
                            if ($scope.treeview.currentNode.calendar.length === 0) {
                                hubber.server.requestDownTime(vm.treeview.currentNode.Id);
@@ -98,4 +106,11 @@
 
                    });
+               }
+               $scope.clearTreeSelect = function () {
+                   if (vm.treeview.currentNode != undefined) {
+                       vm.treeview.currentNode.selected = undefined;
+                       vm.treeview.currentNode = undefined;
+                       vm.selectedEventId = -1;
+                   }
                }
                $scope.buildTree = function () {
@@ -103,15 +118,30 @@
                    vm.temptree = [];
                    vm.top = false;
+                   var ungrouped = {
+                       children: [],
+                       Name: 'Ungrouped'
+                   }
                    for (; vm.data.length > 0;) {
 
-                       if (vm.data[0].ParentResourceId == null) {
+                       if (vm.data[0].ParentResourceId == null && vm.data[0].IsDisposable !== undefined) {
                            var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           vm.clients.push(curr);
+                           ungrouped.children.push(curr);
+                       }
+                       else if (vm.data[0].ParentResourceId == null) {
+                           var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           vm.groups.push(curr);
                            vm.tree.push(curr);
                        }
                        else {
                            var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
+                           if (curr.IsDisposable !== undefined)
+                               vm.clients.push(curr);
+                           else
+                               vm.groups.push(curr);
                            vm.temptree.push(curr);
                        }
                    }
+                   vm.tree.push(ungrouped);
 
                };
@@ -134,4 +164,8 @@
                    for (var t = 0; t < vm.data.length;) {
                        if (current.Id == vm.data[t].ParentResourceId) {
+                           if (vm.data[t].IsDisposable !== undefined)
+                               vm.clients.push(vm.data[t]);
+                           else
+                               vm.groups.push(vm.data[t]);
                            current.children.push(vm.data.splice(t, 1)[0]);
                        }
@@ -145,4 +179,10 @@
                    return current;
                }
+
+               $scope.toggleDisposable = function () {
+                   $scope.calendarDispose = true;
+                   hubber.server.toggleDisposable(vm.treeview.currentNode.Id);
+               }
+
                function collectInfoToSave(node, refresh, last) {
                    var arr = node.calendar.down[0];
@@ -164,5 +204,5 @@
                                "" + Date.parse(arr[i].rec.end),
                                arr[i].rec.days.join(",")
-                               
+
 
                            ]);
@@ -181,5 +221,5 @@
                                "" + Date.parse(arr[i].rec.end),
                                arr[i].rec.days.join(",")
-                               
+
                            ]);
                        }
@@ -189,8 +229,10 @@
                }
                $scope.saveCurrentCalendar = function () {
+                   vm.calendarSaver = true;
                    collectInfoToSave(vm.treeview.currentNode, true, false);
                    //true for refresh, false for showing it's only one calendar saved.
                }
                $scope.saveAllCalendars = function () {
+
                    $scope.allSave = [];
                    for (var i = 0; i < $scope.tree.length; i++)
@@ -205,4 +247,5 @@
                        plain: true
                    }).then(function (success) {
+                       vm.calendarSaver = true;
                        for (var i = 0; i < $scope.allSave.length; i++) {
                            if (i >= $scope.allSave.length - 1)
@@ -255,9 +298,9 @@
                    $scope.currentcal = [];
                    for (var i = 0; i < $scope.tree.length; i++)
-                       removeCalendarsRecurse($scope.tree[i]);
+                       clearCalendarsRecurse($scope.tree[i]);
                    hubber.server.requestDownTime(vm.treeview.currentNode.Id);
                    $(".selected.ng-binding").addClass('loaded');
                }
-               function removeCalendarsRecurse(node) {
+               function clearCalendarsRecurse(node) {
 
                    node.calendar = [];
@@ -265,9 +308,26 @@
                    node.changes = false;
                    for (var i = 0; i < node.children.length; i++) {
-                       removeCalendarsRecurse(node.children[i]);
-                   }
-               }
-
+                       clearCalendarsRecurse(node.children[i]);
+                   }
+               }
+               $scope.deleteAllEvents = function () {
+                   vm.calendarDeleter = true;
+                   vm.selectedEventId = -1;
+                   var node = vm.treeview.currentNode.calendar.down[0];
+                   for (var i = 0; i < node.length;) {
+                       if (node[i].id != '00000000-0000-0000-0000-000000000000')
+                           vm.treeview.currentNode.todelete.push(node[i].id);
+                       $scope.setChanged(vm.selectedEventId);
+                       node.splice(i, 1);
+                   }
+                   vm.calendarDeleter = false;
+                   ngDialog.open({
+                       template:
+                        '<p>All events have been deleted. Save the changes to confirm deletion, clearing will restore all the events from the server</p>',
+                       plain: true
+                   });
+               }
                $scope.deleteAllPreviousEvents = function () {
+                   vm.calendarDeleter = true;
                    vm.selectedEventId = -1;
                    var node = vm.treeview.currentNode.calendar.down[0];
@@ -282,4 +342,5 @@
                            i++;
                    }
+                   vm.calendarDeleter = false;
                    ngDialog.open({
                        template:
@@ -329,5 +390,7 @@
                    vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;
                    vm.setChanged(vm.selectedEventId);
-                   //  $("#resourcecalendar").fullCalendar('refetchEvents');
+                   $scope.currentcal = [];
+                   $scope.currentcal = vm.treeview.currentNode.calendar;
+
 
                }
@@ -342,4 +405,8 @@
                $scope.eventClick = function (date, jsEvent, view) {
                    vm.selectedEventId = checkId(date._id);
+               };
+               $scope.eventClickBtn = function (id) {
+                   vm.selectedEventId = checkId(id);
+                   vm.goToDate();
                };
                /* alert on Drop */
@@ -381,15 +448,26 @@
 
                };
+               $scope.removeList = function (id) {
+                   var index = checkId(id);
+                   vm.selectedEventId = -1;
+                   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);
+                   }
+                   vm.treeview.currentNode.calendar.down[0].splice(index, 1);
+
+
+               };
 
                $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) {
@@ -415,5 +493,5 @@
                                }
                                else {
-                                   
+
                                    arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes());
                                    arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes());
@@ -439,7 +517,7 @@
                                    loop2:
                                        for (var i = 0; i < arr.length; i++) {
-                                           
+
                                            if (arr[i].rec.recid === recid) {
-                                               var dend = (d+1000 * 3600 * 24);
+                                               var dend = (d + 1000 * 3600 * 24);
                                                if (arr[i].start.getTime() >= d &&
                                                    arr[i].end.getTime() <= dend) {
@@ -449,5 +527,5 @@
                                            }
                                        }
- 
+
                                    var ts = new Date(d);
                                    ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes());
@@ -465,7 +543,7 @@
 
                                }
-                               
+
                                d += (1000 * 3600 * 24);// 1 day
-                              
+
                            }
                    });
@@ -491,4 +569,7 @@
                }
 
+               $scope.goToDate = function () {
+                   $("#resourcecalendar").fullCalendar('gotoDate', vm.currentcal.down[0][vm.selectedEventId].start);
+               }
                /* Render Tooltip */
                $scope.eventRender = function (event, element, view) {
@@ -508,5 +589,5 @@
                        header: {
                            left: 'title',
-                           center: '',
+                           center: 'agendaWeek, agendaDay',
                            right: 'today prev,next'
                        },
@@ -520,9 +601,34 @@
 
 
-                   }
-               };
-
-
-
+
+                   }
+               };
+
+
+
+           }).filter('disp', function () {
+               return function (input) {
+                   return input ? 'Disposable' : 'Not disposable';
+               }
+           }).directive('animateOnChange', function ($timeout) {
+               return function (scope, element, attr) {
+                   scope.$watch(attr.animateOnChange, function (nv, ov) {
+
+                       if (nv != ov) {
+                           if (scope.currentcal.down[0][scope.selectedEventId].title === "Unavailable") {
+                               element.addClass('changed');
+                               $timeout(function () {
+                                   element.removeClass('changed');
+                               }, 250); // Could be enhanced to take duration as a parameter
+                           }
+                           else {
+                               element.addClass('changedshut');
+                               $timeout(function () {
+                                   element.removeClass('changedshut');
+                               }, 250); // Could be enhanced to take duration as a parameter
+                           }
+                       }
+                   });
+               };
            });
 
