# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # ----------------------------------------------------------------------------- # INPUT "NESTED" FORM # ----------------------------------------------------------------------------- # Name for this input comes from the Rails gem 'nested_forms'. # # Public methods: # initialize() # hash(hash) # updateValue(@value) # showErrorMessage(message) # hideErrorMessage() # addNewForm(object) # # Dependencies: #= require ./documents_reorder # ----------------------------------------------------------------------------- class @InputForm constructor: (@name, @nestedObjects, @config, @object) -> @forms = [] @config.namePrefix ||= name @config.removeButton = if @config.disableRemoveDocuments then false else true @config.ignoreOnSubmission ||= false @reorderContainerClass = "nested-forms-#{@config.klassName}" if @config.ignoreOnSubmission for key, inputConfig of @config.formSchema inputConfig.ignoreOnSubmission = true @_create_el() @_add_label() @_add_forms() @_add_new_button() return this # PRIVATE =================================================================== _create_el: -> @$el =$ "
" _add_label: -> @$label =$ "" @$labelTitle =$ "#{ @config.label }" @$errorMessage =$ "" @$label.append @$labelTitle @$label.append @$errorMessage @$el.append @$label if @config.label == false @$labelTitle.hide() _extend_schema_with: (name, config) -> schemaConfig = {} schemaConfig[name] = config @config.formSchema = $.extend(schemaConfig, @config.formSchema) _add_forms: -> # add id to schema # @NOTE: here we use _id, cause mongosteen returns objects _id, but we should send id for nested documents @_extend_schema_with('_id', { type: 'hidden', name: 'id', ignoreOnSubmission: @config.ignoreOnSubmission }) # add position to schema if @config.sortBy @_extend_schema_with(@config.sortBy, { type: 'hidden', ignoreOnSubmission: @config.ignoreOnSubmission }) @$forms =$ "