mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Adding countries and states to registration
This commit is contained in:
@@ -1,39 +1,13 @@
|
||||
Darkswarm.controller "RegistrationCtrl", ($scope, $http, RegistrationService, CurrentUser, SpreeApiKey) ->
|
||||
$scope.current_user = CurrentUser
|
||||
|
||||
Darkswarm.controller "RegistrationCtrl", ($scope, RegistrationService, EnterpriseCreationService, availableCountries) ->
|
||||
$scope.currentStep = RegistrationService.currentStep
|
||||
$scope.select = RegistrationService.select
|
||||
$scope.enterprise = EnterpriseCreationService.enterprise
|
||||
$scope.create = EnterpriseCreationService.create
|
||||
|
||||
$scope.steps = ['details','address','contact','about']
|
||||
# ,'images','social'
|
||||
|
||||
$scope.enterprise =
|
||||
user_ids: [CurrentUser.id]
|
||||
email: CurrentUser.email
|
||||
address: {
|
||||
country_id: 12
|
||||
state_id: 1061493592
|
||||
}
|
||||
$scope.countries = availableCountries
|
||||
|
||||
$scope.createEnterprise = ->
|
||||
$http(
|
||||
method: "POST"
|
||||
url: "/api/enterprises"
|
||||
data:
|
||||
enterprise: $scope.prepare($scope.enterprise)
|
||||
params:
|
||||
token: SpreeApiKey
|
||||
).success((data) ->
|
||||
$scope.select('about')
|
||||
).error((data) ->
|
||||
console.log angular.toJson(data)
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
)
|
||||
# $scope.select('about')
|
||||
|
||||
$scope.prepare = (ent_obj) ->
|
||||
enterprise = {}
|
||||
for a, v of ent_obj when a isnt 'address'
|
||||
enterprise[a] = v
|
||||
enterprise.address_attributes = ent_obj.address
|
||||
enterprise
|
||||
$scope.countryHasStates = ->
|
||||
$scope.enterprise.country.states.length > 0
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
Darkswarm.factory "EnterpriseCreationService", ($http, RegistrationService, CurrentUser, SpreeApiKey, availableCountries) ->
|
||||
new class EnterpriseCreationService
|
||||
enterprise:
|
||||
user_ids: [CurrentUser.id]
|
||||
email: CurrentUser.email
|
||||
address: {}
|
||||
country: availableCountries[0]
|
||||
|
||||
create: =>
|
||||
$http(
|
||||
method: "POST"
|
||||
url: "/api/enterprises"
|
||||
data:
|
||||
enterprise: @prepare()
|
||||
params:
|
||||
token: SpreeApiKey
|
||||
).success((data) ->
|
||||
RegistrationService.select('about')
|
||||
).error((data) ->
|
||||
console.log angular.toJson(data)
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
)
|
||||
# RegistrationService.select('about')
|
||||
|
||||
prepare: =>
|
||||
enterprise = {}
|
||||
for a, v of @enterprise when a isnt 'address' && a isnt 'country'
|
||||
enterprise[a] = v
|
||||
enterprise.address_attributes = @enterprise.address
|
||||
enterprise.address_attributes.country_id = @enterprise.country.id
|
||||
enterprise
|
||||
Reference in New Issue
Block a user