Module: AdminAssistant::Column::FormViewMethods

Instance Method Summary collapse

Instance Method Details

#after_html(rails_form) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/admin_assistant/column.rb', line 33

def after_html(rails_form)
  after = render_from_custom_template("_after_#{name}_input", rails_form)
  if after
    after
  else
    helper_method = "after_#{name}_input"
    if @action_view.respond_to?(helper_method)
      @action_view.raw(
        @action_view.send(helper_method, rails_form.object)
      )
    end
  end
end

#descriptionObject



47
48
49
# File 'lib/admin_assistant/column.rb', line 47

def description
  @description
end

#errors(record) ⇒ Object



51
52
53
# File 'lib/admin_assistant/column.rb', line 51

def errors(record)
  record.errors[name]
end

#field_idObject



79
80
81
# File 'lib/admin_assistant/column.rb', line 79

def field_id
  "#{@model_class.name.underscore}_#{name}"
end

#html(rails_form) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/admin_assistant/column.rb', line 55

def html(rails_form)
  record = rails_form.object
  hff = render_from_custom_template "_#{name}_input", rails_form
  hff ||= html_from_helper_method(record)
  hff ||= if @read_only
    value record
  elsif @write_once && @action_view.action_name == 'edit'
    value record
  else
    default_html rails_form
  end
  if ah = after_html(rails_form)
    hff << ah
  end
  hff
end

#html_from_helper_method(record) ⇒ Object



72
73
74
75
76
77
# File 'lib/admin_assistant/column.rb', line 72

def html_from_helper_method(record)
  html_method = "#{name}_input"
  if @action_view.respond_to?(html_method)
    @action_view.send(html_method, record)
  end
end

#render_from_custom_template(slug, rails_form) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/admin_assistant/column.rb', line 83

def render_from_custom_template(slug, rails_form)
  if File.exist?(custom_template_file_path(slug))
    varname = @model_class.name.underscore
    @action_view.instance_variable_set(
      "@#{varname}".to_sym, rails_form.object
    )
    locals = {varname.to_sym => rails_form.object, :form => rails_form}
    if rails_form.respond_to?(:prefix)
      locals[:prefix] = rails_form.prefix
      @action_view.instance_variable_set(:@prefix, rails_form.prefix)
    end
    @action_view.render(
      :file => file_option_for_custom_template_render(slug),
      :locals => locals
    )
  end
end

#set_instance_variables_from_options(admin_assistant, opts) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/admin_assistant/column.rb', line 101

def set_instance_variables_from_options(admin_assistant, opts)
  setting = admin_assistant.form_settings[name.to_sym]
  ivars = %w(
    clear_link datetime_select_options date_select_options description
    image_size input select_choices select_options text_area_options
  )
  ivars.each do |ivar|
    instance_variable_set "@#{ivar}".to_sym, setting.send(ivar)
  end
  if @action_view.respond_to?(name + '_url')
    @file_url_method = @action_view.method(name + '_url')
  end
  @read_only = setting.read_only?
  @write_once = setting.write_once?
end