diff --git a/app/scripts/views/sign_up_password.js b/app/scripts/views/sign_up_password.js index 4786d9c5c..3b57671d3 100644 --- a/app/scripts/views/sign_up_password.js +++ b/app/scripts/views/sign_up_password.js @@ -2,97 +2,93 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -define(function (require, exports, module) { - 'use strict'; +import AuthErrors from '../lib/auth-errors'; +import BackMixin from './mixins/back-mixin'; +import CheckboxMixin from './mixins/checkbox-mixin'; +import Cocktail from 'cocktail'; +import CoppaMixin from './mixins/coppa-mixin'; +import EmailOptInMixin from './mixins/email-opt-in-mixin'; +import FlowEventsMixin from './mixins/flow-events-mixin'; +import FormPrefillMixin from './mixins/form-prefill-mixin'; +import FormView from './form'; +import PasswordMixin from './mixins/password-mixin'; +import ServiceMixin from './mixins/service-mixin'; +import SignUpMixin from './mixins/signup-mixin'; +import Template from 'templates/sign_up_password.mustache'; - const AuthErrors = require('../lib/auth-errors'); - const BackMixin = require('./mixins/back-mixin'); - const CheckboxMixin = require('./mixins/checkbox-mixin'); - const Cocktail = require('cocktail'); - const CoppaMixin = require('./mixins/coppa-mixin'); - const EmailOptInMixin = require('./mixins/email-opt-in-mixin'); - const FlowEventsMixin = require('./mixins/flow-events-mixin'); - const FormPrefillMixin = require('./mixins/form-prefill-mixin'); - const FormView = require('./form'); - const PasswordMixin = require('./mixins/password-mixin'); - const ServiceMixin = require('./mixins/service-mixin'); - const SignUpMixin = require('./mixins/signup-mixin'); - const Template = require('templates/sign_up_password.mustache'); +class SignUpPasswordView extends FormView { + constructor (options) { + super(options); - class SignUpPasswordView extends FormView { - constructor (options) { - super(options); + this.template = Template; + } - this.template = Template; - } + getAccount () { + return this.model.get('account'); + } - getAccount () { - return this.model.get('account'); - } - - beforeRender () { - if (! this.getAccount()) { - this.navigate('/'); - } - } - - setInitialContext (context) { - context.set(this.getAccount().pick('email')); - } - - isValidEnd () { - if (! this._doPasswordsMatch()) { - return false; - } - - return super.isValidEnd(); - } - - showValidationErrorsEnd () { - if (! this._doPasswordsMatch()) { - this.displayError(AuthErrors.toError('PASSWORDS_DO_NOT_MATCH')); - } - } - - submit () { - return Promise.resolve().then(() => { - if (! this.isUserOldEnough()) { - return this.tooYoung(); - } - - const account = this.getAccount(); - account.set('needsOptedInToMarketingEmail', this.hasOptedInToMarketingEmail()); - return this.signUp(account, this._getPassword()); - }); - } - - _getPassword () { - return this.getElementValue('#password'); - } - - _getVPassword () { - return this.getElementValue('#vpassword'); - } - - _doPasswordsMatch() { - return this._getPassword() === this._getVPassword(); + beforeRender () { + if (! this.getAccount()) { + this.navigate('/'); } } - Cocktail.mixin( - SignUpPasswordView, - BackMixin, - CheckboxMixin, - CoppaMixin({ - required: true - }), - EmailOptInMixin, - FlowEventsMixin, - FormPrefillMixin, - PasswordMixin, - ServiceMixin, - SignUpMixin - ); + setInitialContext (context) { + context.set(this.getAccount().pick('email')); + } - module.exports = SignUpPasswordView; -}); + isValidEnd () { + if (! this._doPasswordsMatch()) { + return false; + } + + return super.isValidEnd(); + } + + showValidationErrorsEnd () { + if (! this._doPasswordsMatch()) { + this.displayError(AuthErrors.toError('PASSWORDS_DO_NOT_MATCH')); + } + } + + submit () { + return Promise.resolve().then(() => { + if (! this.isUserOldEnough()) { + return this.tooYoung(); + } + + const account = this.getAccount(); + account.set('needsOptedInToMarketingEmail', this.hasOptedInToMarketingEmail()); + return this.signUp(account, this._getPassword()); + }); + } + + _getPassword () { + return this.getElementValue('#password'); + } + + _getVPassword () { + return this.getElementValue('#vpassword'); + } + + _doPasswordsMatch() { + return this._getPassword() === this._getVPassword(); + } +} + +Cocktail.mixin( + SignUpPasswordView, + BackMixin, + CheckboxMixin, + CoppaMixin({ + required: true + }), + EmailOptInMixin, + FlowEventsMixin, + FormPrefillMixin, + PasswordMixin, + ServiceMixin, + SignUpMixin +); + +module.exports = SignUpPasswordView;