MCPcopy Create free account
hub / github.com/codecombat/codecombat / afterRender

Method afterRender

app/views/teachers/RequestQuoteView.js:147–212  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145 }
146
147 afterRender () {
148 super.afterRender()
149
150 // apply existing trial request on form
151 const properties = this.trialRequest.get('properties')
152 if (properties) {
153 forms.objectToForm(this.$('#request-form'), properties)
154 }
155
156 $('#organization-control').algolia_autocomplete({ hint: false }, [{
157 source (query, callback) {
158 return algolia.schoolsIndex.search(query, { hitsPerPage: 5, aroundLatLngViaIP: false }).then(answer => callback(answer.hits)
159 , () => callback([])) // eslint-disable-line n/no-callback-literal
160 },
161 displayKey: 'name',
162 templates: {
163 suggestion (suggestion) {
164 const hr = suggestion._highlightResult
165 return `<div class='school'> ${hr.name.value} </div>` +
166 `<div class='district'>${hr.district.value}, ` +
167 `<span>${(hr.city != null ? hr.city.value : undefined)}, ${hr.state.value}</span></div>`
168 }
169 }
170 }
171 ]).on('autocomplete:selected', (event, suggestion, dataset) => {
172 this.$('input[name="district"]').val(suggestion.district)
173 this.$('input[name="city"]').val(suggestion.city)
174 this.$('input[name="state"]').val(suggestion.state)
175 this.$('select[name="state"]').val(suggestion.state)
176 this.$('select[name="country"]').val('United States')
177 this.state.set({ showUsaStateDropdown: true })
178 this.state.set({ stateValue: suggestion.state })
179 for (const key of Array.from(SCHOOL_NCES_KEYS)) {
180 this.$('input[name="nces_' + key + '"]').val(suggestion[key])
181 }
182 return this.onChangeRequestForm()
183 })
184
185 return $('#district-control').algolia_autocomplete({ hint: false }, [{
186 source (query, callback) {
187 return algolia.schoolsIndex.search(query, { hitsPerPage: 5, aroundLatLngViaIP: false }).then(answer => callback(answer.hits)
188 , () => callback([])) // eslint-disable-line n/no-callback-literal
189 },
190 displayKey: 'district',
191 templates: {
192 suggestion (suggestion) {
193 const hr = suggestion._highlightResult
194 return `<div class='district'>${hr.district.value}, ` +
195 `<span>${(hr.city != null ? hr.city.value : undefined)}, ${hr.state.value}</span></div>`
196 }
197 }
198 }
199 ]).on('autocomplete:selected', (event, suggestion, dataset) => {
200 this.$('input[name="organization"]').val('') // TODO: does not persist on tabbing: back to school, back to district
201 this.$('input[name="city"]').val(suggestion.city)
202 this.$('input[name="state"]').val(suggestion.state)
203 this.$('select[name="state"]').val(suggestion.state)
204 this.$('select[name="country"]').val('United States')

Callers

nothing calls this directly

Calls 3

onChangeRequestFormMethod · 0.95
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected