Sha256: de6885bfbae9ab721247b94a454d4f5bf1242a02fe59f958403bbb5e332abec3

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

Signal = require "cronus/signal"
SignalRelay = require "cronus/signal_relay"

FormSubmitter = require 'hoarder/submitter/form_submitter'
FormValidator = require 'hoarder/validator/form_validator'

#
# @author - Tim Shelburne <tim@musiconelive.com>
#
# abstracts submitting and validating forms from the validator and submitter
#
class FormManager
  constructor: (@formSubmitter, @formValidator)->
    @validatedWithErrors = new Signal()
    @submittedWithSuccess = new SignalRelay(@formSubmitter.submittedWithSuccess)
    @submittedWithError = new SignalRelay(@formSubmitter.submittedWithError)

  @default: (pollingUrl="")->
    new @(FormSubmitter.default(pollingUrl), FormValidator.default())

  validateForm: (form)->
    @formValidator.validateForm(form)

  submitForm: (form)->
    errors = @validateForm(form)

    if (errors.length > 0)
      @validatedWithErrors.dispatch(errors)
    else
      @formSubmitter.submitForm(form)

return FormManager

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hoarder-js-0.0.1 assets/scripts/coffee/hoarder/form_manager.coffee