Module: MongoCrushyform::InstanceMethods
- Defined in:
- lib/mongo_crushyform.rb
Instance Method Summary collapse
- #after_delete ⇒ Object
-
#after_save ⇒ Object
Reset dropdowns on hooks.
-
#crushyfield(col, o = {}) ⇒ Object
crushyfield is crushyinput but with label+error.
- #crushyform(columns = model.schema.keys, action = nil, meth = 'POST') ⇒ Object
- #crushyinput(col, o = {}) ⇒ Object
-
#fix_type_string_list(k, v) ⇒ Object
Fix types.
-
#to_thumb(c) ⇒ Object
Provide a thumbnail for the column.
Instance Method Details
#after_delete ⇒ Object
216 |
# File 'lib/mongo_crushyform.rb', line 216 def after_delete; model.reset_dropdown_cache; super; end |
#after_save ⇒ Object
Reset dropdowns on hooks
215 |
# File 'lib/mongo_crushyform.rb', line 215 def after_save; model.reset_dropdown_cache; super; end |
#crushyfield(col, o = {}) ⇒ Object
crushyfield is crushyinput but with label+error
190 191 192 193 194 195 196 197 |
# File 'lib/mongo_crushyform.rb', line 190 def crushyfield(col, o={}) return '' if (o[:type]==:none || model.schema[col][:type]==:none) default_field_name = col[/^id_/] ? Kernel.const_get(col.sub(/^id_/, '')).human_name : col.tr('_', ' ').capitalize field_name = o[:name] || model.schema[col][:name] || default_field_name error_list = errors_on(col).map{|e|" - #{e}"} if !errors_on(col).nil? invisibility = "style='display: none;'" if (o[:invisible]==true || model.schema[col][:invisible]==true) "<p class='crushyfield %s' %s><label for='%s'>%s</label><span class='crushyfield-error-list'>%s</span><br />\n%s</p>\n" % [error_list&&'crushyfield-error', invisibility, field_id_for(col), field_name, error_list, (col, o)] end |
#crushyform(columns = model.schema.keys, action = nil, meth = 'POST') ⇒ Object
183 184 185 186 187 188 |
# File 'lib/mongo_crushyform.rb', line 183 def crushyform(columns=model.schema.keys, action=nil, meth='POST') columns.delete('_id') fields = columns.inject(""){|out,c|out+crushyfield(c)} enctype = fields.match(/type='file'/) ? "enctype='multipart/form-data'" : '' action.nil? ? fields : "<form action='%s' method='%s' %s>%s</form>\n" % [action, meth, enctype, fields] end |
#crushyinput(col, o = {}) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/mongo_crushyform.rb', line 198 def (col, o={}) o = model.schema[col].dup.update(o) o[:input_name] ||= "model[#{col}]" o[:input_value] = o[:input_value].nil? ? self[col] : o[:input_value] o[:input_value] = model.html_escape(o[:input_value]) if (o[:input_value].is_a?(String) && o[:html_escape]!=false) o[:required] = o[:required]==true ? model.crushyfield_required : o[:required] crushyform_type = model.crushyform_types[o[:type]] || model.crushyform_types[:string] crushyform_type.call(self,col,o) end |
#fix_type_string_list(k, v) ⇒ Object
Fix types
218 |
# File 'lib/mongo_crushyform.rb', line 218 def fix_type_string_list(k,v); @doc[k] = v.to_s.strip.split(/\s*,\s*/).compact if v.is_a?(String); end |
#to_thumb(c) ⇒ Object
Provide a thumbnail for the column
208 209 210 211 212 213 |
# File 'lib/mongo_crushyform.rb', line 208 def to_thumb(c) current = @doc[c] if current.respond_to?(:[]) "<img src='/gridfs/#{@doc[c]['stash_thumb_gif']}' width='100' onerror=\"this.style.display='none'\" />\n" end end |