Module: PhantomForms::Helper

Defined in:
lib/phantom_forms/helper.rb

Instance Method Summary collapse

Instance Method Details

#buttons_for(object, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/phantom_forms/helper.rb', line 68

def buttons_for(object, options = {})
  object_name = get_class(object)
  object_class = options[:resource] || object_name

  locale_name =  object_name.underscore
  locale = options[:label] || t("#{locale_name}.save")
   :div, class: 'row' do
     :div, class: 'col-xs-12' do
      submit_button(locale, :id => "submit-#{object_class}-button")
    end
  end
end

#get_class(object) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/phantom_forms/helper.rb', line 85

def get_class(object)
  object_class_name = object.class.to_s.underscore.dasherize.split('/').last
  if object_class_name.include? '-decorator'
    object_class_name.split('-decorator').first
  else
    object_class_name
  end
end


81
82
83
# File 'lib/phantom_forms/helper.rb', line 81

def modal_form_error(id)
   :div, nil, :id => id
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/phantom_forms/helper.rb', line 35

def modal_form_for(object, options = {}, &block)
  options[:validate] = true
  options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
  options[:html] = {:'data-type' => 'script', :class => 'remote-form'}
  options[:remote] = true

  object_name = get_class(extract_object(object))
  object_class = options[:resource] || object_name
  label = options[:label] || t("#{object_name.underscore}.singular")

   :div, class: "col-md-12 alert-dismissable" do
     :div, class: "panel panel-primary" do
      concat(panel_title(label, modal_close_button))
      concat((:div, class: "panel-body") { form_for(object, options, &block) })
    end
  end
end

#normal_form_for(object, options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/phantom_forms/helper.rb', line 20

def normal_form_for(object, options = {}, &block)
  options[:validate] = true
  options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
  options[:html] = {:class => 'normal-form form'}

  object_name = get_class(extract_object(object))
  object_class = options[:resource] || object_name
  label = options[:label] || t("#{object_name.underscore}.singular")

   :div, class: "panel panel-primary" do
    concat(panel_title(label, slide_form_close_button(object_class))) unless label == 'nil'
    concat((:div, class: "panel-body") { form_for(object, options, &block) })
  end
end

#normal_modal_form_for(object, options = {}, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/phantom_forms/helper.rb', line 53

def normal_modal_form_for(object, options = {}, &block)
  options[:validate] = true
  options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
  options[:html] = {:'data-type' => 'script', :class => 'normal-form'}

  object_name = get_class(extract_object(object))
  object_class = options[:resource] || object_name
  label = options[:label] || t("#{object_name.underscore}.singular")

   :div, class: "panel panel-primary" do
    concat(panel_title(label, modal_close_button))
    concat((:div, class: "panel-body") { form_for(object, options, &block) })
  end
end

#remote_form_for(object, options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/phantom_forms/helper.rb', line 4

def remote_form_for(object, options = {}, &block)
  options[:validate] = true
  options[:builder] = PhantomForms::FormBuilders::ValidateFormBuilder
  options[:remote] = true
  options[:html] = {:class => 'remote-form form'}

  object_name = get_class(extract_object(object))
  object_class = options[:resource] || object_name
  label = options[:label] || t("#{object_name.underscore}.singular")

   :div, class: "panel panel-primary" do
    concat(panel_title(label, slide_form_close_button(object_class)))
    concat((:div, class: "panel-body") { form_for(object, options, &block) })
  end
end