{"size": 1248, "ext": "js", "max_stars_repo_path": "src/main/webapp/controllers/contactAddEditController.js", "max_stars_repo_name": "edetec/contact-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/main/webapp/controllers/contactAddEditController.js", "max_issues_repo_name": "edetec/contact-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/main/webapp/controllers/contactAddEditController.js", "max_forks_repo_name": "edetec/contact-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.8947368421, "max_line_length": 100, "alphanum_fraction": 0.640224359}
var contactAddEditController;

contactAddEditController = function($scope, $http, $state) {
	$scope.contact = {};
	$scope.contact.emails = [''];
	$scope.contact.phones = [''];
	$scope.submitted = false;
	
	$scope.save = function() {

		$scope.submitted = true;

		if ($scope.contact.name != null && $scope.contact.name != "") {

			// Chamar o servlet /contacts com um método 'POST' para salvar um contato no banco de dados.

			$http.post('/contacts', $scope.contact)
			.success(function(data) {
				$state.go( "main.contacts" );
			}).error(function(data, status) {
				console.log(status, data);
			});
		}

	};

	$scope.addMorePhones = function() {
		$scope.contact.phones.push('');
	}; 

	$scope.addMoreEmails = function() {
		$scope.contact.emails.push('');
	};

	$scope.deletePhone = function(index){
		if (index > -1) {
    		$scope.contact.phones.splice(index, 1);
		}

		if ($scope.contact.phones.length < 1){
			$scope.addMorePhones();
		}
	};

	$scope.deleteEmail = function(index){
		if (index > -1) {
    		$scope.contact.emails.splice(index, 1);
		}

		if ($scope.contact.emails.length < 1){
			$scope.addMoreEmails();
		}
	};

};

angular.module('avaliacandidatos').controller("contactAddEditController", contactAddEditController);