<commit_before>define [
  'underscore'
  'i18n!registration'
  'compiled/fn/preventDefault'
  'compiled/models/User'
  'compiled/models/Pseudonym'
  'jst/registration/teacherDialog'
  'jst/registration/studentDialog'
  'jst/registration/studentHigherEdDialog'
  'jst/registration/parentDialog'
  'compiled/object/flatten'
  'jquery.instructure_forms'
  'jquery.instructure_date_and_time'
], (_, I18n, preventDefault, User, Pseudonym, teacherDialog, studentDialog, studentHigherEdDialog, parentDialog, flatten) ->

  $nodes = {}
  templates = {teacherDialog, studentDialog, studentHigherEdDialog, parentDialog}

  signupDialog = (id, title) ->
    return unless templates[id]
    $node = $nodes[id] ?= $('<div />')
    $node.html templates[id](
      terms_url: "http://www.instructure.com/terms-of-use"
    )
    $node.find('.date-field').datetime_field()

    $node.find('.signup_link').click preventDefault ->
      $node.dialog('close')
      signupDialog($(this).data('template'), $(this).prop('title'))

    $form = $node.find('form')
    $form.formSubmit
      disableWhileLoading: true
      success: (data) =>
        # they should now be authenticated (either registered or pre_registered)
        window.location = "/?login_success=1&registration_success=1"
      formErrors: false
      error: (errors) ->
        if _.any(errors.user.birthdate ? [], (e) -> e.type is 'too_young')
          $node.find('.registration-dialog').html I18n.t('too_young_error', 'You must be at least %{min_years} years of age to use Canvas without a course join code.', min_years: ENV.USER.MIN_AGE)
          $node.dialog buttons: [
            text: I18n.t('ok', "OK")
            click: -> $node.dialog('close')
            class: 'btn-primary'
          ]
          return
        errors = flatten
          user: User::normalizeErrors(errors.user)
          pseudonym: Pseudonym::normalizeErrors(errors.pseudonym)
          observee: Pseudonym::normalizeErrors(errors.observee)
        , arrays: false
        if errors['user[birthdate]']
          errors['user[birthdate(1)]'] = errors['user[birthdate]']
          delete errors['user[birthdate]']<commit_msg>don't reenable form if we are redirecting<commit_after>define [
  'underscore'
  'i18n!registration'
  'compiled/fn/preventDefault'
  'compiled/models/User'
  'compiled/models/Pseudonym'
  'jst/registration/teacherDialog'
  'jst/registration/studentDialog'
  'jst/registration/studentHigherEdDialog'
  'jst/registration/parentDialog'
  'compiled/object/flatten'
  'jquery.instructure_forms'
  'jquery.instructure_date_and_time'
], (_, I18n, preventDefault, User, Pseudonym, teacherDialog, studentDialog, studentHigherEdDialog, parentDialog, flatten) ->

  $nodes = {}
  templates = {teacherDialog, studentDialog, studentHigherEdDialog, parentDialog}

  signupDialog = (id, title) ->
    return unless templates[id]
    $node = $nodes[id] ?= $('<div />')
    $node.html templates[id](
      terms_url: "http://www.instructure.com/terms-of-use"
    )
    $node.find('.date-field').datetime_field()

    $node.find('.signup_link').click preventDefault ->
      $node.dialog('close')
      signupDialog($(this).data('template'), $(this).prop('title'))

    $form = $node.find('form')
    promise = null
    $form.formSubmit
      beforeSubmit: ->
        promise = $.Deferred()
        $form.disableWhileLoading(promise)
      success: (data) =>
        # they should now be authenticated (either registered or pre_registered)
        window.location = "/?login_success=1&registration_success=1"
      formErrors: false
      error: (errors) ->
        promise.reject()
        if _.any(errors.user.birthdate ? [], (e) -> e.type is 'too_young')
          $node.find('.registration-dialog').html I18n.t('too_young_error', 'You must be at least %{min_years} years of age to use Canvas without a course join code.', min_years: ENV.USER.MIN_AGE)
          $node.dialog buttons: [
            text: I18n.t('ok', "OK")
            click: -> $node.dialog('close')
            class: 'btn-primary'
          ]
          return
        errors = flatten
          user: User::normalizeErrors(errors.user)
          pseudonym: Pseudonym::normalizeErrors(errors.pseudonym)
          observee: Pseudonym::normalizeErrors(errors.observee)
        , arrays: false
        if errors['user[birthdate]']
          errors['user[birthdate(1)]'] = errors['user[birthdate]']
          delete errors['user[birthdate]']
{'fraction_non_alphanumeric': 0.1421822272215973, 'fraction_numerical': 0.0049493813273340835, 'mean_word_length': 3.270893371757925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5824956', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1360, 'n_words': 254}