| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 20:24:03 -07:00
										 |  |  | angular.module('app').controller("SetupController", function($scope, $http, $routeParams, $window, $location) { | 
					
						
							| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// create a remote that will be populated
 | 
					
						
							|  |  |  | 	// and persisted to the database.
 | 
					
						
							|  |  |  | 	$scope.remote = {}; | 
					
						
							|  |  |  | 	$scope.remote.type = $routeParams.remote; | 
					
						
							| 
									
										
										
										
											2014-07-12 19:01:58 -07:00
										 |  |  | 	$scope.remote.register = false; | 
					
						
							|  |  |  | 	$scope.window = $window | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// pre-populate the form if the remote
 | 
					
						
							|  |  |  | 	// type is selected and is a cloud service
 | 
					
						
							|  |  |  | 	// with a known URL and standard configuration.
 | 
					
						
							| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 	switch($scope.remote.type) { | 
					
						
							|  |  |  | 	case 'github.com': | 
					
						
							|  |  |  | 		$scope.remote.type = "github.com" | 
					
						
							|  |  |  | 		$scope.remote.url = "https://github.com"; | 
					
						
							|  |  |  | 		$scope.remote.api = "https://api.github.com"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 'bitbucket.org': | 
					
						
							|  |  |  | 		$scope.remote.url = "https://bitbucket.org"; | 
					
						
							|  |  |  | 		$scope.remote.api = "https://bitbucket.org"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-13 20:24:03 -07:00
										 |  |  | 	// todo(bradrydzewski) move this to the remote.js service.
 | 
					
						
							| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 	$scope.save = function() { | 
					
						
							|  |  |  | 		// request to create a new repository
 | 
					
						
							| 
									
										
										
										
											2014-09-30 00:43:50 -07:00
										 |  |  | 		$http({method: 'POST', url: '/api/remotes', data: $scope.remote }). | 
					
						
							| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 			success(function(data, status, headers, config) { | 
					
						
							|  |  |  | 				delete $scope.failure; | 
					
						
							| 
									
										
										
										
											2014-07-13 20:24:03 -07:00
										 |  |  | 				$location.path("/login"); | 
					
						
							| 
									
										
										
										
											2014-06-21 14:22:38 -07:00
										 |  |  | 			}). | 
					
						
							|  |  |  | 			error(function(data, status, headers, config) { | 
					
						
							|  |  |  | 				$scope.failure = data; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }); |