Sha256: f7e73d74c63757c1eec4cc4181491514519b46e1bdf890b245b78a5389b81c36

Contents?: true

Size: 1.98 KB

Versions: 6

Compression:

Stored size: 1.98 KB

Contents

module ErpForms
  module Extensions
    module ActiveRecord
      module HasDynamicForms

      		def self.included(base)
            base.extend(ClassMethods)  	        	      	
          end

      		module ClassMethods
           	
        		def has_dynamic_forms
  		        attr_accessor :dynamic_form						
        		  
        		  include HasDynamicForms::InstanceMethods  

      				def set_default(form_id)
      				  DynamicForm.update_all({ :default => false }, { :model_name => self.name })
      				  DynamicForm.update_all({ :default => true }, { :id => form_id })
      				end	
      		  end

      		end
				
      		module InstanceMethods

            def new_form
              d = DynamicForm.new
              d.model_name = self.class.to_s
              d.dynamic_form_model_id = self.dynamic_form_model_id
              return self.dynamic_form = d        
            end

            def form
              unless self.dynamic_form.nil?
                return self.dynamic_form
              else
                current_form = default_form
                unless current_form.nil?
                  return current_form
                else
                  return new_form
                end
              end
            end

            def default_form        
              get_form
            end

            # get active form by type and active columns
      			def get_form(internal_identifier='')
      			  self.dynamic_form = DynamicForm.get_form(self.class.to_s, internal_identifier)
      			end

            # get all forms by type
            def forms
      		    DynamicForm.find_all_by_model_name(self.class_name)
            end

            # def set_default(internal_identifier)
            #   DynamicForm.update_all({:default => false}, "model_name=#{self.class.to_s}")
            #   DynamicForm.update_all({:default => true}, "model_name=#{self.class.to_s} AND internal_identifier=#{internal_identifier}")
            # end

      		end	
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
erp_forms-3.1.2 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb
erp_forms-3.1.1 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb
erp_forms-3.1.0 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb
erp_forms-3.0.2 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb
erp_forms-3.0.1 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb
erp_forms-3.0.0 lib/erp_forms/extensions/active_record/has_dynamic_forms.rb