Class: N::FormBuilder
Overview
FormBuilder
Constant Summary collapse
Class Method Summary collapse
-
.render(obj, lc = nil, show_all = false) ⇒ Object
Render a standard form for the given managed object.
Class Method Details
.render(obj, lc = nil, show_all = false) ⇒ Object
Render a standard form for the given managed object. If show_all is false then apply field filtering.
Example:
<p> <form name=“test”> #render(entry) </form> </p>
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/nitro/builders/form.rb', line 29 def self.render(obj, lc = nil, show_all = false) str = '<dl>' for p in obj.class.__props unless show_all next if :oid == p.symbol end if p.klass.ancestors.include?(Integer) or p.klass.ancestors.include?(Float) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> <input type="text" id="#{p.name}" name="#{p.name}" value="#{obj.send(p.symbol)}" /> </dd> } elsif p.klass.ancestors.include?(String) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> } if p.[:markup] val = N::Markup.compact(obj.send(p.symbol)) else val = obj.send(p.symbol) end if :textarea == p.[:ui] str << %{ <textarea id="#{p.name}" name="#{p.name}">#{val}</textarea> } else str << %{ <input type="text" id="#{p.name}" name="#{p.name}" value="#{val}" /> } end str << %{ </dd> } elsif p.klass.ancestors.include?(TrueClass) str << %{ <dt><label for="#{p.name}">#{p.name}</label></dt> <dd> <input type="checkbox" id="#{p.name}" name="#{p.name}" /> </dd> } =begin elsif p.klass.ancestors.include?(Time) return %|#\{@#{p.symbol} ? "'#\{Og::Utils.timestamp(@#{p.symbol})\}'" : 'NULL'\}| elsif p.klass.ancestors.include?(Date) return %|#\{@#{p.symbol} ? "'#\{Og::Utils.date(@#{p.symbol})\}'" : 'NULL'\}| else return %|#\{@#{p.symbol} ? "'#\{Og::Utils.escape(@#{p.symbol}.to_yaml)\}'" : "''"\}| =end end end str << %{ </dl>} return str end |