<commit_before>modalize = require '../modalize/index.coffee'
FlashMessage = require '../flash/index.coffee'
State = require '../branching_state/index.coffee'
StateView = require '../branching_state/view.coffee'
Logger = require '../logger/index.coffee'
analytics = require './analytics.coffee'
openErrorFlash = require './error.coffee'
{ steps, decisions, views } = require './map.coffee'

module.exports = ({ user, artwork, inquiry, bypass }) ->
  { collectorProfile } = user.related()
  { userInterests } = collectorProfile.related()

  user.approximateLocation()

  # Allow us to trigger individual steps for debugging
  # by passing the named step as a `bypass` option
  steps = [bypass] if bypass

  state = new State steps: steps, decisions: decisions
  logger = new Logger 'inquiry-questionnaire-log'

  questionnaire = new StateView
    className: 'inquiry-questionnaire'
    state: state
    views: views

  modal = modalize questionnaire,
    className: 'modalize inquiry-questionnaire-modal'
    dimensions: width: '500px', height: '640px'

  state.inject
    user: user
    artwork: artwork
    inquiry: inquiry
    logger: logger
    modal: modal.view
    collectorProfile: collectorProfile
    userInterests: userInterests

  # Attach/teardown analytics events
  analytics.attach state.context
  modal.view.on 'closed', ->
    analytics.teardown state.context

  # Disable backdrop clicks
  modal.view.$el.off 'click', '.js-modalize-backdrop'

  state
    # Log each step
    .on 'next', logger.log.bind(logger)

    # Abort by clicking 'nevermind'
    .on 'abort', ->
      modal.close()
      logger.reset()

    # End of complete flow
    .on 'done', ->
      # Send the inquiry immediately
      inquiry.send {},
        success: ->
          modal.close()
        error: (model, response, options) ->
          modal.close ->
            openErrorFlash response

  # Prepare the user and open the modal
  modal.load (open) ->
    user.prepareForInquiry()
      .then ->
        open()
      .catch (e) ->
        modal.close ->
          openErrorFlash e
        console.error e
      .done()

  modal
<commit_msg>Removes ability to <esc> out of inquiry flow (Closes #5099)<commit_after>modalize = require '../modalize/index.coffee'
FlashMessage = require '../flash/index.coffee'
State = require '../branching_state/index.coffee'
StateView = require '../branching_state/view.coffee'
Logger = require '../logger/index.coffee'
analytics = require './analytics.coffee'
openErrorFlash = require './error.coffee'
{ steps, decisions, views } = require './map.coffee'

module.exports = ({ user, artwork, inquiry, bypass }) ->
  { collectorProfile } = user.related()
  { userInterests } = collectorProfile.related()

  user.approximateLocation()

  # Allow us to trigger individual steps for debugging
  # by passing the named step as a `bypass` option
  steps = [bypass] if bypass

  state = new State steps: steps, decisions: decisions
  logger = new Logger 'inquiry-questionnaire-log'

  questionnaire = new StateView
    className: 'inquiry-questionnaire'
    state: state
    views: views

  modal = modalize questionnaire,
    className: 'modalize inquiry-questionnaire-modal'
    dimensions: width: '500px', height: '640px'

  state.inject
    user: user
    artwork: artwork
    inquiry: inquiry
    logger: logger
    modal: modal.view
    collectorProfile: collectorProfile
    userInterests: userInterests

  # Attach/teardown analytics events
  analytics.attach state.context
  modal.view.on 'closed', ->
    analytics.teardown state.context

  # Disable backdrop clicks
  modal.view.$el.off 'click', '.js-modalize-backdrop'

  # Disable <esc> close
  $(window).off 'keyup.modalize'

  state
    # Log each step
    .on 'next', logger.log.bind(logger)

    # Abort by clicking 'nevermind'
    .on 'abort', ->
      modal.close()
      logger.reset()

    # End of complete flow
    .on 'done', ->
      # Send the inquiry immediately
      inquiry.send {},
        success: ->
          modal.close()
        error: (model, response, options) ->
          modal.close ->
            openErrorFlash response

  # Prepare the user and open the modal
  modal.load (open) ->
    user.prepareForInquiry()
      .then ->
        open()
      .catch (e) ->
        modal.close ->
          openErrorFlash e
        console.error e
      .done()

  modal

{'fraction_non_alphanumeric': 0.11418764302059496, 'fraction_numerical': 0.0036613272311212816, 'mean_word_length': 2.804177545691906, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '2485004', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1260, 'n_words': 362}