codecombat/app/views/modal/employer_signup_modal.coffee

141 lines
4.5 KiB
CoffeeScript
Raw Normal View History

View = require 'views/kinds/ModalView'
template = require 'templates/modal/employer_signup_modal'
2014-04-24 18:27:37 -04:00
forms = require('lib/forms')
User = require 'models/User'
auth = require('lib/auth')
me = auth.me
module.exports = class EmployerSignupView extends View
id: "employer-signup"
template: template
closeButton: true
2014-04-24 18:27:37 -04:00
2014-04-25 13:46:43 -04:00
2014-04-24 18:27:37 -04:00
subscriptions:
"server-error": "onServerError"
'linkedin-loaded': 'onLinkedInLoaded'
"created-user-without-reload": 'createdAccount'
2014-04-25 13:46:43 -04:00
2014-04-24 18:27:37 -04:00
events:
"click #contract-agreement-button": "agreeToContract"
"click #create-account-button": "createAccount"
"click #more-info-button": "submitMoreInfoEmail"
"click .login-link": "setHashToOpenModalAutomatically"
2014-05-07 16:33:15 -04:00
"keydown": "checkForFormSubmissionEnterPress"
2014-04-25 13:46:43 -04:00
2014-04-23 14:25:36 -04:00
constructor: (options) ->
super(options)
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
2014-04-25 10:48:59 -04:00
window.tracker?.trackEvent 'Started Employer Signup'
2014-04-24 18:27:37 -04:00
@reloadWhenClosed = false
@linkedinLoaded = Boolean(IN.parse)
@waitingForLinkedIn = false
@sentMoreInfoEmail = false
2014-04-25 13:46:43 -04:00
window.contractCallback = =>
2014-04-24 18:27:37 -04:00
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
@render()
2014-04-25 13:46:43 -04:00
onLinkedInLoaded: =>
@linkedinLoaded = true
if @waitingForLinkedIn
@renderLinkedInButton()
renderLinkedInButton: =>
IN.parse()
2014-04-25 13:46:43 -04:00
onServerError: (e) ->
2014-04-24 18:27:37 -04:00
@disableModalInProgress(@$el)
2014-04-25 13:46:43 -04:00
2014-04-23 14:25:36 -04:00
afterInsert: ->
super()
linkedInButtonParentElement = document.getElementById("linkedInAuthButton")
2014-04-24 18:27:37 -04:00
if linkedInButtonParentElement
if @linkedinLoaded
@renderLinkedInButton()
else
@waitingForLinkedIn = true
2014-04-25 13:46:43 -04:00
2014-04-23 14:25:36 -04:00
getRenderData: ->
context = super()
context.userIsAuthorized = @authorizedWithLinkedIn
2014-04-25 10:48:59 -04:00
context.userHasSignedContract = "employer" in me.get("permissions")
2014-04-24 18:27:37 -04:00
context.userIsAnonymous = context.me.get('anonymous')
context.sentMoreInfoEmail = @sentMoreInfoEmail
2014-04-23 14:25:36 -04:00
context
2014-04-25 13:46:43 -04:00
2014-04-24 18:27:37 -04:00
agreeToContract: ->
2014-04-24 20:36:07 -04:00
application.linkedinHandler.constructEmployerAgreementObject (err, profileData) =>
if err? then return handleAgreementFailure err
$.ajax
url: "/db/user/#{me.id}/agreeToEmployerAgreement"
data: profileData
type: "POST"
success: @handleAgreementSuccess
error: @handleAgreementFailure
2014-04-25 13:46:43 -04:00
2014-04-24 20:36:07 -04:00
handleAgreementSuccess: (result) ->
2014-04-25 10:48:59 -04:00
window.tracker?.trackEvent 'Employer Agreed to Contract'
2014-04-24 20:36:07 -04:00
me.fetch()
window.location.reload()
2014-04-25 13:46:43 -04:00
2014-04-24 20:36:07 -04:00
handleAgreementFailure: (error) ->
2014-04-25 10:50:29 -04:00
alert "There was an error signing the contract. Please contact team@codecombat.com with this error: #{error.responseText}"
2014-04-25 13:46:43 -04:00
2014-05-07 16:33:15 -04:00
checkForFormSubmissionEnterPress: (e) ->
if e.which is 13
if $("#signup-email").val() isnt '' and $("#signup-password").val() isnt ''
@createAccount(e)
else if $("#more-info-email").val() isnt ''
@submitMoreInfoEmail e
2014-05-07 16:33:15 -04:00
2014-04-24 18:27:37 -04:00
createAccount: (e) =>
2014-04-25 10:48:59 -04:00
window.tracker?.trackEvent 'Finished Employer Signup'
el = $("#signup-form")
2014-04-24 18:27:37 -04:00
e.stopPropagation()
forms.clearFormAlerts(el)
userObject = forms.formToObject el
2014-04-24 18:27:37 -04:00
delete userObject.subscribe
for key, val of me.attributes when key in ["preferredLanguage", "testGroupNumber", "dateCreated", "wizardColor1", "name", "music", "volume", "emails"]
userObject[key] ?= val
2014-04-25 13:55:37 -04:00
userObject.emails ?= {}
2014-04-25 13:46:43 -04:00
userObject.emails.employerNotes = {enabled: true}
2014-04-24 18:27:37 -04:00
res = tv4.validateMultiple userObject, User.schema
return forms.applyErrorsToForm(el, res.errors) unless res.valid
@enableModalInProgress(el)
2014-04-24 18:27:37 -04:00
auth.createUserWithoutReload userObject, null
submitMoreInfoEmail: (e) =>
emailAddress = $("#more-info-email").val()
window.tracker?.trackEvent 'Employer requested more information.'
successFunc = =>
@sentMoreInfoEmail = true
@render()
errorFunc = =>
alert("Something went wrong! Please contact team@codecombat.com for more information and inform them of this error.")
$.ajax
type: "POST"
url: "/contact"
data:
email: emailAddress
message: "THIS IS AN AUTOMATED MESSAGE FROM THE EMPLOYER SIGNUP FORM \n Please send me more info about hiring CodeCombat players."
success: successFunc
error: errorFunc
$.post "/stacklead", email: emailAddress
setHashToOpenModalAutomatically: (e) ->
window.location.hash = "employerSignupLoggingIn"
createdAccount: ->
2014-04-24 18:27:37 -04:00
@reloadWhenClosed = true
@listenTo me,"sync", =>
@render()
IN.parse()
me.fetch()
2014-04-25 13:46:43 -04:00
2014-04-24 18:27:37 -04:00
destroy: ->
reloadWhenClosed = @reloadWhenClosed
super()
if reloadWhenClosed
window.location.reload()