Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
fix multiple registration
Browse files Browse the repository at this point in the history
  • Loading branch information
poupotte committed Oct 16, 2015
1 parent 3d461d5 commit 29d91af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
30 changes: 12 additions & 18 deletions client/app/states/registration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ module.exports = class Registration extends StateModel
initSignup: ->
# Declares a stream to receive the form submission
@signup = new Bacon.Bus()
@isSignup = false

# If the current step is `preset`, set the valve to block the step flow:
# it will resume when the sign up form request returns a success.
Expand All @@ -142,23 +141,18 @@ module.exports = class Registration extends StateModel
- data: an object containing the form input entries as key/values pairs
###
signupSubmit: (data) =>
if @isSignup
# Map the request end to the next button busy state
@nextBusy.push new Bacon.Next(false)
else
@isSignup = true
# Submit the form content to the register endpoint and creates a stream
# with the ajax promise
req = Bacon.fromPromise $.post '/register', JSON.stringify data
# If the request is successful, we stores the username in the global
# scope to prepare the login view.
req.subscribe -> window.username = data['public_name']
# Unblock the step flow valve when the response is successful
@stepValve.plug req.map false
# Map request errors in the `errors` stream
@errors.plug req.errors().mapError '.responseJSON.errors'
# Map the request end to the next button busy state
@nextBusy.plug req.mapEnd false
# Submit the form content to the register endpoint and creates a stream
# with the ajax promise
req = Bacon.fromPromise $.post '/register', JSON.stringify data
# If the request is successful, we stores the username in the global
# scope to prepare the login view.
req.subscribe -> window.username = data['public_name']
# Unblock the step flow valve when the response is successful
@stepValve.plug req.map false
# Map request errors in the `errors` stream
@errors.plug req.errors().mapError '.responseJSON.errors'
# Map the request end to the next button busy state
@nextBusy.plug req.mapEnd false


###
Expand Down
8 changes: 7 additions & 1 deletion client/app/views/register/preset.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ module.exports = class RegisterPresetView extends FormView
@initForm()
@initErrors()

# Step valve
@onStep = @model.get('step').sampledBy(@form).map (step) ->
step is 'preset'
.toProperty()


# Set the next button enable state when all required fields are filled
@model.nextEnabled.plug @required.changes()

# Create a new stream from the submit one that is filtered onto the step
# (e.g. the form will not be submitted if we're already not in the step)
submit = @form.filter => @model.get('step').map (cur) -> cur is 'preset'
submit = @form.filter @onStep
# We plug it to the signup stream and to the next button busy state (e.g
# the busy state is enable when the form is submitted)
@model.signup.plug submit
Expand Down

0 comments on commit 29d91af

Please sign in to comment.