Module: Admin::Resources::DataTypes::BelongsToHelper
- Defined in:
- app/helpers/admin/resources/data_types/belongs_to_helper.rb
Instance Method Summary collapse
- #belongs_to_filter(filter) ⇒ Object
- #build_add_new_for_belongs_to(klass, options) ⇒ Object
- #build_label_text_for_belongs_to(klass, html_options, options) ⇒ Object
- #display_belongs_to(item, attribute) ⇒ Object
- #table_belongs_to_field(attribute, item) ⇒ Object
- #typus_belongs_to_field(attribute, form) ⇒ Object
Instance Method Details
#belongs_to_filter(filter) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 66 def belongs_to_filter(filter) att_assoc = @resource.reflect_on_association(filter.to_sym) class_name = att_assoc.[:class_name] || filter.capitalize.camelize resource = class_name.constantize items = [[Typus::I18n.t("View all %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase.pluralize), ""]] items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] } end |
#build_add_new_for_belongs_to(klass, options) ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 83 def build_add_new_for_belongs_to(klass, ) = { :controller => "/admin/#{klass.to_resource}", :action => 'new', :attribute => [:attribute], :_popup => true } link_to Typus::I18n.t("Add New"), , { :class => 'iframe' } end |
#build_label_text_for_belongs_to(klass, html_options, options) ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 75 def build_label_text_for_belongs_to(klass, , ) if [:disabled] == true Typus::I18n.t("Read only") elsif admin_user.can?('create', klass) && !headless_mode? build_add_new_for_belongs_to(klass, ) end end |
#display_belongs_to(item, attribute) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 54 def display_belongs_to(item, attribute) data = item.send(attribute) = { :controller => data.class.to_resource, :action => params[:action], :id => data.id } params[:_popup] ? data.to_label : link_to(data.to_label, ) end |
#table_belongs_to_field(attribute, item) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 42 def table_belongs_to_field(attribute, item) if att_value = item.send(attribute) action = item.send(attribute).class.(:default_action_on_item) = att_value.to_label if !params[:_popup] && admin_user.can?(action, att_value.class.name) = link_to(, :controller => "/admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id) end end || mdash end |
#typus_belongs_to_field(attribute, form) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/admin/resources/data_types/belongs_to_helper.rb', line 3 def typus_belongs_to_field(attribute, form) association = @resource.reflect_on_association(attribute.to_sym) = if defined?(set_belongs_to_context) set_belongs_to_context.send(attribute.pluralize.to_sym) else association.class_name.constantize end = association.foreign_key = { :disabled => attribute_disabled?(attribute) } label_text = @resource.human_attribute_name(attribute) = { :attribute => "#{@resource.name.downcase}_#{related_fk}" } label_text = @resource.human_attribute_name(attribute) if (text = build_label_text_for_belongs_to(, , )) label_text += "<small>#{text}</small>" end values = if .respond_to?(:roots) (.roots, ) else .order(.typus_order_by).map { |p| [p.to_label, p.id] } end attribute_id = "#{@resource.name.underscore}_#{attribute}_id".gsub("/", "_") render "admin/templates/belongs_to", :attribute => attribute, :attribute_id => attribute_id, :form => form, :related_fk => , :related => , :label_text => label_text.html_safe, :values => values, :html_options => , :options => { :include_blank => true } end |