Class: AgileFormFields::JournalDiff

Inherits:
AgileFormField show all
Defined in:
app/models/agile_form_fields/journal_diff.rb

Overview

Implementation of journal_diff AgileRails form field. journal_diff field is used to show differences between two fields in ArJournal collection.

Internal use.

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 AgileFormField

#css, #js

Instance Method Summary collapse

Methods inherited from AgileFormField

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 AgileFormFields::AgileFormField

Instance Method Details

#renderObject

Render journal_diff AgileRails form field code



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/agile_form_fields/journal_diff.rb', line 47

def render 
  @yaml['name'] = 'old' if @record[@yaml['name']].nil?
  @html += '<div class="ar-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 class="field">#{@env.check_box('select', k)} #{k}</div>
               <div class="diff-m">#{@env.mi_icon('remove red')}<div>#{old_value}</div></div>
               <div class="diff-p">#{@env.mi_icon('add green')}<div>#{new_value}</div></div>)
  end
  @html += '</div>'
  self
end