25 lines
857 B
CoffeeScript
25 lines
857 B
CoffeeScript
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'))
|
|
|
|
toJSONForSave: ->
|
|
_.tap {}, (hash) =>
|
|
for key, value of @.toJSON()
|
|
hash[key] = value unless _.include(['select_options', 'type_text', 'text_formatting_text', 'undefined_text', 'undefined', 'created_at', 'updated_at'], key)
|
|
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()
|