Class: AdminAssistant::FormView

Inherits:
Object
  • Object
show all
Includes:
FormViewMethods
Defined in:
lib/admin_assistant/form_view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FormViewMethods

#action, #controller

Constructor Details

#initialize(record, admin_assistant, action_view) ⇒ FormView

Returns a new instance of FormView.


21
22
23
24
# File 'lib/admin_assistant/form_view.rb', line 21

def initialize(record, admin_assistant, action_view)
  @record, @admin_assistant, @action_view =
      record, admin_assistant, action_view
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record


19
20
21
# File 'lib/admin_assistant/form_view.rb', line 19

def record
  @record
end

Instance Method Details

#column_namesObject


26
27
28
29
30
31
32
# File 'lib/admin_assistant/form_view.rb', line 26

def column_names
  if %w(new create).include?(@action_view.action_name)
    settings.columns_for_new
  elsif %w(edit update).include?(@action_view.action_name)
    settings.columns_for_edit
  end
end

#columnsObject


34
35
36
37
38
# File 'lib/admin_assistant/form_view.rb', line 34

def columns
  @admin_assistant.accumulate_columns(column_names).map { |c|
    c.form_view @action_view, @admin_assistant
  }
end

#extra_submit_buttonsObject


40
41
42
# File 'lib/admin_assistant/form_view.rb', line 40

def extra_submit_buttons
  settings.submit_buttons
end

#form_for_argsObject


44
45
46
47
48
49
50
# File 'lib/admin_assistant/form_view.rb', line 44

def form_for_args
  args = {:url => {:action => action, :id => @record.id}}
  if !@admin_assistant.paperclip_attachments.empty?
    args[:html] = {:multipart => true}
  end
  args
end

#model_classObject


52
53
54
# File 'lib/admin_assistant/form_view.rb', line 52

def model_class
  @admin_assistant.model_class
end

#settingsObject


56
57
58
# File 'lib/admin_assistant/form_view.rb', line 56

def settings
  @admin_assistant.form_settings
end

#submit_valueObject


60
61
62
# File 'lib/admin_assistant/form_view.rb', line 60

def submit_value
  action.capitalize
end

#titleObject


64
65
66
# File 'lib/admin_assistant/form_view.rb', line 64

def title
  (@record.id ? "Edit" : "New") + " #{@admin_assistant.model_class_name}"
end