Class: DrgcmsFormFields::JournalDiff

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

#html, #js

Instance Method Summary collapse

Methods inherited from DrgcmsField

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



390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'app/models/drgcms_form_fields.rb', line 390

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}</div>
              <div style='background-color: #cfc;'>+<br>#{new_value}</div><br>"
  end
  @html << '</div>'
  self
end