|
class HtmlBuilder::StackingForm < HtmlBuilder::StackingTable
|
|
def initialize(template, form, caption = nil, html_options = {})
|
|
super(caption, html_options)
|
|
|
|
@template = template
|
|
@form = form
|
|
end
|
|
|
|
def create_table
|
|
FormTable.new(@template, @form, @caption)
|
|
end
|
|
|
|
module FormContainer
|
|
def field(field_name, human_name, method, *args)
|
|
if human_name == nil
|
|
c = prepare_field(field_name, "", method, *args)
|
|
content c.last
|
|
else
|
|
content prepare_field(field_name, human_name, method, *args)
|
|
end
|
|
end
|
|
|
|
def custom_field(field_name, human_name, custom_content)
|
|
content [@form.label(field_name, human_name), custom_content]
|
|
end
|
|
|
|
def multifield(name, list)
|
|
m = []
|
|
m << name unless name.nil?
|
|
list.each {|params| m += send :prepare_field, *params }
|
|
content m
|
|
end
|
|
|
|
def conditional_block(tag_id, obj, field, condition = "value != ''", &block)
|
|
content HtmlBuilder::ConditionalFormBlock.new(@template, @form, tag_id, obj, field, condition).build(&block)
|
|
end
|
|
|
|
private
|
|
|
|
def prepare_field(field_name, human_name, method, *args)
|
|
args.unshift field_name
|
|
[@form.label(field_name, human_name), @form.send(method, *args)]
|
|
end
|
|
|
|
def create_category(cat_name)
|
|
FormCategory.new(@template, @form, cat_name)
|
|
end
|
|
end
|
|
|
|
class FormCategory < Category
|
|
include FormContainer
|
|
|
|
def initialize(template, form, name)
|
|
super(name)
|
|
|
|
@template = template
|
|
@form = form
|
|
end
|
|
end
|
|
|
|
class FormTable < Table
|
|
include FormContainer
|
|
|
|
def initialize(template, form, name = nil)
|
|
super(name)
|
|
|
|
@template = template
|
|
@form = form
|
|
end
|
|
end
|
|
end
|