2014-07-17 09:04:21 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller 'CloneProjectModalController', ($scope, $modalInstance, $timeout, $http, ide) ->
|
|
|
|
$scope.inputs =
|
|
|
|
projectName: ide.$scope.project.name + " (Copy)"
|
|
|
|
$scope.state =
|
|
|
|
inflight: false
|
2017-05-19 11:21:02 -04:00
|
|
|
error: false
|
2014-07-17 09:04:21 -04:00
|
|
|
|
|
|
|
$modalInstance.opened.then () ->
|
|
|
|
$timeout () ->
|
|
|
|
$scope.$broadcast "open"
|
|
|
|
, 200
|
|
|
|
|
|
|
|
cloneProject = (cloneName) ->
|
|
|
|
$http.post("/project/#{ide.$scope.project._id}/clone", {
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
projectName: cloneName
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.clone = () ->
|
|
|
|
$scope.state.inflight = true
|
2017-05-19 11:21:02 -04:00
|
|
|
$scope.state.error = false
|
2014-07-17 09:04:21 -04:00
|
|
|
cloneProject($scope.inputs.projectName)
|
2017-06-20 11:04:06 -04:00
|
|
|
.then (response) ->
|
|
|
|
{ data } = response
|
2017-06-05 08:33:32 -04:00
|
|
|
window.location = "/project/#{data.project_id}"
|
2017-06-20 11:04:06 -04:00
|
|
|
.catch (response) ->
|
|
|
|
{ data, status } = response
|
2017-05-19 11:21:02 -04:00
|
|
|
$scope.state.inflight = false
|
2017-06-20 11:04:06 -04:00
|
|
|
if status == 400
|
|
|
|
$scope.state.error = { message: data }
|
2017-05-19 11:21:02 -04:00
|
|
|
else
|
|
|
|
$scope.state.error = true
|
2014-07-17 09:04:21 -04:00
|
|
|
|
|
|
|
$scope.cancel = () ->
|
|
|
|
$modalInstance.dismiss('cancel')
|