Module: PopulateMe::DocumentMixins::AdminAdapter
- Included in:
- PopulateMe::Document
- Defined in:
- lib/populate_me/document_mixins/admin_adapter.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #admin_image_url ⇒ Object
- #to_admin_form(o = {}) ⇒ Object
- #to_admin_list_item(o = {}) ⇒ Object
- #to_admin_url ⇒ Object
Class Method Details
.included(base) ⇒ Object
65 66 67 |
# File 'lib/populate_me/document_mixins/admin_adapter.rb', line 65 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#admin_image_url ⇒ Object
9 10 11 12 13 |
# File 'lib/populate_me/document_mixins/admin_adapter.rb', line 9 def admin_image_url thefield = self.class.admin_image_field return nil if thefield.nil? self.(thefield).url(:populate_me_thumb) end |
#to_admin_form(o = {}) ⇒ Object
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 |
# File 'lib/populate_me/document_mixins/admin_adapter.rb', line 35 def to_admin_form o={} o[:input_name_prefix] ||= 'data' class_item = { type: :hidden, input_name: "#{o[:input_name_prefix]}[_class]", input_value: self.class.name, } self.class. :_class, class_item items = self.class.fields.inject([class_item]) do |out,(k,item)| if item[:form_field] and self.field_applicable?(k) out << outcast(k, item, o) end out end page_title = self.new? ? "New #{self.class.to_s_short}" : self.to_s # page_title << " (#{self.polymorphic_type})" if self.class.polymorphic? batch_field_item = items.find do |item| item[:field_name] == self.class.batch_field end { template: "template#{'_nested' if o[:nested]}_form", page_title: page_title, admin_url: self.to_admin_url, is_new: self.new?, polymorphic_type: self.class.polymorphic? ? self.polymorphic_type : nil, batch_field: (not self.new? or batch_field_item.nil?) ? nil : batch_field_item[:input_name], fields: items } end |
#to_admin_list_item(o = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/populate_me/document_mixins/admin_adapter.rb', line 15 def to_admin_list_item o={} { class_name: self.class.name, id: self.id.to_s, admin_url: to_admin_url, title: WebUtils.truncate(to_s, 60), image_url: admin_image_url, local_menu: self.class.relationships.inject([]) do |out,(k,v)| if not v[:hidden] and self.relationship_applicable?(k) out << { title: "#{v[:label]}", href: "#{o[:request].script_name}/list/#{WebUtils.dasherize_class_name(v[:class_name])}?filter[#{v[:foreign_key]}]=#{self.id}", new_page: false } end out end } end |
#to_admin_url ⇒ Object
5 6 7 |
# File 'lib/populate_me/document_mixins/admin_adapter.rb', line 5 def to_admin_url "#{WebUtils.dasherize_class_name(self.class.name)}/#{id}".sub(/\/$/,'') end |