Class: DrgcmsFormFields::Embedded

Inherits:
DrgcmsField show all
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)

  • formname: 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
  formname: dc_part
  html:
    height: 1000

Instance Attribute Summary

Attributes inherited from DrgcmsField

#html, #js

Instance Method Summary collapse

Methods inherited from DrgcmsField

get_data, #hash_to_options, #initialize, #record_text_for, #ro_standard, #set_initial_value, #t

Constructor Details

This class inherits a constructor from DrgcmsFormFields::DrgcmsField

Instance Method Details

#renderObject

Render embedded field html code



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'app/models/drgcms_form_fields.rb', line 307

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['formname'] if @yaml['formname']
  @yaml['formname'] ||= @yaml['table'] if @yaml['table']
# 
  html = ''  
  @yaml['html'].each {|k,v| html << "#{k}=\"#{v}\" "}
#  
  tables      = @parent.tables.inject('') { |r,v| r << "#{v[1]};" } + @yaml['table']
  ids         = @parent.ids.inject('') { |r,v| r << "#{v};" } + @record._id
  opts = { controller: 'cmsedit', action: 'index', ids: ids, table: tables, formname: @yaml['formname'], 
           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