Class: Edgarj::FormDrawer::Base
- Inherits:
-
Object
- Object
- Edgarj::FormDrawer::Base
- Defined in:
- app/helpers/edgarj/form_drawer.rb
Overview
Edgarj::FormDrawer::Base draws HTML table tag based data entry form. This also provides default methods for SearchFormDrawer search condition entry form.
How to Customize
-
First, it may be enough to just redefine @options
-
Next, when draw_ATTR() is defined, it is called. See ModelPermissionControllerHelper for example.
-
Then, consider to overwrite draw_ATTR() method.
Direct Known Subclasses
Instance Method Summary collapse
-
#_draw_2_lane(&block) ⇒ Object
flip field to left-lane or right-lane.
-
#_draw_belongs_to_field(parent_model, col) ⇒ Object
draw ‘belongs_to’ field for AR.
-
#_draw_field(col) ⇒ Object
draw general field.
-
#_draw_head(col, label = nil, &block) ⇒ Object
draw head(label).
- #columns ⇒ Object
-
#draw ⇒ Object
TODO: draw_field() 層があってもよい form.draw() と form._draw_field(), form._draw_belongs_to_field …
-
#draw_address(col) ⇒ Object
draw address fields.
-
#draw_bitset(col, bitset) ⇒ Object
draw bitset checkboxes field.
- #draw_boolean(col) ⇒ Object
- #draw_created_at(col) ⇒ Object
- #draw_enum(col, enum) ⇒ Object
- #draw_file(col) ⇒ Object
- #draw_id(col) ⇒ Object
- #draw_type(col) ⇒ Object
- #draw_updated_at(col) ⇒ Object
-
#edgarj_address?(col) ⇒ Boolean
base method for derived class.
-
#edgarj_file?(col) ⇒ Boolean
base method for derived class.
-
#get_bitset(col) ⇒ Object
return bitset of the column.
-
#get_enum(col) ⇒ Object
return enum of the column.
-
#initialize(drawer, record, f) ⇒ Base
constructor
INPUTS drawer:: Edgarj::Drawer instance record:: instance of AR f:: FormBuilder.
Constructor Details
#initialize(drawer, record, f) ⇒ Base
INPUTS
- drawer
-
Edgarj::Drawer instance
- record
-
instance of AR
- f
-
FormBuilder
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/edgarj/form_drawer.rb', line 19 def initialize(drawer, record, f) @drawer = drawer @vc = drawer.vc # just short-cut @record = record @f = f # define default options for draw_X() method, where X is :flags, :kind, # and so on. @options can be redefined at derived class. @options = { :flags => {}, :kind => {}, :boolean => {}, :default => { :date => {:use_month_numbers=>true}, :integer => {:size=>16}, :text => {:size=>20}, } } end |
Instance Method Details
#_draw_2_lane(&block) ⇒ Object
flip field to left-lane or right-lane
112 113 114 115 116 117 118 |
# File 'app/helpers/edgarj/form_drawer.rb', line 112 def _draw_2_lane(&block) result = @left ? '<tr>' : '' result += yield result += '</tr>' if !@left @left = !@left # flip it result end |
#_draw_belongs_to_field(parent_model, col) ⇒ Object
draw ‘belongs_to’ field for AR
163 164 165 166 167 168 169 170 |
# File 'app/helpers/edgarj/form_drawer.rb', line 163 def _draw_belongs_to_field(parent_model, col) label = Settings.edgarj.belongs_to.popup_on == 'field' ? nil : @vc.draw_belongs_to_label(@f, @drawer.popup_path(col), col.name) _draw_head(col, label){ @vc.draw_belongs_to_field(@f, @drawer.popup_path(col), col.name) } end |
#_draw_field(col) ⇒ Object
draw general field
185 186 187 188 189 190 191 192 |
# File 'app/helpers/edgarj/form_drawer.rb', line 185 def _draw_field(col) case col.type when :boolean draw_boolean(col) else _draw_head(col){ @vc.draw_field(@f, col, @options[:default]) } end end |
#_draw_head(col, label = nil, &block) ⇒ Object
draw head(label). SearchFormDrawer will overwrite to insert operator.
INPUTS
- col
-
column info
- label
-
if not-nil, label is used rather than human_attribute_name of col.name for field-label
- block
-
wrapped field-drawing logic
127 128 129 130 131 132 133 134 |
# File 'app/helpers/edgarj/form_drawer.rb', line 127 def _draw_head(col, label=nil, &block) _draw_2_lane{ html = @vc.content_tag(:th, label || @vc.column_label(col)) html << @vc.content_tag(:td, '') html << (@vc.content_tag(:td) do yield end) html } end |
#columns ⇒ Object
82 83 84 85 |
# File 'app/helpers/edgarj/form_drawer.rb', line 82 def columns drawer = @vc.drawer drawer.columns_for(drawer.form_columns) end |
#draw ⇒ Object
TODO: draw_field() 層があってもよいform.draw() と form._draw_field(), form._draw_belongs_to_field … はあるけど、抽象化層の form.draw_field がない
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/edgarj/form_drawer.rb', line 51 def draw() adrs_field = {} @vc.content_tag(:table) do @left = true html = '' for col in columns do draw_method = "draw_#{col.name}" html << if self.class.method_defined?(draw_method) then send(draw_method, col) #elsif edgarj_address?(col) # draw_address(col) #elsif edgarj_file?(col) # draw_file(col) elsif (enum = get_enum(col)) draw_enum(col, enum) elsif (bitset = get_bitset(col)) draw_bitset(col, bitset) else parent_model = @vc.model.belongs_to_AR(col) if parent_model _draw_belongs_to_field(parent_model, col) else _draw_field(col) end end end html << '<td colspan=3></td>'.html_safe if !@left html.html_safe end end |
#draw_address(col) ⇒ Object
draw address fields
153 154 155 |
# File 'app/helpers/edgarj/form_drawer.rb', line 153 def draw_address(col) _draw_head(col){ @vc.draw_address(@f, col) } end |
#draw_bitset(col, bitset) ⇒ Object
draw bitset checkboxes field
158 159 160 |
# File 'app/helpers/edgarj/form_drawer.rb', line 158 def draw_bitset(col, bitset) _draw_head(col){ @vc.draw_bitset(@f, col, bitset, @options[:flags]) } end |
#draw_boolean(col) ⇒ Object
172 173 174 |
# File 'app/helpers/edgarj/form_drawer.rb', line 172 def draw_boolean(col) _draw_head(col){ @vc.draw_boolean(@f, col, @options[:boolean]) } end |
#draw_created_at(col) ⇒ Object
144 145 146 |
# File 'app/helpers/edgarj/form_drawer.rb', line 144 def draw_created_at(col) '' end |
#draw_enum(col, enum) ⇒ Object
180 181 182 |
# File 'app/helpers/edgarj/form_drawer.rb', line 180 def draw_enum(col, enum) _draw_head(col){ @vc.draw_enum(@f, col, enum) } end |
#draw_file(col) ⇒ Object
176 177 178 |
# File 'app/helpers/edgarj/form_drawer.rb', line 176 def draw_file(col) _draw_head(col){ @vc.draw_file(@f, col) } end |
#draw_id(col) ⇒ Object
136 137 138 |
# File 'app/helpers/edgarj/form_drawer.rb', line 136 def draw_id(col) '' end |
#draw_type(col) ⇒ Object
140 141 142 |
# File 'app/helpers/edgarj/form_drawer.rb', line 140 def draw_type(col) '' end |
#draw_updated_at(col) ⇒ Object
148 149 150 |
# File 'app/helpers/edgarj/form_drawer.rb', line 148 def draw_updated_at(col) '' end |
#edgarj_address?(col) ⇒ Boolean
base method for derived class
88 89 90 |
# File 'app/helpers/edgarj/form_drawer.rb', line 88 def edgarj_address?(col) @record.class.edgarj_address?(col) end |
#edgarj_file?(col) ⇒ Boolean
base method for derived class
93 94 95 |
# File 'app/helpers/edgarj/form_drawer.rb', line 93 def edgarj_file?(col) @record.class.edgarj_file?(col) end |
#get_bitset(col) ⇒ Object
return bitset of the column
Derived class must overwrite to return expected bitset
107 108 109 |
# File 'app/helpers/edgarj/form_drawer.rb', line 107 def get_bitset(col) @vc.get_bitset(@f.object.class, col) end |
#get_enum(col) ⇒ Object
return enum of the column
Derived class must overwrite to return expected enum
100 101 102 |
# File 'app/helpers/edgarj/form_drawer.rb', line 100 def get_enum(col) @vc.get_enum(@f.object.class, col) end |