<commit_before>React = require 'react'
BS = require 'react-bootstrap'
_ = require 'underscore'
{DateTimePicker} = require 'react-widgets'

TutorInput = React.createClass
  propTypes:
    label: React.PropTypes.string.isRequired
    id: React.PropTypes.string
    className: React.PropTypes.string
    onChange: React.PropTypes.func
    value: React.PropTypes.any

  onChange: (event) ->
    @props.onChange(event.target?.value, event.target)

  render: ->
    classes = ['form-control']
    unless @props.default then classes.push('empty')
    classes.push(@props.class)

    <div className="form-control-wrapper">
      <input
        id={@props.id}
        type='text'
        className={classes.join(' ')}
        defaultValue={@props.default}
        onChange={@onChange} />
      <div className="floating-label">{@props.label}</div>
    </div>

TutorDateInput = React.createClass

  getInitialState: ->
    {expandCalendar: false}

  expandCalendar: ->
    @setState({expandCalendar: true})

  dateSelected: (value) ->
    @setState({expandCalendar: false})
    @props.onChange(value)

  onToggle: (open) ->
    @setState({expandCalendar: false})
    console.log(open)

  render: ->
    classes = ['form-control']
    unless @props.value then classes.push('empty')
    open = false

    if @state.expandCalendar and not @props.readOnly
      open = 'calendar'
      onToggle = @onToggle

    <div className="form-control-wrapper">
      <input type='text' onFocus={@expandCalendar} disabled className={classes.join(' ')} />
      <div className="floating-label">{@props.label}</div>
      <DateTimePicker onFocus={@expandCalendar} 
        id={@props.id}
        format='MMM dd, yyyy'
        time={false}
        calendar={true}
        open={open}
        onToggle={onToggle}
        className="form-control"
        onChange={@dateSelected}
        readOnly={@props.readOnly}
        min={@props.min}
        value={@props.value}
      />
    </div>

TutorTextArea = React.createClass
  propTypes:
    label: React.PropTypes.string.isRequired
    id: React.PropTypes.string
    className: React.PropTypes.string
    onChange: React.PropTypes.func
    value: React.PropTypes.any

  getInitialState: ->
    {height: '2em'}

  onChange: (event) ->
    @setState({height: event.target.scrollHeight})
    @props.onChange(event.target?.value, event.target)

  render: ->
    classes = ['form-control']
    unless @props.default then classes.push('empty')
    classes.push(@props.inputClass)
<commit_msg>updating tutor datepicker to have a click handler and parse function for invalid dates<commit_after>React = require 'react'
BS = require 'react-bootstrap'
_ = require 'underscore'
{DateTimePicker} = require 'react-widgets'

TutorInput = React.createClass
  propTypes:
    label: React.PropTypes.string.isRequired
    id: React.PropTypes.string
    className: React.PropTypes.string
    onChange: React.PropTypes.func
    value: React.PropTypes.any

  onChange: (event) ->
    @props.onChange(event.target?.value, event.target)

  render: ->
    classes = ['form-control']
    unless @props.default then classes.push('empty')
    classes.push(@props.class)

    <div className="form-control-wrapper">
      <input
        id={@props.id}
        type='text'
        className={classes.join(' ')}
        defaultValue={@props.default}
        onChange={@onChange} />
      <div className="floating-label">{@props.label}</div>
    </div>

TutorDateInput = React.createClass

  getInitialState: ->
    {expandCalendar: false}

  expandCalendar: ->
    @setState({expandCalendar: true})

  isValid: (value) ->
    valid = true
    valid = false if (@props.min and value < @props.min)
    valid = false if (@props.max and value > @props.max)
    valid

  dateSelected: (value) ->
    valid = @isValid(value)
    @props.onChange(value) if (valid)
    @setState({expandCalendar: false, valid: valid})

  onToggle: (open) ->
    @setState({expandCalendar: open})

  clickHandler: (event) ->
    if (event.target.tagName is "INPUT" and not @state.expandCalendar)
      @setState({expandCalendar: true})

  parseDate: (dateStr) ->
    date = new Date(dateStr)
    min = @props.min or ""
    if (not date or not @isValid(date))
      date = new Date(min)

    date

  render: ->
    classes = ['form-control']
    unless @props.value then classes.push('empty')
    open = false

    if @state.expandCalendar and not @props.readOnly and not @state.justToggled
      open = 'calendar'
      onToggle = @onToggle

    value = @props.value

    <div className="form-control-wrapper">
      <input type='text' disabled className={classes.join(' ')} />
      <div className="floating-label">{@props.label}</div>
      <DateTimePicker onClick={@clickHandler}
        onFocus={@expandCalendar} 
        parse={@parseDate}
        id={@props.id}
        format='MMM dd, yyyy'
        time={false}
        calendar={true}
        open={open}
        onToggle={onToggle}
        className="form-control"
        onChange={@dateSelected}
        readOnly={@props.readOnly}
        min={@props.min}
        value={value}
      />
    </div>

TutorTextArea = React.createClass
  propTypes:
    label: React.PropTypes.string.isRequired
    id: React.PropTypes.string
    className: React.PropTypes.string
    onChange: React.PropTypes.func
    value: React.PropTypes.any

  getInitialState: ->
    {height: '2em'}

  onChange: (event) ->
    @setState({height: event.target.scrollHeight})
    @props.onChange(event.target?.value, event.target)

  render: ->
    classes = ['form-control']
    unless @props.default then classes.push('empty')
    classes.push(@props.inputClass)

{'fraction_non_alphanumeric': 0.13969938107869143, 'fraction_numerical': 0.00035366931918656057, 'mean_word_length': 3.0603015075376883, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 49, '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': '1761428', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1727, 'n_words': 348}