Class: DrgcmsFormFields::Method

Inherits:
DrgcmsField show all
Defined in:
app/models/drgcms_form_fields/method.rb

Overview

Implementation of custom DRG CMS form field. Method field will call method or class method defined in eval option and add returned code to HTML output code.

It can be used in case when form contains complex data structure. For example set of pictures which can not be simply displayed by any other DRG Forms field.

Form example:

50:
  name: galery
  type: method
  eval: show_gallery
  or
  eval: MyClass.show_gallery

Instance Attribute Summary

Attributes inherited from DrgcmsField

#css, #js

Instance Method Summary collapse

Methods inherited from DrgcmsField

#__css_code, get_data, #hash_to_options, #html, #initialize, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t

Constructor Details

This class inherits a constructor from DrgcmsFormFields::DrgcmsField

Instance Method Details

#renderObject

Render file_select field html code



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/drgcms_form_fields/method.rb', line 46

def render
  # might be defined as my_method or MyClass.my_method
  clas, method = @yaml['eval'].split(/\.|\,/).map(&:strip)
  if method.nil?
    if @parent.respond_to?(clas)
      @html << @parent.send(clas, @record, @yaml, @readonly) 
      return self
    end
  else
    klass = clas.camelize.constantize
    if klass.respond_to?(method)
      @html << klass.send(method, @record, @yaml, @readonly) 
      return self
    end
  end   
  @html << "Error: #{@yaml['name']} : #{@yaml['eval']} not defined!"
  self
end