Class: Gloo::Objs::Form
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Form
- Defined in:
- lib/gloo/objs/web_svr/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
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
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.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, #find_child_resolve_alias, #find_child_value, help, inherited, #initialize, #is_alias?, #is_container?, #is_function?, #msg_blank?, #msg_contains?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #root?, #send_message, #set_parent, #set_value, #sql_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
168 169 170 |
# File 'lib/gloo/objs/web_svr/form.rb', line 168 def self. return super + [ 'render' ] end |
.short_typename ⇒ Object
The short name of the object type.
37 38 39 |
# File 'lib/gloo/objs/web_svr/form.rb', line 37 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
30 31 32 |
# File 'lib/gloo/objs/web_svr/form.rb', line 30 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.
64 65 66 67 68 |
# File 'lib/gloo/objs/web_svr/form.rb', line 64 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.
139 140 141 |
# File 'lib/gloo/objs/web_svr/form.rb', line 139 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.
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gloo/objs/web_svr/form.rb', line 148 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.
125 126 127 |
# File 'lib/gloo/objs/web_svr/form.rb', line 125 def return @styles['cancel'] || '' end |
#cancel_path_value ⇒ Object
Get the cancel path for the form.
73 74 75 76 77 |
# File 'lib/gloo/objs/web_svr/form.rb', line 73 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.
221 222 223 |
# File 'lib/gloo/objs/web_svr/form.rb', line 221 def close_form return "</form>" end |
#form_content ⇒ Object
Get all the form content, the collection of form fields.
82 83 84 85 86 |
# File 'lib/gloo/objs/web_svr/form.rb', line 82 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.
111 112 113 |
# File 'lib/gloo/objs/web_svr/form.rb', line 111 def form_styles return @styles['form'] || name_value end |
#method_value ⇒ Object
Get the method for the form. ‘post’ is the default.
54 55 56 57 58 |
# File 'lib/gloo/objs/web_svr/form.rb', line 54 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.
175 176 177 178 179 |
# File 'lib/gloo/objs/web_svr/form.rb', line 175 def msg_render content = self.render @engine.heap.it.set_to content return content end |
#name_value ⇒ Object
Get the name for the form.
44 45 46 47 48 |
# File 'lib/gloo/objs/web_svr/form.rb', line 44 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.
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 216 |
# File 'lib/gloo/objs/web_svr/form.rb', line 189 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.
228 229 230 231 |
# File 'lib/gloo/objs/web_svr/form.rb', line 228 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).
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/gloo/objs/web_svr/form.rb', line 237 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.
260 261 262 263 264 265 266 267 |
# File 'lib/gloo/objs/web_svr/form.rb', line 260 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’, … }
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gloo/objs/web_svr/form.rb', line 93 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.
118 119 120 |
# File 'lib/gloo/objs/web_svr/form.rb', line 118 def return @styles['submit'] || '' end |