Class: DrgcmsFormFields::Embedded
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::Embedded
- 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 -
load:
when is embedded iframe loaded. default=on form load, delay=on tab select, always=every time tab is selected) -
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
refresh: delay
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, #html, #initialize, #options_to_hash, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #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
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/models/drgcms_form_fields/embedded.rb', line 52 def render # HTML defaults. Some must be set @yaml['html'] ||= {} @yaml['html']['width'] ||= '99%' # message when new record if @record.new_record? @yaml['html']['srcdoc'] = %( <div style='font-family: helvetica; font-size: 1.7rem; font-weight: bold; color: #ddd; padding: 1rem'> #{I18n.t('drgcms.iframe_save_to_view')} </div>) end html = @yaml['html'].inject('') { |r, val| r << "#{val.first}=\"#{val.last}\" " } @yaml['action'] ||= 'index' # defaults both way @yaml['table'] ||= @yaml['form_name'] @yaml['form_name'] ||= @yaml['table'] if @yaml['name'] == @yaml['table'] || @yaml['table'] == 'dc_memory' tables = @yaml['table'] ids = @record.id else tables = (@parent.tables.map(&:first) + [@yaml['table']]).join(';') ids = (@parent.ids + [@record.id]).join(';') end # edit enabled embedded form on a readonly form readonly = @yaml['readonly'].class == FalseClass ? nil : @readonly opts = { controller: 'cmsedit', action: @yaml['action'], ids: ids, table: tables, form_name: @yaml['form_name'], field_name: @yaml['name'], iframe: "if_#{@yaml['name']}", readonly: readonly } # additional parameters if specified @yaml['params'].each { |k, v| opts[k] = @parent.dc_value_for_parameter(v) } if @yaml['params'] @html << "<iframe class='iframe_embedded' id='if_#{@yaml['name']}' name='if_#{@yaml['name']}' #{html}></iframe>" if @record.new_record? else url = @parent.url_for(opts) attributes = case when @yaml['load'].nil? || @yaml['load'].match('default') "'src', '#{url}'" when @yaml['load'].match('delay') "'data-src-#{@yaml['load']}', '#{url}'" when @yaml['load'].match('always') "{'data-src-#{@yaml['load']}': '#{url}', src: '#{url}'}" end @js << %( $(document).ready( function() { $('#if_#{@yaml['name']}').attr(#{attributes}); });) end self end |