Sha256: b7afb4ac2e5f1d0ce80948af92e55fe9ce590dc765e32376e6ba0918a879fb38

Contents?: true

Size: 1.22 KB

Versions: 43

Compression:

Stored size: 1.22 KB

Contents

class Locomotive.Models.CustomField extends Backbone.Model

  initialize: ->
    @_normalize()

    unless @get('name')?
      @set name: @get('label').slugify()

  _normalize: ->
    @set
      select_options: new Locomotive.Models.CustomFieldSelectOptionsCollection(@get('select_options'))

  _undesired_fields:
    ['select_options', 'type_text', 'text_formatting_text', 'inverse_of_text', 'class_name_text', 'undefined_text', 'undefined', 'created_at', 'updated_at']

  _relationship_fields:
    ['class_name', 'inverse_of', 'ui_enabled']

  is_relationship_type: ->
    _.include(['belongs_to', 'has_many', 'many_to_many'], @get('type'))

  toJSONForSave: ->
    _.tap {}, (hash) =>
      for key, value of @.toJSON()
        unless _.include(@_undesired_fields, key)
          if _.include(@_relationship_fields, key)
            hash[key] = value if @is_relationship_type()
          else
            hash[key] = value

      hash.select_options_attributes = @get('select_options').toJSONForSave() if @get('select_options')? && @get('select_options').length > 0

class Locomotive.Models.CustomFieldsCollection extends Backbone.Collection

  model: Locomotive.Models.CustomField

  toJSONForSave: ->
    @map (model) => model.toJSONForSave()

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
locomotive_cms-2.5.7 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.6 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.6.rc2 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.6.rc1 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.5 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.4 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.3 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.2 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.1 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.0 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.0.rc3 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.0.rc2 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.5.0.rc1 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.4.1 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.4.0 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.3.1 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.3.0 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.2.3 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.2.2 app/assets/javascripts/locomotive/models/custom_field.js.coffee
locomotive_cms-2.2.1 app/assets/javascripts/locomotive/models/custom_field.js.coffee