angular.module('agileApp').directive('projectList', ['UserAuthService', 'BackendService', '$modal', '$rootScope', '$timeout', function(userAuthService, backendService, $modal, $rootScope, $timeout) { return { link: function($scope, element, attrs){ $scope.textEdited = function(project) { backendService.upsertIntoDirtyObjects(project); } $scope.countForProject = function(project, type) { var count = 0; for(var c = 0; c < backendService.allTasks.length; c++) { var task = backendService.allTasks[c]; if(task.data.projectId == project.entityId && task.data.taskType == type && !task.deleted) { count++; } } return count; } $scope.newProjectHandler = function() { //$scope.newProjectTitle = ''; $scope.newProject(); //do it on 0 to refresh immediately $timeout(function() {$scope.editProject.$show(), 0}); } }, restrict: 'E', templateUrl: 'partials/project-list-partial.html' } }])