mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +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
|
||||
@@ -1 +1 @@
|
||||
YAY! You created an enterprise!
|
||||
Yay! You created an enterprise!
|
||||
@@ -19,15 +19,10 @@
|
||||
.row
|
||||
.small-12.large-8.columns
|
||||
%label{ for: 'enterprise_country' } Country:
|
||||
-#= select :country_id, available_countries.map{|c|[c.name, c.id]}, {include_blank: false}
|
||||
%input.chunky.small-12.columns{ id: 'enterprise_country', placeholder: "eg. Australia" }
|
||||
-# , ng: { model: 'enterprise.country' } }
|
||||
%select.chunky.small-12.columns{ id: 'enterprise_country', ng: { model: 'enterprise.country', options: 'c as c.name for c in countries' } }
|
||||
.small-12.large-4.columns
|
||||
%label{ for: 'enterprise_state' } State:
|
||||
- binding.pry
|
||||
-#= select :state_id, available_countries.first.states.map{|c|[c.name, c.id]}
|
||||
%input.chunky.small-12.columns{ id: 'enterprise_state', placeholder: "eg. Victoria" }
|
||||
-# , ng: { model: 'enterprise.state' } }
|
||||
%select.chunky.small-12.columns{ id: 'enterprise_state', ng: { model: 'enterprise.address.state_id', options: 's.id as s.abbr for s in enterprise.country.states', show: 'countryHasStates()' } }
|
||||
.small-5.columns
|
||||
%h6
|
||||
Location display
|
||||
|
||||
@@ -34,4 +34,4 @@
|
||||
.row
|
||||
.small-12.columns
|
||||
%input.button.primary{ type: "button", value: "Back", ng: { click: "select('address')" }, style: 'float:left' }
|
||||
%input.button.primary{ type: "button", value: "Continue", ng: { click: "createEnterprise()" }, style: 'float:right' }
|
||||
%input.button.primary{ type: "button", value: "Continue", ng: { click: "create()" }, style: 'float:right' }
|
||||
Reference in New Issue
Block a user