Class: WAB::UI::View

Inherits:
Display show all
Defined in:
lib/wab/ui/view.rb

Overview

An object view display.

Direct Known Subclasses

Create, Update

Instance Attribute Summary

Attributes inherited from Display

#display_class, #kind, #name, #template, #transitions

Instance Method Summary collapse

Constructor Details

#initialize(kind, id, template, transitions, display_class = 'ui.View') ⇒ View

Returns a new instance of View.



8
9
10
# File 'lib/wab/ui/view.rb', line 8

def initialize(kind, id, template, transitions, display_class='ui.View')
  super(kind, id, template, transitions, display_class)
end

Instance Method Details

#append_fields(html, path, template, readonly) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wab/ui/view.rb', line 28

def append_fields(html, path, template, readonly)
  disabled = readonly ? ' disabled="disabled"' : ''
  readonly = readonly ? ' readonly' : ''
  template.each_pair { |id,value|
    next if :kind == id
    input = nil
    input_id = "#{path}.#{id}"
    text_input = %{<input class="form-field" id="#{input_id}" type="text" value="#{value}" #{readonly}>}

    if value.is_a?(String)
      count = value.count("\n")
      if 0 < count # a text area
        input = %{<textarea class="form-field" id="#{input_id}" rows="#{count}" #{readonly}>#{value.strip}</textarea>}
      else
        input = text_input
      end
    elsif value.is_a?(TrueClass)
      input = %{<input class="form-field" id="#{input_id}" type="checkbox"#{disabled} checked>}
    elsif value.is_a?(FalseClass)
      input = %{<input class="form-field" id="#{input_id}" type="checkbox"#{disabled}>}
    elsif value.is_a?(Integer) || WAB::Utils.pre_24_fixnum?(value) || value.is_a?(Number)
      input = %{<input class="form-field" id="#{input_id}" type="number" value="#{value}" #{readonly}>}
    elsif value.is_a?(Hash)
      append_fields(html, input_id, value)
    else
      input = text_input
    end
    html << %{<tr><td class="field-label">#{id.capitalize}</td><td>#{input}</td></tr>}
  }
  html
end

#htmlObject



18
19
20
21
22
23
24
25
26
# File 'lib/wab/ui/view.rb', line 18

def html
  html = %{<div class="obj-form-frame readonly"><table class="obj-form">}
  html = append_fields(html, @name, template, true)
  html << '</table>'
  html << %{<div class="btn" id="#{@name}.edit_button"><span>Edit</span></div>}
  html << %{<div class="btn" id="#{@name}.list_button"><span>List</span></div>}
  html << %{<div class="btn delete-btn" style="float:right;" id="#{@name}.delete_button"><span>Delete</span></div>}
  html << '</div>'
end

#specObject



12
13
14
15
16
# File 'lib/wab/ui/view.rb', line 12

def spec
  ui_spec = super
  ui_spec[:html] = html
  ui_spec
end