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
draw form.
-
#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
108 109 110 111 112 113 114 |
# File 'app/helpers/edgarj/form_drawer.rb', line 108 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
159 160 161 162 163 |
# File 'app/helpers/edgarj/form_drawer.rb', line 159 def _draw_belongs_to_field(parent_model, col) _draw_head(col, @vc.draw_belongs_to_label(@f, @drawer.popup_path(col), col.name)){ @vc.draw_belongs_to_field(@f, col.name) } end |
#_draw_field(col) ⇒ Object
draw general field
178 179 180 181 182 183 184 185 |
# File 'app/helpers/edgarj/form_drawer.rb', line 178 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
123 124 125 126 127 128 129 130 |
# File 'app/helpers/edgarj/form_drawer.rb', line 123 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
78 79 80 81 |
# File 'app/helpers/edgarj/form_drawer.rb', line 78 def columns drawer = @vc.drawer drawer.columns_for(drawer.form_columns) end |
#draw ⇒ Object
draw form
I18n for label is:
-
usual column uses model.human_attribute_name()
-
‘belongs_to’ column uses:
** I18n.t(‘activerecord.attributes.MODEL.EXT_ID’) ** parent.human_name
47 48 49 50 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 |
# File 'app/helpers/edgarj/form_drawer.rb', line 47 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
149 150 151 |
# File 'app/helpers/edgarj/form_drawer.rb', line 149 def draw_address(col) _draw_head(col){ @vc.draw_address(@f, col) } end |
#draw_bitset(col, bitset) ⇒ Object
draw bitset checkboxes field
154 155 156 |
# File 'app/helpers/edgarj/form_drawer.rb', line 154 def draw_bitset(col, bitset) _draw_head(col){ @vc.draw_bitset(@f, col, bitset, @options[:flags]) } end |
#draw_boolean(col) ⇒ Object
165 166 167 |
# File 'app/helpers/edgarj/form_drawer.rb', line 165 def draw_boolean(col) _draw_head(col){ @vc.draw_boolean(@f, col, @options[:boolean]) } end |
#draw_created_at(col) ⇒ Object
140 141 142 |
# File 'app/helpers/edgarj/form_drawer.rb', line 140 def draw_created_at(col) '' end |
#draw_enum(col, enum) ⇒ Object
173 174 175 |
# File 'app/helpers/edgarj/form_drawer.rb', line 173 def draw_enum(col, enum) _draw_head(col){ @vc.draw_enum(@f, col, enum) } end |
#draw_file(col) ⇒ Object
169 170 171 |
# File 'app/helpers/edgarj/form_drawer.rb', line 169 def draw_file(col) _draw_head(col){ @vc.draw_file(@f, col) } end |
#draw_id(col) ⇒ Object
132 133 134 |
# File 'app/helpers/edgarj/form_drawer.rb', line 132 def draw_id(col) '' end |
#draw_type(col) ⇒ Object
136 137 138 |
# File 'app/helpers/edgarj/form_drawer.rb', line 136 def draw_type(col) '' end |
#draw_updated_at(col) ⇒ Object
144 145 146 |
# File 'app/helpers/edgarj/form_drawer.rb', line 144 def draw_updated_at(col) '' end |
#edgarj_address?(col) ⇒ Boolean
base method for derived class
84 85 86 |
# File 'app/helpers/edgarj/form_drawer.rb', line 84 def edgarj_address?(col) @record.class.edgarj_address?(col) end |
#edgarj_file?(col) ⇒ Boolean
base method for derived class
89 90 91 |
# File 'app/helpers/edgarj/form_drawer.rb', line 89 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
103 104 105 |
# File 'app/helpers/edgarj/form_drawer.rb', line 103 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
96 97 98 |
# File 'app/helpers/edgarj/form_drawer.rb', line 96 def get_enum(col) @vc.get_enum(@f.object.class, col) end |