<commit_before>React = require 'react'
TriggeredModalForm = require 'modal-form/triggered'
{Markdown} = require 'markdownz'
Utility = require './utility'

ImageFlipper = React.createClass
  displayName: 'ImageFlipper'

  getDefaultProps: ->
    images: []

  getInitialState: ->
    frame: 0

  PRELOAD_STYLE:
    height: 0
    overflow: 'hidden'
    position: 'fixed'
    right: 0
    width: 0

  render: ->
    <span className="survey-task-image-flipper">
      {@renderPreload()}
      <img src={@props.images[@state.frame]} className="survey-task-image-flipper-image" />
      <div className="survey-task-image-flipper-pips">
        {unless @props.images.length is 1
          for index in [0...@props.images.length]
            <label key={@props.images[index]}  className="survey-task-image-flipper-pip #{if index is @state.frame then 'active' else ''}">
              <input type="radio" name="image-flipper" autoFocus={index is 0} checked={index is @state.frame} onChange={@handleFrameChange.bind this, index} />{index + 1}
            </label>}
      </div>
    </span>

  renderPreload: ->
    <div style={@PRELOAD_STYLE}>
      {for image in @props.images
        <img src={image} key={image} />}
    </div>

  handleFrameChange: (frame) ->
    @setState {frame}

module.exports = React.createClass
  displayName: 'Choice'

  propTypes:
    annotationValue: React.PropTypes.shape({
      answers: React.PropTypes.object,
      choice: React.PropTypes.string,
      filters: React.PropTypes.object
    })

  getDefaultProps: ->
    annotationValue: { answers: {} }
    task: null
    choiceID: ''
    onSwitch: Function.prototype
    onConfirm: Function.prototype
    onCancel: Function.prototype

  getInitialState: ->
    answers: @props.annotationValue.answers
    focusedAnswer: ''

  checkFilledIn: ->
    # if there are no questions, don't make them fill one in
    return true unless Utility.getQuestionIDs(@props.task, @props.choiceID).length

    # if there are questions, it's fine as long as they've filled required ones in
    answerProvided = []
    for questionID in Utility.getQuestionIDs(@props.task, @props.choiceID)
      question = @props.task.questions[questionID]
      if question.required
        answer = @state.answers[questionID]
        if (answer?.length isnt 0) and answer?
          answerProvided.push true
        else
          answerProvided.push false
      else<commit_msg>Copy annotation answers to a new object in Choice. Fixes #3950<commit_after>React = require 'react'
TriggeredModalForm = require 'modal-form/triggered'
{Markdown} = require 'markdownz'
Utility = require './utility'

ImageFlipper = React.createClass
  displayName: 'ImageFlipper'

  getDefaultProps: ->
    images: []

  getInitialState: ->
    frame: 0

  PRELOAD_STYLE:
    height: 0
    overflow: 'hidden'
    position: 'fixed'
    right: 0
    width: 0

  render: ->
    <span className="survey-task-image-flipper">
      {@renderPreload()}
      <img src={@props.images[@state.frame]} className="survey-task-image-flipper-image" />
      <div className="survey-task-image-flipper-pips">
        {unless @props.images.length is 1
          for index in [0...@props.images.length]
            <label key={@props.images[index]}  className="survey-task-image-flipper-pip #{if index is @state.frame then 'active' else ''}">
              <input type="radio" name="image-flipper" autoFocus={index is 0} checked={index is @state.frame} onChange={@handleFrameChange.bind this, index} />{index + 1}
            </label>}
      </div>
    </span>

  renderPreload: ->
    <div style={@PRELOAD_STYLE}>
      {for image in @props.images
        <img src={image} key={image} />}
    </div>

  handleFrameChange: (frame) ->
    @setState {frame}

module.exports = React.createClass
  displayName: 'Choice'

  propTypes:
    annotationValue: React.PropTypes.shape({
      answers: React.PropTypes.object,
      choice: React.PropTypes.string,
      filters: React.PropTypes.object
    })

  getDefaultProps: ->
    annotationValue: { answers: {} }
    task: null
    choiceID: ''
    onSwitch: Function.prototype
    onConfirm: Function.prototype
    onCancel: Function.prototype

  getInitialState: ->
    answers: Object.assign {}, @props.annotationValue.answers
    focusedAnswer: ''

  checkFilledIn: ->
    # if there are no questions, don't make them fill one in
    return true unless Utility.getQuestionIDs(@props.task, @props.choiceID).length

    # if there are questions, it's fine as long as they've filled required ones in
    answerProvided = []
    for questionID in Utility.getQuestionIDs(@props.task, @props.choiceID)
      question = @props.task.questions[questionID]
      if question.required
        answer = @state.answers[questionID]
        if (answer?.length isnt 0) and answer?
          answerProvided.push true
        else
          answerProvided.push false
      else
{'fraction_non_alphanumeric': 0.12349704503770124, 'fraction_numerical': 0.004483391073975953, 'mean_word_length': 3.0130825838103026, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7645278', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1486, 'n_words': 360}