 )
 
 .controller('EditUnitCtrl', ($scope, $state, $stateParams, Convenor, Tutor, UnitRole, unitService, headerService, alertService, analyticsService) ->
+  unitService.getUnit $state.params.unitId, true, true, (unit) ->
+    $scope.unit = unit
+    $scope.newUnit = $scope.unit.id == -1
+    $scope.currentStaff = $scope.unit.staff
+    UnitRole.query (roles) ->
+      $scope.unitRoles = _.filter(roles, (role) -> role.unit_id == unit.id)
+      if $scope.unitRoles
+        $scope.assessingUnitRole = $scope.unitRoles[0]
+  
   #
   # Active tab group
   #

    $scope.activeTab = tab
    $scope.activeTab.active = true
    # Actions to take when selecting this tab
    analyticsService.event "#{if $scope.newUnit then 'Edit' else 'Create'} Unit View", "Switched Tab as #{$scope.assessingUnitRole.role}", "#{tab.title} Tab"

  $scope.activeTab = $scope.tabs.unitTab


      $scope.staff = staff
    )
  )
)

.controller('AddUnitCtrl', ($scope, $modalInstance, alertService, units, Unit) ->
