1 require_dependency "manifest/form/field"
6 def self.manager manifest, my_manifests
7 my_manifests.map {|item_name, form_manifest|
8 self.new(manifest, item_name, form_manifest)
12 attr :form_manifest, :item_name, :manifest,
13 :base, :fields, :field_names
14 def initialize manifest, item_name, form_manifest
16 @item_name = item_name
17 @form_manifest = form_manifest
23 @form_manifest['fields'] ||= {}
24 @form_manifest['field_names'] ||= []
28 @base = @form_manifest['base']
30 @form_manifest['fields'].each {|field_name, field_manifest|
31 @fields[field_name] = List.new(self, field_name, field_manifest)
33 @field_names = @form_manifest['field_names']
44 def initialize conf, field
50 opt = @field.tag_options.merge(@conf['options'] || {})
51 @field.element.field_tag_attributes(@field.column, @field.tag_mounted, opt)
55 view.text_field_tag @field.tag_name, @field.tag_value, self.tag_options
62 view.text_area_tag @field.tag_name, @field.tag_value, self.tag_options
69 view.number_field_tag @field.tag_name, @field.tag_value, self.tag_options
76 view.hidden_field_tag @field.tag_name, @field.tag_value, self.tag_options
82 def initialize conf, field
84 @model = Pettanr::Application::manifest.model(@field.model_name)
85 @source_conf = @model.attributes[@field.column]['source']
89 Pettanr::Application::manifest.select_items[@source_conf['type']][@source_conf['key']]
93 view.select_tag @field.tag_name,
94 view.options_for_select(view.t_select_items(self.items), :selected => @field.tag_value.to_s ), self.tag_options
101 def initialize field, name, conf
121 attr :part, :column, :type, :mounted, :model_name, :tag_options, :helpers, :form
123 'text' => Text, 'text_area' => TextArea, 'number' => Number,
124 'hidden' => Hidden, 'select' => Select
126 def initialize form, mounted, conf, manifest
132 @model_name = @conf['model'] || @form.model_name
133 @part = @conf['part']
134 @column = @conf['column']
135 @label_conf = @conf['label'] || {}
136 @field_conf = @conf['field']
137 @helper_confs = @conf['helpers'] || {}
139 @tag_options = {'data-model' => @model_name}
141 @model_manifest = Pettanr::Application::manifest.model(@model_name)
142 model_attribute_conf = @model_manifest.attributes[self.column] || {}
143 @primary_key = model_attribute_conf['primary_key']
145 @helpers = @helper_confs.map do |helper_name, helper_conf|
146 Helper.new self, helper_name, helper_conf
151 @element ||= if self.part?
152 @form.element.__send__ self.part
163 @primary_key and self.element.new_record?
167 @label_conf['type'] == nil or @label_conf['type'] != 'hidden'
171 view.t 'activerecord.attributes.' + self.model_name + '.' + self.column
175 @label_conf['row_break'] == true
180 @form.model_name + '[' + self.model_name + '_attributes][' + self.column + ']'
182 @form.model_name + '[' + self.column + ']'
187 self.element.attributes[self.column]
195 @field ||= @@type[@field_conf['type']].new @field_conf, self
203 @conf['row_break'] == true
208 attr :element, :mounted, :attributes, :fields, :model_name
209 def initialize element, operators, mounted, manifest
211 @operators = operators
215 @base = @manifest.base
216 @model_name = @base || element.model_name
218 base_field_confs = if @base
219 base_form = Pettanr::Application::manifest.form(@base)
224 extend_field_confs = @manifest.fields
225 @field_confs = base_field_confs.merge(extend_field_confs)
226 @fields = @manifest.field_names.map do |field_name|
227 field_conf = @field_confs[field_name]
228 Field.new self, @mounted, field_conf, manifest
237 @fields.each do |field|
238 next if field.ignore_field?
245 attr :form_manifest, :item_name, :manifest, :form_conf
246 def initialize form_manifest
247 @form_manifest = form_manifest
248 @item_name = @form_manifest.item_name
249 @manifest = @form_manifest.manifest
250 @form_conf = @form_manifest.conf
254 def open element, operators, mounted
255 Form.new element, operators, mounted, @form_manifest