2014-06-21 21:22:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-14 03:24:03 +00:00
|
|
|
angular.module('app').controller("SetupController", function($scope, $http, $routeParams, $window, $location) {
|
2014-06-21 21:22:38 +00:00
|
|
|
|
|
|
|
// create a remote that will be populated
|
|
|
|
// and persisted to the database.
|
|
|
|
$scope.remote = {};
|
|
|
|
$scope.remote.type = $routeParams.remote;
|
2014-07-13 02:01:58 +00: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 21:22:38 +00: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-14 03:24:03 +00:00
|
|
|
// todo(bradrydzewski) move this to the remote.js service.
|
2014-06-21 21:22:38 +00:00
|
|
|
$scope.save = function() {
|
|
|
|
// request to create a new repository
|
2014-09-30 07:43:50 +00:00
|
|
|
$http({method: 'POST', url: '/api/remotes', data: $scope.remote }).
|
2014-06-21 21:22:38 +00:00
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
delete $scope.failure;
|
2014-07-14 03:24:03 +00:00
|
|
|
$location.path("/login");
|
2014-06-21 21:22:38 +00:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
$scope.failure = data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|