mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Updating on later pages of registration process
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
Darkswarm.controller "RegistrationCtrl", ($scope, RegistrationService, EnterpriseCreationService, availableCountries) ->
|
||||
Darkswarm.controller "RegistrationCtrl", ($scope, RegistrationService, EnterpriseRegistrationService, availableCountries) ->
|
||||
$scope.currentStep = RegistrationService.currentStep
|
||||
$scope.select = RegistrationService.select
|
||||
$scope.enterprise = EnterpriseCreationService.enterprise
|
||||
$scope.create = EnterpriseCreationService.create
|
||||
$scope.enterprise = EnterpriseRegistrationService.enterprise
|
||||
$scope.create = EnterpriseRegistrationService.create
|
||||
$scope.update = EnterpriseRegistrationService.update
|
||||
|
||||
$scope.steps = ['details','address','contact','about','images','social']
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Darkswarm.factory "EnterpriseCreationService", ($http, RegistrationService, CurrentUser, SpreeApiKey, availableCountries) ->
|
||||
new class EnterpriseCreationService
|
||||
Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, CurrentUser, SpreeApiKey, Loading, availableCountries) ->
|
||||
new class EnterpriseRegistrationService
|
||||
enterprise:
|
||||
user_ids: [CurrentUser.id]
|
||||
email: CurrentUser.email
|
||||
@@ -7,27 +7,47 @@ Darkswarm.factory "EnterpriseCreationService", ($http, RegistrationService, Curr
|
||||
country: availableCountries[0]
|
||||
|
||||
create: =>
|
||||
# Loading.message = "Creating " + $scope.enterprise.name
|
||||
# $http(
|
||||
# method: "POST"
|
||||
# url: "/api/enterprises"
|
||||
# data:
|
||||
# enterprise: @prepare()
|
||||
# params:
|
||||
# token: SpreeApiKey
|
||||
# ).success((data) ->
|
||||
# Loading.clear()
|
||||
# RegistrationService.select('about')
|
||||
# ).error((data) ->
|
||||
# Loading.clear()
|
||||
# console.log angular.toJson(data)
|
||||
# alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
# )
|
||||
RegistrationService.select('about')
|
||||
Loading.message = "Creating " + @enterprise.name
|
||||
$http(
|
||||
method: "POST"
|
||||
url: "/api/enterprises"
|
||||
data:
|
||||
enterprise: @prepare()
|
||||
params:
|
||||
token: SpreeApiKey
|
||||
).success((data) =>
|
||||
Loading.clear()
|
||||
@enterprise.id = data
|
||||
RegistrationService.select('about')
|
||||
).error((data) =>
|
||||
Loading.clear()
|
||||
console.log angular.toJson(data)
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
)
|
||||
#RegistrationService.select('about')
|
||||
|
||||
update: (step) =>
|
||||
Loading.message = "Updating " + @enterprise.name
|
||||
$http(
|
||||
method: "PUT"
|
||||
url: "/api/enterprises/#{@enterprise.id}"
|
||||
data:
|
||||
enterprise: @prepare()
|
||||
params:
|
||||
token: SpreeApiKey
|
||||
).success((data) ->
|
||||
Loading.clear()
|
||||
RegistrationService.select(step)
|
||||
).error((data) ->
|
||||
Loading.clear()
|
||||
console.log angular.toJson(data)
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
)
|
||||
#RegistrationService.select(step)
|
||||
|
||||
prepare: =>
|
||||
enterprise = {}
|
||||
for a, v of @enterprise when a isnt 'address' && a isnt 'country'
|
||||
for a, v of @enterprise when a isnt 'address' && a isnt 'country' && a isnt 'id'
|
||||
enterprise[a] = v
|
||||
enterprise.address_attributes = @enterprise.address
|
||||
enterprise.address_attributes.country_id = @enterprise.country.id
|
||||
|
||||
@@ -32,4 +32,4 @@
|
||||
%input.chunky.small-12.columns{ id: 'enterprise_acn', placeholder: "eg. 123 456 789", ng: { model: 'enterprise.acn' } }
|
||||
.row.buttons
|
||||
.small-12.columns
|
||||
%input.button.primary.right{ type: "button", value: "Continue", ng: { click: "select('social')" } }
|
||||
%input.button.primary.right{ type: "button", value: "Continue", ng: { click: "update('social')" } }
|
||||
@@ -30,4 +30,4 @@
|
||||
.row.buttons
|
||||
.small-12.columns
|
||||
%input.button.primary.left{ type: "button", value: "Back", ng: { click: "select('about')" } }
|
||||
%input.button.primary.right{ type: "button", value: "Continue", ng: { click: "select('finished')" } }
|
||||
%input.button.primary.right{ type: "button", value: "Continue", ng: { click: "update('finished')" } }
|
||||
@@ -17,7 +17,18 @@ module Api
|
||||
|
||||
@enterprise = Enterprise.new(params[:enterprise])
|
||||
if @enterprise.save
|
||||
render text: '', :status => 201
|
||||
render text: @enterprise.id, :status => 201
|
||||
else
|
||||
invalid_resource!(@enterprise)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
authorize! :update, Enterprise
|
||||
|
||||
@enterprise = Enterprise.find(params[:id])
|
||||
if @enterprise.update_attributes(params[:enterprise])
|
||||
render text: @enterprise.id, :status => 200
|
||||
else
|
||||
invalid_resource!(@enterprise)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user