Created
March 8, 2015 22:32
-
-
Save excid3/a09a1464ecf5407db124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SignUpLink | |
constructor: -> | |
@setEvents() | |
setEvents: -> | |
$("#sign-up-link").on "click", @handleClick | |
handleClick: -> | |
$(".sign-up-form").show() | |
$(".sign-in-form").hide() | |
class SignInLink | |
constructor: -> | |
@setEvents() | |
setEvents: -> | |
$("#sign-in-link").on "click", @handleClick | |
handleClick: -> | |
$(".sign-up-form").hide() | |
$(".sign-in-form").show() | |
class SignUpForm | |
constructor: -> | |
@form = $(".sign-up-form") | |
@setEvents() | |
setEvents: -> | |
@form.on "submit", @handleSubmit | |
handleSubmit: (e) => | |
e.preventDefault() | |
$.ajax | |
url: @form.attr("action") | |
data: @form.serialize() | |
dataType: "json" | |
method: "post" | |
success: @handleSuccess | |
error: @handleError | |
handleSuccess: (data, status, xhr) -> | |
if data.success | |
$("#register-or-sign-in").hide() | |
else | |
errors = $.map(data.errors, (message, i) -> ("<p>#{message}</p>")) | |
$("#registration_errors").html errors | |
$("#registration_errors").show() | |
handleErrors: (xhr, status, error) -> | |
console.log(error) | |
class SignInForm | |
constructor: -> | |
@form = $(".sign-in-form") | |
@setEvents() | |
setEvents: -> | |
@form.on "submit", @handleSubmit | |
handleSubmit: (e) => | |
e.preventDefault() | |
$.ajax | |
url: @form.attr("action") | |
data: @form.serialize() | |
dataType: "json" | |
method: "post" | |
success: @handleSuccess | |
error: @handleError | |
handleSuccess: (data, status, xhr) -> | |
$("meta[name=csrf-token]").attr("content", data.authenticity_token) | |
$("#register-or-sign-in").hide() | |
handleError: (xhr, status, errors) -> | |
$("#session_errors").append("<p>Invalid email or password</p>") | |
$("#session_errors").show() | |
class RegisterOrSignUp | |
constructor: -> | |
new SignUpLink | |
new SignInLink | |
new SignUpForm | |
new SignInForm | |
jQuery -> | |
new RegisterOrSignUp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment