Class: Objs::Form
- Inherits:
-
Gloo::Core::Obj
- Object
- Gloo::Core::Obj
- Objs::Form
- Defined in:
- lib/objs/form.rb
Constant Summary collapse
- KEYWORD =
'form'.freeze
- KEYWORD_SHORT =
'form'.freeze
- NAME =
Form
'name'.freeze
- ID =
'id'.freeze
- METHOD =
'method'.freeze
- METHOD_DEFAULT =
'post'.freeze
- ACTION =
'action'.freeze
- CANCEL_PATH =
'cancel_path'.freeze
- CONTENT =
'content'.freeze
- STYLES =
'styles'.freeze
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#action_value ⇒ Object
Get the action for the form.
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#cancel_button_styles ⇒ Object
Get the cancel button styles.
-
#cancel_path_value ⇒ Object
Get the cancel path for the form.
-
#close_form ⇒ Object
Close the form.
-
#form_content ⇒ Object
Get all the form content, the collection of form fields.
-
#form_styles ⇒ Object
Get the form styles.
-
#method_value ⇒ Object
Get the method for the form.
-
#msg_render ⇒ Object
Render the form and all contained fields.
-
#name_value ⇒ Object
Get the name for the form.
-
#open_form ⇒ Object
Open the form.
-
#render ⇒ Object
Render the Form as HTML.
-
#render_content ⇒ Object
Render the element content using the specified render function.
-
#render_thing(e) ⇒ Object
Render a string or other object.
-
#styles ⇒ Object
Get the styles for the form.
-
#submit_button_styles ⇒ Object
Get the submit button styles.
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
167 168 169 |
# File 'lib/objs/form.rb', line 167 def self. return super + [ 'render' ] end |
.short_typename ⇒ Object
The short name of the object type.
36 37 38 |
# File 'lib/objs/form.rb', line 36 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
29 30 31 |
# File 'lib/objs/form.rb', line 29 def self.typename return KEYWORD end |
Instance Method Details
#action_value ⇒ Object
Get the action for the form. This is the path to POST to, for example.
63 64 65 66 67 |
# File 'lib/objs/form.rb', line 63 def action_value o = find_child ACTION o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
138 139 140 |
# File 'lib/objs/form.rb', line 138 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/objs/form.rb', line 147 def add_default_children fac = @engine.factory # Create attributes with ID and Classes fac.create_string NAME, '', self fac.create_string METHOD, 'post', self fac.create_string ACTION, '', self fac.create_string CANCEL_PATH, '', self fac.create_can CONTENT, self end |
#cancel_button_styles ⇒ Object
Get the cancel button styles.
124 125 126 |
# File 'lib/objs/form.rb', line 124 def return @styles['cancel'] || '' end |
#cancel_path_value ⇒ Object
Get the cancel path for the form.
72 73 74 75 76 |
# File 'lib/objs/form.rb', line 72 def cancel_path_value o = find_child CANCEL_PATH o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#close_form ⇒ Object
Close the form.
220 221 222 |
# File 'lib/objs/form.rb', line 220 def close_form return "</form>" end |
#form_content ⇒ Object
Get all the form content, the collection of form fields.
81 82 83 84 85 |
# File 'lib/objs/form.rb', line 81 def form_content o = find_child CONTENT o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o end |
#form_styles ⇒ Object
Get the form styles. Use the name if none is provided.
110 111 112 |
# File 'lib/objs/form.rb', line 110 def form_styles return @styles['form'] || name_value end |
#method_value ⇒ Object
Get the method for the form. ‘post’ is the default.
53 54 55 56 57 |
# File 'lib/objs/form.rb', line 53 def method_value o = find_child METHOD o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o.value || METHOD_DEFAULT end |
#msg_render ⇒ Object
Render the form and all contained fields.
174 175 176 177 178 |
# File 'lib/objs/form.rb', line 174 def msg_render content = self.render @engine.heap.it.set_to content return content end |
#name_value ⇒ Object
Get the name for the form.
43 44 45 46 47 |
# File 'lib/objs/form.rb', line 43 def name_value o = find_child NAME o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#open_form ⇒ Object
Open the form.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/objs/form.rb', line 188 def open_form name = name_value = "" if cancel_path_value = " <a class=\"\#{cancel_button_styles}\"\n href=\"\#{cancel_path_value}\"> \n Cancel</a>\n HTML\n end\n return <<~HTML\n <form class='\#{form_styles}'\n id='\#{name}'\n method='\#{method_value}'\n action='\#{action_value}'\n accept-charset='UTF-8'>\n <div class=\"actions\">\n <input type=\"submit\" \n name=\"commit\" \n value=\"Save\" \n class=\"\#{submit_button_styles}\" \n data-disable-with=\"Saving...\" />\n\n \#{cancel_button}\n </div>\n HTML\nend\n" |
#render ⇒ Object
Render the Form as HTML.
227 228 229 230 |
# File 'lib/objs/form.rb', line 227 def render @styles = styles return open_form + render_content + close_form end |
#render_content ⇒ Object
Render the element content using the specified render function. This is a recursive function (through one of the other render functions).
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/objs/form.rb', line 236 def render_content fields = "" field_can = form_content return "" if field_can.nil? field_can.children.each do |o| o = Gloo::Objs::Alias.resolve_alias( @engine, o ) if o.class == Field fields << o.render( @styles ) elsif o.class == Element fields << o.render_html elsif o data = render_thing o ( fields << data ) if data end end return fields end |
#render_thing(e) ⇒ Object
Render a string or other object.
259 260 261 262 263 264 265 266 |
# File 'lib/objs/form.rb', line 259 def render_thing e begin return e.render( 'render_html' ) rescue => e @engine.log_exception e return '' end end |
#styles ⇒ Object
Get the styles for the form. Retuns styles in the form of a hash: { ‘field_group’ => ‘form-group mt-3’, … }
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/objs/form.rb', line 92 def styles style_h = {} o = find_child STYLES return style_h unless o o = Gloo::Objs::Alias.resolve_alias( @engine, o ) o.children.each do |c| style_h[ c.name ] = c.value end # puts "styles: #{style_h}" return style_h end |
#submit_button_styles ⇒ Object
Get the submit button styles.
117 118 119 |
# File 'lib/objs/form.rb', line 117 def return @styles['submit'] || '' end |