Class: DrgcmsFormFields::Embedded
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::Embedded
- Defined in:
- app/models/drgcms_form_fields.rb
Overview
Implementation of embedded DRG CMS form field.
Creates html required to paint embedded object on form.
Form options:
-
name:
field name (required) -
type:
embedded (required) -
form_name:
name of form which will be used for editing -
html:
html options (optional)-
height:
height of embedded object in pixels (1000) -
width:
width of embedded object in pixels (500)
-
Form example:
10:
name: dc_parts
type: embedded
form_name: dc_part
html:
height: 1000
Instance Attribute Summary
Attributes inherited from DrgcmsField
Instance Method Summary collapse
-
#render ⇒ Object
Render embedded field html code.
Methods inherited from DrgcmsField
get_data, #hash_to_options, #initialize, #record_text_for, #ro_standard, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Instance Method Details
#render ⇒ Object
Render embedded field html code
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'app/models/drgcms_form_fields.rb', line 338 def render return self if @record.new_record? # would be in error otherwise # HTML defaults. Some must be set @yaml['html'] ||= {} @yaml['html']['height'] ||= 300 @yaml['html']['width'] ||= '99%' # defaults both way @yaml['table'] ||= @yaml['form_name'] if @yaml['form_name'] @yaml['form_name'] ||= @yaml['table'] if @yaml['table'] # html = '' @yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "} # if @yaml['name'] == @yaml['table'] tables = @yaml['table'] ids = @record._id else tables = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table'] ids = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record._id end opts = { controller: 'cmsedit', action: 'index', ids: ids, table: tables, form_name: @yaml['form_name'], field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: @readonly } @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>" @js = <<EOJS $(document).ready( function() { $('#if_#{@yaml['name']}').attr('src', '#{@parent.url_for(opts)}'); }); EOJS self end |