diff --git a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee index fabc2c382a..546186f53d 100644 --- a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee @@ -1,15 +1,23 @@ Darkswarm.controller "RegistrationFormCtrl", ($scope, RegistrationService, EnterpriseRegistrationService) -> $scope.submitted = false + $scope.isDisabled = false $scope.valid = (form) -> $scope.submitted = !form.$valid form.$valid $scope.create = (form) -> - EnterpriseRegistrationService.create() if $scope.valid(form) + $scope.disableButton() + EnterpriseRegistrationService.create($scope.enableButton) if $scope.valid(form) $scope.update = (nextStep, form) -> EnterpriseRegistrationService.update(nextStep) if $scope.valid(form) $scope.selectIfValid = (nextStep, form) -> RegistrationService.select(nextStep) if $scope.valid(form) + + $scope.disableButton = -> + $scope.isDisabled = true + + $scope.enableButton = -> + $scope.isDisabled = false diff --git a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee index 1434ffa44f..25ec644a66 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee @@ -11,7 +11,11 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, for key, value of enterpriseAttributes @enterprise[key] = value - create: => + # Creates the enterprise and redirects to the about step on success. + # + # @param callback [Function] executed at the end of the operation both in + # case of success or failure. + create: (callback) => Loading.message = t('creating') + " " + @enterprise.name $http( method: "POST" @@ -33,6 +37,7 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, else alert(t('failed_to_create_enterprise_unknown')) ) + callback.call() if callback? update: (step) => Loading.message = t('updating') + " " + @enterprise.name diff --git a/app/views/registration/steps/_type.html.haml b/app/views/registration/steps/_type.html.haml index 0a98d851ed..9276a5731a 100644 --- a/app/views/registration/steps/_type.html.haml +++ b/app/views/registration/steps/_type.html.haml @@ -45,4 +45,4 @@ .row.buttons .small-12.columns %input.button.secondary{ type: "button", value: "{{'back' | t}}", ng: { click: "select('contact')" } } - %input.button.primary.right{ type: "submit", value: "{{'create_profile' | t}}" } + %input.button.primary.right{ ng: { disabled: 'isDisabled' }, type: "submit", value: "{{'create_profile' | t}}" }