Add district complete to teacher convert page.

This commit is contained in:
Rob 2016-04-20 10:37:00 -07:00
parent f79a9b96bf
commit 67686e8c71
3 changed files with 49 additions and 1 deletions

View file

@ -76,7 +76,7 @@ block content
.col-md-offset-2.col-md-4.col-sm-6
.form-group
label.control-label(data-i18n="teachers_quote.organization_label")
input.form-control(name="organization")
input.form-control#organization-control(name="organization")
.col-md-4.col-sm-6
.form-group
@ -147,6 +147,14 @@ block content
span(data-i18n="teachers_quote.anything_else")
span.spl.text-muted(data-i18n="signup.optional")
textarea.form-control(rows=8, name="notes")
input(type="hidden" name="nces_id")
input(type="hidden" name="nces_name")
input(type="hidden" name="nces_district")
input(type="hidden" name="nces_district_id")
input(type="hidden" name="nces_district_schools")
input(type="hidden" name="nces_district_students")
input(type="hidden" name="nces_students")
input(type="hidden" name="nces_phone")
#buttons-row.row.m-y-2.text-center
input#create-account-btn.btn.btn-lg.btn-primary(type="submit" data-i18n="[value]teachers_quote.convert_account_title")

View file

@ -7,6 +7,8 @@ storage = require 'core/storage'
errors = require 'core/errors'
User = require 'models/User'
ConfirmModal = require 'views/editor/modal/ConfirmModal'
algolia = require 'core/services/algolia'
NCES_KEYS = ['id', 'name', 'district', 'district_id', 'district_schools', 'district_students', 'students', 'phone']
FORM_KEY = 'request-quote-form'
@ -19,6 +21,10 @@ module.exports = class ConvertToTeacherAccountView extends RootView
'change form': 'onChangeForm'
'submit form': 'onSubmitForm'
'click #logout-link': -> me.logout()
'change input[name="city"]': 'invalidateNCES'
'change input[name="state"]': 'invalidateNCES'
'change input[name="district"]': 'invalidateNCES'
'change input[name="country"]': 'invalidateNCES'
initialize: ->
if me.isAnonymous()
@ -29,6 +35,10 @@ module.exports = class ConvertToTeacherAccountView extends RootView
@trialRequests.fetchOwn()
@supermodel.trackCollection(@trialRequests)
invalidateNCES: ->
for key in NCES_KEYS
@$('input[name="nces_' + key + '"]').val ''
onLoaded: ->
if @trialRequests.size() and me.isTeacher()
return application.router.navigate('/teachers', { trigger: true, replace: true })
@ -55,6 +65,31 @@ module.exports = class ConvertToTeacherAccountView extends RootView
@$('#other-education-level-input').val(obj.otherInput)
forms.objectToForm(@$('form'), obj, { overwriteExisting: true })
$("#organization-control").autocomplete({hint: false}, [
source: (query, callback) ->
algolia.schoolsIndex.search(query, { hitsPerPage: 5, aroundLatLngViaIP: false }).then (answer) ->
callback answer.hits
, ->
callback []
displayKey: 'name',
templates:
suggestion: (suggestion) ->
hr = suggestion._highlightResult
"<div class='school'> #{hr.name.value} </div>" +
"<div class='district'>#{hr.district.value}, " +
"<span>#{hr.city?.value}, #{hr.state.value}</span></div>"
]).on 'autocomplete:selected', (event, suggestion, dataset) =>
@$('input[name="city"]').val suggestion.city
@$('input[name="state"]').val suggestion.state
@$('input[name="district"]').val suggestion.district
@$('input[name="country"]').val 'USA'
for key in NCES_KEYS
@$('input[name="nces_' + key + '"]').val suggestion[key]
@onChangeRequestForm()
onChangeRequestForm: ->
# save changes to local storage
obj = forms.formToObject(@$('form'))
@ -137,3 +172,6 @@ formSchema = {
}
notes: { type: 'string' }
}
for key in NCES_KEYS
formSchema['nces_' + key] = type: 'string'

View file

@ -87,6 +87,8 @@ module.exports = class CreateTeacherAccountView extends RootView
for key in NCES_KEYS
@$('input[name="nces_' + key + '"]').val suggestion[key]
@onChangeRequestForm()
onClickLoginLink: ->
modal = new AuthModal({ initialValues: { email: @trialRequest.get('properties')?.email } })
@openModalView(modal)