 _ = require 'underscore'
-_.mixin(require 'underscore.string')
+_s = require 'underscore.string'
 
 # Extract out into a site-wide language file (?)
 en =

    , {}

    form = _.reduce $form.serializeArray(), (memo, input) ->
      memo[input.name] = _.trim input.value
      memo
    , {}


      parsed = text: 'There was an error'

    # Pull out the appropriate string
    message = if _s.has(parsed, 'text')
      parsed.text
    else if _s.has(parsed, 'error')
      parsed.error.message or parsed.error
    else if _s.has(parsed, 'details') and _.isArray(parsed.details)
      parsed.details.join('; ')
    else if _s.has(parsed, 'detail')
      _.map(parsed.detail, (v, k) =>
        # For param_errors we can point out the problematic fields
        # provided they have name attributes
        @$("[name=#{k}]").attr 'data-state', 'error'

        "#{_s.humanize(k)} #{v}"
      )
        .join('; ')
        # Multiple errors on a single param are
