Class: DrgcmsFormFields::JournalDiff
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::JournalDiff
- Defined in:
- app/models/drgcms_form_fields/journal_diff.rb
Overview
Implementation of journal_diff DRG CMS form field. journal_diff field is used to show differences between two fields in DcJournal collection.
Form options:
-
name:
field name (required) -
type:
journal_diff (required)
Form example:
10:
name: diff
type: journal_diff
html:
size: 100x25
Instance Attribute Summary
Attributes inherited from DrgcmsField
Instance Method Summary collapse
-
#render ⇒ Object
Render journal_diff 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 journal_diff field html code
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/drgcms_form_fields/journal_diff.rb', line 45 def render @yaml['name'] = 'old' if @record[@yaml['name']].nil? @html << '<div class="dc-journal">' JSON.parse(@record[@yaml['name']]).each do |k,v| old_value = v.class == Array ? v[0] : v new_value = v.class == Array ? v[1] : v @html << "<div style='background-color: #eee;'>#{@parent.check_box('select', k)} #{k}</div> <div style='background-color: #fcc;'>-<br>#{old_value.to_s.gsub("\n", '<br>')}</div> <div style='background-color: #cfc;'>+<br>#{new_value.to_s.gsub("\n", '<br>')}</div><br>" end @html << '</div>' self end |