<commit_before><script>
  import BaseModal from 'ozaria/site/components/common/BaseModal'
  import { mapActions, mapMutations } from 'vuex'
  import NcesSearchInput from 'app/views/core/CreateAccountModal/teacher/NcesSearchInput'
  const DISTRICT_NCES_KEYS = ['district', 'district_id', 'district_schools', 'district_students']
  const SCHOOL_NCES_KEYS = DISTRICT_NCES_KEYS.concat(['id', 'name', 'students', 'phone'])

  export default Vue.extend({
    components: {
      BaseModal,
      NcesSearchInput
    },
    data: function () {
      let ncesData = {}
      let formData = {}
      let ncesKeys = []
      SCHOOL_NCES_KEYS.forEach(key => {
        ncesKeys.push('nces_' + key, '')
      })
      ncesData = _.zipObject(ncesKeys)
      formData = _.pick(this.$store.state.modal.trialRequestProperties, ncesKeys.concat([ 'organization', 'district', 'city', 'state', 'country', 'role' ]))

      return _.assign(ncesData, formData, {
        showRequired: false
      })
    },
    async mounted () {
      // do not need to show this modal if seen once
      await this.saveMe({ hourOfCodeOptions: { showCompleteSignupModal: false } })
    },
    methods: {
      ...mapMutations({
        updateTrialRequestProperties: 'modal/updateTrialRequestProperties'
      }),
      ...mapActions({
        updateAccount: 'modal/updateAccount',
        saveMe: 'me/save'
      }),
      updateValue (name, value) {
        this[name] = value
        // Clear relevant NCES fields if they type a custom value instead of an autocompleted value
        if (name === 'organization') {
          this.clearSchoolNcesValues()
        }
        if (name === 'district') {
          this.clearSchoolNcesValues()
          this.clearDistrictNcesValues()
        }
      },

      clearDistrictNcesValues () {
        DISTRICT_NCES_KEYS.forEach(key => {
          this['nces_' + key] = ''
        })
      },

      clearSchoolNcesValues () {
        _.difference(SCHOOL_NCES_KEYS, DISTRICT_NCES_KEYS).forEach(key => {
          this['nces_' + key] = ''
        })
      },

      applySuggestion (displayKey, suggestion) {
        if (!suggestion) {
          return
        }
        _.assign(this, _.pick(suggestion, 'district', 'city', 'state'))
        let NCES_KEYS = []
        if (displayKey === 'name') {
          this.organization = suggestion.name
          NCES_KEYS = SCHOOL_NCES_KEYS
        } else {
          NCES_KEYS = DISTRICT_NCES_KEYS
        }
        this.country = 'USA'
        this.clearSchoolNcesValues()
        this.clearDistrictNcesValues()
        NCES_KEYS.forEach(key => {
          this['nces_' + key] = suggestion[key]
        })
      },

      async clickSave () {
        const requiredAttrs = _.pick(this, 'district', 'city', 'state', 'country', 'role')
        if (!_.all(requiredAttrs)) {
          this.showRequired = true
          return
        }
        const attrs = _.pick(this, 'organization', 'district', 'city', 'state', 'country', 'role')
        SCHOOL_NCES_KEYS.forEach(key => {
          const ncesKey = 'nces_' + key
          attrs[ncesKey] = this[ncesKey].toString()
        })
        this.updateTrialRequestProperties(attrs)
        try {
          await this.updateAccount()<commit_msg>Save HoC modal shut only after submission (#305)<commit_after><script>
  import BaseModal from 'ozaria/site/components/common/BaseModal'
  import { mapActions, mapMutations } from 'vuex'
  import NcesSearchInput from 'app/views/core/CreateAccountModal/teacher/NcesSearchInput'
  const DISTRICT_NCES_KEYS = ['district', 'district_id', 'district_schools', 'district_students']
  const SCHOOL_NCES_KEYS = DISTRICT_NCES_KEYS.concat(['id', 'name', 'students', 'phone'])

  export default Vue.extend({
    components: {
      BaseModal,
      NcesSearchInput
    },
    data: function () {
      let ncesData = {}
      let formData = {}
      let ncesKeys = []
      SCHOOL_NCES_KEYS.forEach(key => {
        ncesKeys.push('nces_' + key, '')
      })
      ncesData = _.zipObject(ncesKeys)
      formData = _.pick(this.$store.state.modal.trialRequestProperties, ncesKeys.concat([ 'organization', 'district', 'city', 'state', 'country', 'role' ]))

      return _.assign(ncesData, formData, {
        showRequired: false
      })
    },
    methods: {
      ...mapMutations({
        updateTrialRequestProperties: 'modal/updateTrialRequestProperties'
      }),
      ...mapActions({
        updateAccount: 'modal/updateAccount',
        saveMe: 'me/save'
      }),
      updateValue (name, value) {
        this[name] = value
        // Clear relevant NCES fields if they type a custom value instead of an autocompleted value
        if (name === 'organization') {
          this.clearSchoolNcesValues()
        }
        if (name === 'district') {
          this.clearSchoolNcesValues()
          this.clearDistrictNcesValues()
        }
      },

      clearDistrictNcesValues () {
        DISTRICT_NCES_KEYS.forEach(key => {
          this['nces_' + key] = ''
        })
      },

      clearSchoolNcesValues () {
        _.difference(SCHOOL_NCES_KEYS, DISTRICT_NCES_KEYS).forEach(key => {
          this['nces_' + key] = ''
        })
      },

      applySuggestion (displayKey, suggestion) {
        if (!suggestion) {
          return
        }
        _.assign(this, _.pick(suggestion, 'district', 'city', 'state'))
        let NCES_KEYS = []
        if (displayKey === 'name') {
          this.organization = suggestion.name
          NCES_KEYS = SCHOOL_NCES_KEYS
        } else {
          NCES_KEYS = DISTRICT_NCES_KEYS
        }
        this.country = 'USA'
        this.clearSchoolNcesValues()
        this.clearDistrictNcesValues()
        NCES_KEYS.forEach(key => {
          this['nces_' + key] = suggestion[key]
        })
      },

      async clickSave () {
        const requiredAttrs = _.pick(this, 'district', 'city', 'state', 'country', 'role')
        if (!_.all(requiredAttrs)) {
          this.showRequired = true
          return
        }
        const attrs = _.pick(this, 'organization', 'district', 'city', 'state', 'country', 'role')
        SCHOOL_NCES_KEYS.forEach(key => {
          const ncesKey = 'nces_' + key
          attrs[ncesKey] = this[ncesKey].toString()
        })
        this.updateTrialRequestProperties(attrs)
        try {
          await this.updateAccount()
          await this.saveMe({ hourOfCodeOptions: { showCompleteSignupModal: false } })
{'fraction_non_alphanumeric': 0.12916277622159975, 'fraction_numerical': 0.00046685340802987864, 'mean_word_length': 2.33350622406639, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6346454', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1923, 'n_words': 372}