(e)
| 114 | } |
| 115 | |
| 116 | onSubmitForm (e) { |
| 117 | // validate form with schema |
| 118 | e.preventDefault() |
| 119 | forms.clearFormAlerts(this.$el) |
| 120 | this.state.set('formError', null) |
| 121 | const data = forms.formToObject(e.currentTarget) |
| 122 | const res = tv4.validateMultiple(data, formSchema) |
| 123 | if (!res.valid) { |
| 124 | forms.applyErrorsToForm(this.$('form'), res.errors) |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | // check for name conflicts |
| 129 | const queryParams = this.state.get('queryParams') |
| 130 | this.displayFormSubmitting() |
| 131 | return User.checkNameConflicts(data.name) |
| 132 | .then(({ suggestedName, conflicts }) => { |
| 133 | const nameField = this.$('input[name="name"]') |
| 134 | if (conflicts) { |
| 135 | const suggestedNameText = $.i18n.t('signup.name_taken').replace('{{suggestedName}}', suggestedName) |
| 136 | forms.setErrorToField(nameField, suggestedNameText) |
| 137 | throw AbortError |
| 138 | } |
| 139 | |
| 140 | // Save new user settings, particularly properties handed in |
| 141 | const school = _.pick(queryParams, 'state', 'city', 'district') |
| 142 | if (queryParams.school) { school.name = queryParams.school } |
| 143 | me.set(_.pick(queryParams, 'firstName', 'lastName', 'israelId')) |
| 144 | me.set({ school }) |
| 145 | return me.save() |
| 146 | }).then(() => { |
| 147 | // sign up |
| 148 | return me.signupWithPassword( |
| 149 | this.state.get('name'), |
| 150 | queryParams.email || '', |
| 151 | this.state.get('password') |
| 152 | ) |
| 153 | }).then(() => { |
| 154 | // successful signup |
| 155 | return application.router.navigate('/play', { trigger: true }) |
| 156 | }).catch(e => { |
| 157 | // if we threw the AbortError, the error was handled |
| 158 | this.displayFormStandingBy() |
| 159 | if (e === AbortError) { |
| 160 | |
| 161 | } else { |
| 162 | // Otherwise, show a generic error |
| 163 | console.error('IsraelSignupView form submission Promise error:', e) |
| 164 | return this.state.set('formError', (e.responseJSON != null ? e.responseJSON.message : undefined) || e.message || 'Unknown Error') |
| 165 | } |
| 166 | }) |
| 167 | } |
| 168 | } |
| 169 | IsraelSignupView.initClass() |
| 170 | return IsraelSignupView |
nothing calls this directly
no test coverage detected