Class: DrgcmsFormFields::Embedded

Inherits:
DrgcmsField show all
Defined in:
app/models/drgcms_form_fields/embedded.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

#js

Instance Method Summary collapse

Methods inherited from DrgcmsField

get_data, #hash_to_options, #html, #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

#renderObject

Render embedded field html code



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/drgcms_form_fields/embedded.rb', line 50

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>"
  unless @record.new_record?
    @js << %Q[
$(document).ready( function() {
  $('#if_#{@yaml['name']}').attr('src', '#{@parent.url_for(opts)}');
});]
  end
  self
end