2016-01-21 17:41:57 -05:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
forms = require 'core/forms'
|
|
|
|
TrialRequest = require 'models/TrialRequest'
|
|
|
|
TrialRequests = require 'collections/TrialRequests'
|
|
|
|
AuthModal = require 'views/core/AuthModal'
|
|
|
|
|
|
|
|
formSchema = {
|
|
|
|
type: 'object'
|
|
|
|
required: ['name', 'email', 'organization', 'role', 'numStudents']
|
|
|
|
properties:
|
|
|
|
name: { type: 'string', minLength: 1 }
|
|
|
|
email: { type: 'string', format: 'email' }
|
|
|
|
phoneNumber: { type: 'string' }
|
|
|
|
role: { type: 'string' }
|
|
|
|
organization: { type: 'string' }
|
|
|
|
city: { type: 'string' }
|
|
|
|
state: { type: 'string' }
|
|
|
|
country: { type: 'string' }
|
|
|
|
numStudents: { type: 'string' }
|
|
|
|
educationLevel: {
|
|
|
|
type: 'array'
|
|
|
|
items: { type: 'string' }
|
|
|
|
}
|
|
|
|
notes: { type: 'string' }
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = class RequestQuoteView extends RootView
|
|
|
|
id: 'request-quote-view'
|
|
|
|
template: require 'templates/request-quote-view'
|
2016-02-02 15:48:19 -05:00
|
|
|
|
2016-01-21 17:41:57 -05:00
|
|
|
events:
|
|
|
|
'submit form': 'onSubmitForm'
|
|
|
|
'click #login-btn': 'onClickLoginButton'
|
|
|
|
'click #signup-btn': 'onClickSignupButton'
|
2016-02-02 15:48:19 -05:00
|
|
|
|
2016-01-21 17:41:57 -05:00
|
|
|
initialize: ->
|
|
|
|
@trialRequest = new TrialRequest()
|
|
|
|
@trialRequests = new TrialRequests()
|
|
|
|
@trialRequests.fetchOwn()
|
|
|
|
@supermodel.loadCollection(@trialRequests)
|
2016-02-02 15:48:19 -05:00
|
|
|
|
2016-01-21 17:41:57 -05:00
|
|
|
onLoaded: ->
|
|
|
|
if @trialRequests.size()
|
|
|
|
@trialRequest = @trialRequests.first()
|
2016-02-05 13:49:46 -05:00
|
|
|
if @trialRequest and @trialRequest.get('status') isnt 'submitted' and @trialRequest.get('status') isnt 'approved'
|
|
|
|
window.tracker?.trackEvent 'View Trial Request', category: 'Teachers', label: 'View Trial Request', ['Mixpanel']
|
2016-01-21 17:41:57 -05:00
|
|
|
super()
|
2016-02-02 15:48:19 -05:00
|
|
|
|
2016-01-21 17:41:57 -05:00
|
|
|
onSubmitForm: (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
form = @$('form')
|
|
|
|
attrs = forms.formToObject(form)
|
|
|
|
if @$('#other-education-level-checkbox').is(':checked')
|
|
|
|
attrs.educationLevel.push(@$('#other-education-level-input').val())
|
|
|
|
forms.clearFormAlerts(form)
|
|
|
|
result = tv4.validateMultiple(attrs, formSchema)
|
2016-02-01 18:51:29 -05:00
|
|
|
error = true
|
2016-01-21 17:41:57 -05:00
|
|
|
if not result.valid
|
2016-02-01 18:51:29 -05:00
|
|
|
forms.applyErrorsToForm(form, result.errors)
|
|
|
|
else if not /^.+@.+\..+$/.test(attrs.email)
|
|
|
|
forms.setErrorToProperty(form, 'email', 'Invalid email.')
|
|
|
|
else if not _.size(attrs.educationLevel)
|
2016-01-21 17:41:57 -05:00
|
|
|
return forms.setErrorToProperty(form, 'educationLevel', 'Check at least one.')
|
2016-02-01 18:51:29 -05:00
|
|
|
else
|
|
|
|
error = false
|
|
|
|
if error
|
|
|
|
forms.scrollToFirstError()
|
|
|
|
return
|
2016-01-21 17:41:57 -05:00
|
|
|
@trialRequest = new TrialRequest({
|
|
|
|
type: 'course'
|
|
|
|
properties: attrs
|
|
|
|
})
|
|
|
|
@$('#submit-request-btn').text('Sending').attr('disabled', true)
|
|
|
|
@trialRequest.save()
|
|
|
|
@trialRequest.on 'sync', @onTrialRequestSubmit, @
|
|
|
|
@trialRequest.on 'error', @onTrialRequestError, @
|
2016-02-02 15:48:19 -05:00
|
|
|
me.setRole attrs.role.toLowerCase(), true
|
2016-01-21 17:41:57 -05:00
|
|
|
|
|
|
|
onTrialRequestError: ->
|
|
|
|
@$('#submit-request-btn').text('Submit').attr('disabled', false)
|
|
|
|
|
|
|
|
onTrialRequestSubmit: ->
|
|
|
|
@$('form, #form-submit-success').toggleClass('hide')
|
2016-02-05 13:49:46 -05:00
|
|
|
window.tracker?.trackEvent 'Submit Trial Request', category: 'Teachers', label: 'Trial Request', ['Mixpanel']
|
2016-01-21 17:41:57 -05:00
|
|
|
|
|
|
|
onClickLoginButton: ->
|
|
|
|
modal = new AuthModal({
|
|
|
|
mode: 'login'
|
|
|
|
initialValues: { email: @trialRequest.get('properties')?.email }
|
|
|
|
})
|
|
|
|
@openModalView(modal)
|
|
|
|
window.nextURL = '/courses/teachers' unless @trialRequest.isNew()
|
2016-02-02 15:48:19 -05:00
|
|
|
|
2016-01-21 17:41:57 -05:00
|
|
|
onClickSignupButton: ->
|
|
|
|
props = @trialRequest.get('properties') or {}
|
|
|
|
me.set('name', props.name)
|
|
|
|
modal = new AuthModal({
|
|
|
|
mode: 'signup'
|
2016-02-02 15:48:19 -05:00
|
|
|
initialValues: {
|
2016-01-21 17:41:57 -05:00
|
|
|
email: props.email
|
|
|
|
schoolName: props.organization
|
|
|
|
}
|
|
|
|
})
|
|
|
|
@openModalView(modal)
|
2016-02-02 15:48:19 -05:00
|
|
|
window.nextURL = '/courses/teachers' unless @trialRequest.isNew()
|