/**
 * ProjectsTasksCtrl Controller
 * Extracted from bookings module
 */

Bookings.controller('ProjectsTasksCtrl', ['$scope', '$http', 'apiUrl', 'ErrorsHandler', '$ClientsManager', function ($scope, $http, apiUrl, ErrorsHandler, $ClientsManager) {

	$scope.navType = 'pills';

	// ------------------------------------------------------------------------
	//
	//	FUNCTIONS BELOW THIS LINE -->
	//
	// ------------------------------------------------------------------------

	$scope.taskAdded = function (response) {
		$scope.data.tasks.push(response);
	};

	$scope.remove = function (task) {
		$http.post(apiUrl('tasks/helpers/remove-task-from-project'), { id: task.id, project_id: $scope.data.id })
			.success(function (response) {
				$scope.data.tasks = _.reject($scope.data.tasks, function (el) { return el.id == task.id; });
			}).error(ErrorsHandler);
	};

}]);
