Class: Katello::KatelloFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/helpers/katello/katello_form_builder.rb

Instance Method Summary collapse

Instance Method Details

#editable(name, options) ⇒ Object

Support for rendering jquery.jeditable fields. Instead of writing complete html code for the field and the label it allows to use ‘editable’ form helper.

Examples:

usage

kt_form_for @record, :data_url => record_path(@record) do |form|
  form.editable :name, :label => _("Name:")
end

kt_form_for @record do |form|
  form.editable :name, :data_url => record_path_1(@record)
  form.editable :surname, :data_url => record_path_2(@record)
end

kt_form_for @record, :data_url => record_path(@record) do |form|
  form.editable :name do
    # Some custom value
  end
end

Parameters:

  • options (Hash)

Options Hash (options):

  • :label (String)

    label text

  • :editable (true, false)

    boolean flag, switches possibility to edit the field

  • :class (String)

    additional css class

  • :help (String)

    help string

  • :type (String)

    editable type, eg. edit_textarea, edit_number. Default is edit_panel_element

  • :tag (Hash)

    options passed directly to the element



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/katello/katello_form_builder.rb', line 42

def editable(name, options)
  options.symbolize_keys!
  options[:editable] = true if options[:editable].nil?
  options[:type] ||= "edit_panel_element"

  tag_options = {}
  tag_options[:name] = "%s[%s]" % [@object_name, name.to_s]
  tag_options[:'data-url'] = options[:'data-url'] || options[:data_url] || @options[:data_url]
  tag_options.update(options[:tag]) if options.key? :tag

  css_class = "%s " % options[:class].to_s
  css_class += "editable %s" % options[:type].to_s if options[:editable]
  css_class.strip!

  field_options = {}
  field_options[:label] = options[:label]
  field_options[:help] = options[:help]
  field_options[:label_help] = options[:label_help]
  field_options[:input_wrapper] = {}
  field_options[:input_wrapper][:class] = css_class
  field_options[:input_wrapper][:tag_options] = tag_options

  base(name, field_options) do
    if block_given?
      yield
    else
      @object.send(name)
    end
  end
end

#field(name, *args, &block) ⇒ Object



11
12
13
# File 'app/helpers/katello/katello_form_builder.rb', line 11

def field(name, *args, &block)
  base(name, *args, &block)
end

#submit(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'app/helpers/katello/katello_form_builder.rb', line 73

def submit(*args)
  options = args.extract_options!
  options.symbolize_keys!
  options[:tabindex] ||= tabindex
  args.push options
   :div, :class => "grid_5 la prefix_2" do
    super
  end
end

#tabindexObject



83
84
85
86
# File 'app/helpers/katello/katello_form_builder.rb', line 83

def tabindex
  @tabindex ||= @options[:tabindex] || 0
  @tabindex += 1
end