Class: DrgcmsFormFields::LinkTo

Inherits:
DrgcmsField show all
Defined in:
app/models/drgcms_form_fields/link_to.rb

Overview

Implementation of link_to DRG CMS form field. link_to form field is mostly used by polls but can be also incorporated anywhere on the form.

Form options:

  • type: link_to (required)

  • caption: Link caption

  • icon: Link icon

  • url: direct url link

  • controller: controller name

  • action: action name

  • html: html options which apply to link_to (optional)

Form example:

30:
  type: link_to
  caption: Some action
  icon: cogs
  controller: my_controller
  action: my_action
  id: id # will be replaced by record._id

Instance Attribute Summary

Attributes inherited from DrgcmsField

#css, #js

Instance Method Summary collapse

Methods inherited from DrgcmsField

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

#renderObject

Render link_to field html code



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/drgcms_form_fields/link_to.rb', line 52

def render
  @yaml['html'] ||= {}
  @yaml['html']['class'] ||= 'dc-link'
  @yaml['html'].symbolize_keys!

  @yaml[:id] = record._id if @yaml[:id] == 'id'
  url = @yaml['url'] || "#{@yaml[:controller]}/#{@yaml[:action]}/#{@yaml[:id]}"
  url.gsub!('//','/')                             # no action and id
  url = '/' + @yaml['url'] unless url[0,1] == '/' # no leading /
  url.chop if url[0,-1] == '/'                    # remove trailing /

  caption = @yaml['caption'] || @yaml['text']
  @html << @parent.dc_link_to(caption, @yaml['icon'], url, @yaml['html'])
  self
end