module PhantomForms::Helper

Public Instance Methods

buttons_for(object, options = {}) click to toggle source
# 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")
  content_tag :div, class: 'row' do
    content_tag :div, class: 'col-xs-12' do
      submit_button(locale, :id => "submit-#{object_class}-button")
    end
  end
end
get_class(object) click to toggle source
# 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
modal_form_error(id) click to toggle source
modal_form_for(object, options = {}, &block) click to toggle source
normal_form_for(object, options = {}, &block) click to toggle source
# 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")

  content_tag :div, class: "panel panel-primary" do
    concat(panel_title(label, slide_form_close_button(object_class))) unless label == 'nil'
    concat(content_tag(:div, class: "panel-body") { form_for(object, options, &block) })
  end
end
normal_modal_form_for(object, options = {}, &block) click to toggle source
# 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")

  content_tag :div, class: "panel panel-primary" do
    concat(panel_title(label, modal_close_button))
    concat(content_tag(:div, class: "panel-body") { form_for(object, options, &block) })
  end
end
remote_form_for(object, options = {}, &block) click to toggle source
# 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")

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

Private Instance Methods

extract_object(object) click to toggle source
# File lib/phantom_forms/helper.rb, line 96
def extract_object(object)
  if object.kind_of?(Array)
    object.last
  else
    object
  end
end
slide_form_close_button(object_class) click to toggle source
# File lib/phantom_forms/helper.rb, line 104
def slide_form_close_button(object_class)
  content_tag :button, id: "close-#{object_class}-button", :class => 'close-form' do
    "&times".html_safe
  end
end