Sha256: 2aa7ae8fe6a6264f51847867fc1887206dd23effb4f0154085b3659389394e46

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

module Noodall
  class Form
    include MongoMapper::Document
    plugin MongoMapper::Plugins::MultiParameterAttributes
    plugin Noodall::GlobalUpdateTime
  
    key :title, String, :required => true
    key :description, String
    key :email, String, :format => /.+\@.+\..+/
  
    MANDATORY_FIELDS = ['Name','Email']
    many :fields, :class => Noodall::Field
    many :responses, :class => Noodall::FormResponse
  
    before_save :create_mandatory_fields!
  
    timestamps!
  
    validates_associated :fields, :message => "have not had a name completed"
  
    def boolean_fields
      self.fields.select{|f| f.class == Noodall::CheckBox }
    end
  
    def required_fields
      self.fields.select{|f| f.required }
    end
  
    def create_mandatory_fields!
      MANDATORY_FIELDS.each do |mf|
        if fields.blank? or fields.select{|f| f.name == mf }.empty?
          self.fields << Noodall::TextField.new(:name => mf, :required => true)
        end
      end
    end
  
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
noodall-form-builder-0.0.6 app/models/noodall/form.rb
noodall-form-builder-0.0.5 app/models/noodall/form.rb
noodall-form-builder-0.0.4 app/models/noodall/form.rb
noodall-form-builder-0.0.3 app/models/noodall/form.rb
noodall-form-builder-0.0.2 app/models/noodall/form.rb
noodall-form-builder-0.0.1 app/models/noodall/form.rb