Sha256: 1a316efeb397282020ec00a26f383d8639e57246d9e1bbb4fb7a7963facfc5fd

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
#         Slate Studio (http://www.slatestudio.com)
#
# Coding Guide:
#   https://github.com/thoughtbot/guides/tree/master/style/coffeescript
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# RAILS FORM OBJECT PARSER
# -----------------------------------------------------------------------------
# Get form data object from serialized form object, it uses special format for
# object names for support of:
#  - files
#  - lists
#  - nested objects
#
# -----------------------------------------------------------------------------

@railsFormObjectParser =

  # PRIVATE ===============================================

  _parse_form_object: (serializedFormObject) ->
    formDataObject = new FormData()

    for attr_name, attr_value of serializedFormObject

      # special case for LIST inputs, values separated with comma
      if attr_name.indexOf('[__LIST__') > -1
        attr_name = attr_name.replace('__LIST__', '')
        values    = attr_value.split('|||')

        for value in values
          formDataObject.append("#{ @config.resource }#{ attr_name }[]", value)

      else
        # special case for FILE inputs
        if attr_name.startsWith('__FILE__')
          attr_name = attr_name.replace('__FILE__', '')

        formDataObject.append("#{ @config.resource }#{ attr_name }", attr_value)

    return formDataObject



Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
chr-0.5.8 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.7 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.6 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.5 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.4 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.3 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.1 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.5.0 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.25 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.24 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.23 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.22 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.21 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.20 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.19 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.18 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.17 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.15 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.14 app/assets/javascripts/stores/rails-form-object-parser.coffee
chr-0.4.13 app/assets/javascripts/stores/rails-form-object-parser.coffee