Module: Admin::Resources::DataTypes::HasManyHelper
- Defined in:
- app/helpers/admin/resources/data_types/has_many_helper.rb
Instance Method Summary collapse
- #build_add_new_for_has_many(klass, field, options = {}) ⇒ Object
- #has_many_filter(filter) ⇒ Object (also: #has_and_belongs_to_many_filter)
- #set_has_many_resource_actions ⇒ Object
- #typus_form_has_many(field) ⇒ Object
Instance Method Details
#build_add_new_for_has_many(klass, field, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/admin/resources/data_types/has_many_helper.rb', line 34 def build_add_new_for_has_many(klass, field, = {}) if admin_user.can?("create", klass) = { :controller => "/admin/#{klass.to_resource}", :action => "new", :_popup => true } link_to Typus::I18n.t("Add New"), .merge(), { :class => "iframe_with_page_reload" } end end |
#has_many_filter(filter) ⇒ Object Also known as: has_and_belongs_to_many_filter
3 4 5 6 7 8 9 10 |
# File 'app/helpers/admin/resources/data_types/has_many_helper.rb', line 3 def has_many_filter(filter) att_assoc = @resource.reflect_on_association(filter.to_sym) class_name = att_assoc.[:class_name] || filter.classify 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 |
#set_has_many_resource_actions ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/admin/resources/data_types/has_many_helper.rb', line 44 def set_has_many_resource_actions @resource_actions = [["Edit", { :action => "edit", :_popup => true }, { :class => 'iframe_with_page_reload' }], ["Show", { :action => "show", :_popup => true }, { :class => 'iframe'}], ["Trash", { :action => "destroy" }, { :confirm => "Trash?" } ]] end |
#typus_form_has_many(field) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/admin/resources/data_types/has_many_helper.rb', line 14 def typus_form_has_many(field) setup_relationship(field) = { "resource[#{@reflection.foreign_key}]" => @item.id } if @reflection. && (as = @reflection.[:as]) klass = @resource.is_sti? ? @resource.superclass : @resource .merge!("#{as}_type" => klass) end build_pagination set_has_many_resource_actions locals = { :association_name => @association_name, :add_new => build_add_new_for_has_many(@model_to_relate, field, ), :table => build_relationship_table } render "admin/templates/has_many", locals end |