Skip to content

Commit

Permalink
fix(admin-projects-edit): ensure selTeamMember is in correct scope
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jun 22, 2013
1 parent fd7d1b2 commit 40785cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions client/src/app/admin/projects/admin-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ angular.module('admin-projects', [
.controller('ProjectsEditCtrl', ['$scope', '$location', 'i18nNotifications', 'users', 'project', function($scope, $location, i18nNotifications, users, project) {

$scope.project = project;
$scope.selTeamMember = undefined;

$scope.users = users;
//prepare users lookup, just keep references for easier lookup
$scope.usersLookup = {};
angular.forEach(users, function(value, key) {
$scope.usersLookup[value.$id()] = value;
});

$scope.onSave = function(project) {
i18nNotifications.pushForNextRoute('crud.project.save.success', 'success', {id : project.$id()});
Expand All @@ -55,8 +48,17 @@ angular.module('admin-projects', [
i18nNotifications.pushForCurrentRoute('crud.project.save.error', 'error');
};

}])

.controller('TeamMembersController', ['$scope', function($scope) {
$scope.project.teamMembers = $scope.project.teamMembers || [];

//prepare users lookup, just keep references for easier lookup
$scope.usersLookup = {};
angular.forEach($scope.users, function(value, key) {
$scope.usersLookup[value.$id()] = value;
});

$scope.productOwnerCandidates = function() {
return $scope.users.filter(function(user) {
return $scope.usersLookup[user.$id()] && $scope.project.canActAsProductOwner(user.$id());
Expand All @@ -75,6 +77,8 @@ angular.module('admin-projects', [
});
};

$scope.selTeamMember = undefined;

$scope.addTeamMember = function() {
if($scope.selTeamMember) {
$scope.project.teamMembers.push($scope.selTeamMember);
Expand All @@ -87,5 +91,9 @@ angular.module('admin-projects', [
if(idx >= 0) {
$scope.project.teamMembers.splice(idx, 1);
}
// If we have removed the team member that is currently selected then clear this object
if($scope.selTeamMember === teamMember) {
$scope.selTeamMember = undefined;
}
};
}]);
4 changes: 2 additions & 2 deletions client/src/app/admin/projects/projects-edit.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<textarea rows="10" cols="10" ng-model="project.desc" class="span10">
</textarea>
</div>
<div class="span6">
<div class="span6" ng-controller="TeamMembersController">
<label>Product Owner</label>
<select class="span12" ng-model="project.productOwner"
ng-options="user.$id() as user.getFullName() for user in productOwnerCandidates()" required>
Expand Down Expand Up @@ -40,7 +40,7 @@
ng-options="user.$id() as user.getFullName() for user in teamMemberCandidates()"></select>
</td>
<td>
<button class="btn btn-small" ng-click="addTeamMember()" ng-disabled="!selTeamMember">Add
<button class="btn btn-small" ng-click="addTeamMember(selTeamMember)" ng-disabled="!selTeamMember">Add
</button>
</td>
</tr>
Expand Down

0 comments on commit 40785cb

Please sign in to comment.